@@ -618,6 +618,7 @@ enum RankFlags {
618
618
RF_NOT_ADDR_SET = 1 << 27 ,
619
619
RF_NOT_ALLOC = 1 << 26 ,
620
620
RF_PARTITION = 1 << 18 , // Partition number (8 bits)
621
+ RF_NOT_SPECIAL = 1 << 17 ,
621
622
RF_LARGE_ALT = 1 << 15 ,
622
623
RF_WRITE = 1 << 14 ,
623
624
RF_EXEC_WRITE = 1 << 13 ,
@@ -643,6 +644,24 @@ unsigned elf::getSectionRank(OutputSection &osec) {
643
644
if (!(osec.flags & SHF_ALLOC))
644
645
return rank | RF_NOT_ALLOC;
645
646
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
+
646
665
// Sort sections based on their access permission in the following
647
666
// order: R, RX, RXW, RW(RELRO), RW(non-RELRO).
648
667
//
@@ -658,6 +677,11 @@ unsigned elf::getSectionRank(OutputSection &osec) {
658
677
bool isWrite = osec.flags & SHF_WRITE;
659
678
660
679
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;
661
685
// Among PROGBITS sections, place .lrodata further from .text.
662
686
// For -z lrodata-after-bss, place .lrodata after .lbss like GNU ld. This
663
687
// layout has one extra PT_LOAD, but alleviates relocation overflow
@@ -667,25 +691,6 @@ unsigned elf::getSectionRank(OutputSection &osec) {
667
691
rank |= config->zLrodataAfterBss ? RF_LARGE_ALT : 0 ;
668
692
else
669
693
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;
689
694
} else if (isExec) {
690
695
rank |= isWrite ? RF_EXEC_WRITE : RF_EXEC;
691
696
} else {
0 commit comments