[lld] r260477 - ELF: Sort .[cd]tors by priority as we do for .{init, fini}_array.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 10 17:07:19 PST 2016
Author: ruiu
Date: Wed Feb 10 19:07:19 2016
New Revision: 260477
URL: http://llvm.org/viewvc/llvm-project?rev=260477&view=rev
Log:
ELF: Sort .[cd]tors by priority as we do for .{init,fini}_array.
Added:
lld/trunk/test/ELF/ctors_dtors_priority.s
Modified:
lld/trunk/ELF/Writer.cpp
Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=260477&r1=260476&r2=260477&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Wed Feb 10 19:07:19 2016
@@ -726,7 +726,7 @@ StringRef Writer<ELFT>::getOutputSection
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>:
// 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
Added: lld/trunk/test/ELF/ctors_dtors_priority.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/ctors_dtors_priority.s?rev=260477&view=auto
==============================================================================
--- lld/trunk/test/ELF/ctors_dtors_priority.s (added)
+++ lld/trunk/test/ELF/ctors_dtors_priority.s Wed Feb 10 19:07:19 2016
@@ -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
More information about the llvm-commits
mailing list