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

Rollup of 15 pull requests #122338

Merged
merged 50 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
a03d19e
Allow targets to override default codegen backend
WaffleLapkin Feb 14, 2024
5441523
Refactor out a repeating pattern with `get_or_default_sysroot`
WaffleLapkin Feb 15, 2024
9a77ec9
Rename `-Zno_parallel_llvm` -> `-Zno_parallel_backend`
WaffleLapkin Feb 15, 2024
f368922
Allow codegen backends to opt-out of parallel codegen
WaffleLapkin Feb 15, 2024
8bb49e2
Propagate the resolved type of assoc const bindings via query feeding
fmease Dec 31, 2023
6d115f5
Refactor out another repeating pattern
WaffleLapkin Feb 18, 2024
b94498a
Use existing query feeding workarounds
oli-obk Feb 21, 2024
3908a93
std support for wasm32 panic=unwind
coolreader18 Feb 21, 2024
861c7e7
Fix llvm hang
coolreader18 Feb 22, 2024
658a0a2
Unconditionally pass -wasm-enable-eh
coolreader18 Feb 22, 2024
125b26a
Use Itanium ABI for thrown exceptions
coolreader18 Feb 22, 2024
c7fcf43
Don't codegen wasm.throw unless with -Zbuild-std
coolreader18 Feb 26, 2024
858d336
Slightly simplify feeding of assoc const eq bounds
fmease Feb 23, 2024
d9a2886
add comment and test: we do not do value-based reasoning for promotio…
RalfJung Feb 29, 2024
30fa6a8
Rename `DropTreeBuilder::add_entry` to `link_entry_point`
Zalathar Mar 6, 2024
3bd8df9
Assert that `link_entry_point` sees the expected dummy terminator
Zalathar Mar 6, 2024
fbdac30
Rename `DropTree::add_entry` to `add_entry_point`
Zalathar Mar 6, 2024
5ba70bd
Replace tuples in `DropTree` with named structs
Zalathar Mar 6, 2024
d673fd8
Remove the unused `field_remapping` field from `TypeLowering`
beetrees Mar 8, 2024
bf47df8
interpret: do not call machine read hooks during validation
RalfJung Mar 9, 2024
58f6aaa
Improve diagnostics for parenthesized type arguments
wutchzone Mar 7, 2024
3830510
Ignore tests w/ current/next revisions from compare-mode=next-solver
compiler-errors Mar 11, 2024
a7cd803
use ptradd for vtable indexing
erikdesjardins Mar 11, 2024
73fc170
Store backtrace for must_produce_diag
compiler-errors Mar 10, 2024
01e6b43
Mark some next-solver-behavior tests explicitly with revisions
compiler-errors Mar 11, 2024
aea60b0
unix_sigpipe: Replace `inherit` with `sig_dfl` in syntax tests
Enselic Feb 9, 2024
816dc96
bootstrap readme: fix, improve, update
tshepang Mar 11, 2024
ed252e9
LLVM_TOOLS: Include llvm-link as a llvm tool
Oct 26, 2023
222ce4f
LLVM Bitcode Linker: Added crate
Feb 6, 2024
af42d2a
NVPTX: Enable self-contained for the nvptx target
Dec 1, 2023
43f2055
LLVM Bitcode Linker: Add as a linker known to the compiler
Feb 6, 2024
6a50d05
Bootstrap: Add argument for building llvm bitcode linker
Feb 6, 2024
843dd28
NVPTX: Enable previously disabled tests
Mar 4, 2024
279465b
const-checking: add some corner case tests, and fix some nits
RalfJung Mar 2, 2024
fb802f2
promote-not: add test that distinguishes promotion from outer scope rule
RalfJung Mar 11, 2024
88d387b
Rollup merge of #116791 - WaffleLapkin:unparallel-backends, r=oli-obk
workingjubilee Mar 11, 2024
86af4d2
Rollup merge of #116793 - WaffleLapkin:target_rules_the_backend, r=cj…
workingjubilee Mar 11, 2024
e1ceadc
Rollup merge of #117458 - kjetilkjeka:embedded-linker, r=petrochenkov
workingjubilee Mar 11, 2024
a450339
Rollup merge of #119385 - fmease:assoc-const-eq-fixes-2, r=oli-obk,cj…
workingjubilee Mar 11, 2024
1279830
Rollup merge of #121438 - coolreader18:wasm32-panic-unwind, r=cuviper
workingjubilee Mar 11, 2024
9300fbb
Rollup merge of #121893 - RalfJung:const-interior-mut-tests, r=oli-obk
workingjubilee Mar 11, 2024
e3f9b2f
Rollup merge of #122080 - Zalathar:drop-tree, r=oli-obk
workingjubilee Mar 11, 2024
05ff86c
Rollup merge of #122152 - wutchzone:120892, r=fmease
workingjubilee Mar 11, 2024
afa0581
Rollup merge of #122166 - beetrees:remove-field-remapping, r=davidtwco
workingjubilee Mar 11, 2024
f6ca425
Rollup merge of #122249 - RalfJung:machine-read-hook, r=oli-obk
workingjubilee Mar 11, 2024
671fc18
Rollup merge of #122299 - compiler-errors:bt-for-must-diag, r=nnether…
workingjubilee Mar 11, 2024
a11e6c3
Rollup merge of #122318 - compiler-errors:next-solver-tests, r=lcnr
workingjubilee Mar 11, 2024
028e260
Rollup merge of #122320 - erikdesjardins:vtable, r=nikic
workingjubilee Mar 11, 2024
9aca5c0
Rollup merge of #122328 - Enselic:sig_dfl-not-inherit, r=davidtwco
workingjubilee Mar 11, 2024
7fa6fa4
Rollup merge of #122330 - tshepang:patch-1, r=clubby789
workingjubilee Mar 11, 2024
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
Prev Previous commit
Next Next commit
std support for wasm32 panic=unwind
  • Loading branch information
coolreader18 committed Feb 22, 2024
commit 3908a935ef821c2828a7d825eac859f8ff54702a
13 changes: 11 additions & 2 deletions compiler/rustc_codegen_llvm/src/llvm_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::errors::{
};
use crate::llvm;
use libc::c_int;
use rustc_codegen_ssa::base::wants_wasm_eh;
use rustc_codegen_ssa::traits::PrintBackendInfo;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::small_c_str::SmallCStr;
Expand Down Expand Up @@ -98,8 +99,12 @@ unsafe fn configure_llvm(sess: &Session) {
}
}

if sess.target.os == "emscripten" && sess.panic_strategy() == PanicStrategy::Unwind {
add("-enable-emscripten-cxx-exceptions", false);
if sess.panic_strategy() == PanicStrategy::Unwind {
if sess.target.os == "emscripten" {
add("-enable-emscripten-cxx-exceptions", false);
} else if wants_wasm_eh(sess) {
add("-wasm-enable-eh", false);
}
}

// HACK(eddyb) LLVM inserts `llvm.assume` calls to preserve align attributes
Expand Down Expand Up @@ -520,6 +525,10 @@ pub(crate) fn global_llvm_features(sess: &Session, diagnostics: bool) -> Vec<Str
.map(String::from),
);

if wants_wasm_eh(sess) && sess.panic_strategy() == PanicStrategy::Unwind {
features.push("+exception-handling".into());
}

// -Ctarget-features
let supported_features = sess.target.supported_target_features();
let mut featsmap = FxHashMap::default();
Expand Down
13 changes: 12 additions & 1 deletion library/panic_unwind/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
#![doc(issue_tracker_base_url = "https://github.com/rust-lang/rust/issues/")]
#![feature(core_intrinsics)]
#![feature(lang_items)]
#![cfg_attr(
all(target_family = "wasm", not(target_os = "emscripten")),
feature(link_llvm_intrinsics)
)]
#![feature(panic_unwind)]
#![feature(staged_api)]
#![feature(std_internals)]
Expand Down Expand Up @@ -56,9 +60,16 @@ cfg_if::cfg_if! {
))] {
#[path = "gcc.rs"]
mod real_imp;
} else if #[cfg(all(target_family = "wasm", panic = "unwind"))] {
// for now, PanicStrategy::Unwind is not the default for wasm targets,
// so we need the panic = "unwind" in the cfg above. to use llvm.wasm.throw,
// we need to pass -wasm-enable-eh to LLVM, but that only happens if rustc
// is compiling with -C panic=unwind. So, this lets us -Zbuild-std with
// panic=unwind, while keeping the default panic=abort working.
#[path = "wasm.rs"]
mod real_imp;
} else {
// Targets that don't support unwinding.
// - family=wasm
// - os=none ("bare metal" targets)
// - os=uefi
// - os=espidf
Expand Down
32 changes: 32 additions & 0 deletions library/panic_unwind/src/wasm.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//! Unwinding panics for wasm32.
use alloc::boxed::Box;
use core::any::Any;

// The type of the exception payload that the wasm engine propagates
// through unwinding for us. LLVM requires that it be a thin pointer.
type Payload = Box<Box<dyn Any + Send>>;

extern "C" {
/// LLVM lowers this intrinsic to the `throw` instruction.
#[link_name = "llvm.wasm.throw"]
fn wasm_throw(tag: i32, ptr: *mut u8) -> !;
}

pub unsafe fn panic(payload: Box<dyn Any + Send>) -> u32 {
// The payload we pass to `wasm_throw` will be exactly the argument we get
// in `cleanup` below. So we just box it up once, to get something pointer-sized.
let payload_box: Payload = Box::new(payload);
// The wasm `throw` instruction takes a "tag", which differentiates certain
// types of exceptions from others. LLVM currently just identifies these
// via integers, with 0 corresponding to C++ exceptions and 1 to C setjmp()/longjmp().
// Ideally, we'd be able to choose something unique for Rust, such that we
// don't try to treat a C++ exception payload as a `Box<Box<dyn Any>>`, but
// otherwise, pretending to be C++ works for now.
wasm_throw(0, Box::into_raw(payload_box) as *mut u8)
}

pub unsafe fn cleanup(payload_box: *mut u8) -> Box<dyn Any + Send> {
// Recover the underlying `Box`.
let payload_box: Payload = Box::from_raw(payload_box as *mut _);
*payload_box
}
8 changes: 4 additions & 4 deletions library/std/src/sys/personality/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ mod dwarf;
cfg_if::cfg_if! {
if #[cfg(target_os = "emscripten")] {
mod emcc;
} else if #[cfg(target_env = "msvc")] {
} else if #[cfg(any(target_env = "msvc", target_family = "wasm"))] {
// This is required by the compiler to exist (e.g., it's a lang item),
// but it's never actually called by the compiler because
// _CxxFrameHandler3 is the personality function that is always used.
// Hence this is just an aborting stub.
// __CxxFrameHandler3 (msvc) / __gxx_wasm_personality_v0 (wasm) is the
// personality function that is always used. Hence this is just an
// aborting stub.
#[lang = "eh_personality"]
fn rust_eh_personality() {
core::intrinsics::abort()
Expand All @@ -36,7 +37,6 @@ cfg_if::cfg_if! {
mod gcc;
} else {
// Targets that don't support unwinding.
// - family=wasm
// - os=none ("bare metal" targets)
// - os=uefi
// - os=espidf
Expand Down