Index: docs/AMDGPUUsage.rst =================================================================== --- docs/AMDGPUUsage.rst +++ docs/AMDGPUUsage.rst @@ -359,18 +359,20 @@ .. 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 @@ ============================ ===== ``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: Index: include/llvm/BinaryFormat/ELF.h =================================================================== --- include/llvm/BinaryFormat/ELF.h +++ include/llvm/BinaryFormat/ELF.h @@ -354,8 +354,9 @@ ELFOSABI_FENIXOS = 16, // FenixOS ELFOSABI_CLOUDABI = 17, // Nuxi CloudABI ELFOSABI_C6000_ELFABI = 64, // Bare-metal TMS320C6000 - ELFOSABI_AMDGPU_HSA = 64, // AMD HSA runtime ELFOSABI_C6000_LINUX = 65, // Linux TMS320C6000 + ELFOSABI_AMDGPU_HSA = 64, // AMD HSA runtime + ELFOSABI_AMDGPU_PAL = 65, // AMD PAL runtime ELFOSABI_ARM = 97, // ARM ELFOSABI_STANDALONE = 255 // Standalone (embedded) application }; Index: include/llvm/Object/ELFObjectFile.h =================================================================== --- include/llvm/Object/ELFObjectFile.h +++ include/llvm/Object/ELFObjectFile.h @@ -995,9 +995,7 @@ 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,16 @@ } 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; + switch (EF.getHeader()->e_ident[ELF::EI_CLASS]) { + case ELF::ELFCLASS32: + return Triple::UnknownArch; + case ELF::ELFCLASS64: + switch (EF.getHeader()->e_ident[ELF::EI_OSABI]) { + case ELF::ELFOSABI_AMDGPU_HSA: + case ELF::ELFOSABI_AMDGPU_PAL: + return Triple::amdgcn; + } + } case ELF::EM_BPF: return IsLittleEndian ? Triple::bpfel : Triple::bpfeb; Index: lib/ObjectYAML/ELFYAML.cpp =================================================================== --- lib/ObjectYAML/ELFYAML.cpp +++ lib/ObjectYAML/ELFYAML.cpp @@ -261,8 +261,9 @@ ECase(ELFOSABI_FENIXOS); ECase(ELFOSABI_CLOUDABI); ECase(ELFOSABI_C6000_ELFABI); - ECase(ELFOSABI_AMDGPU_HSA); ECase(ELFOSABI_C6000_LINUX); + ECase(ELFOSABI_AMDGPU_HSA); + ECase(ELFOSABI_AMDGPU_PAL); ECase(ELFOSABI_ARM); ECase(ELFOSABI_STANDALONE); #undef ECase Index: test/CodeGen/AMDGPU/elf.ll =================================================================== --- test/CodeGen/AMDGPU/elf.ll +++ test/CodeGen/AMDGPU/elf.ll @@ -9,7 +9,7 @@ ; RUN: llc < %s -mtriple=amdgcn-pc-mingw -verify-machineinstrs -filetype=obj | llvm-readobj -s -symbols -file-headers - | FileCheck --check-prefix=ELF %s ; ELF: Format: ELF64 -; ELF: OS/ABI: AMDGPU_HSA (0x40) +; ELF: OS/ABI: AMDHSA (0x40) ; ELF: Machine: EM_AMDGPU (0xE0) ; ELF: Name: .AMDGPU.config ; ELF: Type: SHT_PROGBITS Index: test/Object/AMDGPU/elf-definitions.yaml =================================================================== --- test/Object/AMDGPU/elf-definitions.yaml +++ /dev/null @@ -1,21 +0,0 @@ -# RUN: yaml2obj %s > %t.o -# RUN: llvm-readobj -s -file-headers %t.o | FileCheck %s - -# CHECK: Format: ELF64-amdgpu-hsacobj -# CHECK: Arch: amdgcn -# CHECK: ElfHeader { -# CHECK: Ident { -# CHECK: OS/ABI: AMDGPU_HSA (0x40) -# 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_HSA -... Index: test/Object/AMDGPU/elf64-amdgcn-amdhsa-definitions.yaml =================================================================== --- /dev/null +++ test/Object/AMDGPU/elf64-amdgcn-amdhsa-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: AMDHSA (0x40) +# 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_HSA +... Index: test/Object/AMDGPU/elf64-amdgcn-amdpal-definitions.yaml =================================================================== --- /dev/null +++ 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: AMDPAL (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 +... Index: test/Object/AMDGPU/objdump.s =================================================================== --- test/Object/AMDGPU/objdump.s +++ test/Object/AMDGPU/objdump.s @@ -45,7 +45,7 @@ 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 Index: test/tools/llvm-readobj/amdgpu-elf-definitions.test =================================================================== --- test/tools/llvm-readobj/amdgpu-elf-definitions.test +++ test/tools/llvm-readobj/amdgpu-elf-definitions.test @@ -1,10 +1,10 @@ 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 { -CHECK: OS/ABI: AMDGPU_HSA (0x40) +CHECK: OS/ABI: AMDHSA (0x40) CHECK: ABIVersion: 0 CHECK: } CHECK: Machine: EM_AMDGPU (0xE0) Index: tools/llvm-readobj/ELFDumper.cpp =================================================================== --- tools/llvm-readobj/ELFDumper.cpp +++ tools/llvm-readobj/ELFDumper.cpp @@ -827,6 +827,11 @@ {"Standalone", "Standalone App", ELF::ELFOSABI_STANDALONE} }; +static const EnumEntry AMDGPUElfOSABI[] = { + {"AMDHSA", "AMDGPU - HSA", ELF::ELFOSABI_AMDGPU_HSA}, + {"AMDPAL", "AMDGPU - PAL", ELF::ELFOSABI_AMDGPU_PAL} +}; + static const EnumEntry ElfMachineType[] = { ENUM_ENT(EM_NONE, "None"), ENUM_ENT(EM_M32, "WE32100"), @@ -3513,9 +3518,9 @@ W.printNumber("FileVersion", e->e_ident[ELF::EI_VERSION]); // Handle architecture specific OS/ABI values. - if (e->e_machine == ELF::EM_AMDGPU && - e->e_ident[ELF::EI_OSABI] == ELF::ELFOSABI_AMDGPU_HSA) - W.printHex("OS/ABI", "AMDGPU_HSA", ELF::ELFOSABI_AMDGPU_HSA); + if (e->e_machine == ELF::EM_AMDGPU) + W.printEnum("OS/ABI", e->e_ident[ELF::EI_OSABI], + makeArrayRef(AMDGPUElfOSABI)); else W.printEnum("OS/ABI", e->e_ident[ELF::EI_OSABI], makeArrayRef(ElfOSABI));