Index: llvm/trunk/lib/Target/AMDGPU/MCTargetDesc/AMDGPUAsmBackend.cpp =================================================================== --- llvm/trunk/lib/Target/AMDGPU/MCTargetDesc/AMDGPUAsmBackend.cpp +++ llvm/trunk/lib/Target/AMDGPU/MCTargetDesc/AMDGPUAsmBackend.cpp @@ -11,6 +11,7 @@ #include "MCTargetDesc/AMDGPUFixupKinds.h" #include "MCTargetDesc/AMDGPUMCTargetDesc.h" #include "llvm/ADT/StringRef.h" +#include "llvm/BinaryFormat/ELF.h" #include "llvm/MC/MCAsmBackend.h" #include "llvm/MC/MCAssembler.h" #include "llvm/MC/MCContext.h" @@ -167,14 +168,29 @@ class ELFAMDGPUAsmBackend : public AMDGPUAsmBackend { bool Is64Bit; bool HasRelocationAddend; + uint8_t OSABI = ELF::ELFOSABI_NONE; public: ELFAMDGPUAsmBackend(const Target &T, const Triple &TT) : AMDGPUAsmBackend(T), Is64Bit(TT.getArch() == Triple::amdgcn), - HasRelocationAddend(TT.getOS() == Triple::AMDHSA) { } + HasRelocationAddend(TT.getOS() == Triple::AMDHSA) { + switch (TT.getOS()) { + case Triple::AMDHSA: + OSABI = ELF::ELFOSABI_AMDGPU_HSA; + break; + case Triple::AMDPAL: + OSABI = ELF::ELFOSABI_AMDGPU_PAL; + break; + case Triple::Mesa3D: + OSABI = ELF::ELFOSABI_AMDGPU_MESA3D; + break; + default: + break; + } + } MCObjectWriter *createObjectWriter(raw_pwrite_stream &OS) const override { - return createAMDGPUELFObjectWriter(Is64Bit, HasRelocationAddend, OS); + return createAMDGPUELFObjectWriter(Is64Bit, OSABI, HasRelocationAddend, OS); } }; Index: llvm/trunk/lib/Target/AMDGPU/MCTargetDesc/AMDGPUELFObjectWriter.cpp =================================================================== --- llvm/trunk/lib/Target/AMDGPU/MCTargetDesc/AMDGPUELFObjectWriter.cpp +++ llvm/trunk/lib/Target/AMDGPU/MCTargetDesc/AMDGPUELFObjectWriter.cpp @@ -22,7 +22,7 @@ class AMDGPUELFObjectWriter : public MCELFObjectTargetWriter { public: - AMDGPUELFObjectWriter(bool Is64Bit, bool HasRelocationAddend); + AMDGPUELFObjectWriter(bool Is64Bit, uint8_t OSABI, bool HasRelocationAddend); protected: unsigned getRelocType(MCContext &Ctx, const MCValue &Target, @@ -33,10 +33,9 @@ } // end anonymous namespace AMDGPUELFObjectWriter::AMDGPUELFObjectWriter(bool Is64Bit, + uint8_t OSABI, bool HasRelocationAddend) - : MCELFObjectTargetWriter(Is64Bit, - ELF::ELFOSABI_AMDGPU_HSA, - ELF::EM_AMDGPU, + : MCELFObjectTargetWriter(Is64Bit, OSABI, ELF::EM_AMDGPU, HasRelocationAddend) {} unsigned AMDGPUELFObjectWriter::getRelocType(MCContext &Ctx, @@ -83,9 +82,10 @@ } MCObjectWriter *llvm::createAMDGPUELFObjectWriter(bool Is64Bit, + uint8_t OSABI, bool HasRelocationAddend, raw_pwrite_stream &OS) { MCELFObjectTargetWriter *MOTW = - new AMDGPUELFObjectWriter(Is64Bit, HasRelocationAddend); + new AMDGPUELFObjectWriter(Is64Bit, OSABI, HasRelocationAddend); return createELFObjectWriter(MOTW, OS, true); } Index: llvm/trunk/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCTargetDesc.h =================================================================== --- llvm/trunk/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCTargetDesc.h +++ llvm/trunk/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCTargetDesc.h @@ -48,6 +48,7 @@ const MCTargetOptions &Options); MCObjectWriter *createAMDGPUELFObjectWriter(bool Is64Bit, + uint8_t OSABI, bool HasRelocationAddend, raw_pwrite_stream &OS); } // End llvm namespace Index: llvm/trunk/test/CodeGen/AMDGPU/elf-header.ll =================================================================== --- llvm/trunk/test/CodeGen/AMDGPU/elf-header.ll +++ llvm/trunk/test/CodeGen/AMDGPU/elf-header.ll @@ -0,0 +1,43 @@ +; RUN: llc -march=r600 -filetype=obj < %s | llvm-readobj -file-headers - | FileCheck --check-prefix=R600 --check-prefix=R600-OSABI-NONE %s +; RUN: llc -mtriple=r600-- -filetype=obj < %s | llvm-readobj -file-headers - | FileCheck --check-prefix=R600 --check-prefix=R600-OSABI-NONE %s +; RUN: llc -mtriple=r600-amd- -filetype=obj < %s | llvm-readobj -file-headers - | FileCheck --check-prefix=R600 --check-prefix=R600-OSABI-NONE %s +; RUN: llc -mtriple=r600-amd-unknown -filetype=obj < %s | llvm-readobj -file-headers - | FileCheck --check-prefix=R600 --check-prefix=R600-OSABI-NONE %s +; RUN: llc -mtriple=r600-unknown-unknown -filetype=obj < %s | llvm-readobj -file-headers - | FileCheck --check-prefix=R600 --check-prefix=R600-OSABI-NONE %s + +; RUN: llc -march=amdgcn -filetype=obj < %s | llvm-readobj -file-headers - | FileCheck --check-prefix=GCN --check-prefix=GCN-OSABI-NONE %s +; RUN: llc -mtriple=amdgcn-- -filetype=obj < %s | llvm-readobj -file-headers - | FileCheck --check-prefix=GCN --check-prefix=GCN-OSABI-NONE %s +; RUN: llc -mtriple=amdgcn-amd- -filetype=obj < %s | llvm-readobj -file-headers - | FileCheck --check-prefix=GCN --check-prefix=GCN-OSABI-NONE %s +; RUN: llc -mtriple=amdgcn-amd-unknown -filetype=obj < %s | llvm-readobj -file-headers - | FileCheck --check-prefix=GCN --check-prefix=GCN-OSABI-NONE %s +; RUN: llc -mtriple=amdgcn-unknown-unknown -filetype=obj < %s | llvm-readobj -file-headers - | FileCheck --check-prefix=GCN --check-prefix=GCN-OSABI-NONE %s + +; RUN: llc -mtriple=amdgcn--amdhsa -filetype=obj < %s | llvm-readobj -file-headers - | FileCheck --check-prefix=GCN --check-prefix=GCN-OSABI-HSA %s +; RUN: llc -mtriple=amdgcn-amd-amdhsa -filetype=obj < %s | llvm-readobj -file-headers - | FileCheck --check-prefix=GCN --check-prefix=GCN-OSABI-HSA %s +; RUN: llc -mtriple=amdgcn-unknown-amdhsa -filetype=obj < %s | llvm-readobj -file-headers - | FileCheck --check-prefix=GCN --check-prefix=GCN-OSABI-HSA %s + +; RUN: llc -mtriple=amdgcn--amdpal -filetype=obj < %s | llvm-readobj -file-headers - | FileCheck --check-prefix=GCN --check-prefix=GCN-OSABI-PAL %s +; RUN: llc -mtriple=amdgcn-amd-amdpal -filetype=obj < %s | llvm-readobj -file-headers - | FileCheck --check-prefix=GCN --check-prefix=GCN-OSABI-PAL %s +; RUN: llc -mtriple=amdgcn-unknown-amdpal -filetype=obj < %s | llvm-readobj -file-headers - | FileCheck --check-prefix=GCN --check-prefix=GCN-OSABI-PAL %s + +; RUN: llc -mtriple=amdgcn--mesa3d -filetype=obj < %s | llvm-readobj -file-headers - | FileCheck --check-prefix=GCN --check-prefix=GCN-OSABI-MESA3D %s +; RUN: llc -mtriple=amdgcn-amd-mesa3d -filetype=obj < %s | llvm-readobj -file-headers - | FileCheck --check-prefix=GCN --check-prefix=GCN-OSABI-MESA3D %s +; RUN: llc -mtriple=amdgcn-unknown-mesa3d -filetype=obj < %s | llvm-readobj -file-headers - | FileCheck --check-prefix=GCN --check-prefix=GCN-OSABI-MESA3D %s + +; R600: Format: ELF32-amdgpu +; R600: Arch: unknown +; R600: AddressSize: 32bit +; GCN: Format: ELF64-amdgpu +; GCN: Arch: amdgcn +; GCN: AddressSize: 64bit + +; R600-OSABI-NONE: OS/ABI: SystemV (0x0) +; GCN-OSABI-NONE: OS/ABI: SystemV (0x0) +; GCN-OSABI-HSA: OS/ABI: AMDGPU_HSA (0x40) +; GCN-OSABI-PAL: OS/ABI: AMDGPU_PAL (0x41) +; GCN-OSABI-MESA3D: OS/ABI: AMDGPU_MESA3D (0x42) + +; R600: Machine: EM_AMDGPU (0xE0) +; GCN: Machine: EM_AMDGPU (0xE0) + +define amdgpu_kernel void @elf_header() { + ret void +} \ No newline at end of file Index: llvm/trunk/test/CodeGen/AMDGPU/elf.ll =================================================================== --- llvm/trunk/test/CodeGen/AMDGPU/elf.ll +++ llvm/trunk/test/CodeGen/AMDGPU/elf.ll @@ -8,8 +8,8 @@ ; Test that we don't try to produce a COFF file on windows ; 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: Format: ELF64-amdgpu +; ELF: OS/ABI: SystemV (0x0) ; ELF: Machine: EM_AMDGPU (0xE0) ; ELF: Name: .AMDGPU.config ; ELF: Type: SHT_PROGBITS Index: llvm/trunk/test/CodeGen/AMDGPU/elf.r600.ll =================================================================== --- llvm/trunk/test/CodeGen/AMDGPU/elf.r600.ll +++ llvm/trunk/test/CodeGen/AMDGPU/elf.r600.ll @@ -1,7 +1,7 @@ ; RUN: llc < %s -march=r600 -mcpu=redwood -filetype=obj | llvm-readobj -s - | FileCheck --check-prefix=ELF %s ; RUN: llc < %s -march=r600 -mcpu=redwood -o - | FileCheck --check-prefix=CONFIG %s -; ELF: Format: ELF32 +; ELF: Format: ELF32-amdgpu ; ELF: Name: .AMDGPU.config ; CONFIG: .section .AMDGPU.config