Skip to content

Commit 16b7e12

Browse files
committedFeb 22, 2024
Implement -C link-self-contained=(+/-)sanitizers
1 parent 3f39cae commit 16b7e12

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
@@ -1192,6 +1192,8 @@ fn add_sanitizer_libraries(sess: &Session, crate_type: CrateType, linker: &mut d
11921192
// are currently distributed as static libraries which should be linked to
11931193
// executables only.
11941194
let needs_runtime = !sess.target.is_like_android
1195+
&& (!sess.opts.cg.link_self_contained.is_sanitizers_disabled()
1196+
|| sess.opts.cg.link_self_contained.is_sanitizers_enabled())
11951197
&& match crate_type {
11961198
CrateType::Executable => true,
11971199
CrateType::Dylib | CrateType::Cdylib | CrateType::ProcMacro => sess.target.is_like_osx,

‎compiler/rustc_session/src/config.rs

+14-2
Original file line numberDiff line numberDiff line change
@@ -293,17 +293,29 @@ impl LinkSelfContained {
293293
}
294294

295295
/// Returns whether the self-contained linker component was enabled on the CLI, using the
296-
/// `-C link-self-contained=+linker` syntax, or one of the `true` shorcuts.
296+
/// `-C link-self-contained=+linker` syntax, or one of the `true` shortcuts.
297297
pub fn is_linker_enabled(&self) -> bool {
298298
self.enabled_components.contains(LinkSelfContainedComponents::LINKER)
299299
}
300300

301301
/// Returns whether the self-contained linker component was disabled on the CLI, using the
302-
/// `-C link-self-contained=-linker` syntax, or one of the `false` shorcuts.
302+
/// `-C link-self-contained=-linker` syntax, or one of the `false` shortcuts.
303303
pub fn is_linker_disabled(&self) -> bool {
304304
self.disabled_components.contains(LinkSelfContainedComponents::LINKER)
305305
}
306306

307+
// Returns whether the self-contained sanitizer component was enabled on the CLI, using the
308+
// `-C link-self-contained=+sanitizers` syntax, or one of the `true` shortcuts.
309+
pub fn is_sanitizers_enabled(&self) -> bool {
310+
self.enabled_components.contains(LinkSelfContainedComponents::SANITIZERS)
311+
}
312+
313+
/// Returns whether the self-contained linker component was disabled on the CLI, using the
314+
/// `-C link-self-contained=-sanitizers` syntax, or one of the `false` shortcuts.
315+
pub fn is_sanitizers_disabled(&self) -> bool {
316+
self.disabled_components.contains(LinkSelfContainedComponents::SANITIZERS)
317+
}
318+
307319
/// Returns CLI inconsistencies to emit errors: individual components were both enabled and
308320
/// disabled.
309321
fn check_consistency(&self) -> Option<LinkSelfContainedComponents> {

0 commit comments

Comments
 (0)