The generic ABI says:
> Padding is present, if necessary, to ensure 8 or 4-byte alignment for the next note entry (depending on whether the file is a 64-bit or 32-bit object). Such padding is not included in descsz.
Our parsing code currently aligns n_namesz. Fix the bug by aligning the start
offset of the descriptor instead. This issue has been benign because the primary
uses of sh_addralign=8 notes are `.note.gnu.property`, where
`sizeof(Elf_Nhdr) + sizeof("GNU") = 16` (already aligned by 8).
In practice, many 64-bit systems incorrectly use sh_addralign=4 notes.
We can use sh_addralign (= p_align) to decide the descriptor padding.
Treat an alignment of 0 and 1 as 4. This approach matches modern GNU readelf
(since 2018).
We have a few tests incorrectly using sh_addralign=0. We may make our behavior
stricter after fixing these tests.
Linux kernel dumped core files use `p_align=0` notes, so we need to support the
case for compatibility.
Reviewed By: jhenderson
Differential Revision: https://reviews.llvm.org/D150022
40 lines
1.4 KiB
ArmAsm
40 lines
1.4 KiB
ArmAsm
// REQUIRES: x86-registered-target
|
|
// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o %t
|
|
// RUN: llvm-readelf --notes %t | FileCheck %s --check-prefix=GNU
|
|
// RUN: llvm-readobj --elf-output-style LLVM --notes %t | FileCheck %s --check-prefix=LLVM
|
|
|
|
// GNU: Displaying notes found in: .note.gnu.property
|
|
// GNU-NEXT: Owner Data size Description
|
|
// GNU-NEXT: GNU 0x00000004 NT_GNU_PROPERTY_TYPE_0 (property note)
|
|
// GNU-NEXT: Properties: <corrupted GNU_PROPERTY_TYPE_0>
|
|
|
|
// LLVM: Notes [
|
|
// LLVM-NEXT: NoteSection {
|
|
// LLVM-NEXT: Name: .note.gnu.property
|
|
// LLVM-NEXT: Offset: 0x40
|
|
// LLVM-NEXT: Size: 0x18
|
|
// LLVM-NEXT: Note {
|
|
// LLVM-NEXT: Owner: GNU
|
|
// LLVM-NEXT: Data size: 0x4
|
|
// LLVM-NEXT: Type: NT_GNU_PROPERTY_TYPE_0 (property note)
|
|
// LLVM-NEXT: Property [
|
|
// LLVM-NEXT: <corrupted GNU_PROPERTY_TYPE_0>
|
|
// LLVM-NEXT: ]
|
|
// LLVM-NEXT: }
|
|
// LLVM-NEXT: }
|
|
// LLVM-NEXT: ]
|
|
|
|
// Section below is broken, check we report that.
|
|
|
|
.section ".note.gnu.property", "a"
|
|
.align 4
|
|
.long 4 /* Name length is always 4 ("GNU") */
|
|
.long 4 /* Data length (corrupted) */
|
|
.long 5 /* Type: NT_GNU_PROPERTY_TYPE_0 */
|
|
.asciz "GNU" /* Name */
|
|
.p2align 3
|
|
begin:
|
|
.long 1 /* Type: GNU_PROPERTY_STACK_SIZE */
|
|
.p2align 3
|
|
end:
|