[PATCH] D91187: [ELF] Make SORT_INIT_PRIORITY support .ctors.N

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 10 14:28:19 PST 2020


MaskRay added a comment.

Good to hear from you:) Thanks for review!

For GNU ld's internal linker script, the effective part for sections is:

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

Clang emits `.ctors.%05u` and GCC seems to emit `.ctors.%.5u`. Both should work fine with either `SORT` (by name, i.e. string comparison, "100" < "5") and `SORT_BY_INIT_PRIORITY` (by priority). So the change should matter in practice. Note that `.ctors.100` has already been converted to .init_array in GNU ld by priority while with the output section .ctors, they should be sorted by name. So I think this semantic change does not matter.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D91187/new/

https://reviews.llvm.org/D91187



More information about the llvm-commits mailing list