Handle statics and TLS in raw-dylib for ELF#153580
Handle statics and TLS in raw-dylib for ELF#153580rust-bors[bot] merged 6 commits intorust-lang:mainfrom
Conversation
|
r? @jieyouxu rustbot has assigned @jieyouxu. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
cc @bjorn3 |
|
Probably, r? bjorn3 |
|
Shoot, forgot to change the title yesterday. |
|
Actually, for PIE executables we do also need to store the symbol size for statics and maybe thread locals. This because of copy relocations. Basically the linker reserves space in the PIE executable for all statics coming from other DSOs and then at runtime the dynamic linker copies the data from the DSO that the symbol resolves to in the end into the reserved memory. Without the symbol size, the linker can't know how much memory to reserve. |
|
Copy relocations would definitely require known size. I couldn't manage to write Rust code that would make LLVM emit direct access with PIE or PIC, it would use GOT indirection instead which prevents copy relocations. However, I sort of succeeded with static relocation model:
Dunno about TLS, I'm not familiar enough with how it's handled. More detailsI have used WILD_SAVE_BASE to make debugging easier. While at it, posting linker-diff for the future reference: |
|
(forgot to write about it in the previous comment) I have no idea how we can deal with the unknown size. Perhaps we can somehow avoid direct access to raw-dylib statics? |
|
We can derive the size of statics from the type layout, right? We don't support unsized statics. |
|
Right, I feel so dumb. For some reason I thought that size of "string" objects would store the length of the underlying string rather than pointer size 🤦🏻♂️. |
9cb0ca1 to
2e52da9
Compare
To my defence, this is the case with Added size with implementation partially based on GNU ld doesn't look half bad, it didn't emit any copy relocations. One big issue standing out is putting data into Somehow this works, except for LLD didn't like our raw-dylib at all. With sizes set, it no longer rejects linkage, but it'd be better if it did rather than creating this abomination: Yeah, this has zero chance of working. Wild starts off with warnings when linking the same code: And looks like we have a deja vu: How about making static relocation model unsupported for now (with an error emitted) and creating an issue to track fixing it? |
This comment has been minimized.
This comment has been minimized.
2e52da9 to
dc2e08d
Compare
This comment has been minimized.
This comment has been minimized.
dc2e08d to
e14cce4
Compare
|
I think I have figured it out, but I need to double-check that before marking as ready. Pushed just to see if AArch64 also works fine. FYI, there are 2 new changes: Put statics in .data section in raw-dylib for ELF |
e14cce4 to
b18def1
Compare
b18def1 to
0d060dd
Compare
|
Sorry for the constant changes but on the second thought (or rather third in this case) I this bumping the value by the unrelated section alignment might be confusing. Changed that to more intuitive 8 bytes. |
This fixes issues with statics when using static relocation model and linking with GNU ld. Other linkers don't work yet.
With this change LLD finally produces working binaries with static relocation model.
0d060dd to
3531ed9
Compare
|
@bors try jobs=aarch64-msvc-1,aarch64-msvc-2,x86_64-mingw-1,x86_64-mingw-2 |
This comment has been minimized.
This comment has been minimized.
Handle statics and TLS in raw-dylib for ELF try-job: aarch64-msvc-1 try-job: aarch64-msvc-2 try-job: x86_64-mingw-1 try-job: x86_64-mingw-2
|
@bors r=bjorn3 |
| DllImportSymbolType::Static | ||
| } | ||
| } else { | ||
| bug!("Unexpected type for raw-dylib: {}", def_kind.descr(item)); |
There was a problem hiding this comment.
Ah, I have tried to use type there, but only as a definition. Not as a declaration, I'll look into it tomorrow.
Follow-up to #153090