]> git.lizzy.rs Git - rust.git/commitdiff
linker: Pass `/NODEFAULTLIB` in a more regular way
authorVadim Petrochenkov <vadim.petrochenkov@gmail.com>
Sat, 11 Apr 2020 11:53:39 +0000 (14:53 +0300)
committerVadim Petrochenkov <vadim.petrochenkov@gmail.com>
Mon, 13 Apr 2020 15:37:51 +0000 (18:37 +0300)
src/librustc_codegen_ssa/back/link.rs
src/librustc_codegen_ssa/back/linker.rs
src/librustc_target/spec/uefi_base.rs
src/librustc_target/spec/windows_msvc_base.rs
src/librustc_target/spec/windows_uwp_msvc_base.rs

index 5f7a1938a33042ff85b88cdcedb78b43b2e9946b..d58d9b91c73ac86b8a015255f30863efaef0b265 100644 (file)
@@ -1532,13 +1532,8 @@ fn linker_with_args<'a, B: ArchiveBuilder<'a>>(
     cmd.debuginfo();
 
     // OBJECT-FILES-NO, AUDIT-ORDER
-    // We want to, by default, prevent the compiler from accidentally leaking in
-    // any system libraries, so we may explicitly ask linkers to not link to any
-    // libraries by default. Note that this does not happen for windows because
-    // windows pulls in some large number of libraries and I couldn't quite
-    // figure out which subset we wanted.
-    //
-    // This is all naturally configurable via the standard methods as well.
+    // We want to prevent the compiler from accidentally leaking in any system libraries,
+    // so by default we tell linkers not to link to any default libraries.
     if !sess.opts.cg.default_linker_libraries.unwrap_or(false)
         && sess.target.target.options.no_default_libraries
     {
index 0baa37ae9f1ab76eafb6e8fa1fdb185b8bf75c28..d8c5ddf586f453af016f1319095a882198a9a1a9 100644 (file)
@@ -631,15 +631,7 @@ fn no_relro(&mut self) {
     }
 
     fn no_default_libraries(&mut self) {
-        // Currently we don't pass the /NODEFAULTLIB flag to the linker on MSVC
-        // as there's been trouble in the past of linking the C++ standard
-        // library required by LLVM. This likely needs to happen one day, but
-        // in general Windows is also a more controlled environment than
-        // Unix, so it's not necessarily as critical that this be implemented.
-        //
-        // Note that there are also some licensing worries about statically
-        // linking some libraries which require a specific agreement, so it may
-        // not ever be possible for us to pass this flag.
+        self.cmd.arg("/NODEFAULTLIB");
     }
 
     fn include_path(&mut self, path: &Path) {
index 030eb12eb0ec533daa1e8af2b3d8b046132cce13..6f5e1badfb6625c0d7fcee20320a96967643a5e4 100644 (file)
@@ -23,9 +23,6 @@ pub fn opts() -> TargetOptions {
         // will fail if the compiler ever tries placing code on the stack (e.g., trampoline
         // constructs and alike).
         "/NXCOMPAT".to_string(),
-        // There is no runtime for UEFI targets, prevent them from being linked. UEFI targets
-        // must be freestanding.
-        "/nodefaultlib".to_string(),
         // Non-standard subsystems have no default entry-point in PE+ files. We have to define
         // one. "efi_main" seems to be a common choice amongst other implementations and the
         // spec.
index 78567a4382bed5dc4d0705f2d0a695b96f8919db..dc56dd916ff0b602d4186f39718d03cd4ff46ce0 100644 (file)
@@ -30,6 +30,16 @@ pub fn opts() -> TargetOptions {
         abi_return_struct_as_int: true,
         emit_debug_gdb_scripts: false,
         requires_uwtable: true,
+        // Currently we don't pass the /NODEFAULTLIB flag to the linker on MSVC
+        // as there's been trouble in the past of linking the C++ standard
+        // library required by LLVM. This likely needs to happen one day, but
+        // in general Windows is also a more controlled environment than
+        // Unix, so it's not necessarily as critical that this be implemented.
+        //
+        // Note that there are also some licensing worries about statically
+        // linking some libraries which require a specific agreement, so it may
+        // not ever be possible for us to pass this flag.
+        no_default_libraries: false,
 
         ..Default::default()
     }
index 9497e525dd97c64a526ae2a0b62ae36ebc19fbda..2c70ba7abe262e2a3dc23c33da95ae0936aefb07 100644 (file)
@@ -31,6 +31,16 @@ pub fn opts() -> TargetOptions {
         emit_debug_gdb_scripts: false,
         requires_uwtable: true,
         lld_flavor: LldFlavor::Link,
+        // Currently we don't pass the /NODEFAULTLIB flag to the linker on MSVC
+        // as there's been trouble in the past of linking the C++ standard
+        // library required by LLVM. This likely needs to happen one day, but
+        // in general Windows is also a more controlled environment than
+        // Unix, so it's not necessarily as critical that this be implemented.
+        //
+        // Note that there are also some licensing worries about statically
+        // linking some libraries which require a specific agreement, so it may
+        // not ever be possible for us to pass this flag.
+        no_default_libraries: false,
 
         ..Default::default()
     }