ld.gold entsize 0 for .rodata section with AMS flags

Navin P navinp0304@gmail.com
Thu Mar 18 13:09:20 GMT 2021


Hi,
 I have some questions regarding ld.gold

The behaviour of ld.bfd is to merge the sections and mark .rodata as
"A". The flags merge and string "MS" are removed from the executable.

1) Why does ld.gold retain the flags "MS" after merging ? Is it useful
to again merge/update with some other object file more like
incremental merge ?
But in that case the entry size of "AMS" should be "1" rather than 0
.gold generated executable from the object files shold have entsize 1
with AMS flag than 0.
2)  When we link using gcc , it is like gold -O2 -dynamic-linker
/lib64/ld-linux-x86-64.so.2  /usr/lib/x86_64-linux-gnu/crt1.o
/usr/lib/x86_64-linux-gnu/crti.o merge2.o
/usr/lib/x86_64-linux-gnu/crtn.o -lc

readelf -S ./a.out

  [14] .rodata           PROGBITS        00000000004004d8 0004d8
000063 00 AMS  0   0  8


The entsize value is set to 4   due to AM flag from crt1.o
  [ 5] .rodata.cst4      PROGBITS        0000000000000000 0000b8
000004 04  AM  0   0  4

  merge2.o
  [ 5] .rodata.str1.8    PROGBITS        0000000000000000 000070
000025 01 AMS  0   0  8
  [ 6] .rodata.str1.1    PROGBITS        0000000000000000 000095
00000b 01 AMS  0   0  1



Now in the add_input_section from
gold::Output_section::add_input_section<64, false>
we first set the ent size 4 due  to crt1.o. Please note it is not a string.
Then when we merge .rodata.str1.* we already have a conflict due to 04
and 01 entsize . Then
we update the entsize_ as 0 and it stays as that. Had it been not for
gcc and -lc if you just
link that object files the flags "AMS" and entsize is retained as 1.

I would like to add one more requirement that if the section has "AMS"
flags and all the sections
with "AMS" flags have same size usually 1 (like in case of merge2.o) ,
i would like to override
the entsize as 1 in the final executable .

So the output entsize is overridden if all the "AMS" sections have
same size ,then use that , other use the old code path i.e entsize 0.


merge2.c
const char* xbar1() {
    return "gabcdefghijklmnopqrstuvwxyz0123456789";
}
const char* xbar1_short() {
    return "gabcdef";
}
const char* xbar2_short() {
    return "gdef";
}


More information about the Binutils mailing list