about summary refs log tree commit diff
path: root/compiler/rustc_codegen_ssa/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2021-06-06 11:31:16 +0000
committerbors <bors@rust-lang.org>2021-06-06 11:31:16 +0000
commitf57d5ba3c9ffef4cd2402e3e7d8934bd1a6e9cc1 (patch)
tree9bc36b15565d83984822ad38b4d9604e1e09e8af /compiler/rustc_codegen_ssa/src
parent3740ba2a7dd965ca45db500ebf7ad580a7812c07 (diff)
parent19433c44bde0dd6ed674bd03f1cefbfc2f95c676 (diff)
downloadrust-f57d5ba3c9ffef4cd2402e3e7d8934bd1a6e9cc1.tar.gz
rust-f57d5ba3c9ffef4cd2402e3e7d8934bd1a6e9cc1.zip
Auto merge of #86054 - JohnTitor:rollup-j40z7sm, r=JohnTitor
Rollup of 8 pull requests

Successful merges:

 - #85436 (Avoid cloning cache key)
 - #85772 (Preserve metadata w/ Solaris-like linkers.)
 - #85920 (Tweak wasm_base target spec to indicate linker is not GNU and update linker inferring logic for wasm-ld.)
 - #85930 (Update standard library for IntoIterator implementation of arrays )
 - #85972 (Rustdoc html fixes)
 - #86028 (Drop an `if let` that will always succeed)
 - #86043 (don't clone attrs)
 - #86047 (Don't fire `invalid_doc_attributes` on `extern crate` items)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_codegen_ssa/src')
-rw-r--r--compiler/rustc_codegen_ssa/src/back/link.rs11
-rw-r--r--compiler/rustc_codegen_ssa/src/back/linker.rs8
2 files changed, 13 insertions, 6 deletions
diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs
index ce71095b216..2519b0826a9 100644
--- a/compiler/rustc_codegen_ssa/src/back/link.rs
+++ b/compiler/rustc_codegen_ssa/src/back/link.rs
@@ -1199,6 +1199,8 @@ fn linker_and_flavor(sess: &Session) -> (PathBuf, LinkerFlavor) {
                     || stem.ends_with("-clang")
                 {
                     LinkerFlavor::Gcc
+                } else if stem == "wasm-ld" || stem.ends_with("-wasm-ld") {
+                    LinkerFlavor::Lld(LldFlavor::Wasm)
                 } else if stem == "ld" || stem == "ld.lld" || stem.ends_with("-ld") {
                     LinkerFlavor::Ld
                 } else if stem == "link" || stem == "lld-link" {
@@ -1836,10 +1838,16 @@ fn linker_with_args<'a, B: ArchiveBuilder<'a>>(
     // Make the binary compatible with data execution prevention schemes.
     cmd.add_no_exec();
 
+    // OBJECT-FILES-YES
+    add_local_crate_metadata_objects(cmd, crate_type, codegen_results);
+
     // NO-OPT-OUT, OBJECT-FILES-NO
     // Avoid linking to dynamic libraries unless they satisfy some undefined symbols
     // at the point at which they are specified on the command line.
     // Must be passed before any dynamic libraries.
+    // On solaris-like systems, this also will ignore unreferenced ELF sections
+    // from relocatable objects. For that reason, we move the metadata objects
+    // to before this flag as they would otherwise be removed.
     cmd.add_as_needed();
 
     // NO-OPT-OUT, OBJECT-FILES-NO
@@ -1892,9 +1900,6 @@ fn linker_with_args<'a, B: ArchiveBuilder<'a>>(
     cmd.export_symbols(tmpdir, crate_type);
 
     // OBJECT-FILES-YES
-    add_local_crate_metadata_objects(cmd, crate_type, codegen_results);
-
-    // OBJECT-FILES-YES
     add_local_crate_allocator_objects(cmd, codegen_results);
 
     // OBJECT-FILES-NO, AUDIT-ORDER
diff --git a/compiler/rustc_codegen_ssa/src/back/linker.rs b/compiler/rustc_codegen_ssa/src/back/linker.rs
index 9df8a99cdd6..9152a69e7a1 100644
--- a/compiler/rustc_codegen_ssa/src/back/linker.rs
+++ b/compiler/rustc_codegen_ssa/src/back/linker.rs
@@ -476,7 +476,9 @@ impl<'a> Linker for GccLinker<'a> {
         // eliminate the metadata. If we're building an executable, however,
         // --gc-sections drops the size of hello world from 1.8MB to 597K, a 67%
         // reduction.
-        } else if self.sess.target.linker_is_gnu && !keep_metadata {
+        } else if (self.sess.target.linker_is_gnu || self.sess.target.is_like_wasm)
+            && !keep_metadata
+        {
             self.linker_arg("--gc-sections");
         }
     }
@@ -484,13 +486,13 @@ impl<'a> Linker for GccLinker<'a> {
     fn no_gc_sections(&mut self) {
         if self.sess.target.is_like_osx {
             self.linker_arg("-no_dead_strip");
-        } else if self.sess.target.linker_is_gnu {
+        } else if self.sess.target.linker_is_gnu || self.sess.target.is_like_wasm {
             self.linker_arg("--no-gc-sections");
         }
     }
 
     fn optimize(&mut self) {
-        if !self.sess.target.linker_is_gnu {
+        if !self.sess.target.linker_is_gnu && !self.sess.target.is_like_wasm {
             return;
         }