[PATCH] D123411: lld/AMDGPU: Fix asserts if no object files are involved in link

Matt Arsenault via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 8 10:29:06 PDT 2022


arsenm created this revision.
arsenm added reviewers: lld, AMDGPU.
Herald added subscribers: kerbowa, arichardson, t-tye, tpr, dstuttard, yaxunl, jvesely, kzhuravl, emaste.
Herald added a reviewer: MaskRay.
Herald added a project: All.
arsenm requested review of this revision.
Herald added subscribers: StephenFan, wdng.

Fixes issue 47690. The reproduction steps produced a shared object
from clang directly, and then fed the shared object back into
lld. With no regular object files, this assert was hit. I'm not sure
if we need to or should be looking for equivalent fields in shared
objects.


https://reviews.llvm.org/D123411

Files:
  lld/ELF/Arch/AMDGPU.cpp
  lld/ELF/SyntheticSections.cpp
  lld/test/ELF/amdgpu-no-object-files-linked.s


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
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/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<ObjFile<ELF64LE>>(objectFiles[0])->getObj()
       .getHeader().e_ident[EI_ABIVERSION];


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D123411.421577.patch
Type: text/x-patch
Size: 1636 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220408/7e07b606/attachment.bin>


More information about the llvm-commits mailing list