[PATCH] D42671: Sort orphan section if --symbol-ordering-file is given
Rafael Avila de Espindola via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 29 16:40:41 PST 2018
espindola created this revision.
espindola added reviewers: ruiu, grimar, jhenderson, edd.
Herald added a subscriber: emaste.
This changes the interaction of --symbol-ordering-file, but since we created --symbol-ordering-file I think this is reasonable. The new code is simpler and the behavior less surprising.
https://reviews.llvm.org/D42671
Files:
ELF/LinkerScript.cpp
ELF/OutputSections.cpp
ELF/OutputSections.h
ELF/Writer.cpp
test/ELF/linkerscript/symbol-ordering-file.s
Index: test/ELF/linkerscript/symbol-ordering-file.s
===================================================================
--- test/ELF/linkerscript/symbol-ordering-file.s
+++ test/ELF/linkerscript/symbol-ordering-file.s
@@ -14,6 +14,10 @@
# AFTER: Contents of section .foo:
# AFTER-NEXT: 2211
+# RUN: echo "SECTIONS { .text : { *(.text) } }" > %t2.script
+# RUN: ld.lld --symbol-ordering-file %t.ord %t.o --script %t2.script -o %t3.out
+# RUN: llvm-objdump -s %t3.out| FileCheck %s --check-prefix=AFTER
+
.section .foo,"ax", at progbits,unique,1
_foo1:
.byte 0x11
Index: ELF/Writer.cpp
===================================================================
--- ELF/Writer.cpp
+++ ELF/Writer.cpp
@@ -1020,8 +1020,6 @@
// If no layout was provided by linker script, we want to apply default
// sorting for special input sections and handle --symbol-ordering-file.
template <class ELFT> void Writer<ELFT>::sortInputSections() {
- assert(!Script->HasSectionsCommand);
-
// Sort input sections by priority using the list provided
// by --symbol-ordering-file.
DenseMap<SectionBase *, int> Order = buildSectionOrder();
@@ -1031,6 +1029,9 @@
if (Sec->Live)
Sec->sort([&](InputSectionBase *S) { return Order.lookup(S); });
+ if (Script->HasSectionsCommand)
+ return;
+
// Sort input sections by section name suffixes for
// __attribute__((init_priority(N))).
if (OutputSection *Sec = findSection(".init_array"))
@@ -1057,9 +1058,9 @@
if (auto *Sec = dyn_cast<OutputSection>(Base))
Sec->SortRank = getSectionRank(Sec);
- if (!Script->HasSectionsCommand) {
- sortInputSections();
+ sortInputSections();
+ if (!Script->HasSectionsCommand) {
// We know that all the OutputSections are contiguous in this case.
auto E = Script->SectionCommands.end();
auto I = Script->SectionCommands.begin();
Index: ELF/OutputSections.h
===================================================================
--- ELF/OutputSections.h
+++ ELF/OutputSections.h
@@ -143,8 +143,6 @@
namespace elf {
uint64_t getHeaderSize();
-void sortByOrder(llvm::MutableArrayRef<InputSection *> In,
- std::function<int(InputSectionBase *S)> Order);
extern std::vector<OutputSection *> OutputSections;
} // namespace elf
Index: ELF/OutputSections.cpp
===================================================================
--- ELF/OutputSections.cpp
+++ ELF/OutputSections.cpp
@@ -134,8 +134,8 @@
}
}
-void elf::sortByOrder(MutableArrayRef<InputSection *> In,
- std::function<int(InputSectionBase *S)> Order) {
+static void sortByOrder(MutableArrayRef<InputSection *> In,
+ std::function<int(InputSectionBase *S)> Order) {
typedef std::pair<int, InputSection *> Pair;
auto Comp = [](const Pair &A, const Pair &B) { return A.first < B.first; };
Index: ELF/LinkerScript.cpp
===================================================================
--- ELF/LinkerScript.cpp
+++ ELF/LinkerScript.cpp
@@ -257,15 +257,6 @@
if (Pat.SortOuter == SortSectionPolicy::None)
return;
- if (Pat.SortOuter == SortSectionPolicy::Default &&
- Config->SortSection == SortSectionPolicy::Default) {
- // If -symbol-ordering-file was given, sort accordingly.
- // Usually, Order is empty.
- if (!Order.empty())
- sortByOrder(Vec, [&](InputSectionBase *S) { return Order.lookup(S); });
- return;
- }
-
if (Pat.SortInner == SortSectionPolicy::Default)
sortSections(Vec, Config->SortSection);
else
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D42671.131901.patch
Type: text/x-patch
Size: 3529 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180130/f48ffad7/attachment.bin>
More information about the llvm-commits
mailing list