This patch improves the ability of a ObjectFileELF instance to read the .dynamic section. It adds the ability to read the .dynamic section from the PT_DYNAMIC program header which is useful for ELF files that have no section headers and for ELF files that are read from memory. It cleans up the usage of the .dynamic entries so that ObjectFileELF::ParseDynamicSymbols() is the only code that parses .dynamic entries, teaches that function the read and store the string values for each .dynamic entry. We now dump the .dynamic entries in the output of "image dump objfile". It also cleans up the code that gets the dynamic string table so that it can grab it from the DT_STRTAB and DT_STRSZ .dynamic entries for when we have a ELF file with no section headers or we are reading it from memory.
94 lines
3.0 KiB
YAML
94 lines
3.0 KiB
YAML
## This test verifies that loading an ELF file that has no section headers can
|
|
## find the contents on the .dynamic section and the strings associated with
|
|
## the .dynamic seciton.
|
|
## - Loading the .dynamic section from the PT_DYNAMIC
|
|
## This test will make a simple executable that links against libc.so and we
|
|
## verify that we can find the DT_NEEDED entry with the shared library found
|
|
## in the .dynamic dump from "image dump objfile"
|
|
|
|
# RUN: yaml2obj %s -o %t
|
|
|
|
# RUN: %lldb -b \
|
|
# RUN: -o "target create -d '%t'" \
|
|
# RUN: -o "image dump objfile" \
|
|
# RUN: | FileCheck %s --dump-input=always
|
|
# CHECK: (lldb) image dump objfile
|
|
# CHECK: Dumping headers for 1 module(s).
|
|
# CHECK: ObjectFileELF, file =
|
|
# CHECK: ELF Header
|
|
# Make sure there are no section headers
|
|
# CHECK: e_shnum = 0x00000000
|
|
|
|
# Make sure we find the program headers and see a PT_DYNAMIC entry.
|
|
# CHECK: Program Headers
|
|
# CHECK: IDX p_type p_offset p_vaddr p_paddr p_filesz p_memsz p_flags p_align
|
|
# CHECK: ==== --------------- -------- -------- -------- -------- -------- ------------------------- --------
|
|
# CHECK: [ 0] PT_LOAD 000000b0 00000000 00000000 00000170 00000170 00000000 ( ) 00000001
|
|
# CHECK: [ 1] PT_DYNAMIC 000001b0 00000100 00000100 00000070 00000070 00000000 ( ) 00000008
|
|
|
|
# CHECK: Dependent Modules:
|
|
# CHECK: ccc
|
|
# CHECK: aaa
|
|
# CHECK: bbb
|
|
|
|
# Make sure we see some sections created from the program headers
|
|
# MAIN: SectID
|
|
# MAIN: PT_LOAD[0]
|
|
|
|
# CHECK: .dynamic:
|
|
# CHECK: IDX d_tag d_val/d_ptr
|
|
# CHECK: ==== ---------------- ------------------
|
|
# CHECK: [ 0] STRTAB 0x0000000000000000
|
|
# CHECK: [ 1] NEEDED 0x0000000000000009 "ccc"
|
|
# CHECK: [ 2] NEEDED 0x0000000000000001 "aaa"
|
|
# CHECK: [ 3] NEEDED 0x0000000000000005 "bbb"
|
|
# CHECK: [ 4] STRSZ 0x0000000000000100
|
|
# CHECK: [ 5] DEBUG 0x00000000deadbeef
|
|
# CHECK: [ 6] NULL 0x0000000000000000
|
|
|
|
# Make sure the ObjectFileELF::GetImageInfoAddress() works.
|
|
# CHECK: image_info_address = 0x0000000000000158
|
|
|
|
--- !ELF
|
|
FileHeader:
|
|
Class: ELFCLASS64
|
|
Data: ELFDATA2LSB
|
|
Type: ET_EXEC
|
|
Machine: EM_X86_64
|
|
Sections:
|
|
- Type: SectionHeaderTable
|
|
NoHeaders: true
|
|
- Name: .dynstr
|
|
Type: SHT_STRTAB
|
|
Flags: [ SHF_ALLOC ]
|
|
Content: '00616161006262620063636300' ## 0,a,a,a,0,b,b,b,0,c,c,c,0
|
|
Size: 0x100
|
|
- Name: .dynamic
|
|
Type: SHT_DYNAMIC
|
|
Address: 0x100
|
|
Entries:
|
|
- Tag: DT_STRTAB
|
|
Value: 0x0000000000000000
|
|
- Tag: DT_NEEDED
|
|
Value: 9
|
|
- Tag: DT_NEEDED
|
|
Value: 1
|
|
- Tag: DT_NEEDED
|
|
Value: 5
|
|
- Tag: DT_STRSZ
|
|
Value: 0x100
|
|
- Tag: DT_DEBUG
|
|
Value: 0xdeadbeef
|
|
- Tag: DT_NULL
|
|
Value: 0x0
|
|
ProgramHeaders:
|
|
- Type: PT_LOAD
|
|
VAddr: 0x0
|
|
FirstSec: .dynstr
|
|
LastSec: .dynamic
|
|
- Type: PT_DYNAMIC
|
|
FirstSec: .dynamic
|
|
LastSec: .dynamic
|
|
VAddr: 0x100
|
|
Align: 0x8
|