Skip to content

Commit 25cec33

Browse files
committed
[ELF] Place _edata before .bss in the presence of .ldata
This minor issue is identified while working on #81224.
1 parent f7c2c32 commit 25cec33

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

lld/ELF/Writer.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,7 +1104,9 @@ template <class ELFT> void Writer<ELFT>::setReservedSymbolSections() {
11041104

11051105
PhdrEntry *last = nullptr;
11061106
PhdrEntry *lastRO = nullptr;
1107-
1107+
auto isLarge = [](OutputSection *osec) {
1108+
return config->emachine == EM_X86_64 && osec->flags & SHF_X86_64_LARGE;
1109+
};
11081110
for (Partition &part : partitions) {
11091111
for (PhdrEntry *p : part.phdrs) {
11101112
if (p->p_type != PT_LOAD)
@@ -1124,10 +1126,11 @@ template <class ELFT> void Writer<ELFT>::setReservedSymbolSections() {
11241126
}
11251127

11261128
if (last) {
1127-
// _edata points to the end of the last mapped initialized section.
1129+
// _edata points to the end of the last non-large mapped initialized
1130+
// section.
11281131
OutputSection *edata = nullptr;
11291132
for (OutputSection *os : outputSections) {
1130-
if (os->type != SHT_NOBITS)
1133+
if (os->type != SHT_NOBITS && !isLarge(os))
11311134
edata = os;
11321135
if (os == last->lastSec)
11331136
break;

lld/test/ELF/x86-64-section-layout.s

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343

4444
# CHECK: 0000000000201304 0 NOTYPE GLOBAL DEFAULT [[#]] (.text) _start
4545
# CHECK-NEXT: 0000000000201305 0 NOTYPE GLOBAL DEFAULT [[#]] (.text) _etext
46-
# CHECK-NEXT: 0000000000205b0a 0 NOTYPE GLOBAL DEFAULT [[#]] (.ldata2) _edata
46+
# CHECK-NEXT: 0000000000203307 0 NOTYPE GLOBAL DEFAULT [[#]] (.data) _edata
4747
# CHECK-NEXT: 0000000000206d0b 0 NOTYPE GLOBAL DEFAULT [[#]] (.lbss) _end
4848

4949
# CHECK1: .data PROGBITS 0000000000203306 000306 000001 00 WA 0 0 1
@@ -53,7 +53,7 @@
5353

5454
# CHECK1: 0000000000201304 0 NOTYPE GLOBAL DEFAULT [[#]] (.text) _start
5555
# CHECK1-NEXT: 0000000000201305 0 NOTYPE GLOBAL DEFAULT [[#]] (.text) _etext
56-
# CHECK1-NEXT: 000000000020330a 0 NOTYPE GLOBAL DEFAULT [[#]] (.ldata2) _edata
56+
# CHECK1-NEXT: 0000000000203307 0 NOTYPE GLOBAL DEFAULT [[#]] (.data) _edata
5757
# CHECK1-NEXT: 000000000020330a 0 NOTYPE GLOBAL DEFAULT [[#]] (.ldata2) _end
5858

5959
# CHECK2: .note NOTE 0000000000200300 000300 000001 00 A 0 0 1

0 commit comments

Comments
 (0)