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

Konstantin Zhuravlyov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 24 10:28:52 PDT 2017


kzhuravl updated this revision to Diff 120096.
kzhuravl marked 3 inline comments as done.
kzhuravl added a comment.

Address review feedback.


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
===================================================================
--- test/ELF/amdgpu-elf-flags.s
+++ 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
===================================================================
--- test/ELF/amdgpu-elf-flags-err.s
+++ 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
===================================================================
--- test/ELF/Inputs/amdgpu-kernel-1.s
+++ 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
===================================================================
--- test/ELF/Inputs/amdgpu-kernel-0.s
+++ 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 Ret =
+    cast<ObjFile<ELF64LE>>(ObjectFiles.front())->getObj().getHeader()->e_flags;
+
+  // Verify that all input files have the same e_flags.
+  for (InputFile *F : ArrayRef<InputFile*>(ObjectFiles).slice(1)) {
+    if (Ret != cast<ObjFile<ELF64LE>>(F)->getObj().getHeader()->e_flags) {
+      error("incompatible e_flags: " + F->getName());
+      return 0;
+    }
+  }
+
+  return Ret;
+}
+
 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.120096.patch
Type: text/x-patch
Size: 2883 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171024/1e978e0f/attachment.bin>


More information about the llvm-commits mailing list