HomePhabricator

[ELF] Align the first section of a PT_LOAD even if its type is SHT_NOBITS

Authored by MaskRay on Aug 23 2019, 5:41 PM.

Description

[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: 369828

Details

Committed
MaskRayAug 23 2019, 5:41 PM
Reviewer
peter.smith
Differential Revision
D66658: [ELF] Align the first section of a PT_LOAD even if its type is SHT_NOBITS
Parents
rG0a8a225f8e6c: [NFC] Fix comments and formatting.
Branches
Unknown
Tags
Unknown