Allocate the IntervalMap in ELF.h on the heap to work around MSVC alignment bug ...
authorHans Wennborg <hans@hanshq.net>
Tue, 14 Jul 2015 16:27:16 +0000 (16:27 +0000)
committerHans Wennborg <hans@hanshq.net>
Tue, 14 Jul 2015 16:27:16 +0000 (16:27 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@242157 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Object/ELF.h

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