[llvm] r242672 - Simplify the search for which segment has a virtual address. NFC.
Rafael Espindola
rafael.espindola at gmail.com
Mon Jul 20 07:15:39 PDT 2015
Author: rafael
Date: Mon Jul 20 09:15:38 2015
New Revision: 242672
URL: http://llvm.org/viewvc/llvm-project?rev=242672&view=rev
Log:
Simplify the search for which segment has a virtual address. NFC.
Modified:
llvm/trunk/include/llvm/Object/ELF.h
Modified: llvm/trunk/include/llvm/Object/ELF.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/ELF.h?rev=242672&r1=242671&r2=242672&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/ELF.h (original)
+++ llvm/trunk/include/llvm/Object/ELF.h Mon Jul 20 09:15:38 2015
@@ -16,7 +16,6 @@
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMap.h"
-#include "llvm/ADT/IntervalMap.h"
#include "llvm/ADT/PointerIntPair.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringSwitch.h"
@@ -726,17 +725,12 @@ ELFFile<ELFT>::ELFFile(StringRef Object,
}
template <class ELFT>
-void ELFFile<ELFT>::scanDynamicTable() {
- // Build load-address to file-offset map.
- 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));
+static bool compareAddr(uint64_t VAddr, const Elf_Phdr_Impl<ELFT> *Phdr) {
+ return VAddr < Phdr->p_vaddr;
+}
+template <class ELFT> void ELFFile<ELFT>::scanDynamicTable() {
+ SmallVector<const Elf_Phdr *, 4> LoadSegments;
for (const Elf_Phdr &Phdr : program_headers()) {
if (Phdr.p_type == ELF::PT_DYNAMIC) {
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)
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 I = LoadMap->find(VAddr);
- if (I == LoadMap->end())
+ const Elf_Phdr **I = std::upper_bound(
+ LoadSegments.begin(), LoadSegments.end(), VAddr, compareAddr<ELFT>);
+ if (I == LoadSegments.begin())
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();
More information about the llvm-commits
mailing list