[llvm-dev] [lld] [arm] Linker Cannot Set Custom Section Type to NOBITS
Peter Smith via llvm-dev
llvm-dev at lists.llvm.org
Tue Sep 1 03:32:41 PDT 2020
Hello Daniel,
>From looking at the code I would expect LLD to give the .stack section type SHT_NOBITS if (NOLOAD) is used. If (NOLOAD) is not used then it is difficult to tell what the type of the section should be as it is likely to depend on the type of the previous Output Section. It is possible that ld.bfd is inheriting the type and LLD is not. I recommend being as explicit as possible in the linker script and using (NOLOAD) if you can.
A change since LLD 10.0 https://reviews.llvm.org/D64930 may have made LLD closer to ld.bfd in this area. If you are able to try out LLD 11.0 when it releases (or build it from source) that would be great.
If all else fails it would be great if you could raise a PR with an example so we can look into it. The lld --reproduce=<filename> can capture the dependencies.
Peter
________________________________________
From: llvm-dev <llvm-dev-bounces at lists.llvm.org> on behalf of Daniel Way via llvm-dev <llvm-dev at lists.llvm.org>
Sent: 01 September 2020 08:26
To: llvm-dev at lists.llvm.org
Subject: [llvm-dev] [lld] [arm] Linker Cannot Set Custom Section Type to NOBITS
I am linking a program to be loaded in an ARM Cortex-M0+ based microcontroller. In the linker script, I have a section allocated for the stack which roughly looks like the following.
.stack : { . += __stack_size__; } > ram
Using the linker in the gcc arm toolchain, arm-none-eabi-ld, this section is automatically set to type NOBITS, however, when linking with version 10.0.0 of ld.lld, the section type is PROGBITS.
Here is the output when using readelf.
ld.lld
Section Headers:
[Nr] Name Type Addr Off Size ES Flg Lk Inf Al
...
[ 5] .stack PROGBITS 1ffff000 0014f0 000400 00 A 0 0 1
arm-none-eabi-ld
Section Headers:
[Nr] Name Type Addr Off Size ES Flg Lk Inf Al
...
[ 5] .stack NOBITS 1ffff000 01f000 000400 00 WA 0 0 1
Reading online, I found that I should add the (NOLOAD) directive to my linker script, so I tried the following.
.stack (NOLOAD) : { . += __stack_size__; } > ram
But this change to the linker script does not seem to affect the output ELF file. Interestingly, if I add the (NOLOAD) directive to the script's .data section, the .data section will change to type NOBITS.
I'd like to know if I'm making any errors, either in the section definition itself or when I call the linker.
Thank you,
Daniel Way
More information about the llvm-dev
mailing list