Index: lld/ELF/Arch/AMDGPU.cpp =================================================================== --- lld/ELF/Arch/AMDGPU.cpp +++ lld/ELF/Arch/AMDGPU.cpp @@ -105,7 +105,8 @@ } uint32_t AMDGPU::calcEFlags() const { - assert(!objectFiles.empty()); + if (objectFiles.empty()) + return 0; uint8_t abiVersion = cast>(objectFiles[0])->getObj() .getHeader().e_ident[EI_ABIVERSION]; Index: lld/ELF/SyntheticSections.cpp =================================================================== --- lld/ELF/SyntheticSections.cpp +++ lld/ELF/SyntheticSections.cpp @@ -3712,7 +3712,7 @@ return 0; } - if (config->emachine == EM_AMDGPU) { + if (config->emachine == EM_AMDGPU && !objectFiles.empty()) { uint8_t ver = objectFiles[0]->abiVersion; for (InputFile *file : makeArrayRef(objectFiles).slice(1)) if (file->abiVersion != ver) Index: lld/test/ELF/amdgpu-no-object-files-linked.s =================================================================== --- /dev/null +++ lld/test/ELF/amdgpu-no-object-files-linked.s @@ -0,0 +1,18 @@ +# REQUIRES: amdgpu + +# Produce an object file that we can use to produce a shared object +# RUN: llvm-mc -triple amdgcn-amd-amdhsa -mcpu=gfx906 --amdhsa-code-object-version=4 -filetype=obj %s -o %t.o + +# Produce a shared object we can try to re-link +# RUN: ld.lld -shared %t.o -o %t.so + +# Try to link again where there are no object file inputs, only a shared library. +# RUN: ld.lld -shared %t.so -o /dev/null + +# Test that there is no assertion if there no plain object files involved in link. +# Issue 47690 + + +.text + s_nop 0x0 + s_endpgm