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

Peter Smith via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 10 14:12:01 PST 2020


psmith added a comment.

Apologies for being so quiet recently. It looks like this is changing .ctors/.dtors away from SORT_BY_NAME when they aren't mixed with .init_array.



================
Comment at: lld/ELF/OutputSections.cpp:474
     return endB;
-  StringRef x = a->name;
-  StringRef y = b->name;
-  assert(x.startswith(".ctors") || x.startswith(".dtors"));
-  assert(y.startswith(".ctors") || y.startswith(".dtors"));
-  x = x.substr(6);
-  y = y.substr(6);
-  return x < y;
+  return getPriority(a->name) > getPriority(b->name);
 }
----------------
I'm not sure this is right. As I understand it compCtors will only be called when not using a linker script. 

In that case we'd have a separate .ctors and .dtors section to an existing .init_array section and in this case the rules for sorting ctors and dtors are different i.e. the default is sort by name (see comment above). It looks like this bit of code will change the default linker script to the equivalent of:
```
   .ctors : { SORT_BY_INIT_PRIORITY (*(.ctors)) }
```
from:
```
   .ctors : { SORT_BY_NAME (*(.ctors)) }
```
I think the old way was closer to BFD as that only changes to SORT_BY_INIT_PRIORITY if .ctors are placed in the .init_array OutputSection.


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