diff options
author | Fangrui Song <i@maskray.me> | 2020-11-12 08:56:12 -0800 |
---|---|---|
committer | Fangrui Song <i@maskray.me> | 2020-11-12 08:56:12 -0800 |
commit | 40a42f9f3fe9bf34f2d365705e72f12960cbb16c (patch) | |
tree | d59001571f679f9bd3b131d6f959f47d27942936 /clang/lib/Frontend/CompilerInvocation.cpp | |
parent | 73d01a80cec397cb4e66ebb88a1204866b31ca59 (diff) | |
download | llvm-40a42f9f3fe9bf34f2d365705e72f12960cbb16c.zip llvm-40a42f9f3fe9bf34f2d365705e72f12960cbb16c.tar.gz llvm-40a42f9f3fe9bf34f2d365705e72f12960cbb16c.tar.bz2 |
[ELF] Make SORT_INIT_PRIORITY support .ctors.N
Input sections `.ctors/.ctors.N` may go to either the output section `.init_array` or the output section `.ctors`:
* output `.ctors`: currently we sort them by name. This patch changes to sort by priority from high to low. If N in `.ctors.N` is in the form of %05u, there is no semantic difference. Actually GCC and Clang do use %05u. (In the test `ctors_dtors_priority.s` and Gold's test `gold/testsuite/script_test_14.s`, we can see %03u, but they are not really produced by compilers.)
* output `.init_array`: users can provide an input section description `SORT_BY_INIT_PRIORITY(.init_array.* .ctors.*)` to mix `.init_array.*` and `.ctors.*`. This can make .init_array.N and .ctors.(65535-N) interchangeable.
With this change, users can mix `.ctors.N` and `.init_array.N` in `.init_array` (PR44698 and PR48096) with linker scripts. As an example:
```
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;
```
Reviewed By: psmith
Differential Revision: https://reviews.llvm.org/D91187
Diffstat (limited to 'clang/lib/Frontend/CompilerInvocation.cpp')
0 files changed, 0 insertions, 0 deletions