Skip to content

Commit 5275bf1

Browse files
committed
linker: Restore the old order of linking native libraries
1 parent b7994f9 commit 5275bf1

File tree

1 file changed

+12
-4
lines changed
  • compiler/rustc_codegen_ssa/src/back

1 file changed

+12
-4
lines changed

compiler/rustc_codegen_ssa/src/back/link.rs

+12-4
Original file line numberDiff line numberDiff line change
@@ -1801,16 +1801,17 @@ fn linker_with_args<'a, B: ArchiveBuilder<'a>>(
18011801
// such:
18021802
//
18031803
// 1. The local object that LLVM just generated
1804-
// 2. Upstream rust libraries
1805-
// 3. Local native libraries
1804+
// 2. Local native libraries
1805+
// 3. Upstream rust libraries
18061806
// 4. Upstream native libraries
18071807
//
18081808
// The rationale behind this ordering is that those items lower down in the
18091809
// list can't depend on items higher up in the list. For example nothing can
18101810
// depend on what we just generated (e.g., that'd be a circular dependency).
1811-
// Upstream rust libraries are not allowed to depend on our local native
1811+
// Upstream rust libraries are not supposed to depend on our local native
18121812
// libraries as that would violate the structure of the DAG, in that
18131813
// scenario they are required to link to them as well in a shared fashion.
1814+
// (The current implementation still doesn't prevent it though, see the FIXME below.)
18141815
//
18151816
// Note that upstream rust libraries may contain native dependencies as
18161817
// well, but they also can't depend on what we just started to add to the
@@ -1821,6 +1822,14 @@ fn linker_with_args<'a, B: ArchiveBuilder<'a>>(
18211822
add_local_crate_metadata_objects(cmd, crate_type, codegen_results);
18221823
add_local_crate_allocator_objects(cmd, codegen_results);
18231824

1825+
// FIXME: Move this below to other native libraries
1826+
// (or alternatively link all native libraries after their respective crates).
1827+
// This change is somewhat breaking in practice due to local static libraries being linked
1828+
// as whole-archive (#85144), so removing whole-archive may be a pre-requisite.
1829+
if sess.opts.debugging_opts.link_native_libraries {
1830+
add_local_native_libraries(cmd, sess, codegen_results);
1831+
}
1832+
18241833
// Rust libraries.
18251834
add_upstream_rust_crates::<B>(cmd, sess, codegen_results, crate_type, tmpdir);
18261835

@@ -1829,7 +1838,6 @@ fn linker_with_args<'a, B: ArchiveBuilder<'a>>(
18291838
// external build system already has the native dependencies defined, and it
18301839
// will provide them to the linker itself.
18311840
if sess.opts.debugging_opts.link_native_libraries {
1832-
add_local_native_libraries(cmd, sess, codegen_results);
18331841
add_upstream_native_libraries(cmd, sess, codegen_results, crate_type);
18341842
}
18351843

0 commit comments

Comments
 (0)