about summary refs log tree commit diff
path: root/library/unwind/src/lib.rs
AgeCommit message (Collapse)AuthorLines
2025-08-16library: Migrate from `cfg_if` to `cfg_select`Josh Triplett-24/+37
Migrate the standard library from using the external `cfg_if` crate to using the now-built-in `cfg_select` macro. This does not yet eliminate the dependency from `library/std/Cargo.toml`, because while the standard library itself no longer uses `cfg_if`, it also incorporates the `backtrace` crate, which does. Migration assisted by the following vim command (after selecting the full `cfg_if!` invocation): ``` '<,'>s/\(cfg_if::\)\?cfg_if/cfg_select/ | '<,'>s/^\( *\)} else {/\1}\r\1_ => {/c | '<,'>s/^\( *\)} else if #\[cfg(\(.*\))\] /\1}\r\1\2 => /e | '<,'>s/if #\[cfg(\(.*\))\] {/\1 => {/e ``` This is imperfect, but substantially accelerated the process. This prompts for confirmation on the `} else {` since that can also appear inside one of the arms. This also requires manual intervention to handle any multi-line conditions.
2025-02-18update `cfg(bootstrap)`Josh Stone-1/+1
2025-02-14unwind: Apply unsafe_op_in_unsafe_fnEric Huss-0/+1
2025-02-09Mark extern blocks as unsafeMichael Goulet-23/+23
2025-01-06Rollup merge of #131830 - hoodmane:emscripten-wasm-eh, r=workingjubileeJacob Pratt-1/+2
Add support for wasm exception handling to Emscripten target This is a draft because we need some additional setting for the Emscripten target to select between the old exception handling and the new exception handling. I don't know how to add a setting like that, would appreciate advice from Rust folks. We could maybe choose to use the new exception handling if `Ctarget-feature=+exception-handling` is passed? I tried this but I get errors from llvm so I'm not doing it right.
2025-01-06Add support for wasm exception handling to Emscripten targetHood Chatham-1/+2
Gated behind an unstable `-Z emscripten-wasm-eh` flag
2025-01-03Rollup merge of #133420 - thesummer:rtems-unwind, r=workingjubileeMatthias Krüger-1/+0
Switch rtems target to panic unwind Switch the RTEMS target to `panic_unwind`. Relates to https://github.com/rust-lang/backtrace-rs/pull/682
2024-12-12Rollup merge of #122003 - mati865:gnullvm-build-libunwind, r=petrochenkovMatthias Krüger-0/+5
link libunwind dynamically and allow controlling it via `crt-static` on gnullvm targets Alternative to https://github.com/rust-lang/rust/pull/121794 ``` $ cargo b -r Finished `release` profile [optimized] target(s) in 0.38s $ ntldd target/release/hello.exe | rg unwind libunwind.dll => H:\msys64\clang64\bin\libunwind.dll (0x0000020c35df0000) $ RUSTFLAGS="-C target-feature=+crt-static" cargo b -r Finished `release` profile [optimized] target(s) in 0.23s $ ntldd target/release/hello.exe | rg unwind ```
2024-11-30Switch rtems target to panic unwindJan Sommer-1/+0
2024-10-21move strict provenance lints to new feature gate, remove old feature gatesRalf Jung-1/+0
2024-10-08Use throw intrinsic from stdarch in wasm libunwindNoa-2/+1
2024-10-03control libunwind linkage mode via `crt-static` on gnullvm targetsMateusz Mikuła-0/+5
Co-authored-by: Kleis Auke Wolthuizen <github@kleisauke.nl>
2024-09-24Initial std library support for NuttXHuang Qi-0/+1
Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2024-09-03Port std library to RTEMSJan Sommer-0/+1
2024-08-30Squashed `aarch64_unknown_nto_qnx700` supportYuri Astrakhan-2/+9
2024-07-28step cfg(bootstrap)Mark Rousskov-1/+0
2024-06-19Stabilise c_unwindGary Guo-1/+1
2024-04-14Replace libc::c_int with core::ffi::c_intChris Denton-0/+4
And remove the libc crate when it isn't needed
2024-03-20Fix compile of wasm64-unknown-unknown targetAlex Crichton-0/+1
This target is a Tier 3 target so it's not tested on CI, and it's broken since last used so this commit fixes a small unwind-related issue that cropped up in the meantime.
2024-03-20step cfgsMark Rousskov-1/+0
2024-03-11Rollup merge of #121438 - coolreader18:wasm32-panic-unwind, r=cuviperJubilee-1/+7
std support for wasm32 panic=unwind Tracking issue: #118168 This adds std support for `-Cpanic=unwind` on wasm, and with it slightly more fleshed out rustc support. Now, the stable default is still panic=abort without exception-handling, but if you `-Zbuild-std` with `RUSTFLAGS=-Cpanic=unwind`, you get wasm exception-handling try/catch blocks in the binary: ```rust #[no_mangle] pub fn foo_bar(x: bool) -> *mut u8 { let s = Box::<str>::from("hello"); maybe_panic(x); Box::into_raw(s).cast() } #[inline(never)] #[no_mangle] fn maybe_panic(x: bool) { if x { panic!("AAAAA"); } } ``` ```wat ;; snip... (try $label$5 (do (call $maybe_panic (local.get $0) ) (br $label$1) ) (catch_all (global.set $__stack_pointer (local.get $1) ) (call $__rust_dealloc (local.get $2) (i32.const 5) (i32.const 1) ) (rethrow $label$5) ) ) ;; snip... ```
2024-02-24Stabilize `cfg_target_abi`Chris Denton-1/+1
2024-02-22Use Itanium ABI for thrown exceptionsNoa-1/+7
2024-01-11Enable Static Builds for FreeBSDNathan Reller-1/+7
Enable crt-static for FreeBSD to enable statically compiled binaries.
2023-11-16unwind: add support for using `unwinding` crateSean Cross-0/+3
The `unwinding` crate supports processing unwinding data, and is written entirely in Rust. This allows it to be ported to new platforms more easily than using the llvm-based `libunwind`. While `libunwind` is very well supported on major targets, it is difficult to use on other targets. SGX is an example of this where Rust carries custom patches in order to enable backtrace support. This adds an alternative for supported architectures. Rather than providing a custom target, `unwinding` allows for a solution that is completely written in Rust. This adds `xous` as the first consumer, and forthcoming patches will modify libstd to take advantage of this. Signed-off-by: Sean Cross <sean@xobs.io>
2023-11-02Remove obsolete support for linking unwinder on AndroidPeter Collingbourne-5/+1
Linking libgcc is no longer supported (see #103673), so remove the related link attributes and the check in unwind's build.rs. The check was the last remaining significant piece of logic in build.rs, so remove build.rs as well.
2023-10-10Use pointers instead of `usize` addresses for landing padsniluxv-0/+1
This bring unwind and personality code more in line with strict-provenance
2023-10-09Support AIX in Rust standard libraryQiu Chaofan-0/+4
2023-09-21added support for GNU/HurdSamuel Thibault-0/+4
2023-08-23Bump cfg(bootstrap)Mark Rousskov-1/+1
2023-08-03Add `internal_features` lintNilstrieb-0/+1
It lints against features that are inteded to be internal to the compiler and standard library. Implements MCP #596. We allow `internal_features` in the standard library and compiler as those use many features and this _is_ the standard library from the "internal to the compiler and standard library" after all. Marking some features as internal wasn't exactly the most scientific approach, I just marked some mostly obvious features. While there is a categorization in the macro, it's not very well upheld (should probably be fixed in another PR). We always pass `-Ainternal_features` in the testsuite About 400 UI tests and several other tests use internal features. Instead of throwing the attribute on each one, just always allow them. There's nothing wrong with testing internal features^^
2023-03-28Add OpenHarmony targetsAmanieu d'Antras-0/+16
- `aarch64-unknown-linux-ohos` - `armv7-unknown-linux-ohos`
2023-02-28Add QNX Neutrino support to libstdFlorian Bartels-0/+4
Co-authored-by: gh-tr <troach@qnx.com>
2022-11-14Move most of unwind's build script to lib.rsbjorn3-0/+24
Only the android libunwind detection remains in the build script * Reduces dependence on build scripts for building the standard library * Reduces dependence on exact target names in favor of using semantic cfg(target_*) usage. * Keeps almost all code related to linking of the unwinder in one file
2022-11-13Auto merge of #103894 - mati865:gnullvm-libunwind-changes, r=thomccbors-4/+0
Change the way libunwind is linked for *-windows-gnullvm targets I have no idea why previous way works for `x86_64-fortanix-unknown-sgx` (assuming it actually works...) but not for `gnullvm`. It fails when linking libtest during Rust build (unless somebody adds `RUSTFLAGS='-Clinkarg=-lunwind'`). Also fixes exception handling on AArch64.
2022-11-05Remove linuxkernel targetsAlex Gaynor-1/+0
These are not used by the actual Rust-for-Linux project, so they're mostly just confusing.
2022-11-01Change the way libunwind is linked for `*-windows-gnullvm` targetsMateusz Mikuła-4/+0
2022-08-10add crt-static for androidBryanskiy-0/+20
2022-07-01update cfg(bootstrap)sPietro Albini-1/+0
2022-06-09Stabilize the `bundle` native library modifierVadim Petrochenkov-1/+1
2022-06-03Fully stabilize NLLJack Huey-1/+0
2022-05-13Add LLVM based mingw-w64 targetsMateusz Mikuła-0/+5
2022-04-05trivial cfg(bootstrap) changesPietro Albini-1/+0
2022-03-30Stabilize native library modifier syntax and the `whole-archive` modifier ↵Vadim Petrochenkov-1/+1
specifically
2021-10-23Repace use of `static_nobundle` with `native_link_modifiers`Mateusz Mikuła-1/+0
This fixes warning when building Rust and running tests: ``` warning: library kind `static-nobundle` has been superseded by specifying `-bundle` on library kind `static`. Try `static:-bundle` warning: `rustc_llvm` (lib) generated 2 warnings (1 duplicate) ```
2021-10-06Add new target armv7-unknown-linux-uclibceabihfYannick Koehler-2/+2
Co-authored-by: Jonah Petri <jonah@petri.us>
2021-09-28Add SOLID targetsTomoaki Kawada-0/+1
SOLID[1] is an embedded development platform provided by Kyoto Microcomputer Co., Ltd. This commit introduces a basic Tier 3 support for SOLID. # New Targets The following targets are added: - `aarch64-kmc-solid_asp3` - `armv7a-kmc-solid_asp3-eabi` - `armv7a-kmc-solid_asp3-eabihf` SOLID's target software system can be divided into two parts: an RTOS kernel, which is responsible for threading and synchronization, and Core Services, which provides filesystems, networking, and other things. The RTOS kernel is a μITRON4.0[2][3]-derived kernel based on the open-source TOPPERS RTOS kernels[4]. For uniprocessor systems (more precisely, systems where only one processor core is allocated for SOLID), this will be the TOPPERS/ASP3 kernel. As μITRON is traditionally only specified at the source-code level, the ABI is unique to each implementation, which is why `asp3` is included in the target names. More targets could be added later, as we support other base kernels (there are at least three at the point of writing) and are interested in supporting other processor architectures in the future. # C Compiler Although SOLID provides its own supported C/C++ build toolchain, GNU Arm Embedded Toolchain seems to work for the purpose of building Rust. # Unresolved Questions A μITRON4 kernel can support `Thread::unpark` natively, but it's not used by this commit's implementation because the underlying kernel feature is also used to implement `Condvar`, and it's unclear whether `std` should guarantee that parking tokens are not clobbered by other synchronization primitives. # Unsupported or Unimplemented Features Most features are implemented. The following features are not implemented due to the lack of native support: - `fs::File::{file_attr, truncate, duplicate, set_permissions}` - `fs::{symlink, link, canonicalize}` - Process creation - Command-line arguments Backtrace generation is not really a good fit for embedded targets, so it's intentionally left unimplemented. Unwinding is functional, however. ## Dynamic Linking Dynamic linking is not supported. The target platform supports dynamic linking, but enabling this in Rust causes several problems. - The linker invocation used to build the shared object of `std` is too long for the platform-provided linker to handle. - A linker script with specific requirements is required for the compiled shared object to be actually loadable. As such, we decided to disable dynamic linking for now. Regardless, the users can try to create shared objects by manually invoking the linker. ## Executable Building an executable is not supported as the notion of "executable files" isn't well-defined for these targets. [1] https://solid.kmckk.com/SOLID/ [2] http://ertl.jp/ITRON/SPEC/mitron4-e.html [3] https://en.wikipedia.org/wiki/ITRON_project [4] https://toppers.jp/
2021-08-28build llvm libunwind.a in rustbuild12101111-5/+7
2021-08-10STD support for the ESP-IDF frameworkivmarkov-0/+1
2021-08-03rustc: Fill out remaining parts of C-unwind ABIAlex Crichton-1/+1
This commit intends to fill out some of the remaining pieces of the C-unwind ABI. This has a number of other changes with it though to move this design space forward a bit. Notably contained within here is: * On `panic=unwind`, the `extern "C"` ABI is now considered as "may unwind". This fixes a longstanding soundness issue where if you `panic!()` in an `extern "C"` function defined in Rust that's actually UB because the LLVM representation for the function has the `nounwind` attribute, but then you unwind. * Whether or not a function unwinds now mainly considers the ABI of the function instead of first checking the panic strategy. This fixes a miscompile of `extern "C-unwind"` with `panic=abort` because that ABI can still unwind. * The aborting stub for non-unwinding ABIs with `panic=unwind` has been reimplemented. Previously this was done as a small tweak during MIR generation, but this has been moved to a separate and dedicated MIR pass. This new pass will, for appropriate functions and function calls, insert a `cleanup` landing pad for any function call that may unwind within a function that is itself not allowed to unwind. Note that this subtly changes some behavior from before where previously on an unwind which was caught-to-abort it would run active destructors in the function, and now it simply immediately aborts the process. * The `#[unwind]` attribute has been removed and all users in tests and such are now using `C-unwind` and `#![feature(c_unwind)]`. I think this is largely the last piece of the RFC to implement. Unfortunately I believe this is still not stabilizable as-is because activating the feature gate changes the behavior of the existing `extern "C"` ABI in a way that has no replacement. My thinking for how to enable this is that we add support for the `C-unwind` ABI on stable Rust first, and then after it hits stable we change the behavior of the `C` ABI. That way anyone straddling stable/beta/nightly can switch to `C-unwind` safely.