Handle statics and TLS in raw-dylib for ELF#153580
Handle statics and TLS in raw-dylib for ELF#153580mati865 wants to merge 3 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. |
| DllImportSymbolType::Static | ||
| } | ||
| } else { | ||
| DllImportSymbolType::Unknown |
There was a problem hiding this comment.
In what cases does this get reached? Can this be a bug!()?
There was a problem hiding this comment.
Hopefully never, I was worried to break Windows impl because previous code distinguished only functions and everything else.
|
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 🤦🏻♂️. |
f8a5ba3 to
9cb0ca1
Compare
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? |
|
The job Click to see the possible cause of the failure (guessed by this bot)For more information how to resolve CI failures of this job, visit this link. |
Follow-up to #153090