[lld] r324656 - [ELF] Don't sort non reorderable sections with --symbol-ordering-file
Michael J. Spencer via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 8 14:03:23 PST 2018
Author: mspencer
Date: Thu Feb 8 14:03:23 2018
New Revision: 324656
URL: http://llvm.org/viewvc/llvm-project?rev=324656&view=rev
Log:
[ELF] Don't sort non reorderable sections with --symbol-ordering-file
Differential Revision: https://reviews.llvm.org/D43038
Modified:
lld/trunk/ELF/Writer.cpp
lld/trunk/test/ELF/symbol-ordering-file.s
Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=324656&r1=324655&r2=324656&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Thu Feb 8 14:03:23 2018
@@ -1048,6 +1048,13 @@ static DenseMap<SectionBase *, int> buil
return SectionOrder;
}
+static bool isKnownNonreorderableSection(const OutputSection *OS) {
+ return llvm::StringSwitch<bool>(OS->Name)
+ .Cases(".init", ".fini", ".init_array", ".fini_array", ".ctors",
+ ".dtors", true)
+ .Default(false);
+}
+
// If no layout was provided by linker script, we want to apply default
// sorting for special input sections. This also handles --symbol-ordering-file.
template <class ELFT> void Writer<ELFT>::sortInputSections() {
@@ -1057,7 +1064,7 @@ template <class ELFT> void Writer<ELFT>:
if (!Order.empty())
for (BaseCommand *Base : Script->SectionCommands)
if (auto *Sec = dyn_cast<OutputSection>(Base))
- if (Sec->Live)
+ if (Sec->Live && !isKnownNonreorderableSection(Sec))
Sec->sort([&](InputSectionBase *S) { return Order.lookup(S); });
if (Script->HasSectionsCommand)
Modified: lld/trunk/test/ELF/symbol-ordering-file.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/symbol-ordering-file.s?rev=324656&r1=324655&r2=324656&view=diff
==============================================================================
--- lld/trunk/test/ELF/symbol-ordering-file.s (original)
+++ lld/trunk/test/ELF/symbol-ordering-file.s Thu Feb 8 14:03:23 2018
@@ -5,6 +5,8 @@
# BEFORE: Contents of section .foo:
# BEFORE-NEXT: 201000 11223344 5566
+# BEFORE: Contents of section .init:
+# BEFORE-NEXT: 201006 1122
# RUN: echo "_foo4 " > %t_order.txt
# RUN: echo " _foo3" >> %t_order.txt
@@ -14,12 +16,16 @@
# RUN: echo "_foo4" >> %t_order.txt
# RUN: echo "_bar1" >> %t_order.txt
# RUN: echo "_foo1" >> %t_order.txt
+# RUN: echo "_init2" >> %t_order.txt
+# RUN: echo "_init1" >> %t_order.txt
# RUN: ld.lld --symbol-ordering-file %t_order.txt %t.o -o %t2.out
# RUN: llvm-objdump -s %t2.out| FileCheck %s --check-prefix=AFTER
# AFTER: Contents of section .foo:
# AFTER-NEXT: 201000 44335566 2211
+# AFTER: Contents of section .init:
+# AFTER-NEXT: 201006 1122
.section .foo,"ax", at progbits,unique,1
_foo1:
@@ -42,3 +48,11 @@ _foo5:
.byte 0x55
_bar1:
.byte 0x66
+
+.section .init,"ax", at progbits,unique,1
+_init1:
+ .byte 0x11
+
+.section .init,"ax", at progbits,unique,2
+_init2:
+ .byte 0x22
More information about the llvm-commits
mailing list