Skip to content

Commit c28317f

Browse files
authored
Unrolled build for rust-lang#121207
Rollup merge of rust-lang#121207 - chriswailes:z-external-clangrt, r=michaelwoerister Add `-Z external-clangrt` This adds the unstable `-Z external-clangrt` flag that will prevent rustc from emitting linker paths for the in-tree LLVM sanitizer runtime library.
2 parents ee03c28 + f46acea commit c28317f

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

compiler/rustc_codegen_ssa/src/back/link.rs

+19-10
Original file line numberDiff line numberDiff line change
@@ -1216,20 +1216,29 @@ fn add_sanitizer_libraries(
12161216
crate_type: CrateType,
12171217
linker: &mut dyn Linker,
12181218
) {
1219+
if sess.target.is_like_android {
1220+
// Sanitizer runtime libraries are provided dynamically on Android
1221+
// targets.
1222+
return;
1223+
}
1224+
1225+
if sess.opts.unstable_opts.external_clangrt {
1226+
// Linking against in-tree sanitizer runtimes is disabled via
1227+
// `-Z external-clangrt`
1228+
return;
1229+
}
1230+
1231+
if matches!(crate_type, CrateType::Rlib | CrateType::Staticlib) {
1232+
return;
1233+
}
1234+
12191235
// On macOS and Windows using MSVC the runtimes are distributed as dylibs
12201236
// which should be linked to both executables and dynamic libraries.
12211237
// Everywhere else the runtimes are currently distributed as static
12221238
// libraries which should be linked to executables only.
1223-
let needs_runtime = !sess.target.is_like_android
1224-
&& match crate_type {
1225-
CrateType::Executable => true,
1226-
CrateType::Dylib | CrateType::Cdylib | CrateType::ProcMacro => {
1227-
sess.target.is_like_osx || sess.target.is_like_msvc
1228-
}
1229-
CrateType::Rlib | CrateType::Staticlib => false,
1230-
};
1231-
1232-
if !needs_runtime {
1239+
if matches!(crate_type, CrateType::Dylib | CrateType::Cdylib | CrateType::ProcMacro)
1240+
&& !(sess.target.is_like_osx || sess.target.is_like_msvc)
1241+
{
12331242
return;
12341243
}
12351244

compiler/rustc_session/src/options.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1645,6 +1645,8 @@ options! {
16451645
"emit the bc module with thin LTO info (default: yes)"),
16461646
export_executable_symbols: bool = (false, parse_bool, [TRACKED],
16471647
"export symbols from executables, as if they were dynamic libraries"),
1648+
external_clangrt: bool = (false, parse_bool, [UNTRACKED],
1649+
"rely on user specified linker commands to find clangrt"),
16481650
extra_const_ub_checks: bool = (false, parse_bool, [TRACKED],
16491651
"turns on more checks to detect const UB, which can be slow (default: no)"),
16501652
#[rustc_lint_opt_deny_field_access("use `Session::fewer_names` instead of this field")]

0 commit comments

Comments
 (0)