[llvm-branch-commits] [llvm] 54ec9bb - [llvm-readelf/obj] - Report a warning when the value of the DT_PLTREL dynamic tag is invalid.

Georgii Rymar via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Thu Nov 26 02:20:47 PST 2020


Author: Georgii Rymar
Date: 2020-11-26T13:15:59+03:00
New Revision: 54ec9bb5510de301d05e8b34bb8c2484e8c95eaa

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

LOG: [llvm-readelf/obj] - Report a warning when the value of the DT_PLTREL dynamic tag is invalid.

We report an error for unknown `DT_PLTREL` values.
This switches the error to warning.

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

Added: 
    

Modified: 
    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

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 741eaec90d13..8793a3e9980c 100644
--- a/llvm/test/tools/llvm-readobj/ELF/broken-dynamic-reloc.test
+++ b/llvm/test/tools/llvm-readobj/ELF/broken-dynamic-reloc.test
@@ -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:

diff  --git a/llvm/test/tools/llvm-readobj/ELF/dynamic-reloc.test b/llvm/test/tools/llvm-readobj/ELF/dynamic-reloc.test
index 221e0b80058e..bed9985cdc68 100644
--- a/llvm/test/tools/llvm-readobj/ELF/dynamic-reloc.test
+++ b/llvm/test/tools/llvm-readobj/ELF/dynamic-reloc.test
@@ -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)

diff  --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp
index 656b9924ece0..c546be25a951 100644
--- a/llvm/tools/llvm-readobj/ELFDumper.cpp
+++ b/llvm/tools/llvm-readobj/ELFDumper.cpp
@@ -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());


        


More information about the llvm-branch-commits mailing list