summaryrefslogtreecommitdiff
path: root/lldb
diff options
context:
space:
mode:
authorPavel Labath <pavel@labath.sk>2019-01-11 10:18:40 +0000
committerPavel Labath <pavel@labath.sk>2019-01-11 10:18:40 +0000
commitad5545d4c071d19984985980b3eb40d59ef5bdf5 (patch)
treea160333c7dd941ac90f1876c905071af66c1e2b7 /lldb
parentc18a877acb9c1f60e556ef0353ea642998fa2453 (diff)
ELF: Fix base address computation code for files generated by yaml2obj
The code was assuming that the elf file will have a PT_LOAD segment starting from the first byte of the file. While this is true for files generated by most linkers (it's a way of saving space), it is not a requirement. And files not satisfying this constraint can still be perfectly executable. yaml2obj is one of the tools which produces files like this. This patch relaxes the check in ObjectFileELF to take the address of the first PT_LOAD segment as the base address of the object (instead of the one with the offset 0). Since the PT_LOAD segments are supposed to be sorted according to the VM address, this entry will also be the one with the lowest VM address. If we ever run into files which don't have the PT_LOAD segments sorted, we can easily change this code to return the lowest VM address as the base address (if that is the correct thing to do for these files).
Diffstat (limited to 'lldb')
-rw-r--r--lldb/lit/Modules/ELF/base-address.yaml34
-rw-r--r--lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp2
2 files changed, 35 insertions, 1 deletions
diff --git a/lldb/lit/Modules/ELF/base-address.yaml b/lldb/lit/Modules/ELF/base-address.yaml
new file mode 100644
index 00000000000..68f11770835
--- /dev/null
+++ b/lldb/lit/Modules/ELF/base-address.yaml
@@ -0,0 +1,34 @@
+# RUN: yaml2obj %s > %t
+# RUN: lldb-test object-file %t | FileCheck %s
+
+# CHECK: Base VM address: 0x400000
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_EXEC
+ Machine: EM_X86_64
+ Entry: 0x0000000000400078
+Sections:
+ - Name: .pad
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC ]
+ Address: 0x0000000000400000
+ AddressAlign: 0x0000000000001000
+ Size: 0x78
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ Address: 0x0000000000400078
+ AddressAlign: 0x0000000000000001
+ Content: 48C7C0E700000048C7C72F0000000F05CC
+ProgramHeaders:
+ - Type: PT_LOAD
+ Flags: [ PF_X, PF_R ]
+ VAddr: 0x400000
+ Align: 0x200000
+ Sections:
+ - Section: .pad
+ - Section: .text
+...
diff --git a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
index 71b535e055b..9a6563afa0a 100644
--- a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
+++ b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
@@ -1051,7 +1051,7 @@ lldb_private::Address ObjectFileELF::GetEntryPointAddress() {
Address ObjectFileELF::GetBaseAddress() {
for (const auto &EnumPHdr : llvm::enumerate(ProgramHeaders())) {
const ELFProgramHeader &H = EnumPHdr.value();
- if (H.p_type != PT_LOAD || H.p_offset != 0)
+ if (H.p_type != PT_LOAD)
continue;
return Address(