Bug 17350 - ld cannot handle .init_array mixed with comdat
Summary: ld cannot handle .init_array mixed with comdat
Status: RESOLVED INVALID
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.25
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-09-04 23:59 UTC by Rafael Ávila de Espíndola
Modified: 2014-09-05 18:05 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
testcase (434 bytes, application/x-object)
2014-09-04 23:59 UTC, Rafael Ávila de Espíndola
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Rafael Ávila de Espíndola 2014-09-04 23:59:04 UTC
Created attachment 7770 [details]
testcase

The attached testcase has a .init_array that is in a comdat.

With gold

$ ~/binutils/build/gold/ld-new -shared -o test.so test.o
$ readelf  -x .init_array test.so

Hex dump of section '.init_array':
  0x00001468 90020000 00000000                   ........

$ readelf -sDW test.so | grep FUNC
    1   0: 0000000000000290     1 FUNC    WEAK   DEFAULT   7 f

That is, .init_array points to the function f, as expected.

With bfd ld:

$ ~/binutils/build/ld/ld-new -shared -o test.so test.o
[espindola@localhost llvm]$ readelf  -x .init_array test.so

Hex dump of section '.init_array':
  0x00200268 00000000 00000000                   ........

The section has a null.


As to why this is useful: In C++ when doing static initialization of a variable in a comdat we can put the .init_array in that comdat. That way the linker should keep only one copy.
Comment 1 Alan Modra 2014-09-05 14:29:12 UTC
Both ld.bfd and ld.gold produce a shared library with a dynamic relocation against "f" on the first element of .init_array.  Seems to me that section contents don't matter.
Comment 2 Rafael Ávila de Espíndola 2014-09-05 18:05:21 UTC
You are right. Sorry for the noise, I forgot this relocation was using Rela format and the value in the relocated position was not relevant.