forked from OSchip/llvm-project
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. llvm-svn: 350804
This commit is contained in:
parent
8f85b9f867
commit
976af43ba9
|
@ -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
|
||||
...
|
|
@ -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: ()
|
||||
|
|
|
@ -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
|
||||
//----------------------------------------------------------------------
|
||||
|
|
|
@ -134,6 +134,8 @@ public:
|
|||
|
||||
lldb_private::Address GetEntryPointAddress() override;
|
||||
|
||||
lldb_private::Address GetBaseAddress() override;
|
||||
|
||||
ObjectFile::Type CalculateType() override;
|
||||
|
||||
ObjectFile::Strata CalculateStrata() override;
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue