3

Stabilize default_alloc_error_handler by Amanieu · Pull Request #102318 · rust-l...

 1 year ago
source link: https://github.com/rust-lang/rust/pull/102318
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Conversation

Member

@Amanieu Amanieu commented Sep 26, 2022

Tracking issue: #66741

This turns feature(default_alloc_error_handler) on by default, which causes the compiler to automatically generate a default OOM handler which panics if #[alloc_error_handler] is not provided.

The FCP completed over 2 years ago but the stabilization was blocked due to an issue with unwinding. This was fixed by #88098 so stabilization can be unblocked.

Closes #66741

CryZe, jplatte, SimonSapin, alex, phil-opp, lexxvir, sam0x17, tomaka, ordian, NukeManDan, and 23 more reacted with hooray emojiCryZe, alex, sam0x17, NukeManDan, Kobzol, DianaNites, ogoffart, toku-sa-n, nwadih, and emoon reacted with heart emojijschwe, alex, lexxvir, sam0x17, dgiger42, NukeManDan, Kobzol, DianaNites, toku-sa-n, nwadih, and 3 more reacted with rocket emoji

rustbot

added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label

Sep 26, 2022

Collaborator

rust-highfive commented Sep 26, 2022

r? @lcnr

(rust-highfive has picked a reviewer for you, use r? to override)

Contributor

lcnr commented Sep 26, 2022

considering that the FCP was 2 years ago, i would expect us to go through another FCP which explains the reason why stabilization was blocked. Won't block this without an FCP, but i definitely want someone to look at this who's a bit more knowledgeable about this than me

r? compiler

Contributor

bjorn3 commented Sep 26, 2022

When using this with cg_clif I get:

           /home/gh-bjorn3/cg_clif/build_sysroot/sysroot_src/library/alloc/src/alloc.rs:419: undefined reference to `rust_oom'

It seems that the current implementation depends on -Zfunction-sections=yes, while cg_clif sets it to no for linker performance reasons. To elaborate on why it depends on this. The code in question is

pub mod __alloc_error_handler {
    use crate::alloc::Layout;

    // called via generated `__rust_alloc_error_handler`

    // if there is no `#[alloc_error_handler]`
    #[rustc_std_internal_symbol]
    pub unsafe fn __rdl_oom(size: usize, _align: usize) -> ! {
        panic!("memory allocation of {size} bytes failed")
    }

    // if there is an `#[alloc_error_handler]`
    #[rustc_std_internal_symbol]
    pub unsafe fn __rg_oom(size: usize, align: usize) -> ! {
        let layout = unsafe { Layout::from_size_align_unchecked(size, align) };
        extern "Rust" {
            #[lang = "oom"]
            fn oom_impl(layout: Layout) -> !;
        }
        unsafe { oom_impl(layout) }
    }
}

__rust_alloc_error_handler will be generated as a call to either of these functions. __rdl_oom when #![feature(default_alloc_error_handler)] is used, no problem here and __rg_oom when it isn't used. The problem is that in this case rust_oom (which is the actual symbol name of oom_impl) is not defined. In other words it only just so happens to work because __rg_oom is garbage collected by the linker by default. Both compiling liballoc with -Zfunction-sections=no and using -Clink-dead-code when compiling the executable or dylib will cause __rg_oom to not be garbage collected and thus give a linker error.

Amanieu

marked this pull request as draft

Sep 26, 2022

Contributor

Ericson2314 commented Sep 26, 2022

I guess this is fine, but for people using alloc without global error handling at all (the current unstable cfg stuff, a feature hopefully someday) I hope one doesn't get needlessly synthesized.

pellico reacted with thumbs up emoji

Contributor

oli-obk commented Sep 27, 2022

We should probably have a test that uses this in a way we expect it to be used without requiring other feature gates. The tests touched by this PR all use other feature gates.

Ericson2314, pellico, and riking reacted with thumbs up emoji

petrochenkov

added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.

and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.

labels

Oct 6, 2022

This comment has been hidden.

rustbot

added the A-translation Area: Translation infrastructure, and migrating existing diagnostics to SessionDiagnostic label

Nov 3, 2022

Amanieu

marked this pull request as ready for review

Nov 3, 2022

Member

Author

Amanieu commented Nov 3, 2022

@rustbot ready

rustbot

added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.

and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.

labels

Nov 3, 2022

Contributor

CryZe commented Nov 30, 2022

Same thing for WASM where you don't use libc / eh_personality usually.

dvdhrm, mkroening, and gngshn reacted with thumbs up emoji

Member

Author

Amanieu commented Nov 30, 2022

I've removed most of the unstable features from the tests. The only remaining features are:

  • rustc_private which is needed to use rustc's private copy of libc. The test harness doesn't have access to cargo to use the normal libc crate.
  • lang_items is needed because the standard library is built with -C panic=unwind so a personality function must be provided. This isn't needed on targets that build the standard library with -C panic=abort.
oli-obk, gngshn, dnrusakov, eldruin, phip1611, and dvdhrm reacted with thumbs up emojijeffparsons reacted with hooray emoji

Contributor

oli-obk commented Dec 5, 2022

Stabilization report for @rust-lang/lang

More details (Guide/Reference level explanations) can be found in the main post of the tracking issue. There are no outstanding issues with this feature. The only alternative was to stabilize the #[alloc_error_handler] attribute to allow users to define their own error handler. This alternative was rejected by T-lang in #66740 (comment)

Motivation (verbatim from tracking issue)

As of Rust 1.36, specifying an allocation error handler is the only requirement for using the alloc crate in no_std environments (i.e. without the std crate being also linked in the program) that cannot be fulfilled by users on the Stable release channel.

Removing this requirement by having a default behavior would allow:

  • no_std + liballoc applications to start running on the Stable channel
  • no_std applications that run on Stable to start using liballoc
nicholasbishop, dnrusakov, dvdhrm, gngshn, eldruin, emoon, jschwe, adamgreig, and DianaNites reacted with heart emoji

Member

joshtriplett commented Dec 6, 2022

We talked about this in today's @rust-lang/lang meeting. We're going to confirm consensus via a quick FCP, since it's been 2 years.

@rfcbot merge

rfcbot commented Dec 6, 2022

edited

Team member @joshtriplett has proposed to merge this. The next step is review by the rest of the tagged team members:

No concerns currently listed.

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

See this document for info about what commands tagged team members can give me.

jschwe, CryZe, nicholasbishop, pellico, and jyn514 reacted with rocket emoji

rfcbot

added proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it.

labels

Dec 6, 2022

Contributor

nikomatsakis commented Dec 6, 2022

@rfcbot fcp reviewed

rfcbot

added final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised.

and removed proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off.

labels

Dec 6, 2022

rfcbot commented Dec 6, 2022

bellThis is now entering its final comment period, as per the review above. bell

jschwe, emoon, adamgreig, Dirbaio, ogoffart, gngshn, DianaNites, dvdhrm, dnrusakov, thejpster, and 3 more reacted with hooray emojijschwe, emoon, CryZe, Dirbaio, 9names, DianaNites, and dnrusakov reacted with rocket emoji

Mark-Simulacrum

removed the I-lang-nominated Indicates that an issue has been nominated for discussion during a lang team meeting. label

Dec 13, 2022

rfcbot

added finished-final-comment-period The final comment period is finished for this PR / Issue. to-announce Announce this issue on triage meeting

and removed final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised.

labels

Dec 16, 2022

rfcbot commented Dec 16, 2022

The final comment period, with a disposition to merge, as per the review above, is now complete.

As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed.

This will be merged soon.

jschwe and dvdhrm reacted with heart emoji

Contributor

oli-obk commented Dec 16, 2022

Contributor

bors commented Dec 16, 2022

pushpin Commit e66220f has been approved by oli-obk

It is now in the queue for this repository.

jschwe, x37v, and phip1611 reacted with hooray emojijschwe reacted with rocket emoji

bors

added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.

and removed S-waiting-on-team Status: Awaiting decision from the relevant subteam (see the T-<team> label).

labels

Dec 16, 2022

Contributor

bors commented Dec 16, 2022

hourglass Testing commit e66220f with merge bbb9cfb...

Contributor

bors commented Dec 17, 2022

sunny Test successful - checks-actions
Approved by: oli-obk
Pushing bbb9cfb to master...

bors

added the merged-by-bors This PR was explicitly merged by bors label

Dec 17, 2022

bors

merged commit bbb9cfb into

rust-lang:master

Dec 17, 2022

11 checks passed

Collaborator

rust-timer commented Dec 17, 2022

Finished benchmarking commit (bbb9cfb): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

Results

Cycles

Results

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Assignees

oli-obk

Labels
A-translation Area: Translation infrastructure, and migrating existing diagnostics to SessionDiagnostic disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this PR / Issue. merged-by-bors This PR was explicitly merged by bors S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-lang Relevant to the language team, which will review and decide on the PR/issue. to-announce Announce this issue on triage meeting
Projects

None yet

Milestone

1.68.0

Development

Successfully merging this pull request may close these issues.

Tracking issue for handle_alloc_error defaulting to panic (for no_std + liballoc)

16 participants

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK