Skip to content

Commit

Permalink
[llvm-readobj] Implement LLVM style printer for --notes
Browse files Browse the repository at this point in the history
Summary:
Port the GNU style printNotes method to the LLVMStyle subclass.

This is basically just a heavy refactor so that the note parsing/formatting logic from the GNUStyle::printNotes can be shared with LLVMStyle::printNotes.

Reviewers: MaskRay

Reviewed By: MaskRay

Subscribers: dschuff, fedor.sergeev, llvm-commits

Differential Revision: https://reviews.llvm.org/D54220

llvm-svn: 346371
  • Loading branch information
rupprecht committed Nov 7, 2018
1 parent fb4bcc4 commit 4f36c7a
Show file tree
Hide file tree
Showing 4 changed files with 341 additions and 121 deletions.
62 changes: 53 additions & 9 deletions llvm/test/tools/llvm-readobj/gnu-notes.test
@@ -1,15 +1,55 @@
# RUN: yaml2obj %s > %t.so
# RUN: llvm-readobj -elf-output-style GNU --notes %t.so | FileCheck %s
# RUN: llvm-readobj -elf-output-style GNU --notes %t.so | FileCheck %s --check-prefix=GNU
# RUN: llvm-readobj -elf-output-style LLVM --notes %t.so | FileCheck %s --check-prefix=LLVM

# CHECK: Displaying notes found at file offset 0x00000300 with length 0x00000020:
# CHECK: Owner Data size Description
# CHECK: GNU 0x00000010 NT_GNU_BUILD_ID (unique build ID bitstring)
# CHECK: Build ID: 4fcb712aa6387724a9f465a32cd8c14b
# GNU: Displaying notes found at file offset 0x00000340 with length 0x00000020:
# GNU-NEXT: Owner Data size Description
# GNU-NEXT: GNU 0x00000010 NT_GNU_ABI_TAG (ABI version tag)
# GNU-NEXT: OS: Linux, ABI: 2.6.32

# CHECK: Displaying notes found at file offset 0x0000036c with length 0x0000001c:
# CHECK: Owner Data size Description
# CHECK: GNU 0x00000009 NT_GNU_GOLD_VERSION (gold version)
# CHECK: Version: gold 1.11
# GNU: Displaying notes found at file offset 0x00000360 with length 0x00000020:
# GNU-NEXT: Owner Data size Description
# GNU-NEXT: GNU 0x00000010 NT_GNU_BUILD_ID (unique build ID bitstring)
# GNU-NEXT: Build ID: 4fcb712aa6387724a9f465a32cd8c14b

# GNU: Displaying notes found at file offset 0x000003cc with length 0x0000001c:
# GNU-NEXT: Owner Data size Description
# GNU-NEXT: GNU 0x00000009 NT_GNU_GOLD_VERSION (gold version)
# GNU-NEXT: Version: gold 1.11

# LLVM: Notes [
# LLVM-NEXT: NoteSection {
# LLVM-NEXT: Offset: 0x340
# LLVM-NEXT: Size: 0x20
# LLVM-NEXT: Note {
# LLVM-NEXT: Owner: GNU
# LLVM-NEXT: Data size: 0x10
# LLVM-NEXT: Type: NT_GNU_ABI_TAG (ABI version tag)
# LLVM-NEXT: OS: Linux
# LLVM-NEXT: ABI: 2.6.32
# LLVM-NEXT: }
# LLVM-NEXT: }
# LLVM-NEXT: NoteSection {
# LLVM-NEXT: Offset: 0x360
# LLVM-NEXT: Size: 0x20
# LLVM-NEXT: Note {
# LLVM-NEXT: Owner: GNU
# LLVM-NEXT: Data size: 0x10
# LLVM-NEXT: Type: NT_GNU_BUILD_ID (unique build ID bitstring)
# LLVM-NEXT: Build ID: 4fcb712aa6387724a9f465a32cd8c14b
# LLVM-NEXT: }
# LLVM-NEXT: }
# LLVM-NEXT: NoteSection {
# LLVM-NEXT: Offset: 0x3CC
# LLVM-NEXT: Size: 0x1C
# LLVM-NEXT: Note {
# LLVM-NEXT: Owner: GNU
# LLVM-NEXT: Data size: 0x9
# LLVM-NEXT: Type: NT_GNU_GOLD_VERSION (gold version)
# LLVM-NEXT: Version: gold 1.11
# LLVM-NEXT: }
# LLVM-NEXT: }
# LLVM-NEXT: ]

--- !ELF
FileHeader:
Expand All @@ -18,6 +58,10 @@ FileHeader:
Type: ET_EXEC
Machine: EM_X86_64
Sections:
- Name: .note.ABI-tag
Type: SHT_NOTE
AddressAlign: 0x0000000000000004
Content: 040000001000000001000000474E550000000000020000000600000020000000
- Name: .note.gnu.build-id
Type: SHT_NOTE
Flags: [ SHF_ALLOC ]
Expand Down
62 changes: 45 additions & 17 deletions llvm/test/tools/llvm-readobj/note-gnu-property.s
@@ -1,23 +1,51 @@
// REQUIRES: x86-registered-target
// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o %t
// RUN: llvm-readobj -elf-output-style GNU --notes %t | FileCheck %s
// RUN: llvm-readobj -elf-output-style GNU --notes %t | FileCheck %s --check-prefix=GNU
// RUN: llvm-readobj -elf-output-style LLVM --notes %t | FileCheck %s --check-prefix=LLVM

// CHECK: Displaying notes found at file offset 0x00000040 with length 0x000000b8:
// CHECK-NEXT: Owner Data size Description
// CHECK-NEXT: GNU 0x000000a8 NT_GNU_PROPERTY_TYPE_0 (property note)
// CHECK-NEXT: Properties: stack size: 0x100
// CHECK-NEXT: stack size: 0x100
// CHECK-NEXT: no copy on protected
// CHECK-NEXT: X86 features: SHSTK
// CHECK-NEXT: X86 features: IBT, SHSTK
// CHECK-NEXT: X86 features: none
// CHECK-NEXT: <application-specific type 0xfefefefe>
// CHECK-NEXT: stack size: <corrupt length: 0x0>
// CHECK-NEXT: stack size: <corrupt length: 0x4>
// CHECK-NEXT: no copy on protected <corrupt length: 0x1>
// CHECK-NEXT: X86 features: <corrupt length: 0x0>
// CHECK-NEXT: X86 features: IBT, <unknown flags: 0xf000f000f000f000>
// CHECK-NEXT: <corrupt type (0x2) datasz: 0x1>
// GNU: Displaying notes found at file offset 0x00000040 with length 0x000000b8:
// GNU-NEXT: Owner Data size Description
// GNU-NEXT: GNU 0x000000a8 NT_GNU_PROPERTY_TYPE_0 (property note)
// GNU-NEXT: Properties: stack size: 0x100
// GNU-NEXT: stack size: 0x100
// GNU-NEXT: no copy on protected
// GNU-NEXT: X86 features: SHSTK
// GNU-NEXT: X86 features: IBT, SHSTK
// GNU-NEXT: X86 features: none
// GNU-NEXT: <application-specific type 0xfefefefe>
// GNU-NEXT: stack size: <corrupt length: 0x0>
// GNU-NEXT: stack size: <corrupt length: 0x4>
// GNU-NEXT: no copy on protected <corrupt length: 0x1>
// GNU-NEXT: X86 features: <corrupt length: 0x0>
// GNU-NEXT: X86 features: IBT, <unknown flags: 0xf000f000f000f000>
// GNU-NEXT: <corrupt type (0x2) datasz: 0x1>

// LLVM: Notes [
// LLVM-NEXT: NoteSection {
// LLVM-NEXT: Offset: 0x40
// LLVM-NEXT: Size: 0xB8
// LLVM-NEXT: Note {
// LLVM-NEXT: Owner: GNU
// LLVM-NEXT: Data size: 0xA8
// LLVM-NEXT: Type: NT_GNU_PROPERTY_TYPE_0 (property note)
// LLVM-NEXT: Property [
// LLVM-NEXT: stack size: 0x100
// LLVM-NEXT: stack size: 0x100
// LLVM-NEXT: no copy on protected
// LLVM-NEXT: X86 features: SHSTK
// LLVM-NEXT: X86 features: IBT, SHSTK
// LLVM-NEXT: X86 features: none
// LLVM-NEXT: <application-specific type 0xfefefefe>
// LLVM-NEXT: stack size: <corrupt length: 0x0>
// LLVM-NEXT: stack size: <corrupt length: 0x4>
// LLVM-NEXT: no copy on protected <corrupt length: 0x1>
// LLVM-NEXT: X86 features: <corrupt length: 0x0>
// LLVM-NEXT: X86 features: IBT, <unknown flags: 0xf000f000f000f000>
// LLVM-NEXT: <corrupt type (0x2) datasz: 0x1>
// LLVM-NEXT: ]
// LLVM-NEXT: }
// LLVM-NEXT: }
// LLVM-NEXT: ]

.section ".note.gnu.property", "a"
.align 4
Expand Down
26 changes: 21 additions & 5 deletions llvm/test/tools/llvm-readobj/note-gnu-property2.s
@@ -1,11 +1,27 @@
// REQUIRES: x86-registered-target
// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o %t
// RUN: llvm-readobj -elf-output-style GNU --notes %t | FileCheck %s
// RUN: llvm-readobj -elf-output-style GNU --notes %t | FileCheck %s --check-prefix=GNU
// RUN: llvm-readobj -elf-output-style LLVM --notes %t | FileCheck %s --check-prefix=LLVM

// CHECK: Displaying notes found at file offset 0x00000040 with length 0x00000014:
// CHECK-NEXT: Owner Data size Description
// CHECK-NEXT: GNU 0x00000004 NT_GNU_PROPERTY_TYPE_0 (property note)
// CHECK-NEXT: Properties: <corrupted GNU_PROPERTY_TYPE_0>
// GNU: Displaying notes found at file offset 0x00000040 with length 0x00000014:
// 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: Offset: 0x40
// LLVM-NEXT: Size: 0x14
// 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.

Expand Down

0 comments on commit 4f36c7a

Please sign in to comment.