Index: lld/trunk/ELF/Arch/AMDGPU.cpp =================================================================== --- lld/trunk/ELF/Arch/AMDGPU.cpp +++ lld/trunk/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>(ObjectFiles.front())->getObj().getHeader()->e_flags; + + // Verify that all input files have the same e_flags. + for (InputFile *F : ArrayRef(ObjectFiles).slice(1)) { + if (Ret != cast>(F)->getObj().getHeader()->e_flags) { + error("incompatible e_flags: " + toString(F)); + return 0; + } + } + + return Ret; +} + void AMDGPU::relocateOne(uint8_t *Loc, RelType Type, uint64_t Val) const { switch (Type) { case R_AMDGPU_ABS32: Index: lld/trunk/test/ELF/Inputs/amdgpu-kernel-0.s =================================================================== --- lld/trunk/test/ELF/Inputs/amdgpu-kernel-0.s +++ lld/trunk/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: lld/trunk/test/ELF/Inputs/amdgpu-kernel-1.s =================================================================== --- lld/trunk/test/ELF/Inputs/amdgpu-kernel-1.s +++ lld/trunk/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: lld/trunk/test/ELF/amdgpu-elf-flags-err.s =================================================================== --- lld/trunk/test/ELF/amdgpu-elf-flags-err.s +++ lld/trunk/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: lld/trunk/test/ELF/amdgpu-elf-flags.s =================================================================== --- lld/trunk/test/ELF/amdgpu-elf-flags.s +++ lld/trunk/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: ]