[llvm] bd99fb4 - [llvm-readelf/obj] - Fix extended section symbol indices printed in warnings for MIPS GOT/PLT entries.

Georgii Rymar via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 23 03:53:02 PDT 2020


Author: Georgii Rymar
Date: 2020-09-23T13:42:56+03:00
New Revision: bd99fb4e0b5f2f3dcd8c9b81b30b4faebb765001

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

LOG: [llvm-readelf/obj] - Fix extended section symbol indices printed in warnings for MIPS GOT/PLT entries.

Recent refactoring introduced a symbol index argument for `getFullSymbolName` method,
which is only used for reporting error messages about invalid extended symbol indexes.

There are few issues in the implementation and we don't report correct symbol indices
when dumping MIPS GOT/PLT entries currently.

This patch adds test cases and fixes the issue.

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

Added: 
    

Modified: 
    llvm/test/tools/llvm-readobj/ELF/mips-got.test
    llvm/test/tools/llvm-readobj/ELF/mips-plt.test
    llvm/tools/llvm-readobj/ELFDumper.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/test/tools/llvm-readobj/ELF/mips-got.test b/llvm/test/tools/llvm-readobj/ELF/mips-got.test
index dac5284c5dee..abee5b8b0015 100644
--- a/llvm/test/tools/llvm-readobj/ELF/mips-got.test
+++ b/llvm/test/tools/llvm-readobj/ELF/mips-got.test
@@ -672,6 +672,12 @@ DynamicSymbols:
 # SEC-SYMS-LLVM-NEXT: warning: '[[FILE]]': unable to get section index for symbol with st_shndx = 0xfff2 (SHN_COMMON)
 # SEC-SYMS-LLVM-NEXT:     Name: <?> (0)
 # SEC-SYMS-LLVM-NEXT:   }
+# SEC-SYMS-LLVM-NEXT: Entry {
+# SEC-SYMS-LLVM:          Type: Section (0x3)
+# SEC-SYMS-LLVM-NEXT: warning: '[[FILE]]': extended symbol index (4) is past the end of the SHT_SYMTAB_SHNDX section of size 0
+# SEC-SYMS-LLVM-NEXT:     Section: Reserved (0xFFFF)
+# SEC-SYMS-LLVM-NEXT:     Name: <?> (0)
+# SEC-SYMS-LLVM-NEXT:   }
 # SEC-SYMS-LLVM-NEXT: ]
 
 # SEC-SYMS-GNU:      Global entries:
@@ -681,6 +687,8 @@ DynamicSymbols:
 # SEC-SYMS-GNU-NEXT:  {{.*}}   1 .got
 # SEC-SYMS-GNU-NEXT: warning: '[[FILE]]': unable to get section index for symbol with st_shndx = 0xfff2 (SHN_COMMON)
 # SEC-SYMS-GNU-NEXT:  {{.*}} COM <?>
+# SEC-SYMS-GNU-NEXT: warning: '[[FILE]]': extended symbol index (4) is past the end of the SHT_SYMTAB_SHNDX section of size 0
+# SEC-SYMS-GNU-NEXT:  {{.*}} RSV[0xffff] <?>
 
 --- !ELF
 FileHeader:
@@ -709,3 +717,5 @@ DynamicSymbols:
     Section: .got
   - Type:    STT_SECTION
     Index:   SHN_COMMON
+  - Type:    STT_SECTION
+    Index:   SHN_XINDEX

diff  --git a/llvm/test/tools/llvm-readobj/ELF/mips-plt.test b/llvm/test/tools/llvm-readobj/ELF/mips-plt.test
index 3d4c70f38cd1..3dfe46c4b786 100644
--- a/llvm/test/tools/llvm-readobj/ELF/mips-plt.test
+++ b/llvm/test/tools/llvm-readobj/ELF/mips-plt.test
@@ -162,6 +162,12 @@ DynamicSymbols: []
 # SEC-SYMS-LLVM-NEXT: warning: '[[FILE]]': unable to get section index for symbol with st_shndx = 0xfff2 (SHN_COMMON)
 # SEC-SYMS-LLVM-NEXT:       Name: <?> (0)
 # SEC-SYMS-LLVM-NEXT:     }
+# SEC-SYMS-LLVM-NEXT:     Entry {
+# SEC-SYMS-LLVM:            Type: Section (0x3)
+# SEC-SYMS-LLVM-NEXT: warning: '[[FILE]]': extended symbol index (4) is past the end of the SHT_SYMTAB_SHNDX section of size 0
+# SEC-SYMS-LLVM-NEXT:       Section: Reserved (0xFFFF)
+# SEC-SYMS-LLVM-NEXT:       Name: <?> (0)
+# SEC-SYMS-LLVM-NEXT:     }
 # SEC-SYMS-LLVM-NEXT:   ]
 # SEC-SYMS-LLVM-NEXT: }
 
@@ -173,6 +179,8 @@ DynamicSymbols: []
 # SEC-SYMS-GNU-NEXT:   0000000000002018 {{.*}}   2 .got.plt
 # SEC-SYMS-GNU-NEXT: warning: '[[FILE]]': unable to get section index for symbol with st_shndx = 0xfff2 (SHN_COMMON)
 # SEC-SYMS-GNU-NEXT:   0000000000002020 {{.*}} COM <?>
+# SEC-SYMS-GNU-NEXT: warning: '[[FILE]]': extended symbol index (4) is past the end of the SHT_SYMTAB_SHNDX section of size 0
+# SEC-SYMS-GNU-NEXT:   0000000000002028 {{.*}} RSV[0xffff] <?>
 
 --- !ELF
 FileHeader:
@@ -196,11 +204,14 @@ Sections:
       - Offset: 0x2
         Symbol: 3
         Type:   R_MIPS_JUMP_SLOT
+      - Offset: 0x3
+        Symbol: 4
+        Type:   R_MIPS_JUMP_SLOT
   - Name:    .got.plt
     Type:    SHT_PROGBITS
     Flags:   [ SHF_WRITE, SHF_ALLOC ]
     Address: 0x2000
-    Size:    40 ## (dynamic symbols number + 2) * 8
+    Size:    48 ## (dynamic symbols number + 2) * 8
   - Name: .dynamic
     Type: SHT_DYNAMIC
     Entries:
@@ -215,3 +226,5 @@ DynamicSymbols:
     Section: .got.plt
   - Type:    STT_SECTION
     Index:   SHN_COMMON
+  - Type:    STT_SECTION
+    Index:   SHN_XINDEX

diff  --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp
index 758fae5b65f3..b5393314436e 100644
--- a/llvm/tools/llvm-readobj/ELFDumper.cpp
+++ b/llvm/tools/llvm-readobj/ELFDumper.cpp
@@ -2895,7 +2895,6 @@ template <class ELFT> class MipsGOTParser {
   uint64_t getGotAddress(const Entry * E) const;
   int64_t getGotOffset(const Entry * E) const;
   const Elf_Sym *getGotSym(const Entry *E) const;
-  Elf_Sym_Range getGotDynSyms() const { return GotDynSyms; }
 
   uint64_t getPltAddress(const Entry * E) const;
   const Elf_Sym *getPltSym(const Entry *E) const;
@@ -5785,7 +5784,7 @@ void GNUStyle<ELFT>::printMipsGOT(const MipsGOTParser<ELFT> &Parser) {
       const Elf_Sym &Sym = *Parser.getGotSym(&E);
       const Elf_Sym &FirstSym = this->dumper().dynamic_symbols()[0];
       std::string SymName = this->dumper().getFullSymbolName(
-          Sym, &FirstSym - &Sym, this->dumper().getDynamicStringTable(), false);
+          Sym, &Sym - &FirstSym, this->dumper().getDynamicStringTable(), false);
 
       OS.PadToColumn(2);
       OS << to_string(format_hex_no_prefix(Parser.getGotAddress(&E), 8 + Bias));
@@ -5840,7 +5839,7 @@ void GNUStyle<ELFT>::printMipsPLT(const MipsGOTParser<ELFT> &Parser) {
           *cantFail(this->Obj.template getEntry<const Elf_Sym>(
               *Parser.getPltSymTable(), 0));
       std::string SymName = this->dumper().getFullSymbolName(
-          Sym, &FirstSym - &Sym, this->dumper().getDynamicStringTable(), false);
+          Sym, &Sym - &FirstSym, this->dumper().getDynamicStringTable(), false);
 
       OS.PadToColumn(2);
       OS << to_string(format_hex_no_prefix(Parser.getPltAddress(&E), 8 + Bias));
@@ -6708,11 +6707,12 @@ void LLVMStyle<ELFT>::printMipsGOT(const MipsGOTParser<ELFT> &Parser) {
       const Elf_Sym &Sym = *Parser.getGotSym(&E);
       W.printHex("Value", Sym.st_value);
       W.printEnum("Type", Sym.getType(), makeArrayRef(ElfSymbolTypes));
-      printSymbolSection(Sym, &Sym - this->dumper().dynamic_symbols().begin());
+
+      const unsigned SymIndex = &Sym - this->dumper().dynamic_symbols().begin();
+      printSymbolSection(Sym, SymIndex);
 
       std::string SymName = this->dumper().getFullSymbolName(
-          Sym, &Sym - &Parser.getGotDynSyms()[0],
-          this->dumper().getDynamicStringTable(), true);
+          Sym, SymIndex, this->dumper().getDynamicStringTable(), true);
       W.printNumber("Name", SymName, Sym.st_name);
     }
   }


        


More information about the llvm-commits mailing list