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

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 11 11:37:31 PST 2020


MaskRay added a comment.

In D91187#2388190 <https://reviews.llvm.org/D91187#2388190>, @psmith wrote:

> Will take another look tonight.For reference, I tried helping out someone last year with https://bugs.llvm.org/show_bug.cgi?id=44698 I think they had old objects, or a an old GCC on their system and it was mixing with a modern clang. Maybe worth a read through.

Thanks for the pointer. (I did recall we had another bug about .ctors (which motivated me to investigate the behaviors and observe several problems) but did not find the bug number..

With this patch, the user can provide a linker script fragment

  SECTIONS {
    .init_array : {
      *(SORT_BY_INIT_PRIORITY(.init_array.* .ctors.*))
      *(.init_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .ctors)
    }
  } INSERT AFTER .fini_array;
  SECTIONS {
    .fini_array : {
      *(SORT_BY_INIT_PRIORITY(.fini_array.* .dtors.*))
      *(.fini_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .dtors)
    }
  } INSERT BEFORE .init_array;

The use of `INSERT [AFTER|BEFORE]` is a bit of an abuse but in the absence of a better syntax (https://sourceware.org/bugzilla/show_bug.cgi?id=26404) this may be the best the user can achieve without providing a full script.


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