Index: test/tools/llvm-readobj/elf-hash-symbols.test =================================================================== --- test/tools/llvm-readobj/elf-hash-symbols.test +++ test/tools/llvm-readobj/elf-hash-symbols.test @@ -75,16 +75,91 @@ - Section: .gnu.hash - Section: .dynamic +# RUN: yaml2obj --docnum=2 %s -o %t1-x86_64.o +# RUN: llvm-readelf --hash-symbols %t1-x86_64.o | FileCheck %s --check-prefix HASH-X86-64 + +# HASH-X86-64: Symbol table of .hash for image: +# HASH-X86-64-NEXT: Num Buc: Value Size Type Bind Vis Ndx Name +# HASH-X86-64-NEXT: 1 0: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND ccc +# HASH-X86-64-NEXT: 5 0: 0000000000001001 0 NOTYPE WEAK DEFAULT 1 bbb +# HASH-X86-64-NEXT: 3 0: 0000000000000001 0 NOTYPE GLOBAL DEFAULT ABS ddd +# HASH-X86-64-NEXT: 2 0: 0000000000001000 0 NOTYPE GLOBAL DEFAULT 1 aaa +# HASH-X86-64-NEXT: 4 0: 0000000000000000 0 NOTYPE GLOBAL DEFAULT 2 eee +# HASH-X86-64-EMPTY: +# HASH-X86-64-NEXT: Symbol table of .gnu.hash for image: +# HASH-X86-64-NEXT: Num Buc: Value Size Type Bind Vis Ndx Name +# HASH-X86-64-NEXT: 2 1: 0000000000001000 0 NOTYPE GLOBAL DEFAULT 1 aaa +# HASH-X86-64-NEXT: 3 1: 0000000000000001 0 NOTYPE GLOBAL DEFAULT ABS ddd +# HASH-X86-64-NEXT: 4 2: 0000000000000000 0 NOTYPE GLOBAL DEFAULT 2 eee +# HASH-X86-64-NEXT: 5 2: 0000000000001001 0 NOTYPE WEAK DEFAULT 1 bbb + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_DYN + Machine: EM_X86_64 +Sections: + - 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_WRITE, SHF_ALLOC ] + Link: .dynstr + Entries: + - Tag: DT_HASH + ## Address of .hash + Value: 0x00000000000002b8 + - Tag: DT_GNU_HASH + ## Address of .gnu.hash + Value: 0x00000000000002e4 + - 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 ] + Offset: 0 + Sections: + - Section: .hash + - Section: .gnu.hash + - Section: .dynamic + ## Show that if there are no hash sections, we do not print anything. -# RUN: yaml2obj --docnum=2 %s -o %t2.o -# RUN: llvm-readelf --hash-symbols %t2.o \ +# RUN: yaml2obj --docnum=3 %s -o %t3.o +# RUN: llvm-readelf --hash-symbols %t3.o \ # RUN: | FileCheck %s --check-prefix NO-HASH --allow-empty # NO-HASH-NOT: {{.}} ## Sanity check that we can still find the dynamic symbols (i.e. the above test ## doesn't pass due to a mistake in the dynamic section). -# RUN: llvm-readelf --dyn-symbols %t2.o | FileCheck %s --check-prefix DYNSYMS +# RUN: llvm-readelf --dyn-symbols %t3.o | FileCheck %s --check-prefix DYNSYMS # DYNSYMS: Symbol table '.dynsym' contains 2 entries: Index: tools/llvm-readobj/ELFDumper.cpp =================================================================== --- tools/llvm-readobj/ELFDumper.cpp +++ tools/llvm-readobj/ELFDumper.cpp @@ -3186,7 +3186,7 @@ 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();