This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Unexpected behavior regarding linking sections


Hi,

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:

  .init_array     :
  {
    KEEP (*(.init_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o 
                                      *crtend?.o ) .ctors))
  }
  .fini_array     :
  {
    KEEP (*(.fini_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o 
                                      *crtend?.o ) .dtors))
  }

...
  .dtors          :
  {
    KEEP (*crtbegin.o(.dtors))
    KEEP (*crtbegin?.o(.dtors))
    KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors))
    KEEP (*(SORT(.dtors.*)))
    KEEP (*(.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.


Ciao,
Michael.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]