[AMDGPU] add AMDGPU target support to ELFObjectFile.h header
authorValery Pykhtin <Valery.Pykhtin@amd.com>
Wed, 9 Mar 2016 17:08:19 +0000 (17:08 +0000)
committerValery Pykhtin <Valery.Pykhtin@amd.com>
Wed, 9 Mar 2016 17:08:19 +0000 (17:08 +0000)
Differential Revision: http://reviews.llvm.org/D17144

llvm-svn: 263026

llvm/include/llvm/Object/ELFObjectFile.h
llvm/lib/ObjectYAML/ELFYAML.cpp
llvm/test/Object/AMDGPU/elf-definitios.yaml
llvm/test/Object/AMDGPU/elf32-unknown.yaml [new file with mode: 0644]
llvm/test/Object/AMDGPU/elf64-unknown.yaml [new file with mode: 0644]

index d927aac..b01fa1d 100644 (file)
@@ -846,6 +846,8 @@ StringRef ELFObjectFile<ELFT>::getFileFormatName() const {
       return "ELF32-sparc";
     case ELF::EM_WEBASSEMBLY:
       return "ELF32-wasm";
+    case ELF::EM_AMDGPU:
+      return "ELF32-amdgpu";
     default:
       return "ELF32-unknown";
     }
@@ -867,6 +869,10 @@ StringRef ELFObjectFile<ELFT>::getFileFormatName() const {
       return "ELF64-mips";
     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";
     default:
       return "ELF64-unknown";
     }
@@ -923,6 +929,12 @@ unsigned ELFObjectFile<ELFT>::getArch() const {
     default: return Triple::UnknownArch;
     }
 
+  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;
+
   default:
     return Triple::UnknownArch;
   }
index 06db57a..3b94fa6 100644 (file)
@@ -239,6 +239,7 @@ void ScalarEnumerationTraits<ELFYAML::ELF_ELFOSABI>::enumeration(
   ECase(ELFOSABI_FENIXOS)
   ECase(ELFOSABI_CLOUDABI)
   ECase(ELFOSABI_C6000_ELFABI)
+  ECase(ELFOSABI_AMDGPU_HSA)
   ECase(ELFOSABI_C6000_LINUX)
   ECase(ELFOSABI_ARM)
   ECase(ELFOSABI_STANDALONE)
index 5f5e200..6d53509 100644 (file)
@@ -1,6 +1,8 @@
 # RUN: yaml2obj -format=elf %s > %t.o
 # RUN: llvm-readobj -s -file-headers %t.o | FileCheck %s
 
+# CHECK: Format: ELF64-amdgpu-hsacobj
+# CHECK: Arch: amdgcn
 # CHECK:  Machine: EM_AMDGPU (0xE0)
 # CHECK: Sections [
 # CHECK: Section {
@@ -18,6 +20,7 @@ FileHeader:
   Data:    ELFDATA2LSB
   Type:    ET_REL
   Machine: EM_AMDGPU
+  OSABI:   ELFOSABI_AMDGPU_HSA
 
 Sections:
   - Name:  .shf_amdgpu
diff --git a/llvm/test/Object/AMDGPU/elf32-unknown.yaml b/llvm/test/Object/AMDGPU/elf32-unknown.yaml
new file mode 100644 (file)
index 0000000..708db8d
--- /dev/null
@@ -0,0 +1,11 @@
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: llvm-readobj -s -file-headers %t.o | FileCheck %s
+
+# CHECK: Format: ELF32-amdgpu
+
+---
+FileHeader:
+  Class:   ELFCLASS32
+  Data:    ELFDATA2LSB
+  Type:    ET_REL
+  Machine: EM_AMDGPU
diff --git a/llvm/test/Object/AMDGPU/elf64-unknown.yaml b/llvm/test/Object/AMDGPU/elf64-unknown.yaml
new file mode 100644 (file)
index 0000000..cae2488
--- /dev/null
@@ -0,0 +1,11 @@
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: llvm-readobj -s -file-headers %t.o | FileCheck %s
+
+# CHECK: Format: ELF64-amdgpu
+
+---
+FileHeader:
+  Class:   ELFCLASS64
+  Data:    ELFDATA2LSB
+  Type:    ET_REL
+  Machine: EM_AMDGPU