[llvm] r366558 - [llvm-readelf] - A fix for: "--hash-symbols asserts for 64-bit ELFs"

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 19 03:15:04 PDT 2019


Author: grimar
Date: Fri Jul 19 03:15:03 2019
New Revision: 366558

URL: http://llvm.org/viewvc/llvm-project?rev=366558&view=rev
Log:
[llvm-readelf] - A fix for: "--hash-symbols asserts for 64-bit ELFs"

Fixes https://bugs.llvm.org/show_bug.cgi?id=42622.
(--hash-symbols switch is currently broken for 64-bit ELF files, due to r352630.)

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

Modified:
    llvm/trunk/test/tools/llvm-readobj/elf-hash-symbols.test
    llvm/trunk/tools/llvm-readobj/ELFDumper.cpp

Modified: llvm/trunk/test/tools/llvm-readobj/elf-hash-symbols.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-readobj/elf-hash-symbols.test?rev=366558&r1=366557&r2=366558&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-readobj/elf-hash-symbols.test (original)
+++ llvm/trunk/test/tools/llvm-readobj/elf-hash-symbols.test Fri Jul 19 03:15:03 2019
@@ -83,9 +83,89 @@ ProgramHeaders:
       - Section: .gnu.hash
       - Section: .dynamic
 
+# RUN: yaml2obj --docnum=2 %s -o %t1-64.so
+# RUN: llvm-readelf --hash-symbols %t1-64.so | FileCheck %s --check-prefix HASH-64
+
+# HASH-64:      Symbol table of .hash for image:
+# HASH-64-NEXT:  Num Buc:    Value          Size   Type   Bind Vis      Ndx Name
+# HASH-64-NEXT:    1   0: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT UND ccc
+# HASH-64-NEXT:    5   0: 0000000000001001     0 NOTYPE  WEAK   DEFAULT   1 bbb
+# HASH-64-NEXT:    3   0: 0000000000000001     0 NOTYPE  GLOBAL DEFAULT ABS ddd
+# HASH-64-NEXT:    2   0: 0000000000001000     0 NOTYPE  GLOBAL DEFAULT   1 aaa
+# HASH-64-NEXT:    4   0: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT   2 eee
+# HASH-64-EMPTY:
+# HASH-64-NEXT: Symbol table of .gnu.hash for image:
+# HASH-64-NEXT:  Num Buc:    Value          Size   Type   Bind Vis      Ndx Name
+# HASH-64-NEXT:    2   1: 0000000000001000     0 NOTYPE  GLOBAL DEFAULT   1 aaa
+# HASH-64-NEXT:    3   1: 0000000000000001     0 NOTYPE  GLOBAL DEFAULT ABS ddd
+# HASH-64-NEXT:    4   2: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT   2 eee
+# HASH-64-NEXT:    5   2: 0000000000001001     0 NOTYPE  WEAK   DEFAULT   1 bbb
+# HASH-64-NOT: {{.}}
+
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS64
+  Data:    ELFDATA2LSB
+  Type:    ET_DYN
+  Machine: EM_X86_64
+Sections:
+## The contents of .hash and .gnu.hash were generated by a linker.
+  - Name:    .hash
+    Type:    SHT_HASH
+    Flags:   [ SHF_ALLOC ]
+    Link:    .dynsym
+    Content: '0300000006000000010000000000000000000000000000000500000004000000020000000000000003000000'
+  - Name:    .gnu.hash
+    Type:    SHT_GNU_HASH
+    Flags:   [ SHF_ALLOC ]
+    Link:    .dynsym
+    Content: 030000000200000001000000060000000808020040019200000000000200000004000000685C880B9169880BF46D880BCB60880B
+  - Name:  .dynamic
+    Type:  SHT_DYNAMIC
+    Flags: [ SHF_ALLOC ]
+    Link:  .dynstr
+    Entries:
+      - Tag:   DT_HASH
+## PT_LOAD's p_vaddr is 0x0. PT_LOAD's p_offset = 0x2b8. DT_HASH value is 0x0. 
+## llvm-readelf will read .hash content from p_offset + (p_vaddr - DT_HASH value) = 0x2b8.
+## This matches the file offset of the .hash section. 
+        Value: 0x0000000000000000
+      - Tag:   DT_GNU_HASH
+## PT_LOAD's p_vaddr is 0x0. PT_LOAD's p_offset = 0x2b8. DT_GNU_HASH value is 0x2c (size of .hash = 0x2c).
+## llvm-readelf will read .gnu.hash content from p_offset + (p_vaddr - DT_GNU_HASH value) = 0x2e4.
+## This matches the file offset of the .gnu.hash section.
+        Value: 0x000000000000002c
+      - Tag:   DT_NULL
+        Value: 0x0000000000000000
+DynamicSymbols:
+  - Name:    ccc
+    Binding: STB_GLOBAL
+  - Name:    aaa
+    Section: .hash
+    Binding: STB_GLOBAL
+    Value:   0x0000000000001000
+  - Name:    ddd
+    Index:   SHN_ABS
+    Binding: STB_GLOBAL
+    Value:   0x0000000000000001
+  - Name:    eee
+    Section: .gnu.hash
+    Binding: STB_GLOBAL
+  - Name:    bbb
+    Section: .hash
+    Binding: STB_WEAK
+    Value:   0x0000000000001001
+ProgramHeaders:
+  - Type:  PT_LOAD
+    Flags: [ PF_R, PF_X ]
+    Sections:
+      - Section: .hash
+      - Section: .gnu.hash
+      - Section: .dynamic
+
 ## Check the output when only .hash section is present.
 
-# RUN: yaml2obj --docnum=2 %s -o %t2-32.so
+# RUN: yaml2obj --docnum=3 %s -o %t2-32.so
 # RUN: llvm-readelf --hash-symbols %t2-32.so \
 # RUN:   | FileCheck %s --strict-whitespace --match-full-lines --check-prefix ONLY-HASH-32
 
@@ -147,7 +227,7 @@ ProgramHeaders:
 
 ## Check the output when only .gnu.hash section is present.
 
-# RUN: yaml2obj --docnum=3 %s -o %t3-32.so
+# RUN: yaml2obj --docnum=4 %s -o %t3-32.so
 # RUN: llvm-readelf --hash-symbols %t3-32.so \
 # RUN:   | FileCheck %s --strict-whitespace --match-full-lines --check-prefix ONLY-GNUHASH-32
 
@@ -207,7 +287,7 @@ ProgramHeaders:
       - Section: .dynamic
 
 ## Show that if there are no hash sections, we do not print anything.
-# RUN: yaml2obj --docnum=4 %s -o %t4.so
+# RUN: yaml2obj --docnum=5 %s -o %t4.so
 # RUN: llvm-readelf --hash-symbols %t4.so \
 # RUN:   | FileCheck %s --check-prefix NO-HASH --allow-empty
 

Modified: llvm/trunk/tools/llvm-readobj/ELFDumper.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/ELFDumper.cpp?rev=366558&r1=366557&r2=366558&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/ELFDumper.cpp (original)
+++ llvm/trunk/tools/llvm-readobj/ELFDumper.cpp Fri Jul 19 03:15:03 2019
@@ -3189,7 +3189,7 @@ void GNUStyle<ELFT>::printHashedSymbol(c
 
   const auto Symbol = FirstSym + Sym;
   Fields[2].Str = to_string(
-      format_hex_no_prefix(Symbol->st_value, ELFT::Is64Bits ? 18 : 8));
+      format_hex_no_prefix(Symbol->st_value, ELFT::Is64Bits ? 16 : 8));
   Fields[3].Str = to_string(format_decimal(Symbol->st_size, 5));
 
   unsigned char SymbolType = Symbol->getType();




More information about the llvm-commits mailing list