[PATCH] D39140: LLD/ELF/AMDGPU: Process AMDGPU-specific e_flags

Konstantin Zhuravlyov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 20 13:20:23 PDT 2017


kzhuravl created this revision.
Herald added subscribers: tpr, dstuttard, yaxunl, nhaehnle, wdng, emaste.

https://reviews.llvm.org/D39140

Files:
  ELF/Arch/AMDGPU.cpp
  test/ELF/Inputs/amdgpu-kernel-0.s
  test/ELF/Inputs/amdgpu-kernel-1.s
  test/ELF/Inputs/amdgpu-kernel-2.o
  test/ELF/amdgpu-elf-flags-err.s
  test/ELF/amdgpu-elf-flags.s


Index: test/ELF/amdgpu-elf-flags.s
===================================================================
--- /dev/null
+++ test/ELF/amdgpu-elf-flags.s
@@ -0,0 +1,10 @@
+# RUN: llvm-mc -triple amdgcn-amd-amdhsa -mcpu=gfx803 -filetype=obj %S/Inputs/amdgpu-kernel-0.s -o %t-0.o
+# RUN: llvm-mc -triple amdgcn-amd-amdhsa -mcpu=gfx803 -filetype=obj %S/Inputs/amdgpu-kernel-1.s -o %t-1.o
+# RUN: ld.lld -shared %t-0.o %t-1.o -o %t.so
+# RUN: llvm-readobj -file-headers %t.so | FileCheck %s
+
+# REQUIRES: amdgpu
+
+# CHECK: Flags [ (0x2)
+# CHECK:   EF_AMDGPU_ARCH_GCN (0x2)
+# CHECK: ]
Index: test/ELF/amdgpu-elf-flags-err.s
===================================================================
--- /dev/null
+++ test/ELF/amdgpu-elf-flags-err.s
@@ -0,0 +1,7 @@
+# RUN: llvm-mc -triple amdgcn-amd-amdhsa -mcpu=gfx803 -filetype=obj %S/Inputs/amdgpu-kernel-0.s -o %t-0.o
+# RUN: llvm-mc -triple amdgcn-amd-amdhsa -mcpu=gfx803 -filetype=obj %S/Inputs/amdgpu-kernel-1.s -o %t-1.o
+# RUN: not ld.lld -shared %t-0.o %t-1.o %S/Inputs/amdgpu-kernel-2.o -o %t.so 2>&1 | FileCheck %s
+
+# REQUIRES: amdgpu
+
+# CHECK: error: incompatible e_flags: {{.*}}amdgpu-kernel-2.o
Index: test/ELF/Inputs/amdgpu-kernel-1.s
===================================================================
--- /dev/null
+++ test/ELF/Inputs/amdgpu-kernel-1.s
@@ -0,0 +1,6 @@
+.text
+.globl kernel_1
+.align 64
+.amdgpu_hsa_kernel kernel_1
+kernel_1:
+  s_endpgm
Index: test/ELF/Inputs/amdgpu-kernel-0.s
===================================================================
--- /dev/null
+++ test/ELF/Inputs/amdgpu-kernel-0.s
@@ -0,0 +1,6 @@
+.text
+.globl kernel_0
+.align 64
+.amdgpu_hsa_kernel kernel_0
+kernel_0:
+  s_endpgm
Index: ELF/Arch/AMDGPU.cpp
===================================================================
--- ELF/Arch/AMDGPU.cpp
+++ ELF/Arch/AMDGPU.cpp
@@ -25,6 +25,7 @@
 class AMDGPU final : public TargetInfo {
 public:
   AMDGPU();
+  uint32_t calcEFlags() const override;
   void relocateOne(uint8_t *Loc, RelType Type, uint64_t Val) const override;
   RelExpr getRelExpr(RelType Type, const SymbolBody &S,
                      const uint8_t *Loc) const override;
@@ -37,6 +38,24 @@
   GotEntrySize = 8;
 }
 
+uint32_t AMDGPU::calcEFlags() const {
+  if (ObjectFiles.empty())
+    return 0;
+
+  uint32_t FirstEFlags =
+    cast<ObjFile<ELF64LE>>(ObjectFiles.front())->getObj().getHeader()->e_flags;
+  for (const auto &F : ObjectFiles) {
+    uint32_t CurrentEFlags =
+      cast<ObjFile<ELF64LE>>(F)->getObj().getHeader()->e_flags;
+    if (FirstEFlags != CurrentEFlags) {
+      error("incompatible e_flags: " + F->getName());
+      return 0;
+    }
+  }
+
+  return FirstEFlags;
+}
+
 void AMDGPU::relocateOne(uint8_t *Loc, RelType Type, uint64_t Val) const {
   switch (Type) {
   case R_AMDGPU_ABS32:


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D39140.119699.patch
Type: text/x-patch
Size: 2782 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171020/3e691c55/attachment.bin>


More information about the llvm-commits mailing list