Reported at https://reviews.llvm.org/D64930#1642223 If the only section of a PT_LOAD is a SHT_NOBITS section (e.g. .bss), we may not align its sh_offset. p_offset of the PT_LOAD will be set to sh_offset, and we will get p_offset!=p_vaddr (mod p_align). If such executable is mapped by the Linux kernel, it will segfault. After D64906, this may happen the non-linker script case. The linker script case has had this issue for a long time. This was fixed by rL321657 (but the test linkerscript/nobits-offset.s failed to test a SHT_NOBITS section), but broken by rL345154. Reviewed By: peter.smith Differential Revision: https://reviews.llvm.org/D66658 llvm-svn: 369828
22 lines
750 B
ArmAsm
22 lines
750 B
ArmAsm
# REQUIRES: aarch64
|
|
# RUN: llvm-mc -filetype=obj -triple=aarch64 %s -o %t.o
|
|
# RUN: ld.lld %t.o -o %t
|
|
# RUN: llvm-readelf -S -l %t | FileCheck %s
|
|
|
|
## If a SHT_NOBITS section is the only section of a PT_LOAD segment,
|
|
## p_offset will be set to the sh_offset field of the section. Check we align
|
|
## sh_offset to sh_addr modulo max-page-size, so that p_vaddr=p_offset (mod
|
|
## p_align).
|
|
|
|
# CHECK: Name Type Address Off Size ES Flg Lk Inf Al
|
|
# CHECK: .bss NOBITS 0000000000221000 001000 000001 00 WA 0 0 4096
|
|
|
|
# CHECK: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
|
|
# CHECK: LOAD 0x001000 0x0000000000221000 0x0000000000221000 0x000000 0x000001 RW 0x10000
|
|
|
|
# CHECK: 02 .bss
|
|
|
|
.bss
|
|
.p2align 12
|
|
.byte 0
|