[PATCH] D17120: ELF: Implement the correct semantics of .[cd]tors.

Simon Atanasyan via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 10 23:08:01 PST 2016


atanasyan added a comment.

GNU ld 2.22 has the following default linker script for `.ctors/.dtors` sections. I am sure that other versions have the same declarations.

  .ctors          :
  {
    KEEP (*crtbegin.o(.ctors))
    KEEP (*crtbegin?.o(.ctors))
    /* We don't want to include the .ctor section from
       the crtend.o file until after the sorted ctors.
       The .ctor section from the crtend file contains the
       end of ctors marker and it must be last */
    KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors))
    KEEP (*(SORT(.ctors.*)))
    KEEP (*(.ctors))
  }
  .dtors          :
  {
    KEEP (*crtbegin.o(.dtors))
    KEEP (*crtbegin?.o(.dtors))
    KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors))
    KEEP (*(SORT(.dtors.*)))
    KEEP (*(.dtors))
  }

So the order should be follow:

1. .ctors section from *crtbegin.o
2. .ctors section from *crtbegin?.o
3. .ctors sections from other object files except *crtend.o and *crtend?.o
4. .ctors.* from any files sorted by priority
5. .ctors sections from *crtend.o and *crtend?.o

As far as I can see now `.ctors/.dtors` sections from  the `crtend.o` go first.


http://reviews.llvm.org/D17120





More information about the llvm-commits mailing list