From faac72340641d3886453f186d204d28241bdf8db Mon Sep 17 00:00:00 2001 From: Konstantin Zhuravlyov Date: Tue, 3 Oct 2017 20:54:07 +0000 Subject: [PATCH] AMDGPU: Add ELFOSABI_AMDGPU_PAL llvm-svn: 314843 --- docs/AMDGPUUsage.rst | 38 +++++++++++++------ include/llvm/BinaryFormat/ELF.h | 3 +- include/llvm/Object/ELFObjectFile.h | 15 ++++---- lib/ObjectYAML/ELFYAML.cpp | 5 ++- ...l => elf64-amdgcn-amdhsa-definitions.yaml} | 2 +- .../elf64-amdgcn-amdpal-definitions.yaml | 21 ++++++++++ test/Object/AMDGPU/objdump.s | 2 +- .../llvm-readobj/amdgpu-elf-definitions.test | 2 +- tools/llvm-readobj/ELFDumper.cpp | 3 +- 9 files changed, 65 insertions(+), 26 deletions(-) rename test/Object/AMDGPU/{elf-definitions.yaml => elf64-amdgcn-amdhsa-definitions.yaml} (91%) create mode 100644 test/Object/AMDGPU/elf64-amdgcn-amdpal-definitions.yaml diff --git a/docs/AMDGPUUsage.rst b/docs/AMDGPUUsage.rst index 42131f8d1a8..2e9840905e2 100644 --- a/docs/AMDGPUUsage.rst +++ b/docs/AMDGPUUsage.rst @@ -359,18 +359,20 @@ The AMDGPU backend uses the following ELF header: .. table:: AMDGPU ELF Header :name: amdgpu-elf-header-table - ========================== ========================= + ========================== =============================== Field Value - ========================== ========================= + ========================== =============================== ``e_ident[EI_CLASS]`` ``ELFCLASS64`` ``e_ident[EI_DATA]`` ``ELFDATA2LSB`` - ``e_ident[EI_OSABI]`` ``ELFOSABI_AMDGPU_HSA`` - ``e_ident[EI_ABIVERSION]`` ``ELFABIVERSION_AMDGPU_HSA`` + ``e_ident[EI_OSABI]`` ``ELFOSABI_AMDGPU_HSA`` or + ``ELFOSABI_AMDGPU_PAL`` + ``e_ident[EI_ABIVERSION]`` ``ELFABIVERSION_AMDGPU_HSA`` or + ``ELFABIVERSION_AMDGPU_PAL`` ``e_type`` ``ET_REL`` or ``ET_DYN`` ``e_machine`` ``EM_AMDGPU`` ``e_entry`` 0 ``e_flags`` 0 - ========================== ========================= + ========================== =============================== .. @@ -382,24 +384,36 @@ The AMDGPU backend uses the following ELF header: ============================ ===== ``EM_AMDGPU`` 224 ``ELFOSABI_AMDGPU_HSA`` 64 + ``ELFOSABI_AMDGPU_PAL`` 65 ``ELFABIVERSION_AMDGPU_HSA`` 1 + ``ELFABIVERSION_AMDGPU_PAL`` 0 ============================ ===== ``e_ident[EI_CLASS]`` - The ELF class is always ``ELFCLASS64``. The AMDGPU backend only supports 64 bit - applications. + The ELF class is always ``ELFCLASS64``. The AMDGPU backend only supports 64 + bit applications. ``e_ident[EI_DATA]`` All AMDGPU targets use ELFDATA2LSB for little-endian byte ordering. ``e_ident[EI_OSABI]`` - The AMD GPU architecture specific OS ABI of ``ELFOSABI_AMDGPU_HSA`` is used to - specify that the code object conforms to the AMD HSA runtime ABI [HSA]_. + One of two AMD GPU architecture specific OS ABI: + + * ``ELFOSABI_AMDGPU_HSA`` is used to specify that the code object conforms to + the AMD HSA runtime ABI [HSA]_. + + * ``ELFOSABI_AMDGPU_PAL`` is used to specify that the code object conforms to + the AMD PAL runtime ABI. ``e_ident[EI_ABIVERSION]`` - The AMD GPU architecture specific OS ABI version of - ``ELFABIVERSION_AMDGPU_HSA`` is used to specify the version of AMD HSA runtime - ABI to which the code object conforms. + The ABI version of the AMD GPU architecture specific OS ABI to which the code + object conforms: + + * ``ELFABIVERSION_AMDGPU_HSA`` is used to specify the version of AMD HSA + runtime ABI. + + * ``ELFABIVERSION_AMDGPU_PAL`` is used to specify the version of AMD PAL + runtime ABI. ``e_type`` Can be one of the following values: diff --git a/include/llvm/BinaryFormat/ELF.h b/include/llvm/BinaryFormat/ELF.h index 47869c16eb4..f83946a48c2 100644 --- a/include/llvm/BinaryFormat/ELF.h +++ b/include/llvm/BinaryFormat/ELF.h @@ -355,9 +355,10 @@ enum { ELFOSABI_CLOUDABI = 17, // Nuxi CloudABI ELFOSABI_FIRST_ARCH = 64, // First architecture-specific OS ABI ELFOSABI_AMDGPU_HSA = 64, // AMD HSA runtime + ELFOSABI_AMDGPU_PAL = 65, // AMD PAL runtime + ELFOSABI_ARM = 97, // ARM ELFOSABI_C6000_ELFABI = 64, // Bare-metal TMS320C6000 ELFOSABI_C6000_LINUX = 65, // Linux TMS320C6000 - ELFOSABI_ARM = 97, // ARM ELFOSABI_STANDALONE = 255, // Standalone (embedded) application ELFOSABI_LAST_ARCH = 255 // Last Architecture-specific OS ABI }; diff --git a/include/llvm/Object/ELFObjectFile.h b/include/llvm/Object/ELFObjectFile.h index f436e4534ce..b4411ce984e 100644 --- a/include/llvm/Object/ELFObjectFile.h +++ b/include/llvm/Object/ELFObjectFile.h @@ -995,9 +995,7 @@ StringRef ELFObjectFile::getFileFormatName() const { case ELF::EM_WEBASSEMBLY: return "ELF64-wasm"; case ELF::EM_AMDGPU: - return (EF.getHeader()->e_ident[ELF::EI_OSABI] == ELF::ELFOSABI_AMDGPU_HSA - && IsLittleEndian) ? - "ELF64-amdgpu-hsacobj" : "ELF64-amdgpu"; + return "ELF64-amdgpu"; case ELF::EM_BPF: return "ELF64-BPF"; default: @@ -1066,10 +1064,13 @@ unsigned ELFObjectFile::getArch() const { } case ELF::EM_AMDGPU: - return (EF.getHeader()->e_ident[ELF::EI_CLASS] == ELF::ELFCLASS64 - && EF.getHeader()->e_ident[ELF::EI_OSABI] == ELF::ELFOSABI_AMDGPU_HSA - && IsLittleEndian) ? - Triple::amdgcn : Triple::UnknownArch; + if (EF.getHeader()->e_ident[ELF::EI_CLASS] != ELF::ELFCLASS64) + return Triple::UnknownArch; + if (!IsLittleEndian) + return Triple::UnknownArch; + + // TODO: Determine r600/amdgcn architecture based e_flags. + return Triple::amdgcn; case ELF::EM_BPF: return IsLittleEndian ? Triple::bpfel : Triple::bpfeb; diff --git a/lib/ObjectYAML/ELFYAML.cpp b/lib/ObjectYAML/ELFYAML.cpp index ccd9eebb8aa..21777c0f459 100644 --- a/lib/ObjectYAML/ELFYAML.cpp +++ b/lib/ObjectYAML/ELFYAML.cpp @@ -260,10 +260,11 @@ void ScalarEnumerationTraits::enumeration( ECase(ELFOSABI_AROS); ECase(ELFOSABI_FENIXOS); ECase(ELFOSABI_CLOUDABI); - ECase(ELFOSABI_C6000_ELFABI); ECase(ELFOSABI_AMDGPU_HSA); - ECase(ELFOSABI_C6000_LINUX); + ECase(ELFOSABI_AMDGPU_PAL); ECase(ELFOSABI_ARM); + ECase(ELFOSABI_C6000_ELFABI); + ECase(ELFOSABI_C6000_LINUX); ECase(ELFOSABI_STANDALONE); #undef ECase } diff --git a/test/Object/AMDGPU/elf-definitions.yaml b/test/Object/AMDGPU/elf64-amdgcn-amdhsa-definitions.yaml similarity index 91% rename from test/Object/AMDGPU/elf-definitions.yaml rename to test/Object/AMDGPU/elf64-amdgcn-amdhsa-definitions.yaml index 07fe8c62dc4..53639e00158 100644 --- a/test/Object/AMDGPU/elf-definitions.yaml +++ b/test/Object/AMDGPU/elf64-amdgcn-amdhsa-definitions.yaml @@ -1,7 +1,7 @@ # RUN: yaml2obj %s > %t.o # RUN: llvm-readobj -s -file-headers %t.o | FileCheck %s -# CHECK: Format: ELF64-amdgpu-hsacobj +# CHECK: Format: ELF64-amdgpu # CHECK: Arch: amdgcn # CHECK: ElfHeader { # CHECK: Ident { diff --git a/test/Object/AMDGPU/elf64-amdgcn-amdpal-definitions.yaml b/test/Object/AMDGPU/elf64-amdgcn-amdpal-definitions.yaml new file mode 100644 index 00000000000..8e39f6d32eb --- /dev/null +++ b/test/Object/AMDGPU/elf64-amdgcn-amdpal-definitions.yaml @@ -0,0 +1,21 @@ +# RUN: yaml2obj %s > %t.o +# RUN: llvm-readobj -s -file-headers %t.o | FileCheck %s + +# CHECK: Format: ELF64-amdgpu +# CHECK: Arch: amdgcn +# CHECK: ElfHeader { +# CHECK: Ident { +# CHECK: OS/ABI: AMDGPU_PAL (0x41) +# CHECK: ABIVersion: 0 +# CHECK: } +# CHECK: Machine: EM_AMDGPU (0xE0) +# CHECK: } + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_AMDGPU + OSABI: ELFOSABI_AMDGPU_PAL +... diff --git a/test/Object/AMDGPU/objdump.s b/test/Object/AMDGPU/objdump.s index 83f0df2e2e6..3cdf90be696 100644 --- a/test/Object/AMDGPU/objdump.s +++ b/test/Object/AMDGPU/objdump.s @@ -45,7 +45,7 @@ BB5: v_lshlrev_b32_e32 v7, 2, v7 s_endpgm -// CHECK: file format ELF64-amdgpu-hsacobj +// CHECK: file format ELF64-amdgpu // CHECK: Disassembly of section .text: // CHECK: hello_world: // CHECK: s_mov_b32 m0, 0x10000 // 000000000100: BEFC00FF 00010000 diff --git a/test/tools/llvm-readobj/amdgpu-elf-definitions.test b/test/tools/llvm-readobj/amdgpu-elf-definitions.test index c30931242df..e52f9879456 100644 --- a/test/tools/llvm-readobj/amdgpu-elf-definitions.test +++ b/test/tools/llvm-readobj/amdgpu-elf-definitions.test @@ -1,6 +1,6 @@ RUN: llvm-readobj -file-headers -program-headers -sections -symbols %p/Inputs/trivial.obj.elf-amdhsa-gfx803 | FileCheck %s -CHECK: Format: ELF64-amdgpu-hsacobj +CHECK: Format: ELF64-amdgpu CHECK: Arch: amdgcn CHECK: ElfHeader { CHECK: Ident { diff --git a/tools/llvm-readobj/ELFDumper.cpp b/tools/llvm-readobj/ELFDumper.cpp index dd32a8a2fbc..4ea0ed2f5ee 100644 --- a/tools/llvm-readobj/ELFDumper.cpp +++ b/tools/llvm-readobj/ELFDumper.cpp @@ -825,7 +825,8 @@ static const EnumEntry ElfOSABI[] = { }; static const EnumEntry AMDGPUElfOSABI[] = { - {"AMDGPU_HSA", "AMDGPU - HSA", ELF::ELFOSABI_AMDGPU_HSA} + {"AMDGPU_HSA", "AMDGPU - HSA", ELF::ELFOSABI_AMDGPU_HSA}, + {"AMDGPU_PAL", "AMDGPU - PAL", ELF::ELFOSABI_AMDGPU_PAL} }; static const EnumEntry ARMElfOSABI[] = {