[llvm] r244303 - ELF: Add AMDGPU specific defintions

Tom Stellard via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 6 18:35:24 PDT 2015


Author: tstellar
Date: Thu Aug  6 20:35:24 2015
New Revision: 244303

URL: http://llvm.org/viewvc/llvm-project?rev=244303&view=rev
Log:
ELF: Add AMDGPU specific defintions

Reviewers: rafael

Subscribers: llvm-commits

Differential Revision: http://reviews.llvm.org/D11458

Added:
    llvm/trunk/test/tools/llvm-readobj/Inputs/trivial.elf-amdhsa-kaveri   (with props)
    llvm/trunk/test/tools/llvm-readobj/amdgpu-elf-defs.test
Modified:
    llvm/trunk/include/llvm/Support/ELF.h
    llvm/trunk/tools/llvm-readobj/ELFDumper.cpp

Modified: llvm/trunk/include/llvm/Support/ELF.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/ELF.h?rev=244303&r1=244302&r2=244303&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/ELF.h (original)
+++ llvm/trunk/include/llvm/Support/ELF.h Thu Aug  6 20:35:24 2015
@@ -747,7 +747,12 @@ enum : unsigned {
   SHF_MIPS_ADDR    = 0x40000000,
 
   // Section data is string data by default.
-  SHF_MIPS_STRING  = 0x80000000
+  SHF_MIPS_STRING  = 0x80000000,
+
+  SHF_AMDGPU_HSA_GLOBAL   = 0x00100000,
+  SHF_AMDGPU_HSA_READONLY = 0x00200000,
+  SHF_AMDGPU_HSA_CODE     = 0x00400000,
+  SHF_AMDGPU_HSA_AGENT    = 0x00800000
 };
 
 // Section Group Flags
@@ -828,7 +833,12 @@ enum {
   STT_LOOS    = 10,  // Lowest operating system-specific symbol type
   STT_HIOS    = 12,  // Highest operating system-specific symbol type
   STT_LOPROC  = 13,  // Lowest processor-specific symbol type
-  STT_HIPROC  = 15   // Highest processor-specific symbol type
+  STT_HIPROC  = 15,  // Highest processor-specific symbol type
+
+  // AMDGPU symbol types
+  STT_AMDGPU_HSA_KERNEL            = 10,
+  STT_AMDGPU_HSA_INDIRECT_FUNCTION = 11,
+  STT_AMDGPU_HSA_METADATA          = 12
 };
 
 enum {
@@ -979,7 +989,13 @@ enum {
   PT_MIPS_REGINFO  = 0x70000000,  // Register usage information.
   PT_MIPS_RTPROC   = 0x70000001,  // Runtime procedure table.
   PT_MIPS_OPTIONS  = 0x70000002,  // Options segment.
-  PT_MIPS_ABIFLAGS = 0x70000003   // Abiflags segment.
+  PT_MIPS_ABIFLAGS = 0x70000003,  // Abiflags segment.
+
+  // AMDGPU program header types.
+  PT_AMDGPU_HSA_LOAD_GLOBAL_PROGRAM = 0x60000000,
+  PT_AMDGPU_HSA_LOAD_GLOBAL_AGENT   = 0x60000001,
+  PT_AMDGPU_HSA_LOAD_READONLY_AGENT = 0x60000002,
+  PT_AMDGPU_HSA_LOAD_CODE_AGENT     = 0x60000003
 };
 
 // Segment flag bits.

Added: llvm/trunk/test/tools/llvm-readobj/Inputs/trivial.elf-amdhsa-kaveri
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-readobj/Inputs/trivial.elf-amdhsa-kaveri?rev=244303&view=auto
==============================================================================
Binary files llvm/trunk/test/tools/llvm-readobj/Inputs/trivial.elf-amdhsa-kaveri (added) and llvm/trunk/test/tools/llvm-readobj/Inputs/trivial.elf-amdhsa-kaveri Thu Aug  6 20:35:24 2015 differ

Propchange: llvm/trunk/test/tools/llvm-readobj/Inputs/trivial.elf-amdhsa-kaveri
------------------------------------------------------------------------------
    svn:executable = *

Added: llvm/trunk/test/tools/llvm-readobj/amdgpu-elf-defs.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-readobj/amdgpu-elf-defs.test?rev=244303&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-readobj/amdgpu-elf-defs.test (added)
+++ llvm/trunk/test/tools/llvm-readobj/amdgpu-elf-defs.test Thu Aug  6 20:35:24 2015
@@ -0,0 +1,28 @@
+RUN: llvm-readobj  -program-headers -sections -symbols -file-headers \
+RUN: %p/Inputs/trivial.elf-amdhsa-kaveri | FileCheck %s
+
+CHECK: ElfHeader {
+CHECK:  Ident {
+CHECK: Class: 64-bit (0x2)
+CHECK: DataEncoding: LittleEndian (0x1)
+CHECK: Machine: EM_AMDGPU (0xE0)
+
+
+CHECK: Section {
+CHECK: Name: .text
+CHECK: Type: SHT_PROGBITS (0x1)
+CHECK: Flags [ (0xC00007
+CHECK: SHF_ALLOC (0x2)
+CHECK: SHF_AMDGPU_HSA_AGENT (0x800000)
+CHECK: SHF_AMDGPU_HSA_CODE (0x400000)
+CHECK: SHF_EXECINSTR (0x4)
+CHECK: SHF_WRITE (0x1)
+
+CHECK: Symbol {
+CHECK: Name: hello_world
+CHECK: Value: 0x0
+CHECK: Binding: Local (0x0)
+CHECK: Type: AMDGPU_HSA_KERNEL (0xA)
+
+CHECK: ProgramHeader {
+CHECK: Type: PT_AMDGPU_HSA_LOAD_CODE_AGENT (0x60000003)

Modified: llvm/trunk/tools/llvm-readobj/ELFDumper.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/ELFDumper.cpp?rev=244303&r1=244302&r2=244303&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/ELFDumper.cpp (original)
+++ llvm/trunk/tools/llvm-readobj/ELFDumper.cpp Thu Aug  6 20:35:24 2015
@@ -618,6 +618,12 @@ static const EnumEntry<unsigned> ElfSymb
   { "GNU_IFunc", ELF::STT_GNU_IFUNC }
 };
 
+static const EnumEntry<unsigned> AMDGPUSymbolTypes[] = {
+  { "AMDGPU_HSA_KERNEL",            ELF::STT_AMDGPU_HSA_KERNEL },
+  { "AMDGPU_HSA_INDIRECT_FUNCTION", ELF::STT_AMDGPU_HSA_INDIRECT_FUNCTION },
+  { "AMDGPU_HSA_METADATA",          ELF::STT_AMDGPU_HSA_METADATA }
+};
+
 static const char *getElfSectionType(unsigned Arch, unsigned Type) {
   switch (Arch) {
   case ELF::EM_ARM:
@@ -682,13 +688,24 @@ static const EnumEntry<unsigned> ElfSect
   LLVM_READOBJ_ENUM_ENT(ELF, SHF_TLS             ),
   LLVM_READOBJ_ENUM_ENT(ELF, XCORE_SHF_CP_SECTION),
   LLVM_READOBJ_ENUM_ENT(ELF, XCORE_SHF_DP_SECTION),
-  LLVM_READOBJ_ENUM_ENT(ELF, SHF_MIPS_NOSTRIP    )
+  LLVM_READOBJ_ENUM_ENT(ELF, SHF_MIPS_NOSTRIP    ),
+  LLVM_READOBJ_ENUM_ENT(ELF, SHF_AMDGPU_HSA_GLOBAL),
+  LLVM_READOBJ_ENUM_ENT(ELF, SHF_AMDGPU_HSA_READONLY),
+  LLVM_READOBJ_ENUM_ENT(ELF, SHF_AMDGPU_HSA_CODE),
+  LLVM_READOBJ_ENUM_ENT(ELF, SHF_AMDGPU_HSA_AGENT)
 };
 
 static const char *getElfSegmentType(unsigned Arch, unsigned Type) {
   // Check potentially overlapped processor-specific
   // program header type.
   switch (Arch) {
+  case ELF::EM_AMDGPU:
+    switch (Type) {
+    LLVM_READOBJ_ENUM_CASE(ELF, PT_AMDGPU_HSA_LOAD_GLOBAL_PROGRAM);
+    LLVM_READOBJ_ENUM_CASE(ELF, PT_AMDGPU_HSA_LOAD_GLOBAL_AGENT);
+    LLVM_READOBJ_ENUM_CASE(ELF, PT_AMDGPU_HSA_LOAD_READONLY_AGENT);
+    LLVM_READOBJ_ENUM_CASE(ELF, PT_AMDGPU_HSA_LOAD_CODE_AGENT);
+    }
   case ELF::EM_ARM:
     switch (Type) {
     LLVM_READOBJ_ENUM_CASE(ELF, PT_ARM_EXIDX);
@@ -1139,6 +1156,7 @@ void ELFDumper<ELFT>::printSymbol(const
   StringRef SectionName;
   getSectionNameIndex(*Obj, Symbol, SectionName, SectionIndex);
   std::string FullSymbolName = getFullSymbolName(Symbol, StrTable, IsDynamic);
+  unsigned char SymbolType = Symbol->getType();
 
   DictScope D(W, "Symbol");
   W.printNumber("Name", FullSymbolName, Symbol->st_name);
@@ -1146,7 +1164,11 @@ void ELFDumper<ELFT>::printSymbol(const
   W.printNumber("Size", Symbol->st_size);
   W.printEnum  ("Binding", Symbol->getBinding(),
                   makeArrayRef(ElfSymbolBindings));
-  W.printEnum  ("Type", Symbol->getType(), makeArrayRef(ElfSymbolTypes));
+  if (Obj->getHeader()->e_machine == ELF::EM_AMDGPU &&
+      SymbolType >= ELF::STT_LOOS && SymbolType < ELF::STT_HIOS)
+    W.printEnum  ("Type", SymbolType, makeArrayRef(AMDGPUSymbolTypes));
+  else
+    W.printEnum  ("Type", SymbolType, makeArrayRef(ElfSymbolTypes));
   W.printNumber("Other", Symbol->st_other);
   W.printHex("Section", SectionName, SectionIndex);
 }




More information about the llvm-commits mailing list