1

abort immediately on bad mem::zeroed/uninit by RalfJung · Pull Request #105997 ·...

 2 years ago
source link: https://github.com/rust-lang/rust/pull/105997
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

abort immediately on bad mem::zeroed/uninit #105997

Conversation

Member

@RalfJung RalfJung commented Dec 21, 2022

Now that we have non-unwinding panics, let's use them for these assertions. This re-establishes the property that mem::uninitialized and mem::zeroed will never unwind -- the earlier approach of causing panics here sometimes led to hard-to-debug segfaults when the surrounding code was not able to cope with the unexpected unwinding.

Cc @bjorn3 I did not touch cranelift but I assume it needs a similar patch. However it has a codegen_panic abstraction that I did not want to touch since I didn't know how else it is used.

scottmcm reacted with heart emoji

Collaborator

rustbot commented Dec 21, 2022

r? @eholk

(rustbot has picked a reviewer for you, use r? to override)

rustbot

added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue.

labels

Dec 21, 2022

Collaborator

rustbot commented Dec 21, 2022

Hey! It looks like you've submitted a new PR for the library teams!

If this PR contains changes to any rust-lang/rust public library APIs then please comment with @rustbot label +T-libs-api -T-libs to tag it appropriately. If this PR contains changes to any unstable APIs please edit the PR description to add a link to the relevant API Change Proposal or create one if you haven't already. If you're unsure where your change falls no worries, just leave it as is and the reviewer will take a look and make a decision to forward on if necessary.

Examples of T-libs-api changes:

  • Stabilizing library features
  • Introducing insta-stable changes such as new implementations of existing stable traits on existing stable types
  • Introducing new or changing existing unstable library APIs (excluding permanently unstable features / features without a tracking issue)
  • Changing public documentation in ways that create new stability guarantees
  • Changing observable runtime behavior of library APIs

assert!(!res.status.success(), "test did not fail");

let stderr = String::from_utf8_lossy(&res.stderr);

assert!(stderr.contains(msg), "test did not contain expected output: looking for {:?}, output:\n{}", msg, stderr);

}

Member

Author

@RalfJung RalfJung Dec 21, 2022

This does make the test very slow. But that seems fine? I can't think of a better way...

You could spawn all the processes and only once that's done collect all the results. But that requires a bit more plumbing.

Or these tests could be rewritten as #[test] functions. This is also used in some other UI tests.
And lib-test spawns new processes for tests when the it's compiled with panic=abort or some unstable flag is passed. Not sure if compiletest can pass arguments to run-pass tests.

Contributor

@bjorn3 bjorn3 Dec 21, 2022

You have to use -Cpanic=abort and -Zpanic-abort-tests together when compiling the crate to be tested to have libtest spawn new processes.

Member

Author

@RalfJung RalfJung Dec 21, 2022

Hm, yeah I guess that could work, though I would have to restructure the test quite a bit.

Let's see what the reviewer says, for now I'd prefer this approach.

Contributor

@eholk eholk Dec 22, 2022

I think this approach looks okay. It launches 75 processes or so, which I don't think will be too much time in the grand scheme of things. It might be worse on Windows since process creation is more expensive there though. Given that we run the whole test suite in parallel, I doubt one slower test will affect the overall time too much.

This comment has been minimized.

Contributor

bjorn3 commented Dec 21, 2022

Cc @bjorn3 I did not touch cranelift but I assume it needs a similar patch. However it has a codegen_panic abstraction that I did not want to touch since I didn't know how else it is used.

No problem. I think I will update it on the next sync after this PR lands.

Contributor

@eholk eholk left a comment

Looks good to me. I had a minor naming nitpick, but feel free to r=me however you decide to address it!

@@ -232,14 +232,15 @@ language_item_table! {

// is required to define it somewhere. Additionally, there are restrictions on crates that use

// a weak lang item, but do not have it defined.

Panic, sym::panic, panic_fn, Target::Fn, GenericRequirement::Exact(0);

PanicNounwind, sym::panic_nounwind, panic_nounwind, Target::Fn, GenericRequirement::Exact(0);

Contributor

@eholk eholk Dec 22, 2022

Suggested change
PanicNounwind, sym::panic_nounwind, panic_nounwind, Target::Fn, GenericRequirement::Exact(0);
PanicNoUnwind, sym::panic_no_unwind, panic_no_unwind, Target::Fn, GenericRequirement::Exact(0);

My brain wants to parse PanicNounwind as Panic-Noun-Wind, so I'd prefer to keep the original spelling here.

In the snake case variant, I'm fine with either panic_no_unwind or panic_nounwind.

Member

Author

@RalfJung RalfJung Dec 22, 2022

The issue is that the old PanicNoUnwind is actually subtly different from the new PanicNounwind, which is why I did the rename -- the old lang item is equal to what is now called PannicCannotUnwind.

If you are okay with giving a lang item a different meaning without renaming it, I can change this to PanicNoUnwind.

Contributor

@eholk eholk Dec 22, 2022

That makes sense. Changing the name makes it so everyone has to actively do something now that it's changed, which seems like a good thing. If it annoys people in the future we can always change it then, but this reasoning makes sense to leave it as PanicNounwind.

assert!(!res.status.success(), "test did not fail");

let stderr = String::from_utf8_lossy(&res.stderr);

assert!(stderr.contains(msg), "test did not contain expected output: looking for {:?}, output:\n{}", msg, stderr);

}

Contributor

@eholk eholk Dec 22, 2022

I think this approach looks okay. It launches 75 processes or so, which I don't think will be too much time in the grand scheme of things. It might be worse on Windows since process creation is more expensive there though. Given that we run the whole test suite in parallel, I doubt one slower test will affect the overall time too much.

Contributor

bors commented Dec 22, 2022

umbrella The latest upstream changes (presumably #106034) made this pull request unmergeable. Please resolve the merge conflicts.

Contributor

eholk commented Dec 22, 2022

@bors r+

Contributor

bors commented Dec 22, 2022

pushpin Commit 9f241b3 has been approved by eholk

It is now in the queue for this repository.

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-review Status: Awaiting review from the assignee but also interested parties.

labels

Dec 22, 2022

Member

Nilstrieb commented Dec 23, 2022

@bors r-
Failed in rollup on wasm32 #106083 (comment)

bors

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-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.

labels

Dec 23, 2022

Member

Author

RalfJung commented Dec 24, 2022

@bors r=eholk rollup=iffy

Contributor

bors commented Dec 24, 2022

pushpin Commit 26e0139 has been approved by eholk

It is now in the queue for this repository.

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-author Status: This is awaiting some action (such as code changes or more information) from the author.

labels

Dec 24, 2022

Contributor

bors commented Dec 24, 2022

hourglass Testing commit 26e0139 with merge 1e1d386...

This comment has been minimized.

Contributor

bors commented Dec 24, 2022

broken_heart Test failed - checks-actions

bors

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

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

labels

Dec 24, 2022

Member

Author

RalfJung commented Dec 25, 2022

@bors r=eholk

Contributor

bors commented Dec 25, 2022

pushpin Commit c1b443d has been approved by eholk

It is now in the queue for this repository.

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-review Status: Awaiting review from the assignee but also interested parties.

labels

Dec 25, 2022

Contributor

bors commented Dec 25, 2022

hourglass Testing commit c1b443d with merge 8dfb339...

Contributor

bors commented Dec 25, 2022

sunny Test successful - checks-actions
Approved by: eholk
Pushing 8dfb339 to master...

Collaborator

rust-timer commented Dec 26, 2022

Finished benchmarking commit (8dfb339): 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

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

RalfJung

deleted the immediate-abort branch

Dec 27, 2022

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

Assignees

eholk

Labels
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-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects

None yet

Milestone

1.68.0

Development

Successfully merging this pull request may close these issues.

None yet

9 participants

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK