@@ -1801,16 +1801,17 @@ fn linker_with_args<'a, B: ArchiveBuilder<'a>>(
1801
1801
// such:
1802
1802
//
1803
1803
// 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
1806
1806
// 4. Upstream native libraries
1807
1807
//
1808
1808
// The rationale behind this ordering is that those items lower down in the
1809
1809
// list can't depend on items higher up in the list. For example nothing can
1810
1810
// 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
1812
1812
// libraries as that would violate the structure of the DAG, in that
1813
1813
// 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.)
1814
1815
//
1815
1816
// Note that upstream rust libraries may contain native dependencies as
1816
1817
// 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>>(
1821
1822
add_local_crate_metadata_objects ( cmd, crate_type, codegen_results) ;
1822
1823
add_local_crate_allocator_objects ( cmd, codegen_results) ;
1823
1824
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
+
1824
1833
// Rust libraries.
1825
1834
add_upstream_rust_crates :: < B > ( cmd, sess, codegen_results, crate_type, tmpdir) ;
1826
1835
@@ -1829,7 +1838,6 @@ fn linker_with_args<'a, B: ArchiveBuilder<'a>>(
1829
1838
// external build system already has the native dependencies defined, and it
1830
1839
// will provide them to the linker itself.
1831
1840
if sess. opts . debugging_opts . link_native_libraries {
1832
- add_local_native_libraries ( cmd, sess, codegen_results) ;
1833
1841
add_upstream_native_libraries ( cmd, sess, codegen_results, crate_type) ;
1834
1842
}
1835
1843
0 commit comments