Files
clang-p2996/lldb/test/Shell/ObjectFile/ELF/elf-memory.test
Greg Clayton f1e2886261 [LLDB] Impove ObjectFileELF's .dynamic parsing and usage. (#102570)
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.
2024-08-12 10:57:04 -07:00

56 lines
2.3 KiB
Plaintext

// REQUIRES: system-linux, native
// This test verifies that loading an ELF file from memory works and the new
// features that were added when loading from memory work like:
// - Loading the .dynamic section from the PT_DYNAMIC since ELF files loaded
// from memory don't have the section headers available.
// This test will make a simple executable that:
// - links against libc
// - runs and stops at a breakpoint
// - create a memory ELF file
// - verify that "image dump objfile" will dump the dynamic section of the
// memory elf file and find the .dynamic string table.
// RUN: %clang_host %p/Inputs/memory-elf.cpp -g -O0 -o %t
// RUN: %lldb %t -b \
// RUN: -o "b main" \
// RUN: -o "run" \
// RUN: -o "script real_module = lldb.target.module[0]" \
// RUN: -o "script base_addr = real_module.GetObjectFileHeaderAddress().GetLoadAddress(lldb.target)" \
// RUN: -o "script mem_module = lldb.SBModule(lldb.process, base_addr)" \
// RUN: -o "script target2 = lldb.debugger.CreateTarget('')" \
// RUN: -o "script target2.AddModule(mem_module)" \
// RUN: -o "target select 1" \
// RUN: -o "image dump objfile" \
// RUN: | FileCheck %s --check-prefix=MAIN --dump-input=always
// MAIN: (lldb) image dump objfile
// MAIN: Dumping headers for 1 module(s).
// MAIN: ObjectFileELF, file = '', arch = {{.*, addr = 0x[0-9a-f]+}}
// MAIN: ELF Header
// Make sure we find the program headers and see a PT_DYNAMIC entry.
// MAIN: Program Headers
// MAIN: ] PT_DYNAMIC
// Make sure we see some sections created from the program headers
// MAIN: SectID
// MAIN: PT_LOAD[0]
// Ensure we find some dependent modules as won't find these if we aren't able
// to load the .dynamic section from the PT_DYNAMIC program header.
// MAIN: Dependent Modules:
// Check for the .dynamic dump and ensure we find all dynamic entries that are
// required to be there and needed to get the .dynstr section and the symbol
// table, and the DT_DEBUG entry to find the list of shared libraries.
// MAIN: .dynamic:
// Make sure we found the .dynstr section by checking for valid strings after NEEDED
// MAIN-DAG: NEEDED {{0x[0-9a-f]+ ".*libc.*"}}
// MAIN-DAG: STRTAB {{0x[0-9a-f]+}}
// MAIN-DAG: SYMTAB {{0x[0-9a-f]+}}
// MAIN-DAG: STRSZ {{0x[0-9a-f]+}}
// MAIN-DAG: SYMENT {{0x[0-9a-f]+}}
// MAIN-DAG: DEBUG {{0x[0-9a-f]+}}
// MAIN: NULL {{0x[0-9a-f]+}}