about summary refs log tree commit diff
path: root/library/std/src/rt.rs
AgeCommit message (Collapse)AuthorLines
2025-09-21Change the cfg to a dashBen Kimock-2/+2
2025-09-21Add panic=immediate-abortBen Kimock-2/+2
2025-09-20Fix old typo in lang_start_internal commentBen Kimock-1/+1
2025-05-15deduplicate abort implementationsjoboet-1/+8
Currently, the code for process aborts is duplicated across `panic_abort` and `std`. This PR uses `#[rustc_std_internal_symbol]` to make the `std` implementation available to `panic_abort` via the linker, thereby deduplicating the code.
2025-04-18rtprintpanic: clarify that the error is aborting the processLieselotte-1/+1
2025-01-20Rollup merge of #135446 - klensy:panic_immediate_abort_ext, r=Mark-Simulacrum许杰友 Jieyou Xu (Joe)-0/+5
further improve panic_immediate_abort by removing rtprintpanic! messages Reduces binary size using `panic_immediate_abort` by removing strings used by `rtprintpanic!`. for `main.rs` ```rust fn main() { println!("Hello, world!"); } ``` with `Cargo.toml` ```toml [package] name = "tst" version = "0.1.0" edition = "2024" [dependencies] [profile.release] lto = true codegen-units = 1 panic = "abort" ``` and build with `RUSTFLAGS="-Zlocation-detail=none -Zfmt-debug=none" cargo +stage-1 b -r -Z build-std=std,panic_abort -Z build-std-features=optimize_for_size,panic_immediate_abort` for `x86_64-unknown-linux-gnu` This reduces size: | before | after | type | | - | - | - | | 25256 | 21880 | unstripped | | 18072 | 15288 | stripped |
2025-01-14std: lazily allocate the main thread handlejoboet-19/+4
Thereby, we also allow accessing thread::current before main: as the runtime no longer tries to install its own handle, this will no longer trigger an abort. Rather, the name returned from name will only be "main" after the runtime initialization code has run, but I think that is acceptable. This new approach also requires some changes to the signal handling code, as calling `thread::current` would now allocate when called on the main thread, which is not acceptable. I fixed this by adding a new function (`with_current_name`) that performs all the naming logic without allocation or without initializing the thread ID (which could allocate on some platforms).
2025-01-14Revert "Remove the Arc rt::init allocation for thread info"joboet-1/+1
This reverts commit 0747f2898e83df7e601189c0f31762e84328becb.
2025-01-13further improve panic_immediate_abort by removing rtprintpanic messagesklensy-0/+5
2025-01-11avoid nesting the user-defined main so deeply on the stackRalf Jung-12/+17
2025-01-11use a single large catch_unwind in lang_startRalf Jung-14/+22
2024-10-19Remove the Arc rt::init allocation for thread infoGnomedDev-1/+1
2024-10-12std: fix stdout-before-mainjoboet-3/+18
Fixes #130210. Since #124881, `ReentrantLock` uses `ThreadId` to identify threads. This has the unfortunate consequence of breaking uses of `Stdout` before main: Locking the `ReentrantLock` that synchronizes the output will initialize the thread ID before the handle for the main thread is set in `rt::init`. But since that would overwrite the current thread ID, `thread::set_current` triggers an abort. This PR fixes the problem by using the already initialized thread ID for constructing the main thread handle and allowing `set_current` calls that do not change the thread's ID.
2024-10-02std: make `thread::current` available in all `thread_local!` destructorsjoboet-9/+25
2024-08-31Fixed some typos in the standard library documentation/commentsranger-ross-1/+1
2024-07-19Use `#[rustfmt::skip]` on some `use` groups to prevent reordering.Nicholas Nethercote-0/+2
`use` declarations will be reformatted in #125443. Very rarely, there is a desire to force a group of `use` declarations together in a way that auto-formatting will break up. E.g. when you want a single comment to apply to a group. #126776 dealt with all of these in the codebase, ensuring that no comments intended for multiple `use` declarations would end up in the wrong place. But some people were unhappy with it. This commit uses `#[rustfmt::skip]` to create these custom `use` groups in an idiomatic way for a few of the cases changed in #126776. This works because rustfmt treats any `use` item annotated with `#[rustfmt::skip]` as a barrier and won't reorder other `use` items around it.
2024-07-16Rollup merge of #126776 - nnethercote:rustfmt-use-pre-cleanups-2, r=cuviperTrevor Gross-1/+0
Clean up more comments near use declarations #125443 will reformat all use declarations in the repository. There are a few edge cases involving comments on use declarations that require care. This PR fixes them up so #125443 can go ahead with a simple `x fmt --all`. A follow-up to #126717. r? ``@cuviper``
2024-07-17Avoid comments that describe multiple `use` items.Nicholas Nethercote-1/+0
There are some comments describing multiple subsequent `use` items. When the big `use` reformatting happens some of these `use` items will be reordered, possibly moving them away from the comment. With this additional level of formatting it's not really feasible to have comments of this type. This commit removes them in various ways: - merging separate `use` items when appropriate; - inserting blank lines between the comment and the first `use` item; - outright deletion (for comments that are relatively low-value); - adding a separate "top-level" comment. We also entirely skip formatting for four library files that contain nothing but `pub use` re-exports, where reordering would be painful.
2024-07-14sys::init is not unsafe on teeosPavel Grigorenko-5/+6
2024-07-05Move exit guard from sys::common::exit_guard to sys::exit_guard.Zachary S-2/+1
2024-07-03Move unique_thread_exit call to lang_start_internal so it is not in a ↵Zachary S-3/+4
generic function, and wrap it in `catch_unwind`
2024-06-20On `target_os = "linux"`, ensure that only one Rust thread calls ↵Zachary S-0/+3
`libc::exit` or returns from `main`.
2024-06-16std: move `sys_common::backtrace` to `sys`joboet-1/+1
2024-05-02Change `SIGPIPE` ui from `#[unix_sigpipe = "..."]` to `-Zon-broken-pipe=...`Martin Nordholts-1/+1
In the stabilization attempt of `#[unix_sigpipe = "sig_dfl"]`, a concern was raised related to using a language attribute for the feature: Long term, we want `fn lang_start()` to be definable by any crate, not just libstd. Having a special language attribute in that case becomes awkward. So as a first step towards towards the next stabilization attempt, this PR changes the `#[unix_sigpipe = "..."]` attribute to a compiler flag `-Zon-broken-pipe=...` to remove that concern, since now the language is not "contaminated" by this feature. Another point was also raised, namely that the ui should not leak **how** it does things, but rather what the **end effect** is. The new flag uses the proposed naming. This is of course something that can be iterated on further before stabilization.
2024-04-04Remove rt::init allocation for thread nameDavid Thomas-3/+1
2024-04-01update commentjoboet-4/+1
2024-03-31std: move `thread::current` TLS variable out of `thread_info`joboet-4/+2
2023-12-15Cfg remove lang items in doctestCameron Steffen-1/+1
2023-12-14Fix cases where std accidentally relied on inline(never)Ben Kimock-1/+0
2023-10-17Automatically enable cross-crate inlining for small functionsBen Kimock-0/+1
2022-12-30Replace libstd, libcore, liballoc in line comments.jonathanCogan-3/+3
2022-10-20Change process spawning to inherit the parent's signal mask by defaultRain-1/+1
Previously, the signal mask is always reset when a child process is started. This breaks tools like `nohup` which expect `SIGHUP` to be blocked. With this change, the default behavior changes to inherit the signal mask. This also changes the signal disposition for `SIGPIPE` to only be changed if the `#[unix_sigpipe]` attribute isn't set.
2022-09-26remove cfg(bootstrap)Pietro Albini-4/+1
2022-09-01unix_sigpipe: Make `sigpipe` param docs long-formMartin Nordholts-2/+19
2022-08-31unix_sigpipe: Add docs for `init()` `sigpipe` paramMartin Nordholts-0/+2
2022-08-28Support `#[unix_sigpipe = "inherit|sig_dfl|sig_ign"]` on `fn main()`Martin Nordholts-3/+9
This makes it possible to instruct libstd to never touch the signal handler for `SIGPIPE`, which makes programs pipeable by default (e.g. with `./your-program | head -n 1`) without `ErrorKind::BrokenPipe` errors.
2022-01-28Change Termination::report return type to ExitCodeJane Lusby-1/+1
2021-10-31Rollup merge of #89068 - bjorn3:restructure_rt2, r=joshtriplettMatthias Krüger-2/+1
Restructure std::rt (part 2) A couple more cleanups on top of https://github.com/rust-lang/rust/pull/89011 Blocked on #89011
2021-10-19Deduplicate panic_fmtGary Guo-2/+2
std's begin_panic_fmt and core's panic_fmt are duplicates. Merge them to declutter code and remove a lang item.
2021-10-03Use rtabort! instead of rtprintpanic! + abort_internalbjorn3-2/+1
2021-09-29Auto merge of #89011 - bjorn3:restructure_rt, r=dtolnaybors-3/+85
Restructure std::rt These changes should reduce binary size slightly while at the same slightly improving performance of startup, thread spawning and `std::thread::current()`. I haven't verified if the compiler is able to optimize some of these cases already, but at least for some others the compiler is unable to do these optimizations as they slightly change behavior in cases where program startup would crash anyway by omitting a backtrace and panic location. I can remove 6f6bb16 if preferred.
2021-09-18Auto merge of #88988 - Mark-Simulacrum:avoid-into-ok, r=nagisabors-3/+3
Avoid codegen for Result::into_ok in lang_start This extra codegen seems to be the cause for the regressions in max-rss on #86034. While LLVM will certainly optimize the dead code away, avoiding it's generation in the first place seems good, particularly when it is so simple. #86034 produced this [diff](https://gist.github.com/Mark-Simulacrum/95c7599883093af3b960c35ffadf4dab#file-86034-diff) for a simple `fn main() {}`. With this PR, that diff [becomes limited to just a few extra IR instructions](https://gist.github.com/Mark-Simulacrum/95c7599883093af3b960c35ffadf4dab#file-88988-from-pre-diff) -- no extra functions. Note that these are pre-optimization; LLVM surely will eliminate this during optimization. However, that optimization can end up generating more work and bump memory usage, and this eliminates that.
2021-09-16Replace a couple of asserts with rtassert! in rt codebjorn3-32/+32
This replaces a couple of panic locations with hard aborts. The panics can't be catched by the user anyway in these locations.
2021-09-16Remove an allocation from rt::initbjorn3-1/+3
Previously the thread name would first be heap allocated and then re-allocated to add a nul terminator. Now it will be heap allocated only once with nul terminator added form the start.
2021-09-16Merge sys_common::rt into rtbjorn3-3/+83
2021-09-15Avoid codegen for Result::into_ok in lang_startMark Rousskov-3/+3
Otherwise, we end up pulling in an extra module as part of codegen, and that costs us a sizeable amount of work (both in LLVM and outside).
2021-09-15Allow `panic!("{}", computed_str)` in const fn.Gary Guo-0/+1
2021-06-19Change entry point to 🛡️ against 💥 💥-payloadsSimonas Kazlauskas-11/+26
Guard against panic payloads panicking within entrypoints, where it is UB to do so. Note that there are a number of implementation approaches to consider. Some simpler, some more complicated. This particular solution is nice in that it also guards against accidental implementation issues in various pieces of runtime code, something we cannot prevent statically right now. Fixes #86030
2021-04-22Remove `Once` from `init`Christiaan Dirkx-1/+4
2021-04-22Rework `at_exit` to `cleanup`Christiaan Dirkx-24/+4