[PATCH] D45282: COFF: Sort non-discardable sections at the same time as other sections. NFC.
Peter Collingbourne via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 4 13:34:25 PDT 2018
This revision was automatically updated to reflect the committed changes.
Closed by commit rLLD329227: COFF: Sort non-discardable sections at the same time as other sections. NFC. (authored by pcc, committed by ).
Changed prior to commit:
https://reviews.llvm.org/D45282?vs=141032&id=141038#toc
Repository:
rL LLVM
https://reviews.llvm.org/D45282
Files:
COFF/Writer.cpp
Index: COFF/Writer.cpp
===================================================================
--- COFF/Writer.cpp
+++ COFF/Writer.cpp
@@ -644,13 +644,18 @@
FileSize = alignTo(FileOff, SectorSize);
}
-static int sectionIndex(StringRef Name) {
+static int sectionIndex(OutputSection *S) {
+ // Move DISCARDABLE (or non-memory-mapped) sections to the end of file because
+ // the loader cannot handle holes.
+ if (S->getPermissions() & IMAGE_SCN_MEM_DISCARDABLE)
+ return 101;
+
// Try to match the section order used by link.exe. In particular, it's
// important that .reloc comes last since it refers to RVA's of data in
// the previous sections. .rsrc should come late because its size may
// change by the Win32 UpdateResources() function, causing subsequent
// sections to move (see https://crbug.com/827082).
- return StringSwitch<int>(Name)
+ return StringSwitch<int>(S->Name)
.Case(".text", 1)
.Case(".bss", 2)
.Case(".rdata", 3)
@@ -677,15 +682,9 @@
// Reorder the sections.
std::stable_sort(OutputSections.begin(), OutputSections.end(),
[](OutputSection *S, OutputSection *T) {
- return sectionIndex(S->Name) < sectionIndex(T->Name);
+ return sectionIndex(S) < sectionIndex(T);
});
- // Move DISCARDABLE (or non-memory-mapped) sections to the end of file because
- // the loader cannot handle holes.
- std::stable_partition(
- OutputSections.begin(), OutputSections.end(), [](OutputSection *S) {
- return (S->getPermissions() & IMAGE_SCN_MEM_DISCARDABLE) == 0;
- });
for (OutputSection *Sec : OutputSections) {
if (Sec->Name == ".reloc")
addBaserels(Sec);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D45282.141038.patch
Type: text/x-patch
Size: 1733 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180404/5c746e73/attachment.bin>
More information about the llvm-commits
mailing list