Skip to content

Commit

Permalink
ELF: more section creation cleanup
Browse files Browse the repository at this point in the history
Summary:
This patch attempts to move as much code as possible out of the
CreateSections function to make room for future improvements there. Some
of this may be slightly over-engineered (VMAddressProvider), but I
wanted to keep the logic of this function very simple, because once I
start taking segment headers into acount (as discussed in D55356), the
function is going to grow significantly.

While in there, I also added tests for various bits of functionality.

This should be NFC, except that I changed the order of hac^H^Heuristicks
for determining section type slightly. Previously, name-based deduction
(.symtab -> symtab) would take precedence over type-based (SHT_SYMTAB ->
symtab) one. In fact we would assert if we ran into a .text section with
type SHT_SYMTAB. Though unlikely to matter in practice, this order
seemed wrong to me, so I have inverted it.

Reviewers: clayborg, krytarowski, espindola

Subscribers: emaste, arichardson, lldb-commits

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

llvm-svn: 349268
  • Loading branch information
labath committed Dec 15, 2018
1 parent c8e364e commit 62a8254
Show file tree
Hide file tree
Showing 9 changed files with 230 additions and 73 deletions.
6 changes: 2 additions & 4 deletions lldb/lit/Modules/ELF/compressed-sections.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,13 @@ Sections:

# CHECK: Name: .hello_elf
# CHECK-NEXT: Type: regular
# CHECK-NEXT: Thread specific: no
# CHECK-NEXT: VM size: 0
# CHECK: VM size: 0
# CHECK-NEXT: File size: 28
# CHECK-NEXT: Data:
# CHECK-NEXT: 20304050 60708090

# CHECK: Name: .bogus
# CHECK-NEXT: Type: regular
# CHECK-NEXT: Thread specific: no
# CHECK-NEXT: VM size: 0
# CHECK: VM size: 0
# CHECK-NEXT: File size: 8
# CHECK-NEXT: Data: ()
58 changes: 58 additions & 0 deletions lldb/lit/Modules/ELF/section-addresses.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# RUN: yaml2obj %s > %t
# RUN: lldb-test object-file %t | FileCheck %s

# CHECK-LABEL: Name: .one
# CHECK: VM address: 0x0

# CHECK-LABEL: Name: .nonalloc
# CHECK: VM address: 0x0

# CHECK-LABEL: Name: .two
# CHECK: VM address: 0x8

# CHECK-LABEL: Name: .three
# CHECK: VM address: 0xc

# CHECK-LABEL: Name: .four
# CHECK: VM address: 0xc

# CHECK-LABEL: Name: .five
# CHECK: VM address: 0x1000

--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_REL
Machine: EM_X86_64
Entry: 0x00000000000007A0
Sections:
- Name: .one
Type: SHT_PROGBITS
Flags: [ SHF_ALLOC ]
AddressAlign: 0x0000000000000004
Content: DEADBEEFBAADF00D
- Name: .nonalloc
Type: SHT_PROGBITS
AddressAlign: 0x0000000000000004
Content: DEADBEEFBAADF00D
- Name: .two
Type: SHT_PROGBITS
Flags: [ SHF_ALLOC ]
AddressAlign: 0x0000000000000004
Content: DE
- Name: .three
Type: SHT_PROGBITS
Flags: [ SHF_ALLOC ]
AddressAlign: 0x0000000000000004
- Name: .four
Type: SHT_PROGBITS
Flags: [ SHF_ALLOC ]
AddressAlign: 0x0000000000000004
Content: DEADBEEFBAADF00D
- Name: .five
Type: SHT_PROGBITS
Flags: [ SHF_ALLOC ]
AddressAlign: 0x0000000000001000
Content: DEADBEEFBAADF00D
...
34 changes: 34 additions & 0 deletions lldb/lit/Modules/ELF/section-permissions.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# RUN: yaml2obj %s > %t
# RUN: lldb-test object-file %t | FileCheck %s

# CHECK-LABEL: Name: .r-x
# CHECK: Permissions: r-x
#
# CHECK-LABEL: Name: .rw-
# CHECK: Permissions: rw-

# CHECK-LABEL: Name: .---
# CHECK: Permissions: ---

--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_DYN
Machine: EM_X86_64
Entry: 0x00000000000007A0
Sections:
- Name: .r-x
Type: SHT_PROGBITS
Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
Content: DEADBEEFBAADF00D
- Name: .rw-
Type: SHT_PROGBITS
Flags: [ SHF_WRITE, SHF_ALLOC ]
AddressAlign: 0x0000000000000004
Content: DEADBEEFBAADF00D
- Name: .---
Type: SHT_PROGBITS
AddressAlign: 0x0000000000000001
Content: DEADBEEFBAADF00D
...
35 changes: 35 additions & 0 deletions lldb/lit/Modules/ELF/section-types-edgecases.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# This test doesn't attempt to mandate a specific section classification. It is
# here to document the existing behavior and to make sure we don't do something
# completely crazy (like crashing).

# RUN: yaml2obj %s > %t
# RUN: lldb-test object-file %t | FileCheck %s

# The section is called .data, but it has the SHF_EXECINSTR flag set. Have
# the flag take precedence over the name.
# CHECK-LABEL: Name: .data
# CHECK-NEXT: Type: code

# Section type (SHT_SYMTAB) takes precedence over name-based deduction.
# CHECK-LABEL: Name: .text
# CHECK-NEXT: Type: elf-symbol-table

--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_DYN
Machine: EM_X86_64
Entry: 0x00000000000007A0
Sections:
- Name: .data
Type: SHT_PROGBITS
Flags: [ SHF_EXECINSTR, SHF_ALLOC ]
AddressAlign: 0x0000000000000004
Content: DEADBEEFBAADF00D
- Name: .text
Type: SHT_SYMTAB
Flags: [ ]
AddressAlign: 0x0000000000000004
Content: DEADBEEFBAADF00D
...
4 changes: 2 additions & 2 deletions lldb/lit/Modules/ELF/section-types.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@

# CHECK-LABEL: Name: .tdata
# CHECK-NEXT: Type: data
# CHECK-NEXT: Thread specific: yes
# CHECK: Thread specific: yes

# CHECK-LABEL: Name: .tbss
# CHECK-NEXT: Type: zero-fill
# CHECK-NEXT: Thread specific: yes
# CHECK: Thread specific: yes

--- !ELF
FileHeader:
Expand Down
10 changes: 10 additions & 0 deletions lldb/lit/Modules/MachO/subsections.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,46 @@
#CHECK-NEXT: Index: 0
#CHECK-NEXT: Name: __PAGEZERO
#CHECK-NEXT: Type: container
#CHECK-NEXT: Permissions: ---
#CHECK-NEXT: Thread specific: no
#CHECK-NEXT: VM address: 0x0
#CHECK-NEXT: VM size: 4294967296
#CHECK-NEXT: File size: 0
#CHECK-NEXT: There are no subsections
#
#CHECK: Index: 1
#CHECK-NEXT: Name: __TEXT
#CHECK-NEXT: Type: container
#CHECK-NEXT: Permissions: r-x
#CHECK-NEXT: Thread specific: no
#CHECK-NEXT: VM address: 0x100000000
#CHECK-NEXT: VM size: 4096
#CHECK-NEXT: File size: 4096
#CHECK-NEXT: Showing 3 subsections
#CHECK-NEXT: Index: 0
#CHECK-NEXT: Name: __text
#CHECK-NEXT: Type: code
#CHECK-NEXT: Permissions: r-x
#CHECK-NEXT: Thread specific: no
#CHECK-NEXT: VM address: 0x100000f30
#CHECK-NEXT: VM size: 22
#CHECK-NEXT: File size: 22
#
#CHECK: Index: 1
#CHECK-NEXT: Name: __unwind_info
#CHECK-NEXT: Type: compact-unwind
#CHECK-NEXT: Permissions: r-x
#CHECK-NEXT: Thread specific: no
#CHECK-NEXT: VM address: 0x100000f48
#CHECK-NEXT: VM size: 76
#CHECK-NEXT: File size: 76
#
#CHECK: Index: 2
#CHECK-NEXT: Name: __eh_frame
#CHECK-NEXT: Type: eh-frame
#CHECK-NEXT: Permissions: r-x
#CHECK-NEXT: Thread specific: no
#CHECK-NEXT: VM address: 0x100000f98
#CHECK-NEXT: VM size: 104
#CHECK-NEXT: File size: 104

Expand Down

0 comments on commit 62a8254

Please sign in to comment.