Skip to content

Commit 3bdef53

Browse files
committed
Implement -C link-self-contained=(+/-)sanitizers
1 parent f62f490 commit 3bdef53

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

compiler/rustc_codegen_ssa/src/back/link.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1202,6 +1202,8 @@ fn add_sanitizer_libraries(
12021202
// Everywhere else the runtimes are currently distributed as static
12031203
// libraries which should be linked to executables only.
12041204
let needs_runtime = !sess.target.is_like_android
1205+
&& (!sess.opts.cg.link_self_contained.is_sanitizers_disabled()
1206+
|| sess.opts.cg.link_self_contained.is_sanitizers_enabled())
12051207
&& match crate_type {
12061208
CrateType::Executable => true,
12071209
CrateType::Dylib | CrateType::Cdylib | CrateType::ProcMacro => {

compiler/rustc_session/src/config.rs

+14-2
Original file line numberDiff line numberDiff line change
@@ -278,17 +278,29 @@ impl LinkSelfContained {
278278
}
279279

280280
/// Returns whether the self-contained linker component was enabled on the CLI, using the
281-
/// `-C link-self-contained=+linker` syntax, or one of the `true` shorcuts.
281+
/// `-C link-self-contained=+linker` syntax, or one of the `true` shortcuts.
282282
pub fn is_linker_enabled(&self) -> bool {
283283
self.enabled_components.contains(LinkSelfContainedComponents::LINKER)
284284
}
285285

286286
/// Returns whether the self-contained linker component was disabled on the CLI, using the
287-
/// `-C link-self-contained=-linker` syntax, or one of the `false` shorcuts.
287+
/// `-C link-self-contained=-linker` syntax, or one of the `false` shortcuts.
288288
pub fn is_linker_disabled(&self) -> bool {
289289
self.disabled_components.contains(LinkSelfContainedComponents::LINKER)
290290
}
291291

292+
// Returns whether the self-contained sanitizer component was enabled on the CLI, using the
293+
// `-C link-self-contained=+sanitizers` syntax, or one of the `true` shortcuts.
294+
pub fn is_sanitizers_enabled(&self) -> bool {
295+
self.enabled_components.contains(LinkSelfContainedComponents::SANITIZERS)
296+
}
297+
298+
/// Returns whether the self-contained linker component was disabled on the CLI, using the
299+
/// `-C link-self-contained=-sanitizers` syntax, or one of the `false` shortcuts.
300+
pub fn is_sanitizers_disabled(&self) -> bool {
301+
self.disabled_components.contains(LinkSelfContainedComponents::SANITIZERS)
302+
}
303+
292304
/// Returns CLI inconsistencies to emit errors: individual components were both enabled and
293305
/// disabled.
294306
fn check_consistency(&self) -> Option<LinkSelfContainedComponents> {

0 commit comments

Comments
 (0)