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 PPC_DYNAMIC_TAG +#define PPC_DYNAMIC_TAG(name, value) DYNAMIC_TAG(name, value) +#define PPC_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. +// PPC specific dynamic table entries. +PPC_DYNAMIC_TAG(PPC_GOT, 0x70000000) // Uses Secure PLT ABI. +PPC_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. @@ -212,6 +221,10 @@ #undef HEXAGON_DYNAMIC_TAG #undef HEXAGON_DYNAMIC_TAG_DEFINED #endif +#ifdef PPC_DYNAMIC_TAG_DEFINED +#undef PPC_DYNAMIC_TAG +#undef PPC_DYNAMIC_TAG_DEFINED +#endif #ifdef PPC64_DYNAMIC_TAG_DEFINED #undef PPC64_DYNAMIC_TAG #undef PPC64_DYNAMIC_TAG_DEFINED Index: lib/ObjectYAML/ELFYAML.cpp =================================================================== --- lib/ObjectYAML/ELFYAML.cpp +++ lib/ObjectYAML/ELFYAML.cpp @@ -682,6 +682,7 @@ // Disable architecture specific tags by default. We might enable them below. #define MIPS_DYNAMIC_TAG(name, value) #define HEXAGON_DYNAMIC_TAG(name, value) +#define PPC_DYNAMIC_TAG(name, value) #define PPC64_DYNAMIC_TAG(name, value) // Ignore marker tags such as DT_HIOS (maps to DT_VERNEEDNUM), etc. #define DYNAMIC_TAG_MARKER(name, value) @@ -703,6 +704,13 @@ #undef HEXAGON_DYNAMIC_TAG #define HEXAGON_DYNAMIC_TAG(name, value) break; + case ELF::EM_PPC: +#undef PPC_DYNAMIC_TAG +#define PPC_DYNAMIC_TAG(name, value) DYNAMIC_TAG(name, value) +#include "llvm/BinaryFormat/DynamicTags.def" +#undef PPC_DYNAMIC_TAG +#define PPC_DYNAMIC_TAG(name, value) + break; case ELF::EM_PPC64: #undef PPC64_DYNAMIC_TAG #define PPC64_DYNAMIC_TAG(name, value) DYNAMIC_TAG(name, value) @@ -717,6 +725,7 @@ #undef MIPS_DYNAMIC_TAG #undef HEXAGON_DYNAMIC_TAG +#undef PPC_DYNAMIC_TAG #undef PPC64_DYNAMIC_TAG #undef DYNAMIC_TAG_MARKER #undef STRINGIFY Index: test/tools/llvm-objdump/elf-dynamic-section-machine-specific.test =================================================================== --- test/tools/llvm-objdump/elf-dynamic-section-machine-specific.test +++ test/tools/llvm-objdump/elf-dynamic-section-machine-specific.test @@ -66,12 +66,23 @@ # MIPS-NEXT: 0x1234abcd 0x0000000000000001 -# Test that PPC64 machine-specific tags can be dumped. +## Test that PPC machine-specific tags can be dumped. # RUN: yaml2obj --docnum=3 -o %t.ppc \ # RUN: %S/../llvm-readobj/Inputs/elf-dynamic-tags-machine-specific.yaml # RUN: llvm-objdump -p %t.ppc | FileCheck %s --check-prefix=PPC # PPC: Dynamic Section: -# PPC-NEXT: HASH 0x0000000000001000 -# PPC-NEXT: PPC64_GLINK 0x0000000000001000 -# PPC-NEXT: 0x1234abcd 0x0000000000000001 +# PPC-NEXT: PPC_GOT 0x000200c0 +# PPC-NEXT: PPC_OPT 0x00000001 +# PPC-NEXT: 0x1234abcd 0x00000001 +# + +## Test that PPC64 machine-specific tags can be dumped. +# RUN: yaml2obj --docnum=4 -o %t.ppc64 \ +# RUN: %S/../llvm-readobj/Inputs/elf-dynamic-tags-machine-specific.yaml +# RUN: llvm-objdump -p %t.ppc64 | FileCheck %s --check-prefix=PPC64 + +# PPC64: Dynamic Section: +# PPC64-NEXT: HASH 0x0000000000001000 +# PPC64-NEXT: PPC64_GLINK 0x0000000000001000 +# PPC64-NEXT: 0x1234abcd 0x0000000000000001 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: test/tools/obj2yaml/dynamic-section-arch-tags.test =================================================================== --- test/tools/obj2yaml/dynamic-section-arch-tags.test +++ test/tools/obj2yaml/dynamic-section-arch-tags.test @@ -229,9 +229,33 @@ - Tag: DT_HEXAGON_PLT Value: 0x0000000000000003 -## Check we can handle PPC64 specific tags. +## Check we can handle PPC specific tags. # RUN: yaml2obj -docnum=3 %s -o %t3 -# RUN: obj2yaml %t3 | FileCheck %s --check-prefix=EM_PPC64 +# RUN: obj2yaml %t3 | FileCheck %s --check-prefix=EM_PPC + +# EM_PPC: - Tag: DT_PPC_GOT +# EM_PPC-NEXT: Value: 0x0000000000020000 +# EM_PPC-NEXT: - Tag: DT_PPC_OPT +# EM_PPC-NEXT: Value: 0x0000000000000001 + +--- !ELF +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2MSB + Type: ET_REL + Machine: EM_PPC +Sections: + - Name: .dynamic + Type: SHT_DYNAMIC + Entries: + - Tag: DT_PPC_GOT + Value: 0x0000000000020000 + - Tag: DT_PPC_OPT + Value: 0x0000000000000001 + +## Check we can handle PPC64 specific tags. +# RUN: yaml2obj -docnum=4 %s -o %t4 +# RUN: obj2yaml %t4 | FileCheck %s --check-prefix=EM_PPC64 # EM_PPC64: - Tag: DT_PPC64_GLINK # EM_PPC64-NEXT: Value: 0x0000000000000001 @@ -254,7 +278,7 @@ ## Here for EM_PPC64 we are trying to use DT_HEXAGON_SYMSZ ## instead of DT_PPC64_GLINK. They both have value of 0x70000000. -# RUN: not yaml2obj -docnum=4 %s 2>&1 | FileCheck %s --check-prefix=ERR +# RUN: not yaml2obj -docnum=5 %s 2>&1 | FileCheck %s --check-prefix=ERR # ERR: error: invalid hex64 number # ERR-NEXT: - Tag: DT_HEXAGON_SYMSZ 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;