diff options
| -rw-r--r-- | lld/ELF/Writer.cpp | 4 | ||||
| -rw-r--r-- | lld/test/ELF/ctors_dtors_priority.s | 37 |
2 files changed, 40 insertions, 1 deletions
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index aa4bd43f988..9289bdce875 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -726,7 +726,7 @@ StringRef Writer<ELFT>::getOutputSectionName(StringRef S) const { return It->second; for (StringRef V : {".text.", ".rodata.", ".data.rel.ro.", ".data.", ".bss.", - ".init_array.", ".fini_array."}) + ".init_array.", ".fini_array.", ".ctors.", ".dtors."}) if (S.startswith(V)) return V.drop_back(); return S; @@ -966,6 +966,8 @@ template <class ELFT> bool Writer<ELFT>::createSections() { // Sort section contents for __attribute__((init_priority(N)). sortByPriority(Out<ELFT>::Dynamic->InitArraySec); sortByPriority(Out<ELFT>::Dynamic->FiniArraySec); + sortByPriority(Factory.lookup(".ctors", SHT_PROGBITS, SHF_WRITE | SHF_ALLOC)); + sortByPriority(Factory.lookup(".dtors", SHT_PROGBITS, SHF_WRITE | SHF_ALLOC)); // The linker needs to define SECNAME_start, SECNAME_end and SECNAME_stop // symbols for sections, so that the runtime can get the start and end diff --git a/lld/test/ELF/ctors_dtors_priority.s b/lld/test/ELF/ctors_dtors_priority.s new file mode 100644 index 00000000000..c4a1eb51d8a --- /dev/null +++ b/lld/test/ELF/ctors_dtors_priority.s @@ -0,0 +1,37 @@ +// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t +// RUN: ld.lld %t -o %t.exe +// RUN: llvm-objdump -s %t.exe | FileCheck %s +// REQUIRES: x86 + +.globl _start +_start: + nop + +.section .ctors, "aw", @progbits + .align 8 + .byte 1 +.section .ctors.100, "aw", @progbits + .long 2 +.section .ctors.5, "aw", @progbits + .byte 3 +.section .ctors, "aw", @progbits + .byte 4 +.section .ctors, "aw", @progbits + .byte 5 + +.section .dtors, "aw", @progbits + .align 8 + .byte 0x11 +.section .dtors.100, "aw", @progbits + .long 0x12 +.section .dtors.5, "aw", @progbits + .byte 0x13 +.section .dtors, "aw", @progbits + .byte 0x14 +.section .dtors, "aw", @progbits + .byte 0x15 + +// CHECK: Contents of section .ctors: +// CHECK-NEXT: 03020000 00000000 010405 +// CHECK: Contents of section .dtors: +// CHECK-NEXT: 13120000 00000000 111415 |

