forked from OSchip/llvm-project
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. llvm-svn: 260463
This commit is contained in:
parent
c87d7d02e1
commit
2625882ebb
|
@ -772,8 +772,9 @@ template <class ELFT> void OutputSection<ELFT>::sortByPriority() {
|
|||
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);
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue