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

std: Mark allocation functions as nounwind #44049

Merged
merged 1 commit into from
Aug 29, 2017

Conversation

alexcrichton
Copy link
Member

This commit flags all allocation-related functions in liballoc as "this can't
unwind" which should largely resolve the size-related issues found on #42808.
The documentation on the trait was updated with such a restriction (they can't
panic) as well as some other words about the relative instability about
implementing a bullet-proof allocator.

Closes #42808

@rust-highfive
Copy link
Collaborator

r? @BurntSushi

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

@alexcrichton
Copy link
Member Author

This is perhaps best exemplified with this test which has no invoke instructions on stable and has invoke instructions on nightly. After this PR there are no invoke instructions either.

@alexcrichton alexcrichton added beta-accepted Accepted for backporting to the compiler in the beta channel. beta-nominated Nominated for backporting to the compiler in the beta channel. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Aug 22, 2017
bors added a commit that referenced this pull request Aug 23, 2017
[beta] Final round of beta backports

Includes:

* [x] #43723
* [x] #43830
* [x] #43844
* [x] #44013
* [x] #44049
* [x] #43948
@retep998
Copy link
Member

Windows required unwind tables for all functions because anything can unwind due to an SEH exception. Does this PR make sure to not break that?

@alexcrichton alexcrichton removed the beta-nominated Nominated for backporting to the compiler in the beta channel. label Aug 23, 2017
@alexcrichton
Copy link
Member Author

That's uwtable, not nounwind

@@ -27,36 +27,46 @@ pub mod __core {

extern "Rust" {
#[allocator]
#[allocator_nounwind]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, this is a new ungated attribute, right?
Since it's internal and the name doesn't matter much, rustc_allocator_nounwind can be used instead, it'll be gated automatically.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure yeah, I can change the name (currently this is just allowed under "custom_attributes")

/// retain their validity until at least the instance of `Alloc` is dropped
/// itself.
///
/// * Implementations of `Alloc` are not currently memory safe if they unwind.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, I'm not clear on how to parse this. The way it reads now, I interpret this as saying that any implementation of Alloc is not memory safe if it has a method that unwinds (panics), which AFAICT would even include the fn oom method...

But if I'm understanding the change here correctly, the memory unsafety only arises for implementations that are installed as global allocators, right?

(Maybe we do need to make a unsafe trait GlobalAllocator: Allocator { } just to track this extra-constraint on the implementations then...?)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that if I am wrong, and that this somehow is relevant to all implementations of Alloc, including ones that cannot be installed as global allocators, then I think more of the documentation for this trait needs to be revised.

E.g. text like this on fn alloc implies that an implementor may panic (even if it is not recommended):

Implementations are encouraged to return Err on memory exhaustion rather than panicking or aborting, but this is not a strict requirement.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh right yeah, I intended to make this specific to just global allocators

@alexcrichton
Copy link
Member Author

Updated

@alexcrichton alexcrichton added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 24, 2017
/// in the future, but currently an panic from any of these functions may lead
/// to memory unsafety. Note that as of the time of this writing allocators
/// *not* intending to be global allocators can still in their implementation
/// without violating memory safety.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a word missing in this sentence: panic/unwind 😃

/// itself.
///
/// * Implementations of `Alloc` intended to be used for global allocators are
/// not currently memory safe if they unwind. This restriction may be lifted
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer "it's undefined behavior if a global allocator unwinds" to "not currently memory safe".

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"not memory safe" implies there's an edge case in which UB can happen, but allocators unwinding is always UB.

@alexcrichton alexcrichton added the beta-nominated Nominated for backporting to the compiler in the beta channel. label Aug 28, 2017
@alexcrichton
Copy link
Member Author

Beta-nominating again as this needs to be backported again.

Copy link
Member

@BurntSushi BurntSushi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have a ton of context on the allocator stuff, so I'm probably not the best person to review this, but it LGTM.

/// itself.
///
/// * It's undefined behavior if global allocators unwind. This restriction may
/// be lifted in the future, but currently an panic from any of these
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/an/a

This commit flags all allocation-related functions in liballoc as "this can't
unwind" which should largely resolve the size-related issues found on rust-lang#42808.
The documentation on the trait was updated with such a restriction (they can't
panic) as well as some other words about the relative instability about
implementing a bullet-proof allocator.

Closes rust-lang#42808
@alexcrichton
Copy link
Member Author

@bors: r=BurntSushi

@bors
Copy link
Contributor

bors commented Aug 28, 2017

📌 Commit b6f554b has been approved by BurntSushi

@bors
Copy link
Contributor

bors commented Aug 29, 2017

⌛ Testing commit b6f554b with merge d2d5069...

bors added a commit that referenced this pull request Aug 29, 2017
std: Mark allocation functions as nounwind

This commit flags all allocation-related functions in liballoc as "this can't
unwind" which should largely resolve the size-related issues found on #42808.
The documentation on the trait was updated with such a restriction (they can't
panic) as well as some other words about the relative instability about
implementing a bullet-proof allocator.

Closes #42808
@bors
Copy link
Contributor

bors commented Aug 29, 2017

☀️ Test successful - status-appveyor, status-travis
Approved by: BurntSushi
Pushing d2d5069 to master...

@bors bors merged commit b6f554b into rust-lang:master Aug 29, 2017
@alexcrichton alexcrichton removed the beta-nominated Nominated for backporting to the compiler in the beta channel. label Sep 1, 2017
bors added a commit that referenced this pull request Sep 1, 2017
[beta] Boostrap from released compilers

No need to use dev any more!

Also contains backports for:

* #44049
* #44121
* #44144
@alexcrichton alexcrichton deleted the nounwind-allocators branch September 1, 2017 23:05
bors added a commit that referenced this pull request Sep 2, 2017
[beta] Boostrap from released compilers

No need to use dev any more!

Also contains backports for:

* #44049
* #44121
* #44144
///
/// * Pointers returned from allocation functions must point to valid memory and
/// retain their validity until at least the instance of `Alloc` is dropped
/// itself.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to imply that dealloc doesn't make the pointer invalid, as it doesn't drop the Alloc instance

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
beta-accepted Accepted for backporting to the compiler in the beta channel. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Binary size blowup presumably because of allocator integration
10 participants