[PATCH] D88817: [llvm-readobj/elf] - Ignore the hash table when on EM_S390/EM_ALPHA platforms.

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 5 03:38:42 PDT 2020


grimar created this revision.
grimar added reviewers: jhenderson, MaskRay.
Herald added subscribers: rupprecht, emaste.
Herald added a reviewer: espindola.
Herald added a project: LLVM.
grimar requested review of this revision.

Specification for `SHT_HASH` table says (https://refspecs.linuxbase.org/elf/gabi4+/ch5.dynamic.html#hash)
that it contains `Elf32_Word` entries for both `32/64` bit objects.

But there is a problem with `EM_S390` and `ELF::EM_ALPHA` platforms: they use 8-bytes entries.
(see the issue reported: https://bugs.llvm.org/show_bug.cgi?id=47681).

Currently we might infer the size of the dynamic symbols table from hash table,
but because of the issue mentioned, the calculation is wrong. And also we don't dump the hash table
properly.

I am not sure if we want to support 8-bytes entries as they violates specification and also the
`.hash` table is kind of deprecated by itself (the `.gnu.hash` table is used nowadays).
So, the solution this patch suggests is to ban using of the hash table on `EM_S390/EM_ALPHA` platforms.


https://reviews.llvm.org/D88817

Files:
  llvm/test/tools/llvm-readobj/ELF/hash-table.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
@@ -2059,10 +2059,25 @@
   Optional<DynRegionInfo> DynSymFromTable;
   for (const Elf_Dyn &Dyn : dynamic_table()) {
     switch (Dyn.d_tag) {
-    case ELF::DT_HASH:
+    case ELF::DT_HASH: {
       HashTable = reinterpret_cast<const Elf_Hash *>(
           toMappedAddr(Dyn.getTag(), Dyn.getPtr()));
+
+      unsigned Machine = Obj.getHeader().e_machine;
+      if (HashTable && (Machine == ELF::EM_S390 || Machine == ELF::EM_ALPHA)) {
+        uint64_t Offset =
+            reinterpret_cast<const uint8_t *>(HashTable) - this->Obj.base();
+        StringRef MachineName =
+            Machine == ELF::EM_S390 ? "IBM System/390" : "DEC Alpha";
+        reportUniqueWarning(createError(
+            "the hash table at 0x" + Twine::utohexstr(Offset) +
+            " is not supported and will be ignored: it contains non-standard 8 "
+            "byte entries on " +
+            MachineName + " platform"));
+        HashTable = nullptr;
+      }
       break;
+    }
     case ELF::DT_GNU_HASH:
       GnuHashTable = reinterpret_cast<const Elf_GnuHash *>(
           toMappedAddr(Dyn.getTag(), Dyn.getPtr()));
Index: llvm/test/tools/llvm-readobj/ELF/hash-table.test
===================================================================
--- llvm/test/tools/llvm-readobj/ELF/hash-table.test
+++ llvm/test/tools/llvm-readobj/ELF/hash-table.test
@@ -18,7 +18,7 @@
 
 --- !ELF
 FileHeader:
-  Class:   ELFCLASS[[BITS]]
+  Class:   ELFCLASS[[BITS=64]]
   Data:    ELFDATA2LSB
   Type:    ET_DYN
   Machine: [[MACHINE]]
@@ -42,6 +42,21 @@
       - Section: .hash
       - Section: .dynamic
 
+## On EM_S390 and EM_ALPHA platforms we ignore the hash table. We do that because on these platforms the size of entries
+## is 8, what violates the ELF specification, which says that the normal size of hash entries in the hash table must be 4.
+
+# RUN: yaml2obj --docnum=1 -DMACHINE=EM_S390 %s -o %t.s390
+# RUN: llvm-readobj --hash-table %t.s390 2>&1 | FileCheck %s -DFILE=%t.s390 --check-prefixes=IGNORED -DNAME="IBM System/390"
+# RUN: llvm-readelf --hash-table %t.s390 2>&1 | FileCheck %s -DFILE=%t.s390 --check-prefixes=IGNORED -DNAME="IBM System/390"
+
+# IGNORED:      warning: '[[FILE]]': the hash table at 0x78 is not supported and will be ignored: it contains non-standard 8 byte entries on [[NAME]] platform
+# IGNORED:      HashTable {
+# IGNORED-NEXT: }
+
+# RUN: yaml2obj --docnum=1 -DMACHINE=EM_ALPHA %s -o %t.alpha
+# RUN: llvm-readobj --hash-table %t.alpha 2>&1 | FileCheck %s -DFILE=%t.alpha --check-prefixes=IGNORED -DNAME="DEC Alpha"
+# RUN: llvm-readelf --hash-table %t.alpha 2>&1 | FileCheck %s -DFILE=%t.alpha --check-prefixes=IGNORED -DNAME="DEC Alpha"
+
 ## Check we can dump the SHT_HASH section even when an object
 ## does not have the section header table.
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D88817.296142.patch
Type: text/x-patch
Size: 2975 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201005/dd2bf2cf/attachment-0001.bin>


More information about the llvm-commits mailing list