[PATCH] D84606: [llvm-readelf] Symbol index in symbol table printing is not reset
Mikhail Kalashnikov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 27 06:57:08 PDT 2020
mikkqu updated this revision to Diff 280898.
mikkqu added a comment.
- Reuse YAML in test case
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D84606/new/
https://reviews.llvm.org/D84606
Files:
llvm/test/tools/llvm-readobj/ELF/symbols.test
llvm/tools/llvm-readobj/ELFDumper.cpp
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<StringRef> 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));
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
@@ -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]]
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D84606.280898.patch
Type: text/x-patch
Size: 2139 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200727/f23f387c/attachment.bin>
More information about the llvm-commits
mailing list