[PATCH] D118840: [ELF] Support (TYPE=<value>) to customize the output section type
Fangrui Song via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu May 5 19:23:18 PDT 2022
MaskRay added a comment.
In D118840#3495114 <https://reviews.llvm.org/D118840#3495114>, @manojgupta wrote:
> This change is breaking rust embedded use cases where NOLOAD in a linker script is no longer being honored. So we had to revert it (locally) in ChromeOS.
>
> example:
>
> #[link_section = ".arena"]
> static mut IMAGE_DATA: [i8; NUM_PIXELS] = [0i8; NUM_PIXELS];
>
> Linker script :
>
> PROVIDE( end = . );
> SECTIONS {
> .arena (NOLOAD) :
> {
> _farena = .;
> *(.arena)
> _earena = .;
> } > arena
> }
>
> With this commit where NOBITS is changed to PROGBITS.
>
> Before:
> [ 8] .arena NOBITS 60000000 006000 012c00 00 WA 0 0 1
> After:
> [ 8] .arena PROGBITS 60000000 006000 012c00 00 WA 0 0 1
>
> This seems to break a common use case in rust embedded
> e.g. https://github.com/rust-embedded/cortex-m/commit/94fbbe01189f97aefa8d6a97cc7cd73e5c6f6ec9
>
> Rust currently do not have a specify to section type and I am not sure llvm even provides an API for that.
>
> @peter.smith wdyt? Should this be reverted for now since it breaks rust embedded without any short term alternatives.
> Fangrui currently is out so we prefer to not revert outright before consulting you.
I think this is an issue with the Rust linker script and I don't think it is ok to revert the patch in the upstream just due to the Rust instance.
Think of another case that an input `.arena` has type SHT_PROGBITS but with non-all-zero content, the output type being SHT_NOBITS will be broken without any diagnostic.
In the current state, ld.lld actually emits a warning:
% ld.lld @response.txt
ld.lld: warning: section type mismatch for .arena
>>> path/to/fpga_rom-2c6c7738d58296f2.fpga_rom.52cb7a2a-cgu.0.rcgu.o:(.arena): SHT_PROGBITS
>>> output section .arena: SHT_NOBITS
To be fair, there are more problems with the linker script, including the superfluous parens surrounding input section descriptions `{ ... (*(.trap)) (*(.trap.rust)) }`.
This does not work with GNU ld but currently is not detected by lld.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D118840/new/
https://reviews.llvm.org/D118840
More information about the llvm-commits
mailing list