Bug 25122 - behaviour of ld when copying .ctors to .init_array
Summary: behaviour of ld when copying .ctors to .init_array
Status: RESOLVED DUPLICATE of bug 12379
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-10-21 10:27 UTC by wxsxsdz
Modified: 2019-10-21 14:46 UTC (History)
0 users

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


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description wxsxsdz 2019-10-21 10:27:41 UTC

    
Comment 1 wxsxsdz 2019-10-21 10:37:28 UTC
ld will copy .ctors section from the input files to .init_array section in the output file.
.ctors section should start with 0xffffffffffffffff and end with 0x0000000000000000. But .init_array shouldn't have these and should have it's size explicitly specified somewhere.
So if we link some files with .ctors sections, the .init_array section in the output file will contain some 0xffffffffffffffff entries. (As is observed in ld 2.30.51) And when ld.so loads the output file, it will segfault when calling the 0xffffffffffffffff entries in .init_array.
In order not to segfault, we must 1) filter out 0xffffffffffffffff entries when ld copies the .ctors section to .init_array section or 2) tell ld.so to ignore the 0xffffffffffffffff entries in .init_array.
(I think ld.so is in glibc, so should I report this to glibc or binutils?)
Comment 2 Andreas Schwab 2019-10-21 10:55:10 UTC
The input .ctors sections should never contain begin and end markers, except for the fragments from crtbegin.o/crtend.o (which are explicitly excluded).
Comment 3 wxsxsdz 2019-10-21 14:46:04 UTC
(In reply to Andreas Schwab from comment #2)
> The input .ctors sections should never contain begin and end markers, except
> for the fragments from crtbegin.o/crtend.o (which are explicitly excluded).

Thanks a lot! I'm compiling glibc, and they use soinit.os/sofini.os instead of crtbegin.o/crtend.o. So I think filtering out them manually would solve my problem.
This is discussed before at https://binutils.sourceware.narkive.com/oqywJAtY/binutils-2-21-51-0-2-fails-to-build-glibc, but the discussion hard to find...
This is a duplicate of 12379, but nothing useful can be found on that page...

*** This bug has been marked as a duplicate of bug 12379 ***