public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* ld: SHF_MERGE sections on both sides of a symbol assignment
@ 2020-05-01  1:11 Song Fangrui
  2020-05-01  2:37 ` Alan Modra
  0 siblings, 1 reply; 2+ messages in thread
From: Song Fangrui @ 2020-05-01  1:11 UTC (permalink / raw)
  To: binutils

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`.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-05-01  2:37 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-01  1:11 ld: SHF_MERGE sections on both sides of a symbol assignment Song Fangrui
2020-05-01  2:37 ` Alan Modra

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).