@@ -618,7 +618,6 @@ 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 ,
622621 RF_LARGE_ALT = 1 << 15 ,
623622 RF_WRITE = 1 << 14 ,
624623 RF_EXEC_WRITE = 1 << 13 ,
@@ -644,24 +643,6 @@ unsigned elf::getSectionRank(OutputSection &osec) {
644643 if (!(osec.flags & SHF_ALLOC))
645644 return rank | RF_NOT_ALLOC;
646645
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-
665646 // Sort sections based on their access permission in the following
666647 // order: R, RX, RXW, RW(RELRO), RW(non-RELRO).
667648 //
@@ -677,11 +658,6 @@ unsigned elf::getSectionRank(OutputSection &osec) {
677658 bool isWrite = osec.flags & SHF_WRITE;
678659
679660 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;
685661 // Among PROGBITS sections, place .lrodata further from .text.
686662 // For -z lrodata-after-bss, place .lrodata after .lbss like GNU ld. This
687663 // layout has one extra PT_LOAD, but alleviates relocation overflow
@@ -691,6 +667,25 @@ unsigned elf::getSectionRank(OutputSection &osec) {
691667 rank |= config->zLrodataAfterBss ? RF_LARGE_ALT : 0 ;
692668 else
693669 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;
694689 } else if (isExec) {
695690 rank |= isWrite ? RF_EXEC_WRITE : RF_EXEC;
696691 } else {
0 commit comments