Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add system-llvm-libunwind config option #77703

Merged
merged 1 commit into from
Oct 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion config.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,8 @@ changelog-seen = 2
#test-compare-mode = false

# Use LLVM libunwind as the implementation for Rust's unwinder.
#llvm-libunwind = false
# Accepted values are 'in-tree' (formerly true), 'system' or 'no' (formerly false).
#llvm-libunwind = 'no'
Keruspe marked this conversation as resolved.
Show resolved Hide resolved

# Enable Windows Control Flow Guard checks in the standard library.
# This only applies from stage 1 onwards, and only for Windows targets.
Expand Down
1 change: 1 addition & 0 deletions library/std/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ profiler = ["profiler_builtins"]
compiler-builtins-c = ["alloc/compiler-builtins-c"]
compiler-builtins-mem = ["alloc/compiler-builtins-mem"]
llvm-libunwind = ["unwind/llvm-libunwind"]
system-llvm-libunwind = ["unwind/system-llvm-libunwind"]

# Make panics and failed asserts immediately abort without formatting any message
panic_immediate_abort = ["core/panic_immediate_abort"]
Expand Down
1 change: 1 addition & 0 deletions library/test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ backtrace = ["std/backtrace"]
compiler-builtins-c = ["std/compiler-builtins-c"]
compiler-builtins-mem = ["std/compiler-builtins-mem"]
llvm-libunwind = ["std/llvm-libunwind"]
system-llvm-libunwind = ["std/system-llvm-libunwind"]
panic-unwind = ["std/panic_unwind"]
panic_immediate_abort = ["std/panic_immediate_abort"]
profiler = ["std/profiler"]
Expand Down
1 change: 1 addition & 0 deletions library/unwind/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ cc = { version = "1.0.1" }

[features]
llvm-libunwind = []
system-llvm-libunwind = []
16 changes: 15 additions & 1 deletion library/unwind/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,24 @@ extern "C" {}
// When building with crt-static, we get `gcc_eh` from the `libc` crate, since
// glibc needs it, and needs it listed later on the linker command line. We
// don't want to duplicate it here.
#[cfg(all(target_os = "linux", target_env = "gnu", not(feature = "llvm-libunwind")))]
#[cfg(all(
target_os = "linux",
target_env = "gnu",
not(feature = "llvm-libunwind"),
not(feature = "system-llvm-libunwind")
))]
#[link(name = "gcc_s", cfg(not(target_feature = "crt-static")))]
extern "C" {}

#[cfg(all(
target_os = "linux",
target_env = "gnu",
not(feature = "llvm-libunwind"),
feature = "system-llvm-libunwind"
))]
#[link(name = "unwind", cfg(not(target_feature = "crt-static")))]
extern "C" {}

#[cfg(target_os = "redox")]
#[link(name = "gcc_eh", kind = "static-nobundle", cfg(target_feature = "crt-static"))]
#[link(name = "gcc_s", cfg(not(target_feature = "crt-static")))]
Expand Down
35 changes: 32 additions & 3 deletions src/bootstrap/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use std::ffi::OsString;
use std::fmt;
use std::fs;
use std::path::{Path, PathBuf};
use std::str::FromStr;

use crate::cache::{Interned, INTERNER};
use crate::flags::Flags;
Expand Down Expand Up @@ -65,7 +66,7 @@ pub struct Config {
pub rustc_error_format: Option<String>,
pub json_output: bool,
pub test_compare_mode: bool,
pub llvm_libunwind: bool,
pub llvm_libunwind: Option<LlvmLibunwind>,

pub on_fail: Option<String>,
pub stage: u32,
Expand Down Expand Up @@ -177,6 +178,32 @@ pub struct Config {
pub out: PathBuf,
}

#[derive(Debug, Clone, Copy, PartialEq)]
pub enum LlvmLibunwind {
No,
InTree,
System,
}

impl Default for LlvmLibunwind {
fn default() -> Self {
Self::No
}
}

impl FromStr for LlvmLibunwind {
type Err = String;

fn from_str(value: &str) -> Result<Self, Self::Err> {
match value {
"no" => Ok(Self::No),
"in-tree" => Ok(Self::InTree),
"system" => Ok(Self::System),
invalid => Err(format!("Invalid value '{}' for rust.llvm-libunwind config.", invalid)),
}
}
}

#[derive(Debug, Copy, Clone, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct TargetSelection {
pub triple: Interned<String>,
Expand Down Expand Up @@ -457,7 +484,7 @@ struct Rust {
remap_debuginfo: Option<bool>,
jemalloc: Option<bool>,
test_compare_mode: Option<bool>,
llvm_libunwind: Option<bool>,
llvm_libunwind: Option<String>,
control_flow_guard: Option<bool>,
new_symbol_mangling: Option<bool>,
}
Expand Down Expand Up @@ -799,7 +826,9 @@ impl Config {
set(&mut config.rust_rpath, rust.rpath);
set(&mut config.jemalloc, rust.jemalloc);
set(&mut config.test_compare_mode, rust.test_compare_mode);
set(&mut config.llvm_libunwind, rust.llvm_libunwind);
config.llvm_libunwind = rust
.llvm_libunwind
.map(|v| v.parse().expect("failed to parse rust.llvm-libunwind"));
set(&mut config.backtrace, rust.backtrace);
set(&mut config.channel, rust.channel);
set(&mut config.rust_dist_src, rust.dist_src);
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def v(*args):
v("llvm-cxxflags", "llvm.cxxflags", "build LLVM with these extra compiler flags")
v("llvm-ldflags", "llvm.ldflags", "build LLVM with these extra linker flags")

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

# Optimization and debugging options. These may be overridden by the release
# channel, etc.
Expand Down
8 changes: 5 additions & 3 deletions src/bootstrap/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ use std::os::windows::fs::symlink_file;
use build_helper::{mtime, output, run, run_suppressed, t, try_run, try_run_suppressed};
use filetime::FileTime;

use crate::config::TargetSelection;
use crate::config::{LlvmLibunwind, TargetSelection};
use crate::util::{exe, libdir, CiEnv};

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

if self.config.llvm_libunwind {
features.push_str(" llvm-libunwind");
match self.config.llvm_libunwind.unwrap_or_default() {
LlvmLibunwind::InTree => features.push_str(" llvm-libunwind"),
LlvmLibunwind::System => features.push_str(" system-llvm-libunwind"),
LlvmLibunwind::No => {}
}
if self.config.backtrace {
features.push_str(" backtrace");
Expand Down