Index: llvm/test/tools/llvm-readobj/ELF/symbols.test =================================================================== --- llvm/test/tools/llvm-readobj/ELF/symbols.test +++ llvm/test/tools/llvm-readobj/ELF/symbols.test @@ -117,11 +117,31 @@ DynamicSymbols: - Name: zed +## Case 6: Test that the Num index starts from zero at every new symbol table. + +# RUN: yaml2obj --docnum=2 %s -o %t1 +# RUN: llvm-readelf --symbols %t1 %t1 | FileCheck %s --check-prefix=NUM-INDEX + +# NUM-INDEX: Symbol table '.symtab' contains 1 entries: +# NUM-INDEX-NEXT: Num: {{.*}} +# NUM-INDEX-NEXT: 0: {{.*}} +# NUM-INDEX: Symbol table '.symtab' contains 1 entries: +# NUM-INDEX-NEXT: Num: {{.*}} +# NUM-INDEX-NEXT: 0: {{.*}} + +--- !ELF +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_386 +Symbols: [] + ## Check the behavior when we are unable to print symbols due to an error. ## Case 1: check we are able to dump symbols even when can't get the string table for the ## SHT_SYMTAB section because of invalid sh_link value. -# RUN: yaml2obj --docnum=2 -DLINK=0xff %s -o %t64.err1 +# RUN: yaml2obj --docnum=3 -DLINK=0xff %s -o %t64.err1 # RUN: llvm-readobj --symbols %t64.err1 2>&1 | \ # RUN: FileCheck %s -DFILE=%t64.err1 --check-prefix=STRTAB-LINK-ERR-LLVM # RUN: llvm-readelf --symbols %t64.err1 2>&1 | \ @@ -178,7 +198,7 @@ ## Case 2: check we report a warning when we are unable to read symbols ## from the the SHT_SYMTAB section. -# RUN: yaml2obj --docnum=2 -DENTSIZE=0xFF %s -o %t64.err2 +# RUN: yaml2obj --docnum=3 -DENTSIZE=0xFF %s -o %t64.err2 # RUN: llvm-readobj --symbols %t64.err2 2>&1 | \ # RUN: FileCheck %s -DFILE=%t64.err2 --check-prefix=SYMTAB-ENTSIZE-ERR-LLVM # RUN: llvm-readelf --symbols %t64.err2 2>&1 | \ @@ -193,7 +213,7 @@ ## Case 3: check we report a warning, but continue dumping, when we are unable to read the name of the SHT_SYMTAB section. ## In this case we set the e_shstrndx field to an invalid index so that the .shstrtab section can't be located. -# RUN: yaml2obj --docnum=2 -DSHSTRTAB=0xff %s -o %t64.err3 +# RUN: yaml2obj --docnum=3 -DSHSTRTAB=0xff %s -o %t64.err3 # RUN: llvm-readobj --symbols %t64.err3 2>&1 | \ # RUN: FileCheck %s -DFILE=%t64.err3 --check-prefix=SYMTAB-SHSTRTAB-ERR-LLVM --implicit-check-not=warning: # RUN: llvm-readelf --symbols %t64.err3 2>&1 | \ Index: llvm/tools/llvm-readobj/ELFDumper.cpp =================================================================== --- llvm/tools/llvm-readobj/ELFDumper.cpp +++ llvm/tools/llvm-readobj/ELFDumper.cpp @@ -3929,21 +3929,10 @@ const Elf_Sym *FirstSym, Optional StrTable, bool IsDynamic, bool NonVisibilityBitsUsed) { - static int Idx = 0; - static bool Dynamic = true; - - // If this function was called with a different value from IsDynamic - // from last call, happens when we move from dynamic to static symbol - // table, "Num" field should be reset. - if (!Dynamic != !IsDynamic) { - Idx = 0; - Dynamic = false; - } - unsigned Bias = ELFT::Is64Bits ? 8 : 0; Field Fields[8] = {0, 8, 17 + Bias, 23 + Bias, 31 + Bias, 38 + Bias, 48 + Bias, 51 + Bias}; - Fields[0].Str = to_string(format_decimal(Idx++, 6)) + ":"; + Fields[0].Str = to_string(format_decimal(Symbol - FirstSym, 6)) + ":"; Fields[1].Str = to_string( format_hex_no_prefix(Symbol->st_value, ELFT::Is64Bits ? 16 : 8)); Fields[2].Str = to_string(format_decimal(Symbol->st_size, 5));