[llvm-readelf/obj] - Report a warning when the value of the DT_PLTREL dynamic tag...
authorGeorgii Rymar <grimar@accesssoftek.com>
Wed, 25 Nov 2020 10:58:40 +0000 (13:58 +0300)
committerGeorgii Rymar <grimar@accesssoftek.com>
Thu, 26 Nov 2020 10:15:59 +0000 (13:15 +0300)
We report an error for unknown `DT_PLTREL` values.
This switches the error to warning.

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

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

index 741eaec..8793a3e 100644 (file)
@@ -163,7 +163,7 @@ ProgramHeaders:
 # RUN: llvm-readelf --dyn-relocations %t10a 2>&1 | \
 # RUN:   FileCheck %s -DFILE=%t10a --check-prefix=INVALID-DT-PLTRELSZ1 --implicit-check-not=warning:
 
-# INVALID-DT-PLTRELSZ1: warning: '[[FILE]]': invalid DT_PLTRELSZ value (0xff){{$}}
+# INVALID-DT-PLTRELSZ1: warning: '[[FILE]]': invalid DT_PLTRELSZ value (0xff) or PLTREL entry size (0x18){{$}}
 
 --- !ELF
 FileHeader:
index 221e0b8..bed9985 100644 (file)
@@ -128,3 +128,38 @@ ProgramHeaders:
   - Type:     PT_LOAD
     FirstSec: .rela.dyn
     LastSec:  .dynamic
+
+## Check we report a warning when the value of the DT_PLTREL dynamic tag is invalid.
+## We currently accept DT_RELA(7) and DT_REL(17) values. This test case uses 0xff.
+
+# RUN: yaml2obj --docnum=2 %s -DDTPLTREL=0xFF -o %t3
+# RUN: llvm-readobj --dyn-relocations %t3 2>&1 | \
+# RUN:   FileCheck %s -DFILE=%t3 --implicit-check-not=warning: --check-prefix=PLTRELUNKNOWN-LLVM
+# RUN: llvm-readelf --dyn-relocations %t3 2>&1 | \
+# RUN:   FileCheck %s -DFILE=%t3 --implicit-check-not=warning: --check-prefix=PLTRELUNKNOWN-GNU
+
+# PLTRELUNKNOWN-LLVM:      warning: '[[FILE]]': unknown DT_PLTREL value of 255
+# PLTRELUNKNOWN-LLVM:      Dynamic Relocations {
+# PLTRELUNKNOWN-LLVM-NEXT:   0x1 R_X86_64_NONE foo 0x0
+# PLTRELUNKNOWN-LLVM-NEXT:   0x2 R_X86_64_NONE foo 0x0
+# PLTRELUNKNOWN-LLVM-NEXT:   0x4 R_X86_64_RELATIVE - 0x0
+# PLTRELUNKNOWN-LLVM-NEXT: warning: '[[FILE]]': invalid DT_PLTRELSZ value (0x10) or PLTREL entry size (0x0)
+# PLTRELUNKNOWN-LLVM-NEXT: }
+
+# PLTRELUNKNOWN-GNU:        warning: '[[FILE]]': unknown DT_PLTREL value of 255
+# PLTRELUNKNOWN-GNU-EMPTY:
+# PLTRELUNKNOWN-GNU-NEXT:   'RELA' relocation section at offset 0x78 contains 24 bytes:
+# PLTRELUNKNOWN-GNU-NEXT:       Offset             Info             Type               Symbol's Value  Symbol's Name + Addend
+# PLTRELUNKNOWN-GNU-NEXT:   0000000000000001  0000000100000000 R_X86_64_NONE          0000000000000000 foo + 0
+# PLTRELUNKNOWN-GNU-EMPTY:
+# PLTRELUNKNOWN-GNU-NEXT:   'REL' relocation section at offset 0x90 contains 16 bytes:
+# PLTRELUNKNOWN-GNU-NEXT:       Offset             Info             Type               Symbol's Value  Symbol's Name
+# PLTRELUNKNOWN-GNU-NEXT:   0000000000000002  0000000100000000 R_X86_64_NONE          0000000000000000 foo
+# PLTRELUNKNOWN-GNU-EMPTY:
+# PLTRELUNKNOWN-GNU-NEXT:   'RELR' relocation section at offset 0xa0 contains 8 bytes:
+# PLTRELUNKNOWN-GNU-NEXT:       Offset             Info             Type               Symbol's Value  Symbol's Name
+# PLTRELUNKNOWN-GNU-NEXT:   0000000000000004  0000000000000008 R_X86_64_RELATIVE
+# PLTRELUNKNOWN-GNU-EMPTY:
+# PLTRELUNKNOWN-GNU-NEXT:   'PLT' relocation section at offset 0xa8 contains 16 bytes:
+# PLTRELUNKNOWN-GNU-NEXT:       Offset             Info             Type               Symbol's Value  Symbol's Name
+# PLTRELUNKNOWN-GNU-NEXT:   warning: '[[FILE]]': invalid DT_PLTRELSZ value (0x10) or PLTREL entry size (0x0)
index 656b992..c546be2 100644 (file)
@@ -2204,10 +2204,9 @@ void ELFDumper<ELFT>::parseDynamicTable() {
       else if (Dyn.getVal() == DT_RELA)
         DynPLTRelRegion.EntSize = sizeof(Elf_Rela);
       else
-        reportError(createError(Twine("unknown DT_PLTREL value of ") +
-                                Twine((uint64_t)Dyn.getVal())),
-                    ObjF.getFileName());
-      DynPLTRelRegion.EntSizePrintName = "";
+        reportUniqueWarning(createError(Twine("unknown DT_PLTREL value of ") +
+                                        Twine((uint64_t)Dyn.getVal())));
+      DynPLTRelRegion.EntSizePrintName = "PLTREL entry size";
       break;
     case ELF::DT_JMPREL:
       DynPLTRelRegion.Addr = toMappedAddr(Dyn.getTag(), Dyn.getPtr());