forked from OSchip/llvm-project
ELF: Sort .[cd]tors by priority as we do for .{init,fini}_array.
llvm-svn: 260477
This commit is contained in:
parent
c2dca5d76e
commit
6f46de21e1
|
@ -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
|
||||
|
|
|
@ -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
|
Loading…
Reference in New Issue