This is the mail archive of the
mailing list for the binutils project.
Re: Unexpected behavior regarding linking sections
On Thu, 13 Dec 2018, Alan Modra wrote:
> > I'm guessing it's too hot right now in Australia and there is some
> > kind of biological explanation for your behavior.
It's generally advisable to listen to Alan carefully. Had you done so you
would have done this:
% ld --verbose | less
Then with the remarks about init/fini_array and ctors/dtors and
crtbegin/crtend you would have found this amongst other things:
KEEP (*(.init_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o
*crtend?.o ) .ctors))
KEEP (*(.fini_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o
*crtend?.o ) .dtors))
KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors))
And there you have your explanation: the .dtors section from your start.o
file is placed into the init_array section (because it's not named
crtbegin.o), but the the one from the crtend.o file is placed into the
.dtors section. Same with .ctors. If your startup code doesn't support
init_array/fini_array you can't used the standard ELF linker scripts.