[lld] 25cec33 - [ELF] Place _edata before .bss in the presence of .ldata
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 12 18:14:24 PST 2024
Author: Fangrui Song
Date: 2024-02-12T18:14:19-08:00
New Revision: 25cec33521ba1c67f5e939ceea277be18b2d0fb7
URL: https://github.com/llvm/llvm-project/commit/25cec33521ba1c67f5e939ceea277be18b2d0fb7
DIFF: https://github.com/llvm/llvm-project/commit/25cec33521ba1c67f5e939ceea277be18b2d0fb7.diff
LOG: [ELF] Place _edata before .bss in the presence of .ldata
This minor issue is identified while working on #81224.
Added:
Modified:
lld/ELF/Writer.cpp
lld/test/ELF/x86-64-section-layout.s
Removed:
################################################################################
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index bd4db1ecedeaa..5b7dfd358e764 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -1104,7 +1104,9 @@ template <class ELFT> void Writer<ELFT>::setReservedSymbolSections() {
PhdrEntry *last = nullptr;
PhdrEntry *lastRO = nullptr;
-
+ auto isLarge = [](OutputSection *osec) {
+ return config->emachine == EM_X86_64 && osec->flags & SHF_X86_64_LARGE;
+ };
for (Partition &part : partitions) {
for (PhdrEntry *p : part.phdrs) {
if (p->p_type != PT_LOAD)
@@ -1124,10 +1126,11 @@ template <class ELFT> void Writer<ELFT>::setReservedSymbolSections() {
}
if (last) {
- // _edata points to the end of the last mapped initialized section.
+ // _edata points to the end of the last non-large mapped initialized
+ // section.
OutputSection *edata = nullptr;
for (OutputSection *os : outputSections) {
- if (os->type != SHT_NOBITS)
+ if (os->type != SHT_NOBITS && !isLarge(os))
edata = os;
if (os == last->lastSec)
break;
diff --git a/lld/test/ELF/x86-64-section-layout.s b/lld/test/ELF/x86-64-section-layout.s
index f2928777e8214..0ba6053938939 100644
--- a/lld/test/ELF/x86-64-section-layout.s
+++ b/lld/test/ELF/x86-64-section-layout.s
@@ -43,7 +43,7 @@
# CHECK: 0000000000201304 0 NOTYPE GLOBAL DEFAULT [[#]] (.text) _start
# CHECK-NEXT: 0000000000201305 0 NOTYPE GLOBAL DEFAULT [[#]] (.text) _etext
-# CHECK-NEXT: 0000000000205b0a 0 NOTYPE GLOBAL DEFAULT [[#]] (.ldata2) _edata
+# CHECK-NEXT: 0000000000203307 0 NOTYPE GLOBAL DEFAULT [[#]] (.data) _edata
# CHECK-NEXT: 0000000000206d0b 0 NOTYPE GLOBAL DEFAULT [[#]] (.lbss) _end
# CHECK1: .data PROGBITS 0000000000203306 000306 000001 00 WA 0 0 1
@@ -53,7 +53,7 @@
# CHECK1: 0000000000201304 0 NOTYPE GLOBAL DEFAULT [[#]] (.text) _start
# CHECK1-NEXT: 0000000000201305 0 NOTYPE GLOBAL DEFAULT [[#]] (.text) _etext
-# CHECK1-NEXT: 000000000020330a 0 NOTYPE GLOBAL DEFAULT [[#]] (.ldata2) _edata
+# CHECK1-NEXT: 0000000000203307 0 NOTYPE GLOBAL DEFAULT [[#]] (.data) _edata
# CHECK1-NEXT: 000000000020330a 0 NOTYPE GLOBAL DEFAULT [[#]] (.ldata2) _end
# CHECK2: .note NOTE 0000000000200300 000300 000001 00 A 0 0 1
More information about the llvm-commits
mailing list