We may have incorrect values of <section>_end symbols due to incorrect handling of orphan sections.
Reproducer:
#!/usr/bin/env bash
cat >1.c <<\EOF
int a[8000] = { 1 };
int b[100] = { 0 };
__attribute__((section(".temp"))) int c = 10;
int main() { return 0; }
EOF
cat >script.t <<\EOF
SECTIONS {
.text (0x1000) : { *(.text) }
.temp (0x2000) : { *(.temp) }
__temp_end = .;
__bss_start = .;
. = ALIGN(1K);
.bss : { *(.bss) }
}
EOF
clang -o 1.o -target x86_64-linux-pc-gnu 1.c -c
LDs=(ld.eld)
SFs=(eld)
for i in "${!SFs[@]}"; do
${LDs[$i]} -o 1.${SFs[$i]}.out 1.o -T script.t -Map 1.${SFs[$i]}.map.txt
done
llvm-readelf -S 1.eld.out | grep .temp
llvm-readelf -s 1.eld.out | grep temp_end
Output:
[ 3] .temp PROGBITS 0000000000002000 002000 000004 00 WA 0 0 4
12: 0000000000009d10 0 NOTYPE GLOBAL DEFAULT ABS __temp_end
__temp_end should be 0x2004 instead of 0x9d10.