diff --git a/llvm/test/tools/llvm-readobj/ELF/symbols.test b/llvm/test/tools/llvm-readobj/ELF/symbols.test --- a/llvm/test/tools/llvm-readobj/ELF/symbols.test +++ b/llvm/test/tools/llvm-readobj/ELF/symbols.test @@ -103,6 +103,16 @@ # RUN: llvm-readobj --dyn-symbols %t64 | FileCheck %s --implicit-check-not="{{^}}Symbols [" # RUN: llvm-readelf --dyn-symbols %t64 | FileCheck %s --implicit-check-not="Symbol table '.symtab'" +## Case 6: Test that the Num index starts from zero at every new symbol table. +# RUN: llvm-readelf --symbols %t64 %t64 | FileCheck %s --check-prefix=NUM-INDEX + +# NUM-INDEX: Symbol table '.symtab' contains 3 entries: +# NUM-INDEX-NEXT: Num: {{.*}} +# NUM-INDEX-NEXT: 0: {{.*}} +# NUM-INDEX: Symbol table '.symtab' contains 3 entries: +# NUM-INDEX-NEXT: Num: {{.*}} +# NUM-INDEX-NEXT: 0: {{.*}} + --- !ELF FileHeader: Class: ELFCLASS[[BITS]] diff --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp --- a/llvm/tools/llvm-readobj/ELFDumper.cpp +++ b/llvm/tools/llvm-readobj/ELFDumper.cpp @@ -3924,21 +3924,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));