Index: lld/ELF/Writer.cpp =================================================================== --- lld/ELF/Writer.cpp +++ lld/ELF/Writer.cpp @@ -825,17 +825,18 @@ // * It is easy to check if a give branch was taken. // * It is easy two see how similar two ranks are (see getRankProximity). enum RankFlags { - RF_NOT_ADDR_SET = 1 << 27, - RF_NOT_ALLOC = 1 << 26, - RF_PARTITION = 1 << 18, // Partition number (8 bits) - RF_NOT_PART_EHDR = 1 << 17, - RF_NOT_PART_PHDR = 1 << 16, - RF_NOT_INTERP = 1 << 15, - RF_NOT_NOTE = 1 << 14, - RF_WRITE = 1 << 13, - RF_EXEC_WRITE = 1 << 12, - RF_EXEC = 1 << 11, - RF_RODATA = 1 << 10, + RF_NOT_ADDR_SET = 1 << 28, + RF_NOT_ALLOC = 1 << 27, + RF_PARTITION = 1 << 19, // Partition number (8 bits) + RF_NOT_PART_EHDR = 1 << 18, + RF_NOT_PART_PHDR = 1 << 17, + RF_NOT_INTERP = 1 << 16, + RF_NOT_NOTE = 1 << 15, + RF_WRITE = 1 << 14, + RF_EXEC_WRITE = 1 << 13, + RF_EXEC = 1 << 12, + RF_RODATA = 1 << 11, + RF_PROGBITS = 1 << 10, RF_NOT_RELRO = 1 << 9, RF_NOT_TLS = 1 << 8, RF_BSS = 1 << 7, @@ -906,11 +907,15 @@ } else if (isWrite) { rank |= RF_WRITE; } else if (sec->type == SHT_PROGBITS) { - // Make non-executable and non-writable PROGBITS sections (e.g .rodata - // .eh_frame) closer to .text. They likely contain PC or GOT relative - // relocations and there could be relocation overflow if other huge sections - // (.dynstr .dynsym) were placed in between. - rank |= RF_RODATA; + rank |= RF_PROGBITS; + + // Place some non-executable and non-writable PROGBITS sections (i.e .rodata*, + // .eh_frame*) closer to .text. They likely contain PC or GOT relative + // relocations and there could be relocation overflows if other huge sections + // (.dynstr .dynsym, .nv_fatbin) were placed in between. + if (sec->name.startswith(".rodata") || sec->name.startswith(".eh_frame")) { + rank |= RF_RODATA; + } } // Place RelRo sections first. After considering SHT_NOBITS below, the Index: lld/test/ELF/nvidia-sections.s =================================================================== --- /dev/null +++ lld/test/ELF/nvidia-sections.s @@ -0,0 +1,35 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t +# RUN: ld.lld %t -o %tout +# RUN: llvm-objdump --section-headers %tout | FileCheck %s + +.global _start +.text +_start: + +.section .text.,"ax" +.byte 0 +.section .rodata,"a" +.byte 0 +.section .data,"aw" +.byte 0 +.section .bss,"aw",@nobits +.byte 0 +.section .nv_fatbin,"a" +.byte 0 +.section __nv_relfatbin,"a" +.byte 0 +.section __nv_module_id,"a" +.byte 0 + +// CHECK: 1 .nv_fatbin 00000001 +// CHECK: 2 __nv_relfatbin 00000001 +// CHECK: 3 __nv_module_id 00000001 +// CHECK: 4 .rodata 00000001 +// CHECK: 5 .text 00000001 +// CHECK: 6 .data 00000001 +// CHECK: 7 .bss 00000001 +// CHECK: 8 .comment 00000008 +// CHECK: 9 .symtab 00000030 +// CHECK: 10 .shstrtab 00000066 +// CHECK: 11 .strtab 00000008 Index: lld/test/ELF/section-name.s =================================================================== --- lld/test/ELF/section-name.s +++ lld/test/ELF/section-name.s @@ -42,8 +42,8 @@ .section .tdata.foo,"aGwT",@progbits,foo,comdat .byte 0 -// CHECK: 1 .rodata 00000002 -// CHECK: 2 .gcc_except_table 00000001 +// CHECK: 1 .gcc_except_table 00000001 +// CHECK: 2 .rodata 00000002 // CHECK: 3 .text 00000002 // CHECK: 4 .tdata 00000001 // CHECK: 5 .tbss 00000001