Allocate the IntervalMap in ELF.h on the heap to work around MSVC alignment bug (PR24113)

llvm-svn: 242157
This commit is contained in:
Hans Wennborg 2015-07-14 16:27:16 +00:00
parent c3eec458ab
commit a6a15b8f2e
1 changed files with 7 additions and 5 deletions

View File

@ -731,7 +731,9 @@ void ELFFile<ELFT>::scanDynamicTable() {
IntervalMapImpl::NodeSizer<uintX_t, uintptr_t>::LeafSize, IntervalMapImpl::NodeSizer<uintX_t, uintptr_t>::LeafSize,
IntervalMapHalfOpenInfo<uintX_t>> LoadMapT; IntervalMapHalfOpenInfo<uintX_t>> LoadMapT;
typename LoadMapT::Allocator Alloc; typename LoadMapT::Allocator Alloc;
LoadMapT LoadMap(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));
for (Elf_Phdr_Iter PhdrI = program_header_begin(), for (Elf_Phdr_Iter PhdrI = program_header_begin(),
PhdrE = program_header_end(); PhdrE = program_header_end();
@ -746,13 +748,13 @@ void ELFFile<ELFT>::scanDynamicTable() {
continue; continue;
if (PhdrI->p_filesz == 0) if (PhdrI->p_filesz == 0)
continue; continue;
LoadMap.insert(PhdrI->p_vaddr, PhdrI->p_vaddr + PhdrI->p_filesz, LoadMap->insert(PhdrI->p_vaddr, PhdrI->p_vaddr + PhdrI->p_filesz,
PhdrI->p_offset); PhdrI->p_offset);
} }
auto toMappedAddr = [&](uint64_t VAddr) -> const uint8_t * { auto toMappedAddr = [&](uint64_t VAddr) -> const uint8_t * {
auto I = LoadMap.find(VAddr); auto I = LoadMap->find(VAddr);
if (I == LoadMap.end()) if (I == LoadMap->end())
return nullptr; return nullptr;
return this->base() + I.value() + (VAddr - I.start()); return this->base() + I.value() + (VAddr - I.start());
}; };