lib/Object/ELFObjectFile.cpp: Fix undefined behavior for MC/ELF/many-section.s not...
authorNAKAMURA Takumi <geek4civic@gmail.com>
Wed, 12 Oct 2011 10:28:55 +0000 (10:28 +0000)
committerNAKAMURA Takumi <geek4civic@gmail.com>
Wed, 12 Oct 2011 10:28:55 +0000 (10:28 +0000)
DenseMap::lookup(k) would return "default constructor value" when k was not met. It would be useless when value type were POD.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@141774 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Object/ELFObjectFile.cpp

index a580dd07dc1d908185d0373de6179c8af151b3d1..7add2d8a52eaf71380d321040469a0b8c8b16412 100644 (file)
@@ -444,8 +444,11 @@ template<support::endianness target_endianness, bool is64Bits>
 const typename ELFObjectFile<target_endianness, is64Bits>::Elf_Shdr *
 ELFObjectFile<target_endianness, is64Bits>
                              ::getSection(const Elf_Sym *symb) const {
-  if (symb->st_shndx == ELF::SHN_XINDEX)
+  if (symb->st_shndx == ELF::SHN_XINDEX) {
+    if (!ExtendedSymbolTable.count(symb))
+      return 0;
     return getSection(ExtendedSymbolTable.lookup(symb));
+  }
   if (symb->st_shndx >= ELF::SHN_LORESERVE)
     return 0;
   return getSection(symb->st_shndx);