[PATCH] D74479: [llvm-readobj] - Report a warning when an unexpected DT_SYMENT tag value is met.

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 13 00:42:48 PST 2020


grimar updated this revision to Diff 244349.
grimar added a comment.

- Addressed review comments.
- Reordered lines in the test case a bit to group them closer to check calls.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D74479/new/

https://reviews.llvm.org/D74479

Files:
  llvm/test/tools/llvm-readobj/ELF/dyn-symbols.test
  llvm/tools/llvm-readobj/ELFDumper.cpp


Index: llvm/tools/llvm-readobj/ELFDumper.cpp
===================================================================
--- llvm/tools/llvm-readobj/ELFDumper.cpp
+++ llvm/tools/llvm-readobj/ELFDumper.cpp
@@ -2060,6 +2060,16 @@
       }
       break;
     }
+    case ELF::DT_SYMENT: {
+      uint64_t Val = Dyn.getVal();
+      if (Val != sizeof(Elf_Sym))
+        reportWarning(createError("DT_SYMENT value of 0x" +
+                                  Twine::utohexstr(Val) +
+                                  " is not the size of a symbol (0x" +
+                                  Twine::utohexstr(sizeof(Elf_Sym)) + ")"),
+                      ObjF->getFileName());
+      break;
+    }
     case ELF::DT_RELA:
       DynRelaRegion.Addr = toMappedAddr(Dyn.getTag(), Dyn.getPtr());
       break;
Index: llvm/test/tools/llvm-readobj/ELF/dyn-symbols.test
===================================================================
--- llvm/test/tools/llvm-readobj/ELF/dyn-symbols.test
+++ llvm/test/tools/llvm-readobj/ELF/dyn-symbols.test
@@ -355,6 +355,9 @@
 # RUN: yaml2obj %s --docnum=10 -o %t10
 # RUN: llvm-readobj --dyn-symbols %t10 2>&1 | FileCheck %s -DFILE=%t10 --check-prefix=DYNSYM-SIZE-INVALID1
 # RUN: llvm-readelf --dyn-symbols %t10 2>&1 | FileCheck %s -DFILE=%t10 --check-prefix=DYNSYM-SIZE-INVALID1
+
+# DYNSYM-SIZE-INVALID1: warning: '[[FILE]]': section with index 1 has invalid size (0x1) or entry size (0x10)
+
 ## b) The same, but the DT_SYMTAB tag is present. In this case the dynamic tag has priority over the
 ##    information about a location and an entity size of the dynamic symbol table from the section header.
 ##    The code uses sizeof(Elf_Sym) for an entity size, so it can't be incorrect and
@@ -363,10 +366,20 @@
 # RUN: llvm-readobj --dyn-symbols %t11 2>&1 | FileCheck %s -DFILE=%t11 --check-prefix=DYNSYM-SIZE-INVALID2
 # RUN: llvm-readelf --dyn-symbols %t11 2>&1 | FileCheck %s -DFILE=%t11 --check-prefix=DYNSYM-SIZE-INVALID2
 
-# DYNSYM-SIZE-INVALID1: warning: '[[FILE]]': section with index 1 has invalid size (0x1) or entry size (0x10)
-
 # DYNSYM-SIZE-INVALID2: warning: '[[FILE]]': section with index 2 has invalid size (0x1){{$}}
 
+## c) In the case when the DT_SYMENT tag is present, we report when it's value does not match the
+#     value of the symbol size for the platform.
+# RUN: yaml2obj %s -D BITS=32 --docnum=12 -o %t12
+# RUN: llvm-readobj --dyn-symbols %t12 2>&1 | FileCheck %s -DFILE=%t12 --check-prefix=DYNSYM-SIZE-INVALID3
+# RUN: llvm-readelf --dyn-symbols %t12 2>&1 | FileCheck %s -DFILE=%t12 --check-prefix=DYNSYM-SIZE-INVALID3
+# RUN: yaml2obj %s -D BITS=64 --docnum=12 -o %t13
+# RUN: llvm-readobj --dyn-symbols %t13 2>&1 | FileCheck %s -DFILE=%t13 --check-prefix=DYNSYM-SIZE-INVALID4
+# RUN: llvm-readelf --dyn-symbols %t13 2>&1 | FileCheck %s -DFILE=%t13 --check-prefix=DYNSYM-SIZE-INVALID4
+
+# DYNSYM-SIZE-INVALID3: warning: '[[FILE]]': DT_SYMENT value of 0x123 is not the size of a symbol (0x10){{$}}
+# DYNSYM-SIZE-INVALID4: warning: '[[FILE]]': DT_SYMENT value of 0x123 is not the size of a symbol (0x18){{$}}
+
 --- !ELF
 FileHeader:
   Class:   ELFCLASS32
@@ -401,3 +414,18 @@
     VAddr: 0x100
     Sections:
       - Section: .dynsym
+
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS[[BITS]]
+  Data:    ELFDATA2LSB
+  Type:    ET_DYN
+  Machine: EM_X86_64
+Sections:
+  - Name:    .dynamic
+    Type:    SHT_DYNAMIC
+    Entries:
+      - Tag:   DT_SYMENT
+        Value: 0x123
+      - Tag:   DT_NULL
+        Value: 0


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D74479.244349.patch
Type: text/x-patch
Size: 3480 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200213/e388bec7/attachment.bin>


More information about the llvm-commits mailing list