Index: test/tools/llvm-readobj/gnu-hash-symbols.test =================================================================== --- test/tools/llvm-readobj/gnu-hash-symbols.test +++ test/tools/llvm-readobj/gnu-hash-symbols.test @@ -1,46 +1,94 @@ -# RUN: llvm-readelf --hash-symbols %p/Inputs/dynamic-table-exe.x86 \ -# RUN: | FileCheck %s --check-prefix HASH +## Check llvm-readelf is able to dump the content of hash sections correctly. -# HASH: Symbol table of .hash for image: -# HASH-NEXT: Num Buc: Value Size Type Bind Vis Ndx Name -# HASH-NEXT: 9 0: 00000000 0 FUNC GLOBAL DEFAULT UND __gxx_personality_v0@CXXABI_1.3 -# HASH-NEXT: 13 0: 00001b64 0 NOTYPE GLOBAL DEFAULT ABS _edata{{$}} -# HASH-NEXT: 7 0: 00000000 0 FUNC GLOBAL DEFAULT UND _ZNSt14basic_ifstreamIcSt11char_traitsIcEEC1EPKcSt13_Ios_Openmode@GLIBCXX_3.4 -# HASH-NEXT: 2 0: 00000000 0 NOTYPE WEAK DEFAULT UND _Jv_RegisterClasses{{$}} -# HASH-NEXT: 1 0: 00000000 0 NOTYPE WEAK DEFAULT UND __gmon_start__{{$}} -# HASH-NEXT: 16 1: 00000850 81 FUNC GLOBAL DEFAULT 14 main{{$}} -# HASH-NEXT: 10 1: 00000000 0 FUNC GLOBAL DEFAULT UND _Unwind_Resume@GCC_3.0 -# HASH-NEXT: 8 1: 00000000 0 FUNC GLOBAL DEFAULT UND puts@GLIBC_2.0 -# HASH-NEXT: 12 1: 00001b68 0 NOTYPE GLOBAL DEFAULT ABS _end{{$}} -# HASH-NEXT: 6 1: 00000000 0 FUNC GLOBAL DEFAULT UND _ZNSt14basic_ifstreamIcSt11char_traitsIcEED1Ev@GLIBCXX_3.4 -# HASH-NEXT: 5 1: 00000000 0 NOTYPE WEAK DEFAULT UND _ITM_registerTMCloneTable{{$}} -# HASH-NEXT: 4 1: 00000000 0 NOTYPE WEAK DEFAULT UND _ITM_deregisterTMCloneTable{{$}} -# HASH-NEXT: 3 1: 00000000 0 FUNC GLOBAL DEFAULT UND __libc_start_main@GLIBC_2.0 -# HASH-NEXT: 11 2: 00000000 0 FUNC WEAK DEFAULT UND __cxa_finalize@GLIBC_2.1.3 -# HASH-NEXT: 15 2: 00001b64 0 NOTYPE GLOBAL DEFAULT ABS __bss_start{{$}} -# HASH-NEXT: 14 2: 0000093c 4 OBJECT GLOBAL DEFAULT 16 _IO_stdin_used{{$}} -# HASH: Symbol table of .gnu.hash for image: -# HASH-NEXT: Num Buc: Value Size Type Bind Vis Ndx Name -# HASH-NEXT: 12 0: 00001b68 0 NOTYPE GLOBAL DEFAULT ABS _end{{$}} -# HASH-NEXT: 13 0: 00001b64 0 NOTYPE GLOBAL DEFAULT ABS _edata{{$}} -# HASH-NEXT: 14 1: 0000093c 4 OBJECT GLOBAL DEFAULT 16 _IO_stdin_used{{$}} -# HASH-NEXT: 15 1: 00001b64 0 NOTYPE GLOBAL DEFAULT ABS __bss_start{{$}} -# HASH-NEXT: 16 1: 00000850 81 FUNC GLOBAL DEFAULT 14 main{{$}} +# RUN: yaml2obj --docnum=1 %s -o %t1-386.o +# RUN: llvm-readelf --hash-symbols %t1-386.o | FileCheck %s --check-prefix HASH-I386 + +# HASH-I386: Symbol table of .hash for image: +# HASH-I386-NEXT: Num Buc: Value Size Type Bind Vis Ndx Name +# HASH-I386-NEXT: 1 0: 00000000 0 NOTYPE GLOBAL DEFAULT UND ccc +# HASH-I386-NEXT: 5 0: 00001001 0 NOTYPE WEAK DEFAULT 1 bbb +# HASH-I386-NEXT: 3 0: 00000001 0 NOTYPE GLOBAL DEFAULT ABS ddd +# HASH-I386-NEXT: 2 0: 00001000 0 NOTYPE GLOBAL DEFAULT 1 aaa +# HASH-I386-NEXT: 4 0: 00000000 0 NOTYPE GLOBAL DEFAULT 2 eee +# HASH-I386-EMPTY: +# HASH-I386: Symbol table of .gnu.hash for image: +# HASH-I386-NEXT: Num Buc: Value Size Type Bind Vis Ndx Name +# HASH-I386-NEXT: 2 1: 00001000 0 NOTYPE GLOBAL DEFAULT 1 aaa +# HASH-I386-NEXT: 3 1: 00000001 0 NOTYPE GLOBAL DEFAULT ABS ddd +# HASH-I386-NEXT: 4 2: 00000000 0 NOTYPE GLOBAL DEFAULT 2 eee +# HASH-I386-NEXT: 5 2: 00001001 0 NOTYPE WEAK DEFAULT 1 bbb + +--- !ELF +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_DYN + Machine: EM_386 +Sections: + - Name: .hash + Type: SHT_HASH + Flags: [ SHF_ALLOC ] + Link: .dynsym +## Here and below it is a linker produced binary content for the symbols under the `DynamicSymbols` tag. + Content: '0300000006000000010000000000000000000000000000000500000004000000020000000000000003000000' + - Name: .gnu.hash + Type: SHT_GNU_HASH + Flags: [ SHF_ALLOC ] + Link: .dynsym + Content: 0300000002000000010000000500000048991200000000000200000004000000685C880B9169880BF46D880BCB60880B + - Name: .dynamic + Type: SHT_DYNAMIC + Flags: [ SHF_WRITE, SHF_ALLOC ] + Link: .dynstr + Entries: +## 0x0 + PT_LOAD's p_offset == offset of .hash + - Tag: DT_HASH + Value: 0x0000000000000000 + - Tag: DT_GNU_HASH +## 0x2C + PT_LOAD's p_offset == offset of .gnu.hash + 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 ## Show that if there are no hash sections, we do not print anything. -# RUN: yaml2obj %s -o %t.o -# RUN: llvm-readelf --hash-symbols %t.o \ +# RUN: yaml2obj --docnum=2 %s -o %t2.o +# RUN: llvm-readelf --hash-symbols %t2.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 %t.o | FileCheck %s --check-prefix DYNSYMS +# RUN: llvm-readelf --dyn-symbols %t2.o | FileCheck %s --check-prefix DYNSYMS # DYNSYMS: Symbol table '.dynsym' contains 2 entries: -!ELF +--- !ELF FileHeader: Class: ELFCLASS64 Data: ELFDATA2LSB