-
Notifications
You must be signed in to change notification settings - Fork 12.3k
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
rustc should specify SHT_INIT_ARRAY
for its init_array
section
#92181
Comments
If it is possible to set |
I'm a bit unclear on how we're supposed to address this in practical terms. As far as I know LLVM still does not support specifying section type or section flags in IR, so we wouldn't be able to expose something like |
Regarding Should LLVM be automatically setting |
LLVM IR provides In C, if you write How does the Rust component in question create |
@MaskRay The relevant difference is that rustc includes a priority in the section name. This can be seen with clang as well: https://c.godbolt.org/z/6PY87sW3v Changing https://github.com/llvm/llvm-project/blob/ba89c6d5056975c046275ce9614eb96eb7ec01f4/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp#L488 to use |
For
For C/C++ users, Changing the code path may make |
Currently, the code in TargetLoweringObjectFile only assigns @init_array section type to plain .init_array sections, but not prioritized sections like .init_array.00001. This is inconsistent with the interpretation in the AsmParser (see https://github.com/llvm/llvm-project/blob/791523bae6153b13bb41ba05c9fc89e502cc4a1a/llvm/lib/MC/MCParser/ELFAsmParser.cpp#L621-L632) and upcoming expectations in LLD (see rust-lang/rust#92181 for context). This patch assigns @init_array section type to all sections with an .init_array prefix. The same is done for .fini_array and .preinit_array as well. With that, the logic matches the AsmParser. Differential Revision: https://reviews.llvm.org/D116528
This should be resolved now by llvm/llvm-project@de92a13 (temporary workaround on the LLD side) and llvm/llvm-project@4ef560e (assigning correct section type for rustc's way of declaring it), so closing this. |
The original issue has been resolved (and will allow ld.lld to remove the workaround after a while) but the state is still not great. The "SHT_INIT_ARRAY' from a special section name does not meet ELF spirits: part of the reason .ctors/.dtors were obsoleted by SHT_INIT_ARRAY/SHT_FINI_ARRAY. GNU as does use special section names like I understand that LLVM IR does not provide a type feature beside |
This recent commit to
lld
broke Rust programs which used that linker. That's because it discards sections entitled.init_array
unless they are labeled with the correct section type,SHT_INIT_ARRAY
.Rust programs continued to link and run successfully, but couldn't see their command-line arguments (
std::env::args
would return nothing) because the Rust standard library relies on usage of.init_array
to retrieve those arguments. This section wasSHT_PROGBITS
rather thanSHT_INIT_ARRAY
so was discarded.This
lld
change has now been undone but my understanding from the LLVM folks (specifically @MaskRay) is that this is temporary.To fix this to the satisfaction of the LLVM folks, rustc would need to set the section type correctly using
llvm::MCContext::getELFSection
. Unfortunately, that isn't currently exposed via LLVM's C API (as far as I can tell), so an LLVM change would first be needed to expose it.After that, we'd need to decide whether to expose the section type ID via something like a new
#[link_section_type]
attribute or whether we'd simply hard-code the section type ID for certain well-known sections such as this.NB I am not personally an LLVM person so forgive me if I've misunderstood the layering of LLVM APIs or similar. I just did a bit of the investigation here to understand why my command-line cupboard was bare.
Related issues:
The text was updated successfully, but these errors were encountered: