-
Notifications
You must be signed in to change notification settings - Fork 13.3k
.rodata bloat with aligned zero sized objects #75524
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
Comments
(I assume you mean zero-sized? "unsized" is something else.) For example, a |
Huh, so having 2MB zeros on disk for nothing is OK? |
I didn't say that. The object can still occupy zero bytes. But it also has an address, and that address must be appropriately aligned. I am afraid I don't know the details of the ELF format or the optimizations involved. All I am saying is that "it has size 0 and alignment is forced" is expected behavior. There is possibly a bug elsewhere, but the fact that "alignment is forced" is not a bug. It would be a critical bug if alignment was not enforced! (See e.g. #70143, #70022.) Cc @Amanieu |
Can't we give it address |
Is it null? |
Except querying the len() you can't do much with it. |
No, address 0 is not a valid address for any object. |
But yeah... |
The problem with reference at zero is that when you get raw pointer from it, |
Ok, this is what it can be reduced to: pub fn main() {
#[repr(align(0x200000))]
pub struct Aligned;
dbg!();
let slice: &mut [Aligned; 0] = &mut [];
dbg!(slice.as_ptr());
} |
|
very good, thank you! |
❯ rustc -C opt-level=3 src/main.rs && strip main && ls -hs main
2,3M main
❯ rustc -C opt-level=3 -Clink-args=-Wl,--sort-section=alignment src/main.rs && strip main && ls -hs main
231K main |
pub fn main() {
dbg!();
#[repr(align(536870912))]
pub struct Aligned;
let slice: &mut [Aligned; 0] = &mut [];
dbg!(slice.as_ptr());
} to the extreme (even with opt-level=s): ❯ rustc -C opt-level=s src/main.rs && strip main && ls -hs main
513M main |
So, I would suggest |
reduce the size of the sev shim See rust-lang/rust#75524
reduce the size of the sev shim See rust-lang/rust#75524
reduce the size of the sev shim See rust-lang/rust#75524
reduce the size of the sev shim See rust-lang/rust#75524
reduce the size of the shims See rust-lang/rust#75524
reduce the size of the shims See rust-lang/rust#75524
reduce the size of the shims See rust-lang/rust#75524
reduce the size of the shims See rust-lang/rust#75524
...wait, what magic happened here exactly? Does telling the linker to sort by alignment seriously just guarantee that all ZSTs overlap the same address in the binary space? If so, there's no obvious reason not to always do it for all ZSTs, is there? |
Still so annoying :-/ |
Note that I can only realize these benefits on GNU ld, for whatever reason lld is reluctant to do the same despite claiming to support sorting sections by alignment. |
I tried this code:
Edit: which can be further reduced to:
I expected to see this happen:
A reasonable section size of
.rodata
, like ifVersion b
is commented out.Instead, this happened:
A
.rodata
section with over 2MB.With this minimal example,
opt-level
makes it go away, but with more complex code it does not.The culprit is:
So, we have a zero-sized object, but an alignment was forced.
I don't know, if this is an LLVM bug.
Again, zero-sized, but with
align 2097152
.Meta
rustc --version --verbose
:and nightly:
The text was updated successfully, but these errors were encountered: