Skip to content

Experimental exception handling support on Linux #1584

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ smallvec = "1.8.1"
unstable-features = ["jit", "inline_asm_sym"]
jit = ["cranelift-jit", "libloading"]
inline_asm_sym = []
unwinding = [] # Not yet included in unstable-features for performance reasons

[package.metadata.rust-analyzer]
rustc_private = true
2 changes: 1 addition & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ See [rustc_testing.md](docs/rustc_testing.md).
## Not yet supported

* SIMD ([tracked here](https://github.com/rust-lang/rustc_codegen_cranelift/issues/171), `std::simd` fully works, `std::arch` is partially supported)
* Unwinding on panics ([no cranelift support](https://github.com/bytecodealliance/wasmtime/issues/1677), `-Cpanic=abort` is enabled by default)
* Unwinding on panics ([experimental and not supported on Windows and macOS](https://github.com/rust-lang/rustc_codegen_cranelift/issues/1567), `-Cpanic=abort` is enabled by default)

## License

Expand Down
2 changes: 2 additions & 0 deletions build_system/abi_cafe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub(crate) fn run(
cg_clif_dylib: &CodegenBackend,
rustup_toolchain_name: Option<&str>,
bootstrap_host_compiler: &Compiler,
panic_unwind_support: bool,
) {
std::fs::create_dir_all(&dirs.download_dir).unwrap();
ABI_CAFE_REPO.fetch(dirs);
Expand All @@ -32,6 +33,7 @@ pub(crate) fn run(
bootstrap_host_compiler,
rustup_toolchain_name,
bootstrap_host_compiler.triple.clone(),
panic_unwind_support,
);

eprintln!("Running abi-cafe");
Expand Down
5 changes: 5 additions & 0 deletions build_system/build_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub(crate) fn build_backend(
dirs: &Dirs,
bootstrap_host_compiler: &Compiler,
use_unstable_features: bool,
panic_unwind_support: bool,
) -> PathBuf {
let _group = LogGroup::guard("Build backend");

Expand All @@ -31,6 +32,10 @@ pub(crate) fn build_backend(
cmd.arg("--features").arg("unstable-features");
}

if panic_unwind_support {
cmd.arg("--features").arg("unwinding");
}

cmd.arg("--release");

eprintln!("[BUILD] rustc_codegen_cranelift");
Expand Down
17 changes: 15 additions & 2 deletions build_system/build_sysroot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub(crate) fn build_sysroot(
bootstrap_host_compiler: &Compiler,
rustup_toolchain_name: Option<&str>,
target_triple: String,
panic_unwind_support: bool,
) -> Compiler {
let _guard = LogGroup::guard("Build sysroot");

Expand Down Expand Up @@ -52,6 +53,9 @@ pub(crate) fn build_sysroot(
.arg("-o")
.arg(&wrapper_path)
.arg("-Cstrip=debuginfo");
if panic_unwind_support {
build_cargo_wrapper_cmd.arg("--cfg").arg("support_panic_unwind");
}
if let Some(rustup_toolchain_name) = &rustup_toolchain_name {
build_cargo_wrapper_cmd
.env("TOOLCHAIN_NAME", rustup_toolchain_name)
Expand All @@ -77,6 +81,7 @@ pub(crate) fn build_sysroot(
bootstrap_host_compiler.clone(),
&cg_clif_dylib_path,
sysroot_kind,
panic_unwind_support,
);
host.install_into_sysroot(dist_dir);

Expand All @@ -91,6 +96,7 @@ pub(crate) fn build_sysroot(
},
&cg_clif_dylib_path,
sysroot_kind,
panic_unwind_support,
)
.install_into_sysroot(dist_dir);
}
Expand Down Expand Up @@ -141,12 +147,15 @@ fn build_sysroot_for_triple(
compiler: Compiler,
cg_clif_dylib_path: &CodegenBackend,
sysroot_kind: SysrootKind,
panic_unwind_support: bool,
) -> SysrootTarget {
match sysroot_kind {
SysrootKind::None => build_rtstartup(dirs, &compiler)
.unwrap_or(SysrootTarget { triple: compiler.triple, libs: vec![] }),
SysrootKind::Llvm => build_llvm_sysroot_for_triple(compiler),
SysrootKind::Clif => build_clif_sysroot_for_triple(dirs, compiler, cg_clif_dylib_path),
SysrootKind::Clif => {
build_clif_sysroot_for_triple(dirs, compiler, cg_clif_dylib_path, panic_unwind_support)
}
}
}

Expand Down Expand Up @@ -188,6 +197,7 @@ fn build_clif_sysroot_for_triple(
dirs: &Dirs,
mut compiler: Compiler,
cg_clif_dylib_path: &CodegenBackend,
panic_unwind_support: bool,
) -> SysrootTarget {
let mut target_libs = SysrootTarget { triple: compiler.triple.clone(), libs: vec![] };

Expand All @@ -206,7 +216,10 @@ fn build_clif_sysroot_for_triple(
}

// Build sysroot
let mut rustflags = vec!["-Zforce-unstable-if-unmarked".to_owned(), "-Cpanic=abort".to_owned()];
let mut rustflags = vec!["-Zforce-unstable-if-unmarked".to_owned()];
if !panic_unwind_support {
rustflags.push("-Cpanic=abort".to_owned());
}
match cg_clif_dylib_path {
CodegenBackend::Local(path) => {
rustflags.push(format!("-Zcodegen-backend={}", path.to_str().unwrap()));
Expand Down
7 changes: 7 additions & 0 deletions build_system/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ fn main() {
let mut download_dir = None;
let mut sysroot_kind = SysrootKind::Clif;
let mut use_unstable_features = true;
let mut panic_unwind_support = false;
let mut frozen = false;
let mut skip_tests = vec![];
let mut use_backend = None;
Expand All @@ -108,6 +109,7 @@ fn main() {
}
}
"--no-unstable-features" => use_unstable_features = false,
"--panic-unwind-support" => panic_unwind_support = true,
"--frozen" => frozen = true,
"--skip-test" => {
// FIXME check that all passed in tests actually exist
Expand Down Expand Up @@ -201,6 +203,7 @@ fn main() {
&dirs,
&bootstrap_host_compiler,
use_unstable_features,
panic_unwind_support,
))
};
match command {
Expand All @@ -212,6 +215,7 @@ fn main() {
&dirs,
sysroot_kind,
use_unstable_features,
panic_unwind_support,
&skip_tests.iter().map(|test| &**test).collect::<Vec<_>>(),
&cg_clif_dylib,
&bootstrap_host_compiler,
Expand All @@ -230,6 +234,7 @@ fn main() {
&cg_clif_dylib,
rustup_toolchain_name.as_deref(),
&bootstrap_host_compiler,
panic_unwind_support,
);
}
Command::Build => {
Expand All @@ -240,6 +245,7 @@ fn main() {
&bootstrap_host_compiler,
rustup_toolchain_name.as_deref(),
target_triple,
panic_unwind_support,
);
}
Command::Bench => {
Expand All @@ -250,6 +256,7 @@ fn main() {
&bootstrap_host_compiler,
rustup_toolchain_name.as_deref(),
target_triple,
panic_unwind_support,
);
bench::benchmark(&dirs, &compiler);
}
Expand Down
21 changes: 19 additions & 2 deletions build_system/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ pub(crate) fn run_tests(
dirs: &Dirs,
sysroot_kind: SysrootKind,
use_unstable_features: bool,
panic_unwind_support: bool,
skip_tests: &[&str],
cg_clif_dylib: &CodegenBackend,
bootstrap_host_compiler: &Compiler,
Expand All @@ -251,12 +252,14 @@ pub(crate) fn run_tests(
bootstrap_host_compiler,
rustup_toolchain_name,
target_triple.clone(),
panic_unwind_support,
);

let runner = TestRunner::new(
dirs.clone(),
target_compiler,
use_unstable_features,
panic_unwind_support,
skip_tests,
bootstrap_host_compiler.triple == target_triple,
stdlib_source.clone(),
Expand All @@ -283,12 +286,14 @@ pub(crate) fn run_tests(
bootstrap_host_compiler,
rustup_toolchain_name,
target_triple.clone(),
panic_unwind_support,
);

let mut runner = TestRunner::new(
dirs.clone(),
target_compiler,
use_unstable_features,
panic_unwind_support,
skip_tests,
bootstrap_host_compiler.triple == target_triple,
stdlib_source,
Expand All @@ -314,6 +319,7 @@ pub(crate) fn run_tests(
struct TestRunner<'a> {
is_native: bool,
jit_supported: bool,
panic_unwind_support: bool,
skip_tests: &'a [&'a str],
dirs: Dirs,
target_compiler: Compiler,
Expand All @@ -325,6 +331,7 @@ impl<'a> TestRunner<'a> {
dirs: Dirs,
mut target_compiler: Compiler,
use_unstable_features: bool,
panic_unwind_support: bool,
skip_tests: &'a [&'a str],
is_native: bool,
stdlib_source: PathBuf,
Expand All @@ -335,7 +342,15 @@ impl<'a> TestRunner<'a> {
let jit_supported =
use_unstable_features && is_native && !target_compiler.triple.contains("windows");

Self { is_native, jit_supported, skip_tests, dirs, target_compiler, stdlib_source }
Self {
is_native,
jit_supported,
panic_unwind_support,
skip_tests,
dirs,
target_compiler,
stdlib_source,
}
}

fn run_testsuite(&self, tests: &[TestCase]) {
Expand Down Expand Up @@ -404,7 +419,9 @@ impl<'a> TestRunner<'a> {
cmd.arg("-Cdebuginfo=2");
cmd.arg("--target");
cmd.arg(&self.target_compiler.triple);
cmd.arg("-Cpanic=abort");
if !self.panic_unwind_support {
cmd.arg("-Cpanic=abort");
}
cmd.arg("--check-cfg=cfg(jit)");
cmd.args(args);
cmd
Expand Down
4 changes: 4 additions & 0 deletions build_system/usage.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ OPTIONS:
Some features are not yet ready for production usage. This option will disable these
features. This includes the JIT mode and inline assembly support.

--panic-unwind-support
Enable support for unwinding when -Cpanic=unwind is used. This currently regresses build
performance.

--frozen
Require Cargo.lock and cache are up to date

Expand Down
6 changes: 5 additions & 1 deletion scripts/cargo-clif.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ fn main() {
sysroot = sysroot.parent().unwrap();
}

let mut rustflags = vec!["-Cpanic=abort".to_owned(), "-Zpanic-abort-tests".to_owned()];
let mut rustflags = vec![];
if !cfg!(support_panic_unwind) {
rustflags.push("-Cpanic=abort".to_owned());
rustflags.push("-Zpanic-abort-tests".to_owned());
}
if let Some(name) = option_env!("BUILTIN_BACKEND") {
rustflags.push(format!("-Zcodegen-backend={name}"));
} else {
Expand Down
6 changes: 4 additions & 2 deletions scripts/rustc-clif.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ fn main() {

let passed_args = std::env::args_os().skip(1).collect::<Vec<_>>();
let mut args = vec![];
args.push(OsString::from("-Cpanic=abort"));
args.push(OsString::from("-Zpanic-abort-tests"));
if !cfg!(support_panic_unwind) {
args.push(OsString::from("-Cpanic=abort"));
args.push(OsString::from("-Zpanic-abort-tests"));
}
if let Some(name) = option_env!("BUILTIN_BACKEND") {
args.push(OsString::from(format!("-Zcodegen-backend={name}")))
} else {
Expand Down
6 changes: 4 additions & 2 deletions scripts/rustdoc-clif.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ fn main() {

let passed_args = std::env::args_os().skip(1).collect::<Vec<_>>();
let mut args = vec![];
args.push(OsString::from("-Cpanic=abort"));
args.push(OsString::from("-Zpanic-abort-tests"));
if !cfg!(support_panic_unwind) {
args.push(OsString::from("-Cpanic=abort"));
args.push(OsString::from("-Zpanic-abort-tests"));
}
if let Some(name) = option_env!("BUILTIN_BACKEND") {
args.push(OsString::from(format!("-Zcodegen-backend={name}")))
} else {
Expand Down
Loading