Skip to content

Commit dca3acb

Browse files
committed
linker: Inline fn link_local_crate_native_libs_and_dependent_crate_libs
1 parent f57d5ba commit dca3acb

File tree

1 file changed

+38
-57
lines changed
  • compiler/rustc_codegen_ssa/src/back

1 file changed

+38
-57
lines changed

compiler/rustc_codegen_ssa/src/back/link.rs

+38-57
Original file line numberDiff line numberDiff line change
@@ -1680,55 +1680,6 @@ fn add_local_crate_metadata_objects(
16801680
}
16811681
}
16821682

1683-
/// Link native libraries corresponding to the current crate and all libraries corresponding to
1684-
/// all its dependency crates.
1685-
/// FIXME: Consider combining this with the functions above adding object files for the local crate.
1686-
fn link_local_crate_native_libs_and_dependent_crate_libs<'a, B: ArchiveBuilder<'a>>(
1687-
cmd: &mut dyn Linker,
1688-
sess: &'a Session,
1689-
crate_type: CrateType,
1690-
codegen_results: &CodegenResults,
1691-
tmpdir: &Path,
1692-
) {
1693-
// Take careful note of the ordering of the arguments we pass to the linker
1694-
// here. Linkers will assume that things on the left depend on things to the
1695-
// right. Things on the right cannot depend on things on the left. This is
1696-
// all formally implemented in terms of resolving symbols (libs on the right
1697-
// resolve unknown symbols of libs on the left, but not vice versa).
1698-
//
1699-
// For this reason, we have organized the arguments we pass to the linker as
1700-
// such:
1701-
//
1702-
// 1. The local object that LLVM just generated
1703-
// 2. Local native libraries
1704-
// 3. Upstream rust libraries
1705-
// 4. Upstream native libraries
1706-
//
1707-
// The rationale behind this ordering is that those items lower down in the
1708-
// list can't depend on items higher up in the list. For example nothing can
1709-
// depend on what we just generated (e.g., that'd be a circular dependency).
1710-
// Upstream rust libraries are not allowed to depend on our local native
1711-
// libraries as that would violate the structure of the DAG, in that
1712-
// scenario they are required to link to them as well in a shared fashion.
1713-
//
1714-
// Note that upstream rust libraries may contain native dependencies as
1715-
// well, but they also can't depend on what we just started to add to the
1716-
// link line. And finally upstream native libraries can't depend on anything
1717-
// in this DAG so far because they're only dylibs and dylibs can only depend
1718-
// on other dylibs (e.g., other native deps).
1719-
//
1720-
// If -Zlink-native-libraries=false is set, then the assumption is that an
1721-
// external build system already has the native dependencies defined, and it
1722-
// will provide them to the linker itself.
1723-
if sess.opts.debugging_opts.link_native_libraries {
1724-
add_local_native_libraries(cmd, sess, codegen_results);
1725-
}
1726-
add_upstream_rust_crates::<B>(cmd, sess, codegen_results, crate_type, tmpdir);
1727-
if sess.opts.debugging_opts.link_native_libraries {
1728-
add_upstream_native_libraries(cmd, sess, codegen_results, crate_type);
1729-
}
1730-
}
1731-
17321683
/// Add sysroot and other globally set directories to the directory search list.
17331684
fn add_library_search_dirs(cmd: &mut dyn Linker, sess: &Session, self_contained: bool) {
17341685
// The default library location, we need this to find the runtime.
@@ -1932,14 +1883,44 @@ fn linker_with_args<'a, B: ArchiveBuilder<'a>>(
19321883
cmd.no_default_libraries();
19331884
}
19341885

1935-
// OBJECT-FILES-YES
1936-
link_local_crate_native_libs_and_dependent_crate_libs::<B>(
1937-
cmd,
1938-
sess,
1939-
crate_type,
1940-
codegen_results,
1941-
tmpdir,
1942-
);
1886+
// OBJECT-FILES-NO, AUDIT-ORDER
1887+
// Take careful note of the ordering of the arguments we pass to the linker
1888+
// here. Linkers will assume that things on the left depend on things to the
1889+
// right. Things on the right cannot depend on things on the left. This is
1890+
// all formally implemented in terms of resolving symbols (libs on the right
1891+
// resolve unknown symbols of libs on the left, but not vice versa).
1892+
//
1893+
// For this reason, we have organized the arguments we pass to the linker as
1894+
// such:
1895+
//
1896+
// 1. The local object that LLVM just generated
1897+
// 2. Local native libraries
1898+
// 3. Upstream rust libraries
1899+
// 4. Upstream native libraries
1900+
//
1901+
// The rationale behind this ordering is that those items lower down in the
1902+
// list can't depend on items higher up in the list. For example nothing can
1903+
// depend on what we just generated (e.g., that'd be a circular dependency).
1904+
// Upstream rust libraries are not allowed to depend on our local native
1905+
// libraries as that would violate the structure of the DAG, in that
1906+
// scenario they are required to link to them as well in a shared fashion.
1907+
//
1908+
// Note that upstream rust libraries may contain native dependencies as
1909+
// well, but they also can't depend on what we just started to add to the
1910+
// link line. And finally upstream native libraries can't depend on anything
1911+
// in this DAG so far because they're only dylibs and dylibs can only depend
1912+
// on other dylibs (e.g., other native deps).
1913+
//
1914+
// If -Zlink-native-libraries=false is set, then the assumption is that an
1915+
// external build system already has the native dependencies defined, and it
1916+
// will provide them to the linker itself.
1917+
if sess.opts.debugging_opts.link_native_libraries {
1918+
add_local_native_libraries(cmd, sess, codegen_results);
1919+
}
1920+
add_upstream_rust_crates::<B>(cmd, sess, codegen_results, crate_type, tmpdir);
1921+
if sess.opts.debugging_opts.link_native_libraries {
1922+
add_upstream_native_libraries(cmd, sess, codegen_results, crate_type);
1923+
}
19431924

19441925
// OBJECT-FILES-NO, AUDIT-ORDER
19451926
if sess.opts.cg.profile_generate.enabled() || sess.instrument_coverage() {

0 commit comments

Comments
 (0)