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>(ObjectFiles.front())->getObj().getHeader()->e_flags; + for (const auto &F : ObjectFiles) { + uint32_t CurrentEFlags = + cast>(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: 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: 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/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/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: ]