diff --git a/test/tools/llvm-readobj/Inputs/got-empty.exe.mipsel b/test/tools/llvm-readobj/Inputs/got-empty.exe.mipsel new file mode 100755 index 00000000000..b57874557c8 Binary files /dev/null and b/test/tools/llvm-readobj/Inputs/got-empty.exe.mipsel differ diff --git a/test/tools/llvm-readobj/mips-got.test b/test/tools/llvm-readobj/mips-got.test index 76db3c845eb..20215871ef0 100644 --- a/test/tools/llvm-readobj/mips-got.test +++ b/test/tools/llvm-readobj/mips-got.test @@ -6,6 +6,8 @@ RUN: llvm-readobj -mips-plt-got %p/Inputs/dynamic-table-so.mips | \ RUN: FileCheck %s -check-prefix GOT-SO RUN: llvm-readobj -mips-plt-got %p/Inputs/got-tls.so.elf-mips64el | \ RUN: FileCheck %s -check-prefix GOT-TLS +RUN: llvm-readobj -mips-plt-got %p/Inputs/got-empty.exe.mipsel | \ +RUN: FileCheck %s -check-prefix GOT-EMPTY GOT-OBJ: Cannot find PLTGOT dynamic table tag. @@ -304,3 +306,26 @@ GOT-TLS-NEXT: } GOT-TLS-NEXT: ] GOT-TLS-NEXT: Number of TLS and multi-GOT entries: 4 GOT-TLS-NEXT: } + +GOT-EMPTY: Primary GOT { +GOT-EMPTY-NEXT: Canonical gp value: 0x409FF0 +GOT-EMPTY-NEXT: Reserved entries [ +GOT-EMPTY-NEXT: Entry { +GOT-EMPTY-NEXT: Address: 0x402000 +GOT-EMPTY-NEXT: Access: -32752 +GOT-EMPTY-NEXT: Initial: 0x0 +GOT-EMPTY-NEXT: Purpose: Lazy resolver +GOT-EMPTY-NEXT: } +GOT-EMPTY-NEXT: Entry { +GOT-EMPTY-NEXT: Address: 0x402004 +GOT-EMPTY-NEXT: Access: -32748 +GOT-EMPTY-NEXT: Initial: 0x80000000 +GOT-EMPTY-NEXT: Purpose: Module pointer (GNU extension) +GOT-EMPTY-NEXT: } +GOT-EMPTY-NEXT: ] +GOT-EMPTY-NEXT: Local entries [ +GOT-EMPTY-NEXT: ] +GOT-EMPTY-NEXT: Global entries [ +GOT-EMPTY-NEXT: ] +GOT-EMPTY-NEXT: Number of TLS and multi-GOT entries: 2 +GOT-EMPTY-NEXT: } diff --git a/tools/llvm-readobj/ELFDumper.cpp b/tools/llvm-readobj/ELFDumper.cpp index 502c7197ddb..5df51e250d2 100644 --- a/tools/llvm-readobj/ELFDumper.cpp +++ b/tools/llvm-readobj/ELFDumper.cpp @@ -1087,7 +1087,7 @@ void MipsGOTParser::parseGOT(const Elf_Shdr &GOTShdr) { Elf_Sym_Iter DynSymEnd = Obj->end_dynamic_symbols(); std::size_t DynSymTotal = std::size_t(std::distance(DynSymBegin, DynSymEnd)); - if (DtGotSym + 1 > DynSymTotal) { + if (DtGotSym > DynSymTotal) { W.startLine() << "MIPS_GOTSYM exceeds a number of dynamic symbols.\n"; return; }