Skip to content

Commit 9d857d9

Browse files
committed
Make llvm-libunwind a per-target option
1 parent 27f5d83 commit 9d857d9

File tree

4 files changed

+35
-17
lines changed

4 files changed

+35
-17
lines changed

config.toml.example

+15-10
Original file line numberDiff line numberDiff line change
@@ -594,16 +594,9 @@ changelog-seen = 2
594594
# development of NLL
595595
#test-compare-mode = false
596596

597-
# Use LLVM libunwind as the implementation for Rust's unwinder.
598-
# Accepted values are 'in-tree' (formerly true), 'system' or 'no' (formerly false).
599-
# This option only applies for Linux and Fuchsia targets.
600-
# On Linux target, if crt-static is not enabled, 'no' means dynamic link to
601-
# `libgcc_s.so`, 'in-tree' means static link to the in-tree build of llvm libunwind
602-
# and 'system' means dynamic link to `libunwind.so`. If crt-static is enabled,
603-
# the behavior is depend on the libc. On musl target, 'no' and 'in-tree' both
604-
# means static link to the in-tree build of llvm libunwind, and 'system' means
605-
# static link to `libunwind.a` provided by system. Due to the limitation of glibc,
606-
# it must link to `libgcc_eh.a` to get a working output, and this option have no effect.
597+
# Global default for llvm-libunwind for all targets. See the target-specific
598+
# documentation for llvm-libunwind below. Note that the target-specific
599+
# option will override this if set.
607600
#llvm-libunwind = 'no'
608601

609602
# Enable Windows Control Flow Guard checks in the standard library.
@@ -660,6 +653,18 @@ changelog-seen = 2
660653
# not, you can specify an explicit file name for it.
661654
#llvm-filecheck = "/path/to/llvm-version/bin/FileCheck"
662655

656+
# Use LLVM libunwind as the implementation for Rust's unwinder.
657+
# Accepted values are 'in-tree' (formerly true), 'system' or 'no' (formerly false).
658+
# This option only applies for Linux and Fuchsia targets.
659+
# On Linux target, if crt-static is not enabled, 'no' means dynamic link to
660+
# `libgcc_s.so`, 'in-tree' means static link to the in-tree build of llvm libunwind
661+
# and 'system' means dynamic link to `libunwind.so`. If crt-static is enabled,
662+
# the behavior is depend on the libc. On musl target, 'no' and 'in-tree' both
663+
# means static link to the in-tree build of llvm libunwind, and 'system' means
664+
# static link to `libunwind.a` provided by system. Due to the limitation of glibc,
665+
# it must link to `libgcc_eh.a` to get a working output, and this option have no effect.
666+
#llvm-libunwind = 'no' if Linux, 'in-tree' if Fuchsia
667+
663668
# If this target is for Android, this option will be required to specify where
664669
# the NDK for the target lives. This is used to find the C compiler to link and
665670
# build native code.

src/bootstrap/compile.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ fn copy_third_party_objects(
177177
}
178178

179179
if target == "x86_64-fortanix-unknown-sgx"
180-
|| builder.config.llvm_libunwind == LlvmLibunwind::InTree
180+
|| builder.config.llvm_libunwind(target) == LlvmLibunwind::InTree
181181
&& (target.contains("linux") || target.contains("fuchsia"))
182182
{
183183
let libunwind_path =

src/bootstrap/config.rs

+18-5
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ pub struct Config {
6868
pub rustc_error_format: Option<String>,
6969
pub json_output: bool,
7070
pub test_compare_mode: bool,
71-
pub llvm_libunwind: LlvmLibunwind,
7271
pub color: Color,
7372

7473
pub on_fail: Option<String>,
@@ -146,6 +145,7 @@ pub struct Config {
146145
pub rust_profile_generate: Option<String>,
147146
pub llvm_profile_use: Option<String>,
148147
pub llvm_profile_generate: bool,
148+
pub llvm_libunwind_default: Option<LlvmLibunwind>,
149149

150150
pub build: TargetSelection,
151151
pub hosts: Vec<TargetSelection>,
@@ -290,6 +290,7 @@ pub struct Target {
290290
pub llvm_config: Option<PathBuf>,
291291
/// Some(path to FileCheck) if one was specified.
292292
pub llvm_filecheck: Option<PathBuf>,
293+
pub llvm_libunwind: Option<LlvmLibunwind>,
293294
pub cc: Option<PathBuf>,
294295
pub cxx: Option<PathBuf>,
295296
pub ar: Option<PathBuf>,
@@ -574,6 +575,7 @@ derive_merge! {
574575
linker: Option<String>,
575576
llvm_config: Option<String>,
576577
llvm_filecheck: Option<String>,
578+
llvm_libunwind: Option<String>,
577579
android_ndk: Option<String>,
578580
sanitizers: Option<bool>,
579581
profiler: Option<bool>,
@@ -921,10 +923,6 @@ impl Config {
921923
set(&mut config.rust_rpath, rust.rpath);
922924
set(&mut config.jemalloc, rust.jemalloc);
923925
set(&mut config.test_compare_mode, rust.test_compare_mode);
924-
config.llvm_libunwind = rust
925-
.llvm_libunwind
926-
.map(|v| v.parse().expect("failed to parse rust.llvm-libunwind"))
927-
.unwrap_or_default();
928926
set(&mut config.backtrace, rust.backtrace);
929927
set(&mut config.channel, rust.channel);
930928
config.description = rust.description;
@@ -947,6 +945,9 @@ impl Config {
947945
config.rust_thin_lto_import_instr_limit = rust.thin_lto_import_instr_limit;
948946
set(&mut config.rust_remap_debuginfo, rust.remap_debuginfo);
949947
set(&mut config.control_flow_guard, rust.control_flow_guard);
948+
config.llvm_libunwind_default = rust
949+
.llvm_libunwind
950+
.map(|v| v.parse().expect("failed to parse rust.llvm-libunwind"));
950951

951952
if let Some(ref backends) = rust.codegen_backends {
952953
config.rust_codegen_backends =
@@ -973,6 +974,10 @@ impl Config {
973974
if let Some(ref s) = cfg.llvm_filecheck {
974975
target.llvm_filecheck = Some(config.src.join(s));
975976
}
977+
target.llvm_libunwind = cfg
978+
.llvm_libunwind
979+
.as_ref()
980+
.map(|v| v.parse().expect("failed to parse rust.llvm-libunwind"));
976981
if let Some(ref s) = cfg.android_ndk {
977982
target.ndk = Some(config.src.join(s));
978983
}
@@ -1170,6 +1175,14 @@ impl Config {
11701175
self.rust_codegen_backends.contains(&INTERNER.intern_str("llvm"))
11711176
}
11721177

1178+
pub fn llvm_libunwind(&self, target: TargetSelection) -> LlvmLibunwind {
1179+
self.target_config
1180+
.get(&target)
1181+
.and_then(|t| t.llvm_libunwind)
1182+
.or(self.llvm_libunwind_default)
1183+
.unwrap_or(LlvmLibunwind::No)
1184+
}
1185+
11731186
pub fn submodules(&self, rust_info: &GitInfo) -> bool {
11741187
self.submodules.unwrap_or(rust_info.is_git())
11751188
}

src/bootstrap/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,7 @@ impl Build {
655655
fn std_features(&self, target: TargetSelection) -> String {
656656
let mut features = "panic-unwind".to_string();
657657

658-
match self.config.llvm_libunwind {
658+
match self.config.llvm_libunwind(target) {
659659
LlvmLibunwind::InTree => features.push_str(" llvm-libunwind"),
660660
LlvmLibunwind::System => features.push_str(" system-llvm-libunwind"),
661661
LlvmLibunwind::No => {}

0 commit comments

Comments
 (0)