Author: Georgii Rymar
Date: 2020-12-03T14:13:26+03:00
New Revision: 50de7d55044a32f65e78b00cea836f0907041b21

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

LOG: [llvm-readelf/obj] - Report unique warnings in getSymbolForReloc() helper.

Use `reportUniqueWarning` instead of `reportWarning` and refine the
interface of the helper.

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

Added: 
    

Modified: 
    llvm/test/tools/llvm-readobj/ELF/broken-dynamic-reloc.test
    llvm/tools/llvm-readobj/ELFDumper.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/test/tools/llvm-readobj/ELF/broken-dynamic-reloc.test 
b/llvm/test/tools/llvm-readobj/ELF/broken-dynamic-reloc.test
index 8793a3e9980c..0513b0913266 100644
--- a/llvm/test/tools/llvm-readobj/ELF/broken-dynamic-reloc.test
+++ b/llvm/test/tools/llvm-readobj/ELF/broken-dynamic-reloc.test
@@ -260,18 +260,22 @@ ProgramHeaders:
 ## Show we print a warning when the symbol index of a dynamic relocation is too
 ## large (goes past the end of the dynamic symbol table).
 # RUN: yaml2obj --docnum=5 %s -o %t12
-# RUN: llvm-readobj --dyn-relocations %t12 2>&1 | FileCheck %s -DFILE=%t12 
--check-prefix=LLVM-INVALID-DYNSYM
-# RUN: llvm-readelf --dyn-relocations %t12 2>&1 | FileCheck %s -DFILE=%t12 
--check-prefix=GNU-INVALID-DYNSYM
+# RUN: llvm-readobj --dyn-relocations %t12 2>&1 | \
+# RUN:   FileCheck %s -DFILE=%t12 --implicit-check-not=warning: 
--check-prefix=LLVM-INVALID-DYNSYM
+# RUN: llvm-readelf --dyn-relocations %t12 2>&1 | \
+# RUN:   FileCheck %s -DFILE=%t12 --implicit-check-not=warning: 
--check-prefix=GNU-INVALID-DYNSYM
 
 # LLVM-INVALID-DYNSYM:      Dynamic Relocations {
 # LLVM-INVALID-DYNSYM-NEXT: warning: '[[FILE]]': unable to get name of the 
dynamic symbol with index 2: index is greater than or equal to the number of 
dynamic symbols (2)
 # LLVM-INVALID-DYNSYM-NEXT:   0x0 R_X86_64_NONE <corrupt> 0x0
+# LLVM-INVALID-DYNSYM-NEXT:   0x0 R_X86_64_NONE <corrupt> 0x0
 # LLVM-INVALID-DYNSYM-NEXT: }
 
-# GNU-INVALID-DYNSYM:      'RELA' relocation section at offset 0x78 contains 
24 bytes:
+# GNU-INVALID-DYNSYM:      'RELA' relocation section at offset 0x78 contains 
48 bytes:
 # GNU-INVALID-DYNSYM-NEXT: Offset            Info             Type             
Symbol's Value   Symbol's Name + Addend
 # GNU-INVALID-DYNSYM-NEXT: warning: '[[FILE]]': unable to get name of the 
dynamic symbol with index 2: index is greater than or equal to the number of 
dynamic symbols (2)
 # GNU-INVALID-DYNSYM-NEXT: 0000000000000000  0000000200000000 R_X86_64_NONE    
                 <corrupt> + 0
+# GNU-INVALID-DYNSYM-NEXT: 0000000000000000  0000000200000000 R_X86_64_NONE    
                 <corrupt> + 0
 
 --- !ELF
 FileHeader:
@@ -285,13 +289,15 @@ Sections:
     Relocations:
       - Type:   R_X86_64_NONE
         Symbol: 0x2
+      - Type:   R_X86_64_NONE
+        Symbol: 0x2
   - Name: .dynamic
     Type: SHT_DYNAMIC
     Entries:
       - Tag:   DT_RELA
         Value: 0x0
       - Tag:   DT_RELASZ
-        Value: 0x18
+        Value: 0x30
       - Tag:   DT_RELAENT
         Value: 0x18
       - Tag:   DT_NULL

diff  --git a/llvm/tools/llvm-readobj/ELFDumper.cpp 
b/llvm/tools/llvm-readobj/ELFDumper.cpp
index ebcad74808ab..13d053179356 100644
--- a/llvm/tools/llvm-readobj/ELFDumper.cpp
+++ b/llvm/tools/llvm-readobj/ELFDumper.cpp
@@ -4554,16 +4554,14 @@ template <class ELFT> void 
GNUStyle<ELFT>::printSectionMapping() {
 namespace {
 
 template <class ELFT>
-RelSymbol<ELFT> getSymbolForReloc(const ELFFile<ELFT> &Obj, StringRef FileName,
-                                  const ELFDumper<ELFT> &Dumper,
+RelSymbol<ELFT> getSymbolForReloc(const ELFDumper<ELFT> &Dumper,
                                   const Relocation<ELFT> &Reloc) {
   using Elf_Sym = typename ELFT::Sym;
   auto WarnAndReturn = [&](const Elf_Sym *Sym,
                            const Twine &Reason) -> RelSymbol<ELFT> {
-    reportWarning(
-        createError("unable to get name of the dynamic symbol with index " +
-                    Twine(Reloc.Symbol) + ": " + Reason),
-        FileName);
+    Dumper.reportUniqueWarning(
+        "unable to get name of the dynamic symbol with index " +
+        Twine(Reloc.Symbol) + ": " + Reason);
     return {Sym, "<corrupt>"};
   };
 
@@ -4581,6 +4579,7 @@ RelSymbol<ELFT> getSymbolForReloc(const ELFFile<ELFT> 
&Obj, StringRef FileName,
         "index is greater than or equal to the number of dynamic symbols (" +
             Twine(Symbols.size()) + ")");
 
+  const ELFFile<ELFT> &Obj = *Dumper.getElfObject().getELFFile();
   const uint64_t FileSize = Obj.getBufSize();
   const uint64_t SymOffset = ((const uint8_t *)FirstSym - Obj.base()) +
                              (uint64_t)Reloc.Symbol * sizeof(Elf_Sym);
@@ -4600,8 +4599,7 @@ RelSymbol<ELFT> getSymbolForReloc(const ELFFile<ELFT> 
&Obj, StringRef FileName,
 
 template <class ELFT>
 void GNUStyle<ELFT>::printDynamicReloc(const Relocation<ELFT> &R) {
-  printRelRelaReloc(
-      R, getSymbolForReloc(this->Obj, this->FileName, this->dumper(), R));
+  printRelRelaReloc(R, getSymbolForReloc(this->dumper(), R));
 }
 
 template <class ELFT>
@@ -6604,8 +6602,7 @@ template <class ELFT> void 
LLVMStyle<ELFT>::printDynamicRelocations() {
 
 template <class ELFT>
 void LLVMStyle<ELFT>::printDynamicReloc(const Relocation<ELFT> &R) {
-  RelSymbol<ELFT> S =
-      getSymbolForReloc(this->Obj, this->FileName, this->dumper(), R);
+  RelSymbol<ELFT> S = getSymbolForReloc(this->dumper(), R);
   printRelRelaReloc(R, S.Name);
 }
 


        
_______________________________________________
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits

Reply via email to