-
Notifications
You must be signed in to change notification settings - Fork 603
document that extern statics may be bigger than the declared size #2334
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -74,6 +74,10 @@ Extern statics can be either immutable or mutable just like [statics] outside of | |
| r[items.extern.static.read-only] | ||
| An immutable static *must* be initialized before any Rust code is executed. It is not enough for the static to be initialized before Rust code reads from it. Once Rust code runs, mutating an immutable static (from inside or outside Rust) is UB, except if the mutation happens to bytes inside of an `UnsafeCell`. | ||
|
|
||
| r[items.extern.static.size] | ||
| The actual memory that the extern static resolves to [must have][extern-static-ub] *at least* the size and alignment of the type that it was declared with in the extern block. | ||
| If the actual memory is bigger, then it is permitted to access that extra memory. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For dynamic libraries that may be used by a PIE executable, the size given by the symbol must be exact given that the PIE executable will emit a copy relocation that copies a block with exactly the size the symbol had at link time to memory the executable image has reserved for this and redirect all accesses to the static to this copy. This way the executable can avoid GOT indirection, which is a slight perf win. And yes, this means adding elements to a static array in a dylib (or otherwise changing the size) is an ABI breaking change on Linux.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Uh... I understand like maybe half of those words. (Can I have some 🥧 please? :D ) But it sounds like you are saying |
||
|
|
||
| r[items.extern.abi] | ||
| ## ABI | ||
|
|
||
|
|
@@ -466,6 +470,7 @@ Attributes on extern function parameters follow the same rules and restrictions | |
| [`verbatim` documentation for rustc]: ../../rustc/command-line-arguments.html#linking-modifiers-verbatim | ||
| [`whole-archive` documentation for rustc]: ../../rustc/command-line-arguments.html#linking-modifiers-whole-archive | ||
| [attributes]: ../attributes.md | ||
| [extern-static-ub]: ../behavior-considered-undefined.md#r-undefined.extern-static | ||
| [functions]: functions.md | ||
| [regular function parameters]: functions.md#attributes-on-function-parameters | ||
| [statics]: static-items.md | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This new kind of UB is kind of remarkable in that it does not require any code to trigger. But I don't see an alternative...
View changes since the review