Skip to content

Commit 30c10fd

Browse files
committed
Revert "[ELF] Simplify getSectionRank"
This reverts commit 2e0cfe6. Buildbots are broken.
1 parent 2b1d1c5 commit 30c10fd

File tree

1 file changed

+24
-19
lines changed

1 file changed

+24
-19
lines changed

lld/ELF/Writer.cpp

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,7 @@ enum RankFlags {
618618
RF_NOT_ADDR_SET = 1 << 27,
619619
RF_NOT_ALLOC = 1 << 26,
620620
RF_PARTITION = 1 << 18, // Partition number (8 bits)
621+
RF_NOT_SPECIAL = 1 << 17,
621622
RF_LARGE_ALT = 1 << 15,
622623
RF_WRITE = 1 << 14,
623624
RF_EXEC_WRITE = 1 << 13,
@@ -643,6 +644,24 @@ unsigned elf::getSectionRank(OutputSection &osec) {
643644
if (!(osec.flags & SHF_ALLOC))
644645
return rank | RF_NOT_ALLOC;
645646

647+
if (osec.type == SHT_LLVM_PART_EHDR)
648+
return rank;
649+
if (osec.type == SHT_LLVM_PART_PHDR)
650+
return rank | 1;
651+
652+
// Put .interp first because some loaders want to see that section
653+
// on the first page of the executable file when loaded into memory.
654+
if (osec.name == ".interp")
655+
return rank | 2;
656+
657+
// Put .note sections at the beginning so that they are likely to be included
658+
// in a truncate core file. In particular, .note.gnu.build-id, if available,
659+
// can identify the object file.
660+
if (osec.type == SHT_NOTE)
661+
return rank | 3;
662+
663+
rank |= RF_NOT_SPECIAL;
664+
646665
// Sort sections based on their access permission in the following
647666
// order: R, RX, RXW, RW(RELRO), RW(non-RELRO).
648667
//
@@ -658,6 +677,11 @@ unsigned elf::getSectionRank(OutputSection &osec) {
658677
bool isWrite = osec.flags & SHF_WRITE;
659678

660679
if (!isWrite && !isExec) {
680+
// Make PROGBITS sections (e.g .rodata .eh_frame) closer to .text to
681+
// alleviate relocation overflow pressure. Large special sections such as
682+
// .dynstr and .dynsym can be away from .text.
683+
if (osec.type == SHT_PROGBITS)
684+
rank |= RF_RODATA;
661685
// Among PROGBITS sections, place .lrodata further from .text.
662686
// For -z lrodata-after-bss, place .lrodata after .lbss like GNU ld. This
663687
// layout has one extra PT_LOAD, but alleviates relocation overflow
@@ -667,25 +691,6 @@ unsigned elf::getSectionRank(OutputSection &osec) {
667691
rank |= config->zLrodataAfterBss ? RF_LARGE_ALT : 0;
668692
else
669693
rank |= config->zLrodataAfterBss ? 0 : RF_LARGE;
670-
671-
if (osec.type == SHT_LLVM_PART_EHDR)
672-
;
673-
else if (osec.type == SHT_LLVM_PART_PHDR)
674-
rank |= 1;
675-
else if (osec.name == ".interp")
676-
rank |= 2;
677-
// Put .note sections at the beginning so that they are likely to be
678-
// included in a truncate core file. In particular, .note.gnu.build-id, if
679-
// available, can identify the object file.
680-
else if (osec.type == SHT_NOTE)
681-
rank |= 3;
682-
// Make PROGBITS sections (e.g .rodata .eh_frame) closer to .text to
683-
// alleviate relocation overflow pressure. Large special sections such as
684-
// .dynstr and .dynsym can be away from .text.
685-
else if (osec.type != SHT_PROGBITS)
686-
rank |= 4;
687-
else
688-
rank |= RF_RODATA;
689694
} else if (isExec) {
690695
rank |= isWrite ? RF_EXEC_WRITE : RF_EXEC;
691696
} else {

0 commit comments

Comments
 (0)