summaryrefslogtreecommitdiff
path: root/lldb
diff options
context:
space:
mode:
authorPavel Labath <pavel@labath.sk>2019-01-10 09:32:31 +0000
committerPavel Labath <pavel@labath.sk>2019-01-10 09:32:31 +0000
commitd194e2eb244b973e19717690ee320237c5fd1915 (patch)
tree5c9c2aa6c190c26a5e66b6b6ebda7aa06e65f091 /lldb
parent9e0697f245e416ad031dc1043e57778ab3899224 (diff)
Implement ObjectFileELF::GetBaseAddress
Summary: The concept of a base address was already present in the implementation (it's needed for computing section load addresses properly), but it was never exposed through this function. This fixes that.
Diffstat (limited to 'lldb')
-rw-r--r--lldb/lit/Modules/ELF/basic-info.yaml27
-rw-r--r--lldb/lit/Modules/ELF/compressed-sections.yaml6
-rw-r--r--lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp25
-rw-r--r--lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h2
-rw-r--r--lldb/tools/lldb-test/lldb-test.cpp2
5 files changed, 50 insertions, 12 deletions
diff --git a/lldb/lit/Modules/ELF/basic-info.yaml b/lldb/lit/Modules/ELF/basic-info.yaml
new file mode 100644
index 00000000000..0e1db67e9d5
--- /dev/null
+++ b/lldb/lit/Modules/ELF/basic-info.yaml
@@ -0,0 +1,27 @@
+# REQUIRES: lld
+
+# RUN: yaml2obj %s > %t.o
+# RUN: ld.lld %t.o -o %t -image-base 0x47000
+# RUN: lldb-test object-file %t | FileCheck %s
+
+# CHECK: Plugin name: elf
+# CHECK: Architecture: x86_64--
+# CHECK: Executable: true
+# CHECK: Stripped: false
+# CHECK: Type: executable
+# CHECK: Strata: user
+# CHECK: Base VM address: 0x47000
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_X86_64
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x0000000000000010
+ Content: 554889E55DC3
+...
diff --git a/lldb/lit/Modules/ELF/compressed-sections.yaml b/lldb/lit/Modules/ELF/compressed-sections.yaml
index b52f0124345..df070a2d53d 100644
--- a/lldb/lit/Modules/ELF/compressed-sections.yaml
+++ b/lldb/lit/Modules/ELF/compressed-sections.yaml
@@ -19,13 +19,15 @@ Sections:
# CHECK: Name: .hello_elf
# CHECK-NEXT: Type: regular
-# CHECK: VM size: 0
+# CHECK: VM address: 0
+# CHECK-NEXT: VM size: 0
# CHECK-NEXT: File size: 28
# CHECK-NEXT: Data:
# CHECK-NEXT: 20304050 60708090
# CHECK: Name: .bogus
# CHECK-NEXT: Type: regular
-# CHECK: VM size: 0
+# CHECK: VM address: 0
+# CHECK-NEXT: VM size: 0
# CHECK-NEXT: File size: 8
# CHECK-NEXT: Data: ()
diff --git a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
index 726aa9b2c6f..71b535e055b 100644
--- a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
+++ b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
@@ -806,17 +806,10 @@ bool ObjectFileELF::SetLoadAddress(Target &target, lldb::addr_t value,
SectionList *section_list = GetSectionList();
if (section_list) {
if (!value_is_offset) {
- bool found_offset = false;
- for (const ELFProgramHeader &H : ProgramHeaders()) {
- if (H.p_type != PT_LOAD || H.p_offset != 0)
- continue;
-
- value = value - H.p_vaddr;
- found_offset = true;
- break;
- }
- if (!found_offset)
+ addr_t base = GetBaseAddress().GetFileAddress();
+ if (base == LLDB_INVALID_ADDRESS)
return false;
+ value -= base;
}
const size_t num_sections = section_list->GetSize();
@@ -1055,6 +1048,18 @@ lldb_private::Address ObjectFileELF::GetEntryPointAddress() {
return m_entry_point_address;
}
+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)
+ continue;
+
+ return Address(
+ GetSectionList()->FindSectionByID(SegmentID(EnumPHdr.index())), 0);
+ }
+ return LLDB_INVALID_ADDRESS;
+}
+
//----------------------------------------------------------------------
// ParseDependentModules
//----------------------------------------------------------------------
diff --git a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
index ff08eb2a1bb..08fd5bdc60a 100644
--- a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
+++ b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
@@ -134,6 +134,8 @@ public:
lldb_private::Address GetEntryPointAddress() override;
+ lldb_private::Address GetBaseAddress() override;
+
ObjectFile::Type CalculateType() override;
ObjectFile::Strata CalculateStrata() override;
diff --git a/lldb/tools/lldb-test/lldb-test.cpp b/lldb/tools/lldb-test/lldb-test.cpp
index 4e2ab504c2d..eb7cc6ece42 100644
--- a/lldb/tools/lldb-test/lldb-test.cpp
+++ b/lldb/tools/lldb-test/lldb-test.cpp
@@ -785,6 +785,8 @@ static int dumpObjectFiles(Debugger &Dbg) {
Printer.formatLine("Stripped: {0}", ObjectPtr->IsStripped());
Printer.formatLine("Type: {0}", ObjectPtr->GetType());
Printer.formatLine("Strata: {0}", ObjectPtr->GetStrata());
+ Printer.formatLine("Base VM address: {0:x}",
+ ObjectPtr->GetBaseAddress().GetFileAddress());
dumpSectionList(Printer, *Sections, /*is_subsection*/ false);