Skip to content

Commit 005d3b7

Browse files
authored
Rollup merge of rust-lang#93604 - tmandry:libunwind-fuchsia-default, r=Mark-Simulacrum
Use in-tree libunwind by default on Fuchsia Fuchsia doesn't ship libunwind in its SDK, so we must provide it statically.
2 parents ba14a83 + 42624ba commit 005d3b7

File tree

4 files changed

+39
-17
lines changed

4 files changed

+39
-17
lines changed

config.toml.example

+15-10
Original file line numberDiff line numberDiff line change
@@ -599,16 +599,9 @@ changelog-seen = 2
599599
# development of NLL
600600
#test-compare-mode = false
601601

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

614607
# Enable Windows Control Flow Guard checks in the standard library.
@@ -665,6 +658,18 @@ changelog-seen = 2
665658
# not, you can specify an explicit file name for it.
666659
#llvm-filecheck = "/path/to/llvm-version/bin/FileCheck"
667660

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

src/bootstrap/compile.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ fn copy_third_party_objects(
175175
}
176176

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

src/bootstrap/config.rs

+22-5
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ pub struct Config {
6666
pub rustc_error_format: Option<String>,
6767
pub json_output: bool,
6868
pub test_compare_mode: bool,
69-
pub llvm_libunwind: LlvmLibunwind,
7069
pub color: Color,
7170

7271
pub on_fail: Option<String>,
@@ -145,6 +144,7 @@ pub struct Config {
145144
pub rust_profile_generate: Option<String>,
146145
pub llvm_profile_use: Option<String>,
147146
pub llvm_profile_generate: bool,
147+
pub llvm_libunwind_default: Option<LlvmLibunwind>,
148148

149149
pub build: TargetSelection,
150150
pub hosts: Vec<TargetSelection>,
@@ -289,6 +289,7 @@ pub struct Target {
289289
pub llvm_config: Option<PathBuf>,
290290
/// Some(path to FileCheck) if one was specified.
291291
pub llvm_filecheck: Option<PathBuf>,
292+
pub llvm_libunwind: Option<LlvmLibunwind>,
292293
pub cc: Option<PathBuf>,
293294
pub cxx: Option<PathBuf>,
294295
pub ar: Option<PathBuf>,
@@ -573,6 +574,7 @@ derive_merge! {
573574
linker: Option<String>,
574575
llvm_config: Option<String>,
575576
llvm_filecheck: Option<String>,
577+
llvm_libunwind: Option<String>,
576578
android_ndk: Option<String>,
577579
sanitizers: Option<bool>,
578580
profiler: Option<bool>,
@@ -925,10 +927,6 @@ impl Config {
925927
set(&mut config.rust_rpath, rust.rpath);
926928
set(&mut config.jemalloc, rust.jemalloc);
927929
set(&mut config.test_compare_mode, rust.test_compare_mode);
928-
config.llvm_libunwind = rust
929-
.llvm_libunwind
930-
.map(|v| v.parse().expect("failed to parse rust.llvm-libunwind"))
931-
.unwrap_or_default();
932930
set(&mut config.backtrace, rust.backtrace);
933931
set(&mut config.channel, rust.channel);
934932
config.description = rust.description;
@@ -951,6 +949,9 @@ impl Config {
951949
config.rust_thin_lto_import_instr_limit = rust.thin_lto_import_instr_limit;
952950
set(&mut config.rust_remap_debuginfo, rust.remap_debuginfo);
953951
set(&mut config.control_flow_guard, rust.control_flow_guard);
952+
config.llvm_libunwind_default = rust
953+
.llvm_libunwind
954+
.map(|v| v.parse().expect("failed to parse rust.llvm-libunwind"));
954955

955956
if let Some(ref backends) = rust.codegen_backends {
956957
config.rust_codegen_backends =
@@ -977,6 +978,10 @@ impl Config {
977978
if let Some(ref s) = cfg.llvm_filecheck {
978979
target.llvm_filecheck = Some(config.src.join(s));
979980
}
981+
target.llvm_libunwind = cfg
982+
.llvm_libunwind
983+
.as_ref()
984+
.map(|v| v.parse().expect("failed to parse rust.llvm-libunwind"));
980985
if let Some(ref s) = cfg.android_ndk {
981986
target.ndk = Some(config.src.join(s));
982987
}
@@ -1174,6 +1179,18 @@ impl Config {
11741179
self.rust_codegen_backends.contains(&INTERNER.intern_str("llvm"))
11751180
}
11761181

1182+
pub fn llvm_libunwind(&self, target: TargetSelection) -> LlvmLibunwind {
1183+
self.target_config
1184+
.get(&target)
1185+
.and_then(|t| t.llvm_libunwind)
1186+
.or(self.llvm_libunwind_default)
1187+
.unwrap_or(if target.contains("fuchsia") {
1188+
LlvmLibunwind::InTree
1189+
} else {
1190+
LlvmLibunwind::No
1191+
})
1192+
}
1193+
11771194
pub fn submodules(&self, rust_info: &GitInfo) -> bool {
11781195
self.submodules.unwrap_or(rust_info.is_git())
11791196
}

src/bootstrap/lib.rs

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

707-
match self.config.llvm_libunwind {
707+
match self.config.llvm_libunwind(target) {
708708
LlvmLibunwind::InTree => features.push_str(" llvm-libunwind"),
709709
LlvmLibunwind::System => features.push_str(" system-llvm-libunwind"),
710710
LlvmLibunwind::No => {}

0 commit comments

Comments
 (0)