[PATCH] D43038: [ELF] Don't sort non reorderable sections with --symbol-ordering-file
Michael Spencer via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 7 13:03:55 PST 2018
Bigcheese created this revision.
Bigcheese added reviewers: ruiu, rafael.
Bigcheese added a project: lld.
Herald added a subscriber: emaste.
Don't sort known non-reorderable sections such as .init with `--symbol-ordering-file`.
Repository:
rLLD LLVM Linker
https://reviews.llvm.org/D43038
Files:
ELF/Writer.cpp
test/ELF/symbol-ordering-file.s
Index: test/ELF/symbol-ordering-file.s
===================================================================
--- test/ELF/symbol-ordering-file.s
+++ test/ELF/symbol-ordering-file.s
@@ -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 @@
.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
Index: ELF/Writer.cpp
===================================================================
--- ELF/Writer.cpp
+++ ELF/Writer.cpp
@@ -1048,6 +1048,13 @@
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 @@
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)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D43038.133282.patch
Type: text/x-patch
Size: 2148 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180207/0af4b5e7/attachment.bin>
More information about the llvm-commits
mailing list