Index: include/llvm/BinaryFormat/DynamicTags.def =================================================================== --- include/llvm/BinaryFormat/DynamicTags.def +++ include/llvm/BinaryFormat/DynamicTags.def @@ -16,6 +16,11 @@ #define MIPS_DYNAMIC_TAG_DEFINED #endif +#ifndef PPC32_DYNAMIC_TAG +#define PPC32_DYNAMIC_TAG(name, value) DYNAMIC_TAG(name, value) +#define PPC32_DYNAMIC_TAG_DEFINED +#endif + #ifndef PPC64_DYNAMIC_TAG #define PPC64_DYNAMIC_TAG(name, value) DYNAMIC_TAG(name, value) #define PPC64_DYNAMIC_TAG_DEFINED @@ -190,6 +195,10 @@ MIPS_DYNAMIC_TAG(MIPS_RLD_MAP_REL, 0x70000035) // Relative offset of run time loader // map, used for debugging. +// PPC32 specific dynamic table entries. +PPC32_DYNAMIC_TAG(PPC_GOT, 0x70000000) // Uses Secure PLT ABI. +PPC32_DYNAMIC_TAG(PPC_OPT, 0x70000001) // Has TLS optimization. + // PPC64 specific dynamic table entries. PPC64_DYNAMIC_TAG(PPC64_GLINK, 0x70000000) // Address of 32 bytes before the // first glink lazy resolver stub. Index: test/tools/llvm-readobj/Inputs/elf-dynamic-tags-machine-specific.yaml =================================================================== --- test/tools/llvm-readobj/Inputs/elf-dynamic-tags-machine-specific.yaml +++ test/tools/llvm-readobj/Inputs/elf-dynamic-tags-machine-specific.yaml @@ -165,7 +165,43 @@ Sections: - Section: .dynamic -# Third document: PPC64 +# Third document: PPC32 +--- !ELF +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2MSB + Type: ET_EXEC + Machine: EM_PPC +Sections: + - Name: .dynstr + Type: SHT_STRTAB + Address: 0x200 + Size: 0x10 + Content: "004400550066007700" + - Name: .dynamic + Type: SHT_DYNAMIC + Address: 0x20000 + Entries: + - Tag: DT_PPC_GOT + Value: 0x200c0 + - Tag: DT_PPC_OPT + Value: 1 + - Tag: 0x1234abcd + Value: 0x1 + - Tag: DT_NULL + Value: 0 +ProgramHeaders: + - Type: PT_LOAD + VAddr: 0x1000 + Sections: + - Section: .dynstr + - Section: .dynamic + - Type: PT_DYNAMIC + VAddr: 0x20000 + Sections: + - Section: .dynamic + +# Fourth document: PPC64 --- !ELF FileHeader: Class: ELFCLASS64 Index: test/tools/llvm-readobj/elf-dynamic-tags-machine-specific.test =================================================================== --- test/tools/llvm-readobj/elf-dynamic-tags-machine-specific.test +++ test/tools/llvm-readobj/elf-dynamic-tags-machine-specific.test @@ -132,22 +132,43 @@ # GNU-MIPS-NEXT: 0x0000000000000000 (NULL) 0x0 +# Test that PPC32 machine-specific tags can be dumped. +# RUN: yaml2obj --docnum=3 %S/Inputs/elf-dynamic-tags-machine-specific.yaml -o %t.ppc32 +# RUN: llvm-readobj --dynamic-table %t.ppc32 | FileCheck %s --check-prefix=LLVM-PPC32 +# RUN: llvm-readelf --dynamic-table %t.ppc32 | FileCheck %s --check-prefix=GNU-PPC32 + +# LLVM-PPC32: DynamicSection [ (4 entries) +# LLVM-PPC32-NEXT: Tag Type Name/Value +# LLVM-PPC32-NEXT: 0x70000000 PPC_GOT 0x200C0 +# LLVM-PPC32-NEXT: 0x70000001 PPC_OPT 0x1 +# LLVM-PPC32-NEXT: 0x1234ABCD unknown 0x1 +# LLVM-PPC32-NEXT: 0x00000000 NULL 0x0 +# LLVM-PPC32-NEXT: ] + +# GNU-PPC32: Dynamic section at offset {{.*}} contains 4 entries: +# GNU-PPC32-NEXT: Tag Type Name/Value +# GNU-PPC32-NEXT: 0x70000000 (PPC_GOT) 0x200c0 +# GNU-PPC32-NEXT: 0x70000001 (PPC_OPT) 0x1 +# GNU-PPC32-NEXT: 0x1234abcd (unknown) 0x1 +# GNU-PPC32-NEXT: 0x00000000 (NULL) 0x0 + + # Test that PPC64 machine-specific tags can be dumped. -# RUN: yaml2obj --docnum=3 %S/Inputs/elf-dynamic-tags-machine-specific.yaml -o %t.ppc -# RUN: llvm-readobj --dynamic-table %t.ppc | FileCheck %s --check-prefix=LLVM-PPC -# RUN: llvm-readelf --dynamic-table %t.ppc | FileCheck %s --check-prefix=GNU-PPC +# RUN: yaml2obj --docnum=4 %S/Inputs/elf-dynamic-tags-machine-specific.yaml -o %t.ppc64 +# RUN: llvm-readobj --dynamic-table %t.ppc64 | FileCheck %s --check-prefix=LLVM-PPC64 +# RUN: llvm-readelf --dynamic-table %t.ppc64 | FileCheck %s --check-prefix=GNU-PPC64 -# LLVM-PPC: DynamicSection [ (4 entries) -# LLVM-PPC-NEXT: Tag Type Name/Value -# LLVM-PPC-NEXT: 0x0000000000000004 HASH 0x1000 -# LLVM-PPC-NEXT: 0x0000000070000000 PPC64_GLINK 0x1000 -# LLVM-PPC-NEXT: 0x000000001234ABCD unknown 0x1 -# LLVM-PPC-NEXT: 0x0000000000000000 NULL 0x0 -# LLVM-PPC-NEXT: ] +# LLVM-PPC64: DynamicSection [ (4 entries) +# LLVM-PPC64-NEXT: Tag Type Name/Value +# LLVM-PPC64-NEXT: 0x0000000000000004 HASH 0x1000 +# LLVM-PPC64-NEXT: 0x0000000070000000 PPC64_GLINK 0x1000 +# LLVM-PPC64-NEXT: 0x000000001234ABCD unknown 0x1 +# LLVM-PPC64-NEXT: 0x0000000000000000 NULL 0x0 +# LLVM-PPC64-NEXT: ] -# 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-PPC64: Dynamic section at offset {{.*}} contains 4 entries: +# GNU-PPC64-NEXT: Tag Type Name/Value +# GNU-PPC64-NEXT: 0x0000000000000004 (HASH) 0x1000 +# GNU-PPC64-NEXT: 0x0000000070000000 (PPC64_GLINK) 0x1000 +# GNU-PPC64-NEXT: 0x000000001234abcd (unknown) 0x1 +# GNU-PPC64-NEXT: 0x0000000000000000 (NULL) 0x0 Index: tools/llvm-readobj/ELFDumper.cpp =================================================================== --- tools/llvm-readobj/ELFDumper.cpp +++ tools/llvm-readobj/ELFDumper.cpp @@ -1783,6 +1783,44 @@ uint64_t Value) const { const char *ConvChar = (opts::Output == opts::GNU) ? "0x%" PRIx64 : "0x%" PRIX64; + switch (ObjF->getELFFile()->getHeader()->e_machine) { + case EM_HEXAGON: + if (Type == DT_HEXAGON_VER) { + OS << Value; + return; + } + break; + case EM_MIPS: + switch (Type) { + case DT_MIPS_BASE_ADDRESS: + case DT_MIPS_GOTSYM: + case DT_MIPS_RLD_MAP: + case DT_MIPS_RLD_MAP_REL: + case DT_MIPS_PLTGOT: + case DT_MIPS_OPTIONS: + OS << format(ConvChar, Value); + return; + case DT_MIPS_RLD_VERSION: + case DT_MIPS_LOCAL_GOTNO: + case DT_MIPS_SYMTABNO: + case DT_MIPS_UNREFEXTNO: + OS << Value; + return; + case DT_MIPS_FLAGS: + printFlags(Value, makeArrayRef(ElfDynamicDTMipsFlags), OS); + return; + } + break; + case EM_PPC: + switch (Type) { + case DT_PPC_GOT: + case DT_PPC_OPT: + OS << format(ConvChar, Value); + return; + } + break; + } + switch (Type) { case DT_PLTREL: if (Value == DT_REL) { @@ -1811,22 +1849,12 @@ case DT_VERSYM: case DT_GNU_HASH: case DT_NULL: - case DT_MIPS_BASE_ADDRESS: - case DT_MIPS_GOTSYM: - case DT_MIPS_RLD_MAP: - case DT_MIPS_RLD_MAP_REL: - case DT_MIPS_PLTGOT: - case DT_MIPS_OPTIONS: OS << format(ConvChar, Value); break; case DT_RELACOUNT: case DT_RELCOUNT: case DT_VERDEFNUM: case DT_VERNEEDNUM: - case DT_MIPS_RLD_VERSION: - case DT_MIPS_LOCAL_GOTNO: - case DT_MIPS_SYMTABNO: - case DT_MIPS_UNREFEXTNO: OS << Value; break; case DT_PLTRELSZ: @@ -1862,9 +1890,6 @@ case DT_RUNPATH: OS << getDynamicString(Value); break; - case DT_MIPS_FLAGS: - printFlags(Value, makeArrayRef(ElfDynamicDTMipsFlags), OS); - break; case DT_FLAGS: printFlags(Value, makeArrayRef(ElfDynamicDTFlags), OS); break;