Skip to content

Commit 3eab280

Browse files
committed
linker: Re-apply Solaris fixes for -z ignore
1 parent 5275bf1 commit 3eab280

File tree

1 file changed

+10
-5
lines changed
  • compiler/rustc_codegen_ssa/src/back

1 file changed

+10
-5
lines changed

compiler/rustc_codegen_ssa/src/back/link.rs

+10-5
Original file line numberDiff line numberDiff line change
@@ -1764,11 +1764,6 @@ fn linker_with_args<'a, B: ArchiveBuilder<'a>>(
17641764

17651765
// ------------ Early order-dependent options ------------
17661766

1767-
// Avoid linking to dynamic libraries unless they satisfy some undefined symbols
1768-
// at the point at which they are specified on the command line.
1769-
// Must be passed before any (dynamic) libraries to have effect on them.
1770-
cmd.add_as_needed();
1771-
17721767
// If we're building something like a dynamic library then some platforms
17731768
// need to make sure that all symbols are exported correctly from the
17741769
// dynamic library.
@@ -1822,6 +1817,16 @@ fn linker_with_args<'a, B: ArchiveBuilder<'a>>(
18221817
add_local_crate_metadata_objects(cmd, crate_type, codegen_results);
18231818
add_local_crate_allocator_objects(cmd, codegen_results);
18241819

1820+
// Avoid linking to dynamic libraries unless they satisfy some undefined symbols
1821+
// at the point at which they are specified on the command line.
1822+
// Must be passed before any (dynamic) libraries to have effect on them.
1823+
// On Solaris-like systems, `-z ignore` acts as both `--as-needed` and `--gc-sections`
1824+
// so it will ignore unreferenced ELF sections from relocatable objects.
1825+
// For that reason, we put this flag after metadata objects as they would otherwise be removed.
1826+
// FIXME: Support more fine-grained dead code removal on Solaris/illumos
1827+
// and move this option back to the top.
1828+
cmd.add_as_needed();
1829+
18251830
// FIXME: Move this below to other native libraries
18261831
// (or alternatively link all native libraries after their respective crates).
18271832
// This change is somewhat breaking in practice due to local static libraries being linked

0 commit comments

Comments
 (0)