[llvm] 53c164e - [llvm/Object] - Fix the error message reported for a broken SHT_SYMTAB_SHNDX section.

via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 25 02:24:59 PDT 2019


Author: georgerim
Date: 2019-10-25T12:19:46+03:00
New Revision: 53c164e2216fd705ceadfdec6ac44b5b175d9248

URL: https://github.com/llvm/llvm-project/commit/53c164e2216fd705ceadfdec6ac44b5b175d9248
DIFF: https://github.com/llvm/llvm-project/commit/53c164e2216fd705ceadfdec6ac44b5b175d9248.diff

LOG: [llvm/Object] - Fix the error message reported for a broken SHT_SYMTAB_SHNDX section.

SHT_SYMTAB_SHNDX should have the same number of entries as the symbol table
associated (https://www.sco.com/developers/gabi/latest/ch4.sheader.html)

We currently can report the following message:
"SHT_SYMTAB_SHNDX section has sh_size (24) which is not equal to the number of symbols (2)"

It is just broken. This patch refines/fixes it.

Differential revision: https://reviews.llvm.org/D69305

Added: 
    

Modified: 
    llvm/include/llvm/Object/ELF.h
    llvm/test/Object/invalid.test
    llvm/test/tools/obj2yaml/elf-sht-symtab-shndx.yaml

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/Object/ELF.h b/llvm/include/llvm/Object/ELF.h
index 28b00c8413de..5a13097a9276 100644
--- a/llvm/include/llvm/Object/ELF.h
+++ b/llvm/include/llvm/Object/ELF.h
@@ -641,11 +641,12 @@ ELFFile<ELFT>::getSHNDXTable(const Elf_Shdr &Section,
                                                      SymTable.sh_type) +
                        " section (expected SHT_SYMTAB/SHT_DYNSYM)");
 
-  if (V.size() != (SymTable.sh_size / sizeof(Elf_Sym)))
-    return createError("SHT_SYMTAB_SHNDX section has sh_size (" +
-                       Twine(SymTable.sh_size) +
-                       ") which is not equal to the number of symbols (" +
-                       Twine(V.size()) + ")");
+  uint64_t Syms = SymTable.sh_size / sizeof(Elf_Sym);
+  if (V.size() != Syms)
+    return createError("SHT_SYMTAB_SHNDX has " + Twine(V.size()) +
+                       "  entries, but the symbol table associated has " +
+                       Twine(Syms));
+
   return V;
 }
 

diff  --git a/llvm/test/Object/invalid.test b/llvm/test/Object/invalid.test
index 56372bf37c24..396776c5f919 100644
--- a/llvm/test/Object/invalid.test
+++ b/llvm/test/Object/invalid.test
@@ -213,7 +213,7 @@ Sections:
 # RUN: yaml2obj %s --docnum=11 -o %t11
 # RUN: not llvm-readobj --symbols %t11 2>&1 | FileCheck --check-prefix=INVALID-XINDEX-SIZE %s
 
-# INVALID-XINDEX-SIZE: error: {{.*}}: SHT_SYMTAB_SHNDX section has sh_size (24) which is not equal to the number of symbols (2)
+# INVALID-XINDEX-SIZE: error: {{.*}}: SHT_SYMTAB_SHNDX has 2 entries, but the symbol table associated has 1
 
 --- !ELF
 FileHeader:

diff  --git a/llvm/test/tools/obj2yaml/elf-sht-symtab-shndx.yaml b/llvm/test/tools/obj2yaml/elf-sht-symtab-shndx.yaml
index 735ad6ed4abe..e0078b9f6be1 100644
--- a/llvm/test/tools/obj2yaml/elf-sht-symtab-shndx.yaml
+++ b/llvm/test/tools/obj2yaml/elf-sht-symtab-shndx.yaml
@@ -98,8 +98,7 @@ Symbols:
 # RUN: yaml2obj --docnum=4 %s -o %t4
 # RUN: not obj2yaml %t4 2>&1 | FileCheck %s -DFILE=%t4 --check-prefix=CASE4
 
-## FIXME: The error message below needs rewording. Size should not be equal to the number of symbols.
-## CASE4: Error reading file: [[FILE]]: SHT_SYMTAB_SHNDX section has sh_size (48) which is not equal to the number of symbols (3)
+## CASE4: Error reading file: [[FILE]]: SHT_SYMTAB_SHNDX has 3 entries, but the symbol table associated has 2
 
 --- !ELF
 FileHeader:


        


More information about the llvm-commits mailing list