mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-08-27 15:29:51 +00:00
Simplify the search for which segment has a virtual address. NFC.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@242672 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
9a4133e1ee
commit
96a1f00376
@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
#include "llvm/ADT/ArrayRef.h"
|
#include "llvm/ADT/ArrayRef.h"
|
||||||
#include "llvm/ADT/DenseMap.h"
|
#include "llvm/ADT/DenseMap.h"
|
||||||
#include "llvm/ADT/IntervalMap.h"
|
|
||||||
#include "llvm/ADT/PointerIntPair.h"
|
#include "llvm/ADT/PointerIntPair.h"
|
||||||
#include "llvm/ADT/SmallVector.h"
|
#include "llvm/ADT/SmallVector.h"
|
||||||
#include "llvm/ADT/StringSwitch.h"
|
#include "llvm/ADT/StringSwitch.h"
|
||||||
@ -726,17 +725,12 @@ ELFFile<ELFT>::ELFFile(StringRef Object, std::error_code &EC)
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <class ELFT>
|
template <class ELFT>
|
||||||
void ELFFile<ELFT>::scanDynamicTable() {
|
static bool compareAddr(uint64_t VAddr, const Elf_Phdr_Impl<ELFT> *Phdr) {
|
||||||
// Build load-address to file-offset map.
|
return VAddr < Phdr->p_vaddr;
|
||||||
typedef IntervalMap<
|
}
|
||||||
uintX_t, uintptr_t,
|
|
||||||
IntervalMapImpl::NodeSizer<uintX_t, uintptr_t>::LeafSize,
|
|
||||||
IntervalMapHalfOpenInfo<uintX_t>> LoadMapT;
|
|
||||||
typename LoadMapT::Allocator Alloc;
|
|
||||||
// Allocate the IntervalMap on the heap to work around MSVC bug where the
|
|
||||||
// stack doesn't get realigned despite LoadMap having alignment 8 (PR24113).
|
|
||||||
std::unique_ptr<LoadMapT> LoadMap(new LoadMapT(Alloc));
|
|
||||||
|
|
||||||
|
template <class ELFT> void ELFFile<ELFT>::scanDynamicTable() {
|
||||||
|
SmallVector<const Elf_Phdr *, 4> LoadSegments;
|
||||||
for (const Elf_Phdr &Phdr : program_headers()) {
|
for (const Elf_Phdr &Phdr : program_headers()) {
|
||||||
if (Phdr.p_type == ELF::PT_DYNAMIC) {
|
if (Phdr.p_type == ELF::PT_DYNAMIC) {
|
||||||
DynamicRegion.Addr = base() + Phdr.p_offset;
|
DynamicRegion.Addr = base() + Phdr.p_offset;
|
||||||
@ -746,14 +740,16 @@ void ELFFile<ELFT>::scanDynamicTable() {
|
|||||||
}
|
}
|
||||||
if (Phdr.p_type != ELF::PT_LOAD || Phdr.p_filesz == 0)
|
if (Phdr.p_type != ELF::PT_LOAD || Phdr.p_filesz == 0)
|
||||||
continue;
|
continue;
|
||||||
LoadMap->insert(Phdr.p_vaddr, Phdr.p_vaddr + Phdr.p_filesz, Phdr.p_offset);
|
LoadSegments.push_back(&Phdr);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto toMappedAddr = [&](uint64_t VAddr) -> const uint8_t * {
|
auto toMappedAddr = [&](uint64_t VAddr) -> const uint8_t * {
|
||||||
auto I = LoadMap->find(VAddr);
|
const Elf_Phdr **I = std::upper_bound(
|
||||||
if (I == LoadMap->end())
|
LoadSegments.begin(), LoadSegments.end(), VAddr, compareAddr<ELFT>);
|
||||||
|
if (I == LoadSegments.begin())
|
||||||
return nullptr;
|
return nullptr;
|
||||||
return this->base() + I.value() + (VAddr - I.start());
|
--I;
|
||||||
|
return this->base() + (*I)->p_offset + (VAddr - (*I)->p_vaddr);
|
||||||
};
|
};
|
||||||
|
|
||||||
for (Elf_Dyn_Iter DynI = dynamic_table_begin(), DynE = dynamic_table_end();
|
for (Elf_Dyn_Iter DynI = dynamic_table_begin(), DynE = dynamic_table_end();
|
||||||
|
Loading…
Reference in New Issue
Block a user