[lld] [LLD][ELF] Change default flags for NOBITS sections with no inputs (PR #70447)
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sun Oct 29 23:53:56 PDT 2023
https://github.com/MaskRay requested changes to this pull request.
Thank you for posting https://discourse.llvm.org/t/lld-output-section-flag-assignment-behavior/74359 but I don't think the change is desirable.
For `custom-section-type.s`, GNU ld's output does not set the `SHF_WRITE` flag for `nobits`.
```
Section Headers:
[Nr] Name Type Address Off Size ES Flg Lk Inf Al
[ 0] trtab GROUP 000000000000001e 00101e 000004 04 A 9 0 1
[ 1] .text PROGBITS 0000000000000000 001000 000002 00 AX 0 0 4
[ 2] progbits PROGBITS 0000000000000002 001002 000001 00 A 0 0 1
[ 3] note NOTE 0000000000000003 001003 000002 00 A 0 0 1
[ 4] nobits NOBITS 0000000000000005 001005 000001 00 A 0 0 1
...
```
We can change `nobits ( TYPE=SHT_NOBITS) : { BYTE(8) }` to reuse `(NOLOAD)` and still get `nobits` without the `SHF_WRITE` flag.
GNU ld has changed to not force `SHF_WRITE` since 2021: https://sourceware.org/bugzilla/show_bug.cgi?id=26378
Regarding
```
HEAP_SIZE = 1K;
SECTIONS { }
SECTIONS
{
.CPU0.heap (NOLOAD) : ALIGN(64) { . = ALIGN(64); . += HEAP_SIZE; }
.CPU1.heap (NOLOAD) : ALIGN(64) { . = ALIGN(64); . += HEAP_SIZE; }
.CPU2.heap (NOLOAD) : ALIGN(64) { . = ALIGN(64); . += HEAP_SIZE; }
.code : { *(.text*) }
}
```
I think GNU sets the `SHF_WRITE` for `. = ALIGN(64);` and `SHF_WRITE|SHF_ALLOC` for `. += HEAP_SIZE;`.
The behavior is inconsistent with data commands.
I believe LLD should not change anything regarding the current consistent behavior.
You probably need to adjust your linker script as Peter suggested.
https://github.com/llvm/llvm-project/pull/70447
More information about the llvm-commits
mailing list