During PHDR creation, the case where an output section does not require a
PT_LOAD header but still occupies memory in the current VMA region was not handled.
If such an output section interleaves two output sections that have the same
VMA and LMA regions set, we would previously re-use the existing PT_LOAD header
for the second output section.
However, since the memory region is not contiguous, we need to start a new PT_LOAD
segment.
This fixes https://bugs.llvm.org/show_bug.cgi?id=50558
Reviewed By: MaskRay
Differential Revision: https://reviews.llvm.org/D103815
}
static bool needsPtLoad(OutputSection *sec) {
- if (!(sec->flags & SHF_ALLOC) || sec->noload)
+ if (!(sec->flags & SHF_ALLOC))
return false;
// Don't allocate VA space for TLS NOBITS sections. The PT_TLS PHDR is
# CHECK: Name Type Address Off Size
# CHECK-NEXT: NULL 0000000000000000 000000 000000
-# CHECK-NEXT: .text PROGBITS 0000000000000000 000158 000000
-# CHECK-NEXT: .sec1 NOBITS 0000000000000000 000158 000001
-# CHECK-NEXT: .bss NOBITS 0000000000000400 000400 000001
+# CHECK-NEXT: .text PROGBITS 0000000000000000 000190 000000
+# CHECK-NEXT: .sec1 NOBITS 0000000000000000 001000 000001
+# CHECK-NEXT: .bss NOBITS 0000000000000400 001400 000001
# CHECK: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
-# CHECK-NEXT: LOAD 0x000400 0x0000000000000400 0x0000000000000400 0x000000 0x000001 RW 0x1000
+# CHECK-NEXT: LOAD 0x001000 0x0000000000000000 0x0000000000000000 0x000000 0x000001 R 0x1000
+# CHECK-NEXT: LOAD 0x001400 0x0000000000000400 0x0000000000000400 0x000000 0x000001 RW 0x1000
-# CHECK: 00 .bss {{$}}
+# CHECK: 00 .sec1 {{$}}
+# CHECK: 01 .bss {{$}}
.bss
.p2align 10
# CHECK-NEXT: .no_input_sec_noload NOBITS 0000000000011000 [[OFF]] 000001
# CHECK: Type Offset VirtAddr PhysAddr
+# CHECK-NEXT: LOAD 0x001000 0x0000000000000000 0x0000000000000000
# CHECK-NEXT: LOAD 0x001000 0x0000000000020000 0x0000000000020000
+# CHECK: 00 .data_noload_a .data_noload_b .no_input_sec_noload {{$}}
+# CHECK: 01 .text {{$}}
+
#--- asm
.section .text,"ax",@progbits
nop