[PATCH] D145132: ELF: Respect MEMORY command when specified without a SECTIONS command.
Peter Collingbourne via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 1 22:41:01 PST 2023
This revision was automatically updated to reflect the committed changes.
pcc marked an inline comment as done.
Closed by commit rG82c2fcffc273: ELF: Respect MEMORY command when specified without a SECTIONS command. (authored by pcc).
Changed prior to commit:
https://reviews.llvm.org/D145132?vs=501703&id=501747#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D145132/new/
https://reviews.llvm.org/D145132
Files:
lld/ELF/Writer.cpp
lld/test/ELF/linkerscript/memory-no-sections.test
Index: lld/test/ELF/linkerscript/memory-no-sections.test
===================================================================
--- /dev/null
+++ lld/test/ELF/linkerscript/memory-no-sections.test
@@ -0,0 +1,26 @@
+REQUIRES: x86
+
+## Check that we respect MEMORY commands in linker scripts without
+## SECTIONS commands.
+
+RUN: split-file %s %ts
+RUN: llvm-mc -filetype=obj -triple=x86_64 %ts/asm.s -o %t.o
+RUN: ld.lld -o %t -T %ts/script %t.o
+RUN: llvm-readelf -S %t | FileCheck %s
+
+CHECK: .text PROGBITS 0000000000001000
+CHECK: .data PROGBITS 0000000010000000
+
+#--- script
+
+MEMORY {
+ flash (rx!w): org = 0x1000, len = 0x3000
+ ram (rwx): org = 0x10000000, len = 0x1000
+}
+
+#--- asm.s
+
+.text
+.byte 1
+.data
+.byte 2
Index: lld/ELF/Writer.cpp
===================================================================
--- lld/ELF/Writer.cpp
+++ lld/ELF/Writer.cpp
@@ -60,6 +60,7 @@
void finalizeAddressDependentContent();
void optimizeBasicBlockJumps();
void sortInputSections();
+ void sortOrphanSections();
void finalizeSections();
void checkExecuteOnly();
void setReservedSymbolSections();
@@ -1456,9 +1457,13 @@
script->processInsertCommands();
script->adjustOutputSections();
- if (!script->hasSectionsCommand)
- return;
+ if (script->hasSectionsCommand)
+ sortOrphanSections();
+ script->adjustSectionsAfterSorting();
+}
+
+template <class ELFT> void Writer<ELFT>::sortOrphanSections() {
// Orphan sections are sections present in the input files which are
// not explicitly placed into the output file by the linker script.
//
@@ -1533,8 +1538,6 @@
std::rotate(pos, nonScriptI, end);
nonScriptI = end;
}
-
- script->adjustSectionsAfterSorting();
}
static bool compareByFilePosition(InputSection *a, InputSection *b) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D145132.501747.patch
Type: text/x-patch
Size: 1836 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230302/f693629e/attachment.bin>
More information about the llvm-commits
mailing list