ld: SHF_MERGE sections on both sides of a symbol assignment
Song Fangrui
i@maskray.me
Fri May 1 01:11:29 GMT 2020
For the following example (SHF_MERGE sections on both sides of a symbol assignment), shall we perform *(.foo*) constant merge and *(.foo*) constant merge separately?
cat > a.lds <<e
SECTIONS {
.out : { start = ABSOLUTE(.); *(.foo*) middle = ABSOLUTE(.); *(.bar*) end = ABSOLUTE(.); }
}
e
cat > a.s <<e
.section .foo.0,"aM",@progbits,1; .byte 1; .byte 1
.section .foo.1,"aM",@progbits,1; .byte 2; .byte 2
.section .bar.0,"aM",@progbits,1; .byte 1; .byte 1
.section .bar.1,"aM",@progbits,1; .byte 2; .byte 2
e
gcc -c a.s
ld.bfd -T a.lds a.o -o a
readelf -x .out -s a
The current output (start=0, middle=end=2, i.e. section contents are before `middle`)
Symbol table '.symtab' contains 5 entries:
Num: Value Size Type Bind Vis Ndx Name
0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND
1: 0000000000000000 0 SECTION LOCAL DEFAULT 1
2: 0000000000000002 0 NOTYPE GLOBAL DEFAULT ABS middle
3: 0000000000000002 0 NOTYPE GLOBAL DEFAULT ABS end
4: 0000000000000000 0 NOTYPE GLOBAL DEFAULT ABS start
Hex dump of section '.out':
0x00000000 0102 ..
If we treat `middle` as a delimiter and perform merges separately, we will see 0102 on both sides of `middle`.
More information about the Binutils
mailing list