[lld] r260463 - ELF: Use stable sort to sort .{init, fini}_array sections.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 10 15:26:27 PST 2016
Author: ruiu
Date: Wed Feb 10 17:26:27 2016
New Revision: 260463
URL: http://llvm.org/viewvc/llvm-project?rev=260463&view=rev
Log:
ELF: Use stable sort to sort .{init,fini}_array sections.
Global constructors and destructors are guaranteed to be called
in the order as they appear in a translation unit. So we don't want
to mess up the order if they have the same priority.
Modified:
lld/trunk/ELF/OutputSections.cpp
lld/trunk/test/ELF/init_fini_priority.s
Modified: lld/trunk/ELF/OutputSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.cpp?rev=260463&r1=260462&r2=260463&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.cpp (original)
+++ lld/trunk/ELF/OutputSections.cpp Wed Feb 10 17:26:27 2016
@@ -772,8 +772,9 @@ template <class ELFT> void OutputSection
std::vector<Pair> V;
for (InputSection<ELFT> *S : Sections)
V.push_back({getPriority(S->getSectionName()), S});
- std::sort(V.begin(), V.end(),
- [](const Pair &A, const Pair &B) { return A.first < B.first; });
+ std::stable_sort(V.begin(), V.end(), [](const Pair &A, const Pair &B) {
+ return A.first < B.first;
+ });
Sections.clear();
for (Pair &P : V)
Sections.push_back(P.second);
Modified: lld/trunk/test/ELF/init_fini_priority.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/init_fini_priority.s?rev=260463&r1=260462&r2=260463&view=diff
==============================================================================
--- lld/trunk/test/ELF/init_fini_priority.s (original)
+++ lld/trunk/test/ELF/init_fini_priority.s Wed Feb 10 17:26:27 2016
@@ -14,16 +14,24 @@ _start:
.long 2
.section .init_array.5, "aw", @init_array
.byte 3
+.section .init_array, "aw", @init_array
+ .byte 4
+.section .init_array, "aw", @init_array
+ .byte 5
.section .fini_array, "aw", @fini_array
.align 8
- .byte 4
+ .byte 0x11
.section .fini_array.100, "aw", @fini_array
- .long 5
+ .long 0x12
.section .fini_array.5, "aw", @fini_array
- .byte 6
+ .byte 0x13
+.section .fini_array, "aw", @fini_array
+ .byte 0x14
+.section .fini_array, "aw", @fini_array
+ .byte 0x15
// CHECK: Contents of section .init_array:
-// CHECK-NEXT: 03020000 00000000 01
+// CHECK-NEXT: 03020000 00000000 010405
// CHECK: Contents of section .fini_array:
-// CHECK-NEXT: 06050000 00000000 04
+// CHECK-NEXT: 13120000 00000000 111415
More information about the llvm-commits
mailing list