Skip to content

Commit 66fa42a

Browse files
committedOct 21, 2020
allow using the system-wide llvm-libunwind as the unwinder
Signed-off-by: Marc-Antoine Perennou <[email protected]>
1 parent f965120 commit 66fa42a

File tree

8 files changed

+58
-9
lines changed

8 files changed

+58
-9
lines changed
 

‎config.toml.example

+2-1
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,8 @@ changelog-seen = 2
527527
#test-compare-mode = false
528528

529529
# Use LLVM libunwind as the implementation for Rust's unwinder.
530-
#llvm-libunwind = false
530+
# Accepted values are 'in-tree' (formerly true), 'system' or 'no' (formerly false).
531+
#llvm-libunwind = 'no'
531532

532533
# Enable Windows Control Flow Guard checks in the standard library.
533534
# This only applies from stage 1 onwards, and only for Windows targets.

‎library/std/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ profiler = ["profiler_builtins"]
6161
compiler-builtins-c = ["alloc/compiler-builtins-c"]
6262
compiler-builtins-mem = ["alloc/compiler-builtins-mem"]
6363
llvm-libunwind = ["unwind/llvm-libunwind"]
64+
system-llvm-libunwind = ["unwind/system-llvm-libunwind"]
6465

6566
# Make panics and failed asserts immediately abort without formatting any message
6667
panic_immediate_abort = ["core/panic_immediate_abort"]

‎library/test/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ backtrace = ["std/backtrace"]
2727
compiler-builtins-c = ["std/compiler-builtins-c"]
2828
compiler-builtins-mem = ["std/compiler-builtins-mem"]
2929
llvm-libunwind = ["std/llvm-libunwind"]
30+
system-llvm-libunwind = ["std/system-llvm-libunwind"]
3031
panic-unwind = ["std/panic_unwind"]
3132
panic_immediate_abort = ["std/panic_immediate_abort"]
3233
profiler = ["std/profiler"]

‎library/unwind/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ cc = { version = "1.0.1" }
2323

2424
[features]
2525
llvm-libunwind = []
26+
system-llvm-libunwind = []

‎library/unwind/src/lib.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,24 @@ extern "C" {}
4545
// When building with crt-static, we get `gcc_eh` from the `libc` crate, since
4646
// glibc needs it, and needs it listed later on the linker command line. We
4747
// don't want to duplicate it here.
48-
#[cfg(all(target_os = "linux", target_env = "gnu", not(feature = "llvm-libunwind")))]
48+
#[cfg(all(
49+
target_os = "linux",
50+
target_env = "gnu",
51+
not(feature = "llvm-libunwind"),
52+
not(feature = "system-llvm-libunwind")
53+
))]
4954
#[link(name = "gcc_s", cfg(not(target_feature = "crt-static")))]
5055
extern "C" {}
5156

57+
#[cfg(all(
58+
target_os = "linux",
59+
target_env = "gnu",
60+
not(feature = "llvm-libunwind"),
61+
feature = "system-llvm-libunwind"
62+
))]
63+
#[link(name = "unwind", cfg(not(target_feature = "crt-static")))]
64+
extern "C" {}
65+
5266
#[cfg(target_os = "redox")]
5367
#[link(name = "gcc_eh", kind = "static-nobundle", cfg(target_feature = "crt-static"))]
5468
#[link(name = "gcc_s", cfg(not(target_feature = "crt-static")))]

‎src/bootstrap/config.rs

+32-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use std::ffi::OsString;
1010
use std::fmt;
1111
use std::fs;
1212
use std::path::{Path, PathBuf};
13+
use std::str::FromStr;
1314

1415
use crate::cache::{Interned, INTERNER};
1516
use crate::flags::Flags;
@@ -65,7 +66,7 @@ pub struct Config {
6566
pub rustc_error_format: Option<String>,
6667
pub json_output: bool,
6768
pub test_compare_mode: bool,
68-
pub llvm_libunwind: bool,
69+
pub llvm_libunwind: Option<LlvmLibunwind>,
6970

7071
pub on_fail: Option<String>,
7172
pub stage: u32,
@@ -177,6 +178,32 @@ pub struct Config {
177178
pub out: PathBuf,
178179
}
179180

181+
#[derive(Debug, Clone, Copy, PartialEq)]
182+
pub enum LlvmLibunwind {
183+
No,
184+
InTree,
185+
System,
186+
}
187+
188+
impl Default for LlvmLibunwind {
189+
fn default() -> Self {
190+
Self::No
191+
}
192+
}
193+
194+
impl FromStr for LlvmLibunwind {
195+
type Err = String;
196+
197+
fn from_str(value: &str) -> Result<Self, Self::Err> {
198+
match value {
199+
"no" => Ok(Self::No),
200+
"in-tree" => Ok(Self::InTree),
201+
"system" => Ok(Self::System),
202+
invalid => Err(format!("Invalid value '{}' for rust.llvm-libunwind config.", invalid)),
203+
}
204+
}
205+
}
206+
180207
#[derive(Debug, Copy, Clone, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
181208
pub struct TargetSelection {
182209
pub triple: Interned<String>,
@@ -457,7 +484,7 @@ struct Rust {
457484
remap_debuginfo: Option<bool>,
458485
jemalloc: Option<bool>,
459486
test_compare_mode: Option<bool>,
460-
llvm_libunwind: Option<bool>,
487+
llvm_libunwind: Option<String>,
461488
control_flow_guard: Option<bool>,
462489
new_symbol_mangling: Option<bool>,
463490
}
@@ -799,7 +826,9 @@ impl Config {
799826
set(&mut config.rust_rpath, rust.rpath);
800827
set(&mut config.jemalloc, rust.jemalloc);
801828
set(&mut config.test_compare_mode, rust.test_compare_mode);
802-
set(&mut config.llvm_libunwind, rust.llvm_libunwind);
829+
config.llvm_libunwind = rust
830+
.llvm_libunwind
831+
.map(|v| v.parse().expect("failed to parse rust.llvm-libunwind"));
803832
set(&mut config.backtrace, rust.backtrace);
804833
set(&mut config.channel, rust.channel);
805834
set(&mut config.rust_dist_src, rust.dist_src);

‎src/bootstrap/configure.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def v(*args):
6565
v("llvm-cxxflags", "llvm.cxxflags", "build LLVM with these extra compiler flags")
6666
v("llvm-ldflags", "llvm.ldflags", "build LLVM with these extra linker flags")
6767

68-
o("llvm-libunwind", "rust.llvm-libunwind", "use LLVM libunwind")
68+
v("llvm-libunwind", "rust.llvm-libunwind", "use LLVM libunwind")
6969

7070
# Optimization and debugging options. These may be overridden by the release
7171
# channel, etc.

‎src/bootstrap/lib.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ use std::os::windows::fs::symlink_file;
121121
use build_helper::{mtime, output, run, run_suppressed, t, try_run, try_run_suppressed};
122122
use filetime::FileTime;
123123

124-
use crate::config::TargetSelection;
124+
use crate::config::{LlvmLibunwind, TargetSelection};
125125
use crate::util::{exe, libdir, CiEnv};
126126

127127
mod builder;
@@ -537,8 +537,10 @@ impl Build {
537537
fn std_features(&self) -> String {
538538
let mut features = "panic-unwind".to_string();
539539

540-
if self.config.llvm_libunwind {
541-
features.push_str(" llvm-libunwind");
540+
match self.config.llvm_libunwind.unwrap_or_default() {
541+
LlvmLibunwind::InTree => features.push_str(" llvm-libunwind"),
542+
LlvmLibunwind::System => features.push_str(" system-llvm-libunwind"),
543+
LlvmLibunwind::No => {}
542544
}
543545
if self.config.backtrace {
544546
features.push_str(" backtrace");

0 commit comments

Comments
 (0)