diff --git a/lld/test/ELF/ppc64-dynamic-relocations.s b/lld/test/ELF/ppc64-dynamic-relocations.s --- a/lld/test/ELF/ppc64-dynamic-relocations.s +++ b/lld/test/ELF/ppc64-dynamic-relocations.s @@ -29,7 +29,7 @@ // DIS: .plt 00000018 0000000010030000 BSS // DT_PLTGOT should point to the start of the .plt section. -// DT: 0x0000000000000003 PLTGOT 0x10030000 +// DT: 0x0000000000000003 (PLTGOT) 0x10030000 .text .abiversion 2 diff --git a/llvm/test/tools/llvm-readobj/dynamic.test b/llvm/test/tools/llvm-readobj/dynamic.test --- a/llvm/test/tools/llvm-readobj/dynamic.test +++ b/llvm/test/tools/llvm-readobj/dynamic.test @@ -1,6 +1,8 @@ // Check dynamic section tags in case of shared library file. RUN: llvm-readobj --dynamic-table %p/Inputs/dynamic-table-so.mips \ RUN: | FileCheck %s -check-prefix ELF-MIPS +RUN: llvm-readelf --dynamic-table %p/Inputs/dynamic-table-so.mips \ +RUN: | FileCheck %s --strict-whitespace -check-prefix ELF-MIPS-GNU ELF-MIPS: Format: ELF32-mips ELF-MIPS: Arch: mipsel @@ -33,6 +35,32 @@ ELF-MIPS: 0x00000000 NULL 0x0 ELF-MIPS: ] +ELF-MIPS-GNU: Dynamic section at offset 0x{{.*}} contains 23 entries: +ELF-MIPS-GNU-NEXT: Tag Type Name/Value +ELF-MIPS-GNU-NEXT: 0x00000001 (NEEDED) Shared library: [libc.so.6] +ELF-MIPS-GNU-NEXT: 0x0000000c (INIT) 0x528 +ELF-MIPS-GNU-NEXT: 0x0000000d (FINI) 0x860 +ELF-MIPS-GNU-NEXT: 0x00000004 (HASH) 0x210 +ELF-MIPS-GNU-NEXT: 0x00000005 (STRTAB) 0x3d8 +ELF-MIPS-GNU-NEXT: 0x00000006 (SYMTAB) 0x2a8 +ELF-MIPS-GNU-NEXT: 0x0000000a (STRSZ) 231 (bytes) +ELF-MIPS-GNU-NEXT: 0x0000000b (SYMENT) 16 (bytes) +ELF-MIPS-GNU-NEXT: 0x00000003 (PLTGOT) 0x108e0 +ELF-MIPS-GNU-NEXT: 0x00000011 (REL) 0x518 +ELF-MIPS-GNU-NEXT: 0x00000012 (RELSZ) 16 (bytes) +ELF-MIPS-GNU-NEXT: 0x00000013 (RELENT) 8 (bytes) +ELF-MIPS-GNU-NEXT: 0x70000001 (MIPS_RLD_VERSION) 1 +ELF-MIPS-GNU-NEXT: 0x70000005 (MIPS_FLAGS) NOTPOT +ELF-MIPS-GNU-NEXT: 0x70000006 (MIPS_BASE_ADDRESS) 0x0 +ELF-MIPS-GNU-NEXT: 0x7000000a (MIPS_LOCAL_GOTNO) 10 +ELF-MIPS-GNU-NEXT: 0x70000011 (MIPS_SYMTABNO) 19 +ELF-MIPS-GNU-NEXT: 0x70000012 (MIPS_UNREFEXTNO) 26 +ELF-MIPS-GNU-NEXT: 0x70000013 (MIPS_GOTSYM) 0xd +ELF-MIPS-GNU-NEXT: 0x6ffffffe (VERNEED) 0x4e8 +ELF-MIPS-GNU-NEXT: 0x6fffffff (VERNEEDNUM) 1 +ELF-MIPS-GNU-NEXT: 0x6ffffff0 (VERSYM) 0x4c0 +ELF-MIPS-GNU-NEXT: 0x00000000 (NULL) 0x0 + // Check dynamic section tags in case of non-pic executable file. RUN: llvm-readobj --dynamic-table %p/Inputs/dynamic-table-exe.mips \ RUN: | FileCheck %s -check-prefix ELF-MIPS-EXE @@ -151,6 +179,8 @@ RUN: llvm-readobj --dynamic-table %p/Inputs/dynamic-table-so.aarch64 \ RUN: | FileCheck %s -check-prefix ELF-AARCH64-SO +RUN: llvm-readelf --dynamic-table %p/Inputs/dynamic-table-so.aarch64 \ +RUN: | FileCheck %s --strict-whitespace -check-prefix ELF-AARCH64-SO-GNU ELF-AARCH64-SO: Format: ELF64-aarch64-little ELF-AARCH64-SO: Arch: aarch64 @@ -185,3 +215,32 @@ ELF-AARCH64-SO: 0x000000006FFFFFF9 RELACOUNT 3 ELF-AARCH64-SO: 0x0000000000000000 NULL 0x0 ELF-AARCH64-SO: ] + +ELF-AARCH64-SO-GNU: Dynamic section at offset 0x{{.*}} contains 26 entries: +ELF-AARCH64-SO-GNU-NEXT: Tag Type Name/Value +ELF-AARCH64-SO-GNU-NEXT: 0x0000000000000001 (NEEDED) Shared library: [libc.so.6] +ELF-AARCH64-SO-GNU-NEXT: 0x000000000000000c (INIT) 0x660 +ELF-AARCH64-SO-GNU-NEXT: 0x000000000000000d (FINI) 0x83c +ELF-AARCH64-SO-GNU-NEXT: 0x0000000000000019 (INIT_ARRAY) 0x10db8 +ELF-AARCH64-SO-GNU-NEXT: 0x000000000000001b (INIT_ARRAYSZ) 8 (bytes) +ELF-AARCH64-SO-GNU-NEXT: 0x000000000000001a (FINI_ARRAY) 0x10dc0 +ELF-AARCH64-SO-GNU-NEXT: 0x000000000000001c (FINI_ARRAYSZ) 8 (bytes) +ELF-AARCH64-SO-GNU-NEXT: 0x000000006ffffef5 (GNU_HASH) 0x1f0 +ELF-AARCH64-SO-GNU-NEXT: 0x0000000000000005 (STRTAB) 0x420 +ELF-AARCH64-SO-GNU-NEXT: 0x0000000000000006 (SYMTAB) 0x240 +ELF-AARCH64-SO-GNU-NEXT: 0x000000000000000a (STRSZ) 210 (bytes) +ELF-AARCH64-SO-GNU-NEXT: 0x000000000000000b (SYMENT) 24 (bytes) +ELF-AARCH64-SO-GNU-NEXT: 0x0000000000000003 (PLTGOT) 0x10fe8 +ELF-AARCH64-SO-GNU-NEXT: 0x0000000000000002 (PLTRELSZ) 96 (bytes) +ELF-AARCH64-SO-GNU-NEXT: 0x0000000000000014 (PLTREL) RELA +ELF-AARCH64-SO-GNU-NEXT: 0x0000000000000017 (JMPREL) 0x600 +ELF-AARCH64-SO-GNU-NEXT: 0x000000006ffffef6 (TLSDESC_PLT) 0x6d0 +ELF-AARCH64-SO-GNU-NEXT: 0x000000006ffffef7 (TLSDESC_GOT) 0x10fe0 +ELF-AARCH64-SO-GNU-NEXT: 0x0000000000000007 (RELA) 0x540 +ELF-AARCH64-SO-GNU-NEXT: 0x0000000000000008 (RELASZ) 192 (bytes) +ELF-AARCH64-SO-GNU-NEXT: 0x0000000000000009 (RELAENT) 24 (bytes) +ELF-AARCH64-SO-GNU-NEXT: 0x000000006ffffffe (VERNEED) 0x520 +ELF-AARCH64-SO-GNU-NEXT: 0x000000006fffffff (VERNEEDNUM) 1 +ELF-AARCH64-SO-GNU-NEXT: 0x000000006ffffff0 (VERSYM) 0x4f2 +ELF-AARCH64-SO-GNU-NEXT: 0x000000006ffffff9 (RELACOUNT) 3 +ELF-AARCH64-SO-GNU-NEXT: 0x0000000000000000 (NULL) 0x0 diff --git a/llvm/test/tools/llvm-readobj/elf-dynamic-malformed.test b/llvm/test/tools/llvm-readobj/elf-dynamic-malformed.test --- a/llvm/test/tools/llvm-readobj/elf-dynamic-malformed.test +++ b/llvm/test/tools/llvm-readobj/elf-dynamic-malformed.test @@ -28,14 +28,19 @@ # Test handling of a .dynamic section with an invalid entsize (i.e. not 2 * sizeof(Elf_Dyn)). # RUN: yaml2obj %s --docnum=2 -o %t.bad-entsize -# RUN: llvm-readobj --dynamic-table %t.bad-entsize | FileCheck %s --check-prefix BAD-ENTSIZE -# RUN: llvm-readelf --dynamic-table %t.bad-entsize | FileCheck %s --check-prefix BAD-ENTSIZE +# RUN: llvm-readobj --dynamic-table %t.bad-entsize | FileCheck %s --check-prefix BAD-ENTSIZE-LLVM +# RUN: llvm-readelf --dynamic-table %t.bad-entsize | FileCheck %s --check-prefix BAD-ENTSIZE-GNU -# BAD-ENTSIZE: DynamicSection [ (2 entries) -# BAD-ENTSIZE-NEXT: Tag Type Name/Value -# BAD-ENTSIZE-NEXT: 0x0000000000000015 DEBUG 0x0 -# BAD-ENTSIZE-NEXT: 0x0000000000000000 NULL 0x0 -# BAD-ENTSIZE-NEXT: ] +# BAD-ENTSIZE-LLVM: DynamicSection [ (2 entries) +# BAD-ENTSIZE-LLVM-NEXT: Tag Type Name/Value +# BAD-ENTSIZE-LLVM-NEXT: 0x0000000000000015 DEBUG 0x0 +# BAD-ENTSIZE-LLVM-NEXT: 0x0000000000000000 NULL 0x0 +# BAD-ENTSIZE-LLVM-NEXT: ] + +# BAD-ENTSIZE-GNU: Dynamic section at offset 0x{{.*}} contains 2 entries: +# BAD-ENTSIZE-GNU-NEXT: Tag Type Name/Value +# BAD-ENTSIZE-GNU-NEXT: 0x0000000000000015 (DEBUG) 0x0 +# BAD-ENTSIZE-GNU-NEXT: 0x0000000000000000 (NULL) 0x0 --- !ELF FileHeader: diff --git a/llvm/test/tools/llvm-readobj/elf-dynamic-not-in-pt-dynamic.test b/llvm/test/tools/llvm-readobj/elf-dynamic-not-in-pt-dynamic.test --- a/llvm/test/tools/llvm-readobj/elf-dynamic-not-in-pt-dynamic.test +++ b/llvm/test/tools/llvm-readobj/elf-dynamic-not-in-pt-dynamic.test @@ -2,15 +2,23 @@ ## section when it is not in a PT_DYNAMIC segment. # RUN: yaml2obj %s -o %t.o -# RUN: llvm-readobj --dynamic-table %t.o 2>&1 | FileCheck %s -# RUN: llvm-readelf --dynamic-table %t.o 2>&1 | FileCheck %s +# RUN: llvm-readobj --dynamic-table %t.o 2>&1 \ +# RUN: | FileCheck --check-prefixes=WARNING,LLVM %s +# RUN: llvm-readelf --dynamic-table %t.o 2>&1 \ +# RUN: | FileCheck --check-prefixes=WARNING,GNU %s -# CHECK: warning: The SHT_DYNAMIC section '.dynamic' is not contained within the PT_DYNAMIC segment -# CHECK: DynamicSection [ (2 entries) -# CHECK-NEXT: Tag Type Name/Value -# CHECK-NEXT: 0x0000000000000018 BIND_NOW 0x1 -# CHECK-NEXT: 0x0000000000000000 NULL 0x0 -# CHECK-NEXT: ] +# WARNING: warning: The SHT_DYNAMIC section '.dynamic' is not contained within the PT_DYNAMIC segment + +# LLVM: DynamicSection [ (2 entries) +# LLVM-NEXT: Tag Type Name/Value +# LLVM-NEXT: 0x0000000000000018 BIND_NOW 0x1 +# LLVM-NEXT: 0x0000000000000000 NULL 0x0 +# LLVM-NEXT: ] + +# GNU: Dynamic section at offset 0x{{.*}} contains 2 entries: +# GNU-NEXT: Tag Type Name/Value +# GNU-NEXT: 0x0000000000000018 (BIND_NOW) 0x1 +# GNU-NEXT: 0x0000000000000000 (NULL) 0x0 --- !ELF FileHeader: diff --git a/llvm/test/tools/llvm-readobj/elf-dynamic-table-dtnull.s b/llvm/test/tools/llvm-readobj/elf-dynamic-table-dtnull.s --- a/llvm/test/tools/llvm-readobj/elf-dynamic-table-dtnull.s +++ b/llvm/test/tools/llvm-readobj/elf-dynamic-table-dtnull.s @@ -1,13 +1,17 @@ # Check we are able to dump the dynamic section without a DT_NULL entry correctly. # RUN: yaml2obj -docnum=1 %s -o %t.o -# RUN: llvm-readobj --dynamic-table %t.o | FileCheck %s --check-prefix=NONULL -# RUN: llvm-readelf --dynamic-table %t.o | FileCheck %s --check-prefix=NONULL +# RUN: llvm-readobj --dynamic-table %t.o | FileCheck %s --check-prefix=NONULL-LLVM +# RUN: llvm-readelf --dynamic-table %t.o | FileCheck %s --check-prefix=NONULL-GNU -# NONULL: DynamicSection [ (1 entries) -# NONULL-NEXT: Tag Type Name/Value -# NONULL-NEXT: 0x0000000000000015 DEBUG 0x0 -# NONULL-NEXT: ] +# NONULL-LLVM: DynamicSection [ (1 entries) +# NONULL-LLVM-NEXT: Tag Type Name/Value +# NONULL-LLVM-NEXT: 0x0000000000000015 DEBUG 0x0 +# NONULL-LLVM-NEXT: ] + +# NONULL-GNU: Dynamic section at offset {{.*}} contains 1 entries: +# NONULL-GNU-NEXT: Tag Type Name/Value +# NONULL-GNU-NEXT: 0x0000000000000015 (DEBUG) 0x0 --- !ELF FileHeader: @@ -39,14 +43,19 @@ # past the DT_NULL entry, which works as a terminator. # RUN: yaml2obj -docnum=2 %s -o %t.o -# RUN: llvm-readobj --dynamic-table %t.o | FileCheck %s --check-prefix=LONG -# RUN: llvm-readelf --dynamic-table %t.o | FileCheck %s --check-prefix=LONG +# RUN: llvm-readobj --dynamic-table %t.o | FileCheck %s --check-prefix=LONG-LLVM +# RUN: llvm-readelf --dynamic-table %t.o | FileCheck %s --check-prefix=LONG-GNU + +# LONG-LLVM: DynamicSection [ (2 entries) +# LONG-LLVM-NEXT: Tag Type Name/Value +# LONG-LLVM-NEXT: 0x0000000000000015 DEBUG 0x0 +# LONG-LLVM-NEXT: 0x0000000000000000 NULL 0x0 +# LONG-LLVM-NEXT: ] -# LONG: DynamicSection [ (2 entries) -# LONG-NEXT: Tag Type Name/Value -# LONG-NEXT: 0x0000000000000015 DEBUG 0x0 -# LONG-NEXT: 0x0000000000000000 NULL 0x0 -# LONG-NEXT: ] +# LONG-GNU: Dynamic section at offset {{.*}} contains 2 entries: +# LONG-GNU-NEXT: Tag Type Name/Value +# LONG-GNU-NEXT: 0x0000000000000015 (DEBUG) 0x0 +# LONG-GNU-NEXT: 0x0000000000000000 (NULL) 0x0 --- !ELF FileHeader: diff --git a/llvm/test/tools/llvm-readobj/elf-dynamic-tags-machine-specific.test b/llvm/test/tools/llvm-readobj/elf-dynamic-tags-machine-specific.test --- a/llvm/test/tools/llvm-readobj/elf-dynamic-tags-machine-specific.test +++ b/llvm/test/tools/llvm-readobj/elf-dynamic-tags-machine-specific.test @@ -13,15 +13,14 @@ # LLVM-HEXAGON-NEXT: 0x0000000000000000 NULL 0x0 # LLVM-HEXAGON-NEXT: ] -# GNU-HEXAGON: DynamicSection [ (6 entries) +# GNU-HEXAGON: Dynamic section at offset {{.*}} contains 6 entries: # GNU-HEXAGON-NEXT: Tag Type Name/Value -# GNU-HEXAGON-NEXT: 0x0000000000000004 HASH 0x1000 -# GNU-HEXAGON-NEXT: 0x0000000070000000 HEXAGON_SYMSZ 0x10 -# GNU-HEXAGON-NEXT: 0x0000000070000001 HEXAGON_VER 4096 -# GNU-HEXAGON-NEXT: 0x0000000070000002 HEXAGON_PLT 0x1000 -# GNU-HEXAGON-NEXT: 0x000000001234abcd unknown 0x1 -# GNU-HEXAGON-NEXT: 0x0000000000000000 NULL 0x0 -# GNU-HEXAGON-NEXT: ] +# GNU-HEXAGON-NEXT: 0x0000000000000004 (HASH) 0x1000 +# GNU-HEXAGON-NEXT: 0x0000000070000000 (HEXAGON_SYMSZ) 0x10 +# GNU-HEXAGON-NEXT: 0x0000000070000001 (HEXAGON_VER) 4096 +# GNU-HEXAGON-NEXT: 0x0000000070000002 (HEXAGON_PLT) 0x1000 +# GNU-HEXAGON-NEXT: 0x000000001234abcd (unknown) 0x1 +# GNU-HEXAGON-NEXT: 0x0000000000000000 (NULL) 0x0 # Test that MIPS machine-specific tags can be dumped. @@ -81,57 +80,56 @@ # LLVM-MIPS-NEXT: 0x0000000000000000 NULL 0x0 # LLVM-MIPS-NEXT: ] -# GNU-MIPS: DynamicSection [ (48 entries) -# GNU-MIPS-NEXT: Tag Type Name/Value -# GNU-MIPS-NEXT: 0x0000000000000004 HASH 0x1000 -# GNU-MIPS-NEXT: 0x0000000070000001 MIPS_RLD_VERSION 305419896 -# GNU-MIPS-NEXT: 0x0000000070000002 MIPS_TIME_STAMP 0x11223344 -# GNU-MIPS-NEXT: 0x0000000070000003 MIPS_ICHECKSUM 0x11112222 -# GNU-MIPS-NEXT: 0x0000000070000004 MIPS_IVERSION 0x1 -# GNU-MIPS-NEXT: 0x0000000070000005 MIPS_FLAGS QUICKSTART SGI_ONLY PIXIE CORD -# GNU-MIPS-NEXT: 0x0000000070000006 MIPS_BASE_ADDRESS 0x87654321 -# GNU-MIPS-NEXT: 0x0000000070000007 MIPS_MSYM 0x1000 -# GNU-MIPS-NEXT: 0x0000000070000008 MIPS_CONFLICT 0x1000 -# GNU-MIPS-NEXT: 0x0000000070000009 MIPS_LIBLIST 0x1000 -# GNU-MIPS-NEXT: 0x000000007000000a MIPS_LOCAL_GOTNO 1 -# GNU-MIPS-NEXT: 0x000000007000000b MIPS_CONFLICTNO 0x1 -# GNU-MIPS-NEXT: 0x0000000070000010 MIPS_LIBLISTNO 0x1 -# GNU-MIPS-NEXT: 0x0000000070000011 MIPS_SYMTABNO 1 -# GNU-MIPS-NEXT: 0x0000000070000012 MIPS_UNREFEXTNO 0 -# GNU-MIPS-NEXT: 0x0000000070000013 MIPS_GOTSYM 0x0 -# GNU-MIPS-NEXT: 0x0000000070000014 MIPS_HIPAGENO 0x88776655 -# GNU-MIPS-NEXT: 0x0000000070000016 MIPS_RLD_MAP 0x1000 -# GNU-MIPS-NEXT: 0x0000000070000017 MIPS_DELTA_CLASS 0x1000 -# GNU-MIPS-NEXT: 0x0000000070000018 MIPS_DELTA_CLASS_NO 0x1 -# GNU-MIPS-NEXT: 0x0000000070000019 MIPS_DELTA_INSTANCE 0x1000 -# GNU-MIPS-NEXT: 0x000000007000001a MIPS_DELTA_INSTANCE_NO0x1 -# GNU-MIPS-NEXT: 0x000000007000001b MIPS_DELTA_RELOC 0x1000 -# GNU-MIPS-NEXT: 0x000000007000001c MIPS_DELTA_RELOC_NO 0x1 -# GNU-MIPS-NEXT: 0x000000007000001d MIPS_DELTA_SYM 0x1000 -# GNU-MIPS-NEXT: 0x000000007000001e MIPS_DELTA_SYM_NO 0x1 -# GNU-MIPS-NEXT: 0x0000000070000020 MIPS_DELTA_CLASSSYM 0x1000 -# GNU-MIPS-NEXT: 0x0000000070000021 MIPS_DELTA_CLASSSYM_NO0x1 -# GNU-MIPS-NEXT: 0x0000000070000022 MIPS_CXX_FLAGS 0x88887777 -# GNU-MIPS-NEXT: 0x0000000070000023 MIPS_PIXIE_INIT 0x1000 -# GNU-MIPS-NEXT: 0x0000000070000025 MIPS_LOCALPAGE_GOTIDX0x1 -# GNU-MIPS-NEXT: 0x0000000070000026 MIPS_LOCAL_GOTIDX 0x1 -# GNU-MIPS-NEXT: 0x0000000070000027 MIPS_HIDDEN_GOTIDX 0x1 -# GNU-MIPS-NEXT: 0x0000000070000028 MIPS_PROTECTED_GOTIDX0x1 -# GNU-MIPS-NEXT: 0x0000000070000029 MIPS_OPTIONS 0x1000 -# GNU-MIPS-NEXT: 0x000000007000002a MIPS_INTERFACE 0x1000 -# GNU-MIPS-NEXT: 0x000000007000002b MIPS_DYNSTR_ALIGN 0x88888888 -# GNU-MIPS-NEXT: 0x000000007000002c MIPS_INTERFACE_SIZE 0x10 -# GNU-MIPS-NEXT: 0x000000007000002d MIPS_RLD_TEXT_RESOLVE_ADDR0x8 -# GNU-MIPS-NEXT: 0x000000007000002e MIPS_PERF_SUFFIX 0x0 -# GNU-MIPS-NEXT: 0x000000007000002f MIPS_COMPACT_SIZE 0x10 -# GNU-MIPS-NEXT: 0x0000000070000030 MIPS_GP_VALUE 0x1 -# GNU-MIPS-NEXT: 0x0000000070000031 MIPS_AUX_DYNAMIC 0x1000 -# GNU-MIPS-NEXT: 0x0000000070000032 MIPS_PLTGOT 0x1000 -# GNU-MIPS-NEXT: 0x0000000070000034 MIPS_RWPLT 0x1000 -# GNU-MIPS-NEXT: 0x0000000070000035 MIPS_RLD_MAP_REL 0x1000 -# GNU-MIPS-NEXT: 0x000000001234abcd unknown 0x1 -# GNU-MIPS-NEXT: 0x0000000000000000 NULL 0x0 -# GNU-MIPS-NEXT: ] +# GNU-MIPS: Dynamic section at offset {{.*}} contains 48 entries: +# GNU-MIPS-NEXT: Tag Type Name/Value +# GNU-MIPS-NEXT: 0x0000000000000004 (HASH) 0x1000 +# GNU-MIPS-NEXT: 0x0000000070000001 (MIPS_RLD_VERSION) 305419896 +# GNU-MIPS-NEXT: 0x0000000070000002 (MIPS_TIME_STAMP) 0x11223344 +# GNU-MIPS-NEXT: 0x0000000070000003 (MIPS_ICHECKSUM) 0x11112222 +# GNU-MIPS-NEXT: 0x0000000070000004 (MIPS_IVERSION) 0x1 +# GNU-MIPS-NEXT: 0x0000000070000005 (MIPS_FLAGS) QUICKSTART SGI_ONLY PIXIE CORD +# GNU-MIPS-NEXT: 0x0000000070000006 (MIPS_BASE_ADDRESS) 0x87654321 +# GNU-MIPS-NEXT: 0x0000000070000007 (MIPS_MSYM) 0x1000 +# GNU-MIPS-NEXT: 0x0000000070000008 (MIPS_CONFLICT) 0x1000 +# GNU-MIPS-NEXT: 0x0000000070000009 (MIPS_LIBLIST) 0x1000 +# GNU-MIPS-NEXT: 0x000000007000000a (MIPS_LOCAL_GOTNO) 1 +# GNU-MIPS-NEXT: 0x000000007000000b (MIPS_CONFLICTNO) 0x1 +# GNU-MIPS-NEXT: 0x0000000070000010 (MIPS_LIBLISTNO) 0x1 +# GNU-MIPS-NEXT: 0x0000000070000011 (MIPS_SYMTABNO) 1 +# GNU-MIPS-NEXT: 0x0000000070000012 (MIPS_UNREFEXTNO) 0 +# GNU-MIPS-NEXT: 0x0000000070000013 (MIPS_GOTSYM) 0x0 +# GNU-MIPS-NEXT: 0x0000000070000014 (MIPS_HIPAGENO) 0x88776655 +# GNU-MIPS-NEXT: 0x0000000070000016 (MIPS_RLD_MAP) 0x1000 +# GNU-MIPS-NEXT: 0x0000000070000017 (MIPS_DELTA_CLASS) 0x1000 +# GNU-MIPS-NEXT: 0x0000000070000018 (MIPS_DELTA_CLASS_NO) 0x1 +# GNU-MIPS-NEXT: 0x0000000070000019 (MIPS_DELTA_INSTANCE) 0x1000 +# GNU-MIPS-NEXT: 0x000000007000001a (MIPS_DELTA_INSTANCE_NO) 0x1 +# GNU-MIPS-NEXT: 0x000000007000001b (MIPS_DELTA_RELOC) 0x1000 +# GNU-MIPS-NEXT: 0x000000007000001c (MIPS_DELTA_RELOC_NO) 0x1 +# GNU-MIPS-NEXT: 0x000000007000001d (MIPS_DELTA_SYM) 0x1000 +# GNU-MIPS-NEXT: 0x000000007000001e (MIPS_DELTA_SYM_NO) 0x1 +# GNU-MIPS-NEXT: 0x0000000070000020 (MIPS_DELTA_CLASSSYM) 0x1000 +# GNU-MIPS-NEXT: 0x0000000070000021 (MIPS_DELTA_CLASSSYM_NO) 0x1 +# GNU-MIPS-NEXT: 0x0000000070000022 (MIPS_CXX_FLAGS) 0x88887777 +# GNU-MIPS-NEXT: 0x0000000070000023 (MIPS_PIXIE_INIT) 0x1000 +# GNU-MIPS-NEXT: 0x0000000070000025 (MIPS_LOCALPAGE_GOTIDX) 0x1 +# GNU-MIPS-NEXT: 0x0000000070000026 (MIPS_LOCAL_GOTIDX) 0x1 +# GNU-MIPS-NEXT: 0x0000000070000027 (MIPS_HIDDEN_GOTIDX) 0x1 +# GNU-MIPS-NEXT: 0x0000000070000028 (MIPS_PROTECTED_GOTIDX) 0x1 +# GNU-MIPS-NEXT: 0x0000000070000029 (MIPS_OPTIONS) 0x1000 +# GNU-MIPS-NEXT: 0x000000007000002a (MIPS_INTERFACE) 0x1000 +# GNU-MIPS-NEXT: 0x000000007000002b (MIPS_DYNSTR_ALIGN) 0x88888888 +# GNU-MIPS-NEXT: 0x000000007000002c (MIPS_INTERFACE_SIZE) 0x10 +# GNU-MIPS-NEXT: 0x000000007000002d (MIPS_RLD_TEXT_RESOLVE_ADDR) 0x8 +# GNU-MIPS-NEXT: 0x000000007000002e (MIPS_PERF_SUFFIX) 0x0 +# GNU-MIPS-NEXT: 0x000000007000002f (MIPS_COMPACT_SIZE) 0x10 +# GNU-MIPS-NEXT: 0x0000000070000030 (MIPS_GP_VALUE) 0x1 +# GNU-MIPS-NEXT: 0x0000000070000031 (MIPS_AUX_DYNAMIC) 0x1000 +# GNU-MIPS-NEXT: 0x0000000070000032 (MIPS_PLTGOT) 0x1000 +# GNU-MIPS-NEXT: 0x0000000070000034 (MIPS_RWPLT) 0x1000 +# GNU-MIPS-NEXT: 0x0000000070000035 (MIPS_RLD_MAP_REL) 0x1000 +# GNU-MIPS-NEXT: 0x000000001234abcd (unknown) 0x1 +# GNU-MIPS-NEXT: 0x0000000000000000 (NULL) 0x0 # Test that PPC64 machine-specific tags can be dumped. @@ -147,10 +145,9 @@ # LLVM-PPC-NEXT: 0x0000000000000000 NULL 0x0 # LLVM-PPC-NEXT: ] -# GNU-PPC: DynamicSection [ (4 entries) +# GNU-PPC: Dynamic section at offset {{.*}} contains 4 entries: # GNU-PPC-NEXT: Tag Type Name/Value -# GNU-PPC-NEXT: 0x0000000000000004 HASH 0x1000 -# GNU-PPC-NEXT: 0x0000000070000000 PPC64_GLINK 0x1000 -# GNU-PPC-NEXT: 0x000000001234abcd unknown 0x1 -# GNU-PPC-NEXT: 0x0000000000000000 NULL 0x0 -# GNU-PPC-NEXT: ] +# GNU-PPC-NEXT: 0x0000000000000004 (HASH) 0x1000 +# GNU-PPC-NEXT: 0x0000000070000000 (PPC64_GLINK) 0x1000 +# GNU-PPC-NEXT: 0x000000001234abcd (unknown) 0x1 +# GNU-PPC-NEXT: 0x0000000000000000 (NULL) 0x0 diff --git a/llvm/test/tools/llvm-readobj/elf-dynamic-tags.test b/llvm/test/tools/llvm-readobj/elf-dynamic-tags.test --- a/llvm/test/tools/llvm-readobj/elf-dynamic-tags.test +++ b/llvm/test/tools/llvm-readobj/elf-dynamic-tags.test @@ -68,70 +68,69 @@ # LLVM-NEXT: 0x0000000000000000 NULL 0x0 # LLVM-NEXT: ] -# GNU: DynamicSection [ (61 entries) +# GNU: Dynamic section at offset {{.*}} contains 61 entries: # GNU-NEXT: Tag Type Name/Value -# GNU-NEXT: 0x0000000000000001 NEEDED Shared library: [D] -# GNU-NEXT: 0x0000000000000002 PLTRELSZ 16 (bytes) -# GNU-NEXT: 0x0000000000000003 PLTGOT 0x1000 -# GNU-NEXT: 0x0000000000000004 HASH 0x1000 -# GNU-NEXT: 0x0000000000000005 STRTAB 0x1000 -# GNU-NEXT: 0x0000000000000006 SYMTAB 0x1000 -# GNU-NEXT: 0x0000000000000007 RELA 0x1000 -# GNU-NEXT: 0x0000000000000008 RELASZ 16 (bytes) -# GNU-NEXT: 0x0000000000000009 RELAENT 1929 (bytes) -# GNU-NEXT: 0x000000000000000a STRSZ 16 (bytes) -# GNU-NEXT: 0x000000000000000b SYMENT 2439 (bytes) -# GNU-NEXT: 0x000000000000000c INIT 0x1000 -# GNU-NEXT: 0x000000000000000d FINI 0x1000 -# GNU-NEXT: 0x000000000000000e SONAME Library soname: [U] -# GNU-NEXT: 0x000000000000000f RPATH f -# GNU-NEXT: 0x0000000000000010 SYMBOLIC 0x1234567890abcdef -# GNU-NEXT: 0x0000000000000011 REL 0x1000 -# GNU-NEXT: 0x0000000000000012 RELSZ 16 (bytes) -# GNU-NEXT: 0x0000000000000013 RELENT 291 (bytes) -# GNU-NEXT: 0x0000000000000014 PLTREL RELA -# GNU-NEXT: 0x0000000000000015 DEBUG 0xfedcba0987654321 -# GNU-NEXT: 0x0000000000000016 TEXTREL 0x1122334455667788 -# GNU-NEXT: 0x0000000000000017 JMPREL 0x1000 -# GNU-NEXT: 0x0000000000000018 BIND_NOW 0x8877665544332211 -# GNU-NEXT: 0x0000000000000019 INIT_ARRAY 0x1000 -# GNU-NEXT: 0x000000000000001a FINI_ARRAY 0x1000 -# GNU-NEXT: 0x000000000000001b INIT_ARRAYSZ 16 (bytes) -# GNU-NEXT: 0x000000000000001c FINI_ARRAYSZ 16 (bytes) -# GNU-NEXT: 0x000000000000001d RUNPATH w -# GNU-NEXT: 0x000000000000001e FLAGS ORIGIN SYMBOLIC TEXTREL BIND_NOW STATIC_TLS {{$}} -# GNU-NEXT: 0x0000000000000020 PREINIT_ARRAY 0x1000 -# GNU-NEXT: 0x0000000000000021 PREINIT_ARRAYSZ 16 (bytes) -# GNU-NEXT: 0x0000000000000022 SYMTAB_SHNDX 0x1000 -# GNU-NEXT: 0x0000000000000023 RELRSZ 0x10 -# GNU-NEXT: 0x0000000000000024 RELR 0x1000 -# GNU-NEXT: 0x0000000000000025 RELRENT 0x4321 -# GNU-NEXT: 0x000000006000000f ANDROID_REL 0x1000 -# GNU-NEXT: 0x0000000060000010 ANDROID_RELSZ 16 (bytes) -# GNU-NEXT: 0x0000000060000011 ANDROID_RELA 0x1000 -# GNU-NEXT: 0x0000000060000012 ANDROID_RELASZ 16 (bytes) -# GNU-NEXT: 0x000000006fffe000 ANDROID_RELR 0x1000 -# GNU-NEXT: 0x000000006fffe001 ANDROID_RELRSZ 0x10 -# GNU-NEXT: 0x000000006fffe003 ANDROID_RELRENT 0x1234 -# GNU-NEXT: 0x000000006ffffef5 GNU_HASH 0x1000 -# GNU-NEXT: 0x000000006ffffef6 TLSDESC_PLT 0x1000 -# GNU-NEXT: 0x000000006ffffef7 TLSDESC_GOT 0x1000 -# GNU-NEXT: 0x000000006ffffff9 RELACOUNT 0 -# GNU-NEXT: 0x000000006ffffffa RELCOUNT 0 -# GNU-NEXT: 0x000000006ffffffb FLAGS_1 NOW GLOBAL GROUP NODELETE LOADFLTR INITFIRST NOOPEN ORIGIN DIRECT TRANS INTERPOSE NODEFLIB NODUMP CONFALT ENDFILTEE DISPRELDNE DISPRELPND NODIRECT IGNMULDEF NOKSYMS NOHDR EDITED NORELOC SYMINTPOSE GLOBAUDIT SINGLETON {{$}} -# GNU-NEXT: 0x000000006ffffff0 VERSYM 0x1000 -# GNU-NEXT: 0x000000006ffffffc VERDEF 0x1000 -# GNU-NEXT: 0x000000006ffffffd VERDEFNUM 0 -# GNU-NEXT: 0x000000006ffffffe VERNEED 0x1000 -# GNU-NEXT: 0x000000006fffffff VERNEEDNUM 0 -# GNU-NEXT: 0x000000007ffffffd AUXILIARY Auxiliary library: [D] -# GNU-NEXT: 0x000000007ffffffe USED Not needed object: [U] -# GNU-NEXT: 0x000000007fffffff FILTER Filter library: [U] -# GNU-NEXT: 0x0000000012345678 unknown 0x8765432187654321 -# GNU-NEXT: 0x000000006abcdef0 unknown 0x9988776655443322 -# GNU-NEXT: 0x0000000076543210 unknown 0x5555666677778888 -# GNU-NEXT: 0x0000000000000000 NULL 0x0 -# GNU-NEXT: ] +# GNU-NEXT: 0x0000000000000001 (NEEDED) Shared library: [D] +# GNU-NEXT: 0x0000000000000002 (PLTRELSZ) 16 (bytes) +# GNU-NEXT: 0x0000000000000003 (PLTGOT) 0x1000 +# GNU-NEXT: 0x0000000000000004 (HASH) 0x1000 +# GNU-NEXT: 0x0000000000000005 (STRTAB) 0x1000 +# GNU-NEXT: 0x0000000000000006 (SYMTAB) 0x1000 +# GNU-NEXT: 0x0000000000000007 (RELA) 0x1000 +# GNU-NEXT: 0x0000000000000008 (RELASZ) 16 (bytes) +# GNU-NEXT: 0x0000000000000009 (RELAENT) 1929 (bytes) +# GNU-NEXT: 0x000000000000000a (STRSZ) 16 (bytes) +# GNU-NEXT: 0x000000000000000b (SYMENT) 2439 (bytes) +# GNU-NEXT: 0x000000000000000c (INIT) 0x1000 +# GNU-NEXT: 0x000000000000000d (FINI) 0x1000 +# GNU-NEXT: 0x000000000000000e (SONAME) Library soname: [U] +# GNU-NEXT: 0x000000000000000f (RPATH) f +# GNU-NEXT: 0x0000000000000010 (SYMBOLIC) 0x1234567890abcdef +# GNU-NEXT: 0x0000000000000011 (REL) 0x1000 +# GNU-NEXT: 0x0000000000000012 (RELSZ) 16 (bytes) +# GNU-NEXT: 0x0000000000000013 (RELENT) 291 (bytes) +# GNU-NEXT: 0x0000000000000014 (PLTREL) RELA +# GNU-NEXT: 0x0000000000000015 (DEBUG) 0xfedcba0987654321 +# GNU-NEXT: 0x0000000000000016 (TEXTREL) 0x1122334455667788 +# GNU-NEXT: 0x0000000000000017 (JMPREL) 0x1000 +# GNU-NEXT: 0x0000000000000018 (BIND_NOW) 0x8877665544332211 +# GNU-NEXT: 0x0000000000000019 (INIT_ARRAY) 0x1000 +# GNU-NEXT: 0x000000000000001a (FINI_ARRAY) 0x1000 +# GNU-NEXT: 0x000000000000001b (INIT_ARRAYSZ) 16 (bytes) +# GNU-NEXT: 0x000000000000001c (FINI_ARRAYSZ) 16 (bytes) +# GNU-NEXT: 0x000000000000001d (RUNPATH) w +# GNU-NEXT: 0x000000000000001e (FLAGS) ORIGIN SYMBOLIC TEXTREL BIND_NOW STATIC_TLS {{$}} +# GNU-NEXT: 0x0000000000000020 (PREINIT_ARRAY) 0x1000 +# GNU-NEXT: 0x0000000000000021 (PREINIT_ARRAYSZ) 16 (bytes) +# GNU-NEXT: 0x0000000000000022 (SYMTAB_SHNDX) 0x1000 +# GNU-NEXT: 0x0000000000000023 (RELRSZ) 0x10 +# GNU-NEXT: 0x0000000000000024 (RELR) 0x1000 +# GNU-NEXT: 0x0000000000000025 (RELRENT) 0x4321 +# GNU-NEXT: 0x000000006000000f (ANDROID_REL) 0x1000 +# GNU-NEXT: 0x0000000060000010 (ANDROID_RELSZ) 16 (bytes) +# GNU-NEXT: 0x0000000060000011 (ANDROID_RELA) 0x1000 +# GNU-NEXT: 0x0000000060000012 (ANDROID_RELASZ) 16 (bytes) +# GNU-NEXT: 0x000000006fffe000 (ANDROID_RELR) 0x1000 +# GNU-NEXT: 0x000000006fffe001 (ANDROID_RELRSZ) 0x10 +# GNU-NEXT: 0x000000006fffe003 (ANDROID_RELRENT) 0x1234 +# GNU-NEXT: 0x000000006ffffef5 (GNU_HASH) 0x1000 +# GNU-NEXT: 0x000000006ffffef6 (TLSDESC_PLT) 0x1000 +# GNU-NEXT: 0x000000006ffffef7 (TLSDESC_GOT) 0x1000 +# GNU-NEXT: 0x000000006ffffff9 (RELACOUNT) 0 +# GNU-NEXT: 0x000000006ffffffa (RELCOUNT) 0 +# GNU-NEXT: 0x000000006ffffffb (FLAGS_1) NOW GLOBAL GROUP NODELETE LOADFLTR INITFIRST NOOPEN ORIGIN DIRECT TRANS INTERPOSE NODEFLIB NODUMP CONFALT ENDFILTEE DISPRELDNE DISPRELPND NODIRECT IGNMULDEF NOKSYMS NOHDR EDITED NORELOC SYMINTPOSE GLOBAUDIT SINGLETON {{$}} +# GNU-NEXT: 0x000000006ffffff0 (VERSYM) 0x1000 +# GNU-NEXT: 0x000000006ffffffc (VERDEF) 0x1000 +# GNU-NEXT: 0x000000006ffffffd (VERDEFNUM) 0 +# GNU-NEXT: 0x000000006ffffffe (VERNEED) 0x1000 +# GNU-NEXT: 0x000000006fffffff (VERNEEDNUM) 0 +# GNU-NEXT: 0x000000007ffffffd (AUXILIARY) Auxiliary library: [D] +# GNU-NEXT: 0x000000007ffffffe (USED) Not needed object: [U] +# GNU-NEXT: 0x000000007fffffff (FILTER) Filter library: [U] +# GNU-NEXT: 0x0000000012345678 (unknown) 0x8765432187654321 +# GNU-NEXT: 0x000000006abcdef0 (unknown) 0x9988776655443322 +# GNU-NEXT: 0x0000000076543210 (unknown) 0x5555666677778888 +# GNU-NEXT: 0x0000000000000000 (NULL) 0x0 --- !ELF FileHeader: diff --git a/llvm/test/tools/llvm-readobj/elf-non-dynamic-in-pt-dynamic.test b/llvm/test/tools/llvm-readobj/elf-non-dynamic-in-pt-dynamic.test --- a/llvm/test/tools/llvm-readobj/elf-non-dynamic-in-pt-dynamic.test +++ b/llvm/test/tools/llvm-readobj/elf-non-dynamic-in-pt-dynamic.test @@ -5,15 +5,23 @@ ## We check that we warn about this case. # RUN: yaml2obj --docnum=1 %s -o %t.o -# RUN: llvm-readobj --dynamic-table %t.o 2>&1 | FileCheck %s --check-prefixes=WARNING,CHECK -# RUN: llvm-readelf --dynamic-table %t.o 2>&1 | FileCheck %s --check-prefixes=WARNING,CHECK +# RUN: llvm-readobj --dynamic-table %t.o 2>&1 \ +# RUN: | FileCheck %s --check-prefixes=WARNING,LLVM +# RUN: llvm-readelf --dynamic-table %t.o 2>&1 \ +# RUN: | FileCheck %s --check-prefixes=WARNING,GNU # WARNING: warning: The SHT_DYNAMIC section '.dynamic' is not at the start of PT_DYNAMIC segment -# CHECK: DynamicSection [ (2 entries) -# CHECK-NEXT: Tag Type Name/Value -# CHECK-NEXT: 0x0000000000000018 BIND_NOW 0x1 -# CHECK-NEXT: 0x0000000000000000 NULL 0x0 -# CHECK-NEXT: ] + +# LLVM: DynamicSection [ (2 entries) +# LLVM-NEXT: Tag Type Name/Value +# LLVM-NEXT: 0x0000000000000018 BIND_NOW 0x1 +# LLVM-NEXT: 0x0000000000000000 NULL 0x0 +# LLVM-NEXT: ] + +# GNU: Dynamic section at offset 0x{{.*}} contains 2 entries: +# GNU-NEXT: Tag Type Name/Value +# GNU-NEXT: 0x0000000000000018 (BIND_NOW) 0x1 +# GNU-NEXT: 0x0000000000000000 (NULL) 0x0 --- !ELF FileHeader: diff --git a/llvm/test/tools/llvm-readobj/elf-versioninfo.test b/llvm/test/tools/llvm-readobj/elf-versioninfo.test --- a/llvm/test/tools/llvm-readobj/elf-versioninfo.test +++ b/llvm/test/tools/llvm-readobj/elf-versioninfo.test @@ -73,9 +73,9 @@ LLVM-VERDEF-NEXT: } LLVM-VERDEF-NEXT: } -GNU-VERDEF: 0x000000006ffffff0 VERSYM 0x24c -GNU-VERDEF: 0x000000006ffffffc VERDEF 0x25c -GNU-VERDEF: 0x000000006ffffffd VERDEFNUM 3 +GNU-VERDEF: 0x000000006ffffff0 (VERSYM) 0x24c +GNU-VERDEF: 0x000000006ffffffc (VERDEF) 0x25c +GNU-VERDEF: 0x000000006ffffffd (VERDEFNUM) 3 GNU-VERDEF: Version symbols section '.gnu.version' contains 8 entries: GNU-VERDEF-NEXT: Addr: 000000000000024c Offset: 0x00024c Link: 1 (.dynsym) diff --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp --- a/llvm/tools/llvm-readobj/ELFDumper.cpp +++ b/llvm/tools/llvm-readobj/ELFDumper.cpp @@ -206,8 +206,6 @@ void loadDynamicTable(const ELFFile *Obj); void parseDynamicTable(); - void printValue(uint64_t Type, uint64_t Value); - StringRef getDynamicString(uint64_t Offset) const; StringRef getSymbolVersion(StringRef StrTab, const Elf_Sym *symb, bool &IsDefault) const; @@ -283,6 +281,8 @@ bool &IsDefault) const; void printSymbolsHelper(bool IsDynamic) const; + void printDynamicEntry(raw_ostream &OS, uint64_t Type, uint64_t Value) const; + const Elf_Shdr *getDotSymtabSec() const { return DotSymtabSec; } const Elf_Shdr *getDotCGProfileSec() const { return DotCGProfileSec; } const Elf_Shdr *getDotAddrsigSec() const { return DotAddrsigSec; } @@ -292,6 +292,7 @@ const DynRegionInfo &getDynRelaRegion() const { return DynRelaRegion; } const DynRegionInfo &getDynRelrRegion() const { return DynRelrRegion; } const DynRegionInfo &getDynPLTRelRegion() const { return DynPLTRelRegion; } + const DynRegionInfo &getDynamicTableRegion() const { return DynamicTable; } const Elf_Hash *getHashTable() const { return HashTable; } const Elf_GnuHash *getGnuHashTable() const { return GnuHashTable; } }; @@ -340,6 +341,7 @@ virtual void printSymbols(const ELFFile *Obj, bool PrintSymbols, bool PrintDynamicSymbols) = 0; virtual void printHashSymbols(const ELFFile *Obj) {} + virtual void printDynamic(const ELFFile *Obj) {} virtual void printDynamicRelocations(const ELFFile *Obj) = 0; virtual void printSymtabMessage(const ELFFile *Obj, StringRef Name, size_t Offset) {} @@ -384,6 +386,7 @@ void printSymbols(const ELFO *Obj, bool PrintSymbols, bool PrintDynamicSymbols) override; void printHashSymbols(const ELFO *Obj) override; + void printDynamic(const ELFFile *Obj) override; void printDynamicRelocations(const ELFO *Obj) override; void printSymtabMessage(const ELFO *Obj, StringRef Name, size_t Offset) override; @@ -488,6 +491,7 @@ void printSectionHeaders(const ELFO *Obj) override; void printSymbols(const ELFO *Obj, bool PrintSymbols, bool PrintDynamicSymbols) override; + void printDynamic(const ELFFile *Obj) override; void printDynamicRelocations(const ELFO *Obj) override; void printProgramHeaders(const ELFO *Obj, bool PrintProgramHeaders, cl::boolOrDefault PrintSectionMapping) override; @@ -1764,8 +1768,8 @@ } template -void ELFDumper::printValue(uint64_t Type, uint64_t Value) { - raw_ostream &OS = W.getOStream(); +void ELFDumper::printDynamicEntry(raw_ostream &OS, uint64_t Type, + uint64_t Value) const { const char *ConvChar = (opts::Output == opts::GNU) ? "0x%" PRIx64 : "0x%" PRIX64; switch (Type) { @@ -1883,41 +1887,7 @@ } // end anonymous namespace template void ELFDumper::printDynamicTable() { - // A valid .dynamic section contains an array of entries terminated with - // a DT_NULL entry. However, sometimes the section content may continue - // past the DT_NULL entry, so to dump the section correctly, we first find - // the end of the entries by iterating over them. - size_t Size = 0; - Elf_Dyn_Range DynTableEntries = dynamic_table(); - for (; Size < DynTableEntries.size();) - if (DynTableEntries[Size++].getTag() == DT_NULL) - break; - - if (!Size) - return; - - raw_ostream &OS = W.getOStream(); - W.startLine() << "DynamicSection [ (" << Size << " entries)\n"; - - bool Is64 = ELFT::Is64Bits; - W.startLine() << " Tag" << (Is64 ? " " : " ") << "Type" - << " " - << "Name/Value\n"; - for (size_t I = 0; I < Size; ++I) { - const Elf_Dyn &Entry = DynTableEntries[I]; - uintX_t Tag = Entry.getTag(); - W.startLine() << " " - << format_hex(Tag, Is64 ? 18 : 10, opts::Output != opts::GNU) - << " " - << format( - "%-21s", - getTypeString( - ObjF->getELFFile()->getHeader()->e_machine, Tag)); - printValue(Tag, Entry.getVal()); - OS << "\n"; - } - - W.startLine() << "]\n"; + ELFDumperStyle->printDynamic(ObjF->getELFFile()); } template void ELFDumper::printNeededLibraries() { @@ -2501,6 +2471,21 @@ ")"; } +template +static typename ELFT::DynRange +rectifyDynamicTable(typename ELFT::DynRange Table) { + // A valid .dynamic section contains an array of entries terminated with + // a DT_NULL entry. However, sometimes the section content may continue + // past the DT_NULL entry, so to dump the section correctly, we first find + // the end of the entries by iterating over them. + size_t Size = 0; + while (Size < Table.size()) + if (Table[Size++].getTag() == DT_NULL) + break; + + return Table.slice(0, Size); +} + template void GNUStyle::printFileHeaders(const ELFO *Obj) { const Elf_Ehdr *e = Obj->getHeader(); OS << "ELF Header:\n"; @@ -3344,6 +3329,35 @@ printRelocation(Obj, Sym, SymbolName, R, IsRela); } +template void GNUStyle::printDynamic(const ELFO *Obj) { + Elf_Dyn_Range Table = + rectifyDynamicTable(this->dumper()->dynamic_table()); + if (Table.empty()) + return; + + const DynRegionInfo &DynamicTableRegion = + this->dumper()->getDynamicTableRegion(); + + OS << "Dynamic section at offset " + << format_hex(reinterpret_cast(DynamicTableRegion.Addr) - + Obj->base(), + 1) + << " contains " << Table.size() << " entries:\n"; + + bool Is64 = ELFT::Is64Bits; + OS << " Tag" << (Is64 ? " " : " ") << "Type" + << " " + << "Name/Value\n"; + for (auto Entry : Table) { + uintX_t Tag = Entry.getTag(); + std::string TypeString = getTypeString(Obj->getHeader()->e_machine, Tag); + OS << format(" 0x%0*x %-20s ", Is64 ? 16 : 8, Tag, + ("(" + TypeString + ")").c_str()); + this->dumper()->printDynamicEntry(OS, Tag, Entry.getVal()); + OS << "\n"; + } +} + template void GNUStyle::printDynamicRelocations(const ELFO *Obj) { const DynRegionInfo &DynRelRegion = this->dumper()->getDynRelRegion(); @@ -4492,6 +4506,31 @@ this->dumper()->printSymbolsHelper(true); } +template void LLVMStyle::printDynamic(const ELFFile *Obj) { + Elf_Dyn_Range Table = + rectifyDynamicTable(this->dumper()->dynamic_table()); + if (Table.empty()) + return; + + raw_ostream &OS = W.getOStream(); + W.startLine() << "DynamicSection [ (" << Table.size() << " entries)\n"; + + bool Is64 = ELFT::Is64Bits; + W.startLine() << " Tag" << (Is64 ? " " : " ") << "Type" + << " " + << "Name/Value\n"; + for (auto Entry : Table) { + uintX_t Tag = Entry.getTag(); + W.startLine() << " " << format_hex(Tag, Is64 ? 18 : 10, true) << " " + << format("%-21s", + getTypeString(Obj->getHeader()->e_machine, Tag)); + this->dumper()->printDynamicEntry(OS, Tag, Entry.getVal()); + OS << "\n"; + } + + W.startLine() << "]\n"; +} + template void LLVMStyle::printDynamicRelocations(const ELFO *Obj) { const DynRegionInfo &DynRelRegion = this->dumper()->getDynRelRegion();