Repository navigation
LLVM target's OS/ABI is lost #97535
Description
Activity
- addedC-bugCategory: This is a bug.Category: This is a bug.regression-untriagedUntriaged performance or correctness regression.Untriaged performance or correctness regression.
on May 29, 2022 - addedI-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}Issue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
on May 29, 2022 Hmm, the
objectcrate setsEI_OSABItoNONE, which seems to be an alias ofSYSV.Unfortunately currently
objectcrate provide no ways to set this field, so to fix this I suppose some postprocessing of the generated ELF file would be needed.I am surprised that this doesn't show up earlier, given that exactly the same routine is used to create rmeta files. Does hermit not support dylibs?
Ah, yes,
objectsets the OS/ABI here:object.rs#L297.I think there are three possibilities:
- Add proper support for setting OS/ABI in
object::write::Object. This would probably take a lot of effort. - Patch
file.write(): Vec<u8>before passing it tostd::fs::writeinrust/compiler/rustc_codegen_ssa/src/back/link.rs
Line 1748 in 5c780b9
let result = std::fs::write(&path, file.write().unwrap());
This can be done quite easily. - Pass the synthetic object file after (?) the real ones. I think lld infers the OS/ABI from the first proper input object file, if I am reading this correctly:
Driver.cpp#L1649
For 1 and 2 we would need to know the proper OS/ABI from the real object files though. I am not sure how easy that would be to come by. What do you think?
I am surprised that this doesn't show up earlier, given that exactly the same routine is used to create rmeta files. Does hermit not support dylibs?
Hermit is a unikernel, which is linked statically to the application. There is no support for dynamic libraries.
A similar problem occurs when using
linker-plugin-ltothough (#73606). This issue was closed, because we did not needlinker-plugin-ltoanyways.- Add proper support for setting OS/ABI in
Here's how LLVM determines what OSABI to use: https://github.com/llvm/llvm-project/blob/18c1ee04de448a6a4babbaf8e5ba42866339b466/llvm/include/llvm/MC/MCELFObjectWriter.h. We could look at
sess.target.options.osand use the same logic to determine the OSABI.The synthetic object can be placed after real object files (it only needs to be linked before any libraries), but assuming the linker only looks at the first object file sounds a bit hacky.
cc @petrochenkov, what's your take on this issue?
object-rs has only recently been taught to set
e_flagsexpected by some MIPS targets (#96930).
In think we can teach object-rs to setEI_OSABItoo, and then just set it, if some linker expects it.All right. Thanks for the quick feedback. I'll cook something up in the coming days.
Assigning priority as discussed in the Zulip thread of the Prioritization Working Group.
@rustbot label -I-prioritize +P-low
- addedP-lowLow priorityLow priorityand removedI-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}Issue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
on May 31, 2022 - addedT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
on May 31, 2022 I opened #97633, but first the necessary changes in
objecthave to be released.
When compiling for
x86_64-unknown-hermit, the resulting binaries should have the OS/ABI (EI_OSABI) field in the ELF header set to Standalone (0xff) as per thex86_64-unknown-hermitLLVM target, which it did beforenightly-2022-04-26. Now, it is set to "UNIX - System V", which I only tested on Linux.git-bisectidentified the introduction of synthetic object files for exported symbols 773f533 from #95604 to have changed this:I did not have a deep dive into the code yet, but I assume the synthetic object file has the host's OS/ABI, which is prevalent over the other OS/ABI.
@nbdd0121, do you have any insight?
Related: hermit-os/hermit-rs#300