Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
------------------------------------------------------------------------ r369828 | maskray | 2019-08-24 02:41:15 +0200 (Sat, 24 Aug 2019) | 18 lines [ELF] Align the first section of a PT_LOAD even if its type is SHT_NOBITS 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: 371196
- Loading branch information
Showing
5 changed files
with
56 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# 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 0000000000210000 010000 000001 00 WA 0 0 4096 | ||
|
||
# CHECK: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align | ||
# CHECK: LOAD 0x010000 0x0000000000210000 0x0000000000210000 0x000000 0x000001 RW 0x10000 | ||
|
||
# CHECK: 02 .bss | ||
|
||
.bss | ||
.p2align 12 | ||
.byte 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters