Index: include/llvm/BinaryFormat/DynamicTags.def =================================================================== --- include/llvm/BinaryFormat/DynamicTags.def +++ include/llvm/BinaryFormat/DynamicTags.def @@ -6,6 +6,11 @@ // such as DT_HIOS, etc. to allow using this file to in other contexts. // For example we can use it to generate a stringification switch statement. +#ifndef AARCH64_DYNAMIC_TAG +#define AARCH64_DYNAMIC_TAG(name, value) DYNAMIC_TAG(name, value) +#define AARCH64_DYNAMIC_TAG_DEFINED +#endif + #ifndef HEXAGON_DYNAMIC_TAG #define HEXAGON_DYNAMIC_TAG(name, value) DYNAMIC_TAG(name, value) #define HEXAGON_DYNAMIC_TAG_DEFINED @@ -107,6 +112,10 @@ // table. DYNAMIC_TAG(VERNEEDNUM, 0X6FFFFFFF) // The number of entries in DT_VERNEED. +// AArch64 specific dynamic table entries +AARCH64_DYNAMIC_TAG(AARCH64_BTI_PLT, 0x70000001) +AARCH64_DYNAMIC_TAG(AARCH64_PAC_PLT, 0x70000003) + // Hexagon specific dynamic table entries HEXAGON_DYNAMIC_TAG(HEXAGON_SYMSZ, 0x70000000) HEXAGON_DYNAMIC_TAG(HEXAGON_VER, 0x70000001) @@ -204,6 +213,10 @@ #undef DYNAMIC_TAG_MARKER #undef DYNAMIC_TAG_MARKER_DEFINED #endif +#ifdef AARCH64_DYNAMIC_TAG_DEFINED +#undef AARCH64_DYNAMIC_TAG +#undef AARCH64_DYNAMIC_TAG_DEFINED +#endif #ifdef MIPS_DYNAMIC_TAG_DEFINED #undef MIPS_DYNAMIC_TAG #undef MIPS_DYNAMIC_TAG_DEFINED Index: lib/Object/ELF.cpp =================================================================== --- lib/Object/ELF.cpp +++ lib/Object/ELF.cpp @@ -434,6 +434,14 @@ #define DYNAMIC_TAG(n, v) switch (Arch) { + case ELF::EM_AARCH64: + switch (Type) { +#define AARCH64_DYNAMIC_TAG(name, value) DYNAMIC_STRINGIFY_ENUM(name, value) +#include "llvm/BinaryFormat/DynamicTags.def" +#undef AARCH64_DYNAMIC_TAG + } + break; + case ELF::EM_HEXAGON: switch (Type) { #define HEXAGON_DYNAMIC_TAG(name, value) DYNAMIC_STRINGIFY_ENUM(name, value) @@ -461,6 +469,7 @@ #undef DYNAMIC_TAG switch (Type) { // Now handle all dynamic tags except the architecture specific ones +#define AARCH64_DYNAMIC_TAG(name, value) #define MIPS_DYNAMIC_TAG(name, value) #define HEXAGON_DYNAMIC_TAG(name, value) #define PPC64_DYNAMIC_TAG(name, value) @@ -469,6 +478,7 @@ #define DYNAMIC_TAG(name, value) DYNAMIC_STRINGIFY_ENUM(name, value) #include "llvm/BinaryFormat/DynamicTags.def" #undef DYNAMIC_TAG +#undef AARCH64_DYNAMIC_TAG #undef MIPS_DYNAMIC_TAG #undef HEXAGON_DYNAMIC_TAG #undef PPC64_DYNAMIC_TAG Index: lib/ObjectYAML/ELFYAML.cpp =================================================================== --- lib/ObjectYAML/ELFYAML.cpp +++ lib/ObjectYAML/ELFYAML.cpp @@ -680,6 +680,7 @@ assert(Object && "The IO context is not initialized"); // Disable architecture specific tags by default. We might enable them below. +#define AARCH64_DYNAMIC_TAG(name, value) #define MIPS_DYNAMIC_TAG(name, value) #define HEXAGON_DYNAMIC_TAG(name, value) #define PPC64_DYNAMIC_TAG(name, value) @@ -689,6 +690,13 @@ #define STRINGIFY(X) (#X) #define DYNAMIC_TAG(X, Y) IO.enumCase(Value, STRINGIFY(DT_##X), ELF::DT_##X); switch (Object->Header.Machine) { + case ELF::EM_AARCH64: +#undef AARCH64_DYNAMIC_TAG +#define AARCH64_DYNAMIC_TAG(name, value) DYNAMIC_TAG(name, value) +#include "llvm/BinaryFormat/DynamicTags.def" +#undef AARCH64_DYNAMIC_TAG +#define AARCH64_DYNAMIC_TAG(name, value) + break; case ELF::EM_MIPS: #undef MIPS_DYNAMIC_TAG #define MIPS_DYNAMIC_TAG(name, value) DYNAMIC_TAG(name, value) @@ -714,7 +722,7 @@ #include "llvm/BinaryFormat/DynamicTags.def" break; } - +#undef AARCH64_DYNAMIC_TAG #undef MIPS_DYNAMIC_TAG #undef HEXAGON_DYNAMIC_TAG #undef PPC64_DYNAMIC_TAG Index: test/tools/llvm-readobj/aarch64-bti-pac-dynamic.test =================================================================== --- /dev/null +++ test/tools/llvm-readobj/aarch64-bti-pac-dynamic.test @@ -0,0 +1,23 @@ +# Check DT_MIPS_OPTIONS .dynamic section tag reading + +RUN: llvm-readobj --dynamic-table %p/Inputs/bti-pac-plt.elf-aarch64 | \ +RUN: FileCheck %s + +CHECK: DynamicSection [ (15 entries) +CHECK-NEXT: Tag Type Name/Value +CHECK-NEXT: 0x0000000000000001 NEEDED Shared library: [shlib.so] +CHECK-NEXT: 0x0000000000000015 DEBUG 0x0 +CHECK-NEXT: 0x0000000000000017 JMPREL 0x200310 +CHECK-NEXT: 0x0000000000000002 PLTRELSZ 72 (bytes) +CHECK-NEXT: 0x0000000000000003 PLTGOT 0x230000 +CHECK-NEXT: 0x0000000000000014 PLTREL RELA +CHECK-NEXT: 0x0000000070000001 AARCH64_BTI_PLT 0 +CHECK-NEXT: 0x0000000070000003 AARCH64_PAC_PLT 0x0 +CHECK-NEXT: 0x0000000000000006 SYMTAB 0x200258 +CHECK-NEXT: 0x000000000000000B SYMENT 24 (bytes) +CHECK-NEXT: 0x0000000000000005 STRTAB 0x2002FC +CHECK-NEXT: 0x000000000000000A STRSZ 19 (bytes) +CHECK-NEXT: 0x000000006FFFFEF5 GNU_HASH 0x2002B8 +CHECK-NEXT: 0x0000000000000004 HASH 0x2002D4 +CHECK-NEXT: 0x0000000000000000 NULL 0x0 +CHECK-NEXT: ] 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 @@ -249,12 +249,36 @@ - Tag: DT_PPC64_GLINK Value: 0x0000000000000001 +## Check we can handle AARCH64 specific tags. +# RUN: yaml2obj -docnum=4 %s -o %t2 +# RUN: obj2yaml %t2 | FileCheck %s --check-prefix=AARCH64 + +# AARCH64: - Tag: DT_AARCH64_BTI_PLT +# AARCH64-NEXT: Value: 0x0000000000000000 +# AARCH64-NEXT: - Tag: DT_AARCH64_PAC_PLT +# AARCH64-NEXT: Value: 0x0000000000000000 + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_AARCH64 +Sections: + - Name: .dynamic + Type: SHT_DYNAMIC + Entries: + - Tag: DT_AARCH64_BTI_PLT + Value: 0x0000000000000000 + - Tag: DT_AARCH64_PAC_PLT + Value: 0x0000000000000000 + ## Check we can't use a tag from a different architecture, ## even if it has the same numeric value as a valid tag. ## 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 @@ -1463,6 +1463,17 @@ static const char *getTypeString(unsigned Arch, uint64_t Type) { #define DYNAMIC_TAG(n, v) switch (Arch) { + + case EM_AARCH64: + switch (Type) { +#define AARCH64_DYNAMIC_TAG(name, value) \ + case DT_##name: \ + return #name; +#include "llvm/BinaryFormat/DynamicTags.def" +#undef AARCH64_DYNAMIC_TAG + } + break; + case EM_HEXAGON: switch (Type) { #define HEXAGON_DYNAMIC_TAG(name, value) \ @@ -1496,6 +1507,7 @@ #undef DYNAMIC_TAG switch (Type) { // Now handle all dynamic tags except the architecture specific ones +#define AARCH64_DYNAMIC_TAG(name, value) #define MIPS_DYNAMIC_TAG(name, value) #define HEXAGON_DYNAMIC_TAG(name, value) #define PPC64_DYNAMIC_TAG(name, value) @@ -1506,6 +1518,7 @@ return #name; #include "llvm/BinaryFormat/DynamicTags.def" #undef DYNAMIC_TAG +#undef AARCH64_DYNAMIC_TAG #undef MIPS_DYNAMIC_TAG #undef HEXAGON_DYNAMIC_TAG #undef PPC64_DYNAMIC_TAG