diff --git a/llvm/test/tools/llvm-readobj/ELF/mips-got.test b/llvm/test/tools/llvm-readobj/ELF/mips-got.test --- a/llvm/test/tools/llvm-readobj/ELF/mips-got.test +++ b/llvm/test/tools/llvm-readobj/ELF/mips-got.test @@ -672,6 +672,12 @@ # 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 @@ # 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 @@ 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 --- a/llvm/test/tools/llvm-readobj/ELF/mips-plt.test +++ b/llvm/test/tools/llvm-readobj/ELF/mips-plt.test @@ -162,6 +162,12 @@ # 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 @@ # 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 @@ - 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 @@ 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 --- a/llvm/tools/llvm-readobj/ELFDumper.cpp +++ b/llvm/tools/llvm-readobj/ELFDumper.cpp @@ -2895,7 +2895,6 @@ 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 @@ 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 @@ *cantFail(this->Obj.template getEntry( *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 @@ 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); } }