[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 11:02:25 PDT 2022
arsenm updated this revision to Diff 421591.
arsenm added a comment.
Merge tests
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D123411/new/
https://reviews.llvm.org/D123411
Files:
lld/ELF/Arch/AMDGPU.cpp
lld/ELF/SyntheticSections.cpp
lld/test/ELF/amdgpu-elf-flags.s
Index: lld/test/ELF/amdgpu-elf-flags.s
===================================================================
--- lld/test/ELF/amdgpu-elf-flags.s
+++ lld/test/ELF/amdgpu-elf-flags.s
@@ -2,8 +2,15 @@
# RUN: llvm-mc -triple amdgcn-amd-amdhsa -mcpu=gfx803 --amdhsa-code-object-version=2 -filetype=obj %S/Inputs/amdgpu-kernel-0.s -o %t-0.o
# RUN: llvm-mc -triple amdgcn-amd-amdhsa -mcpu=gfx803 --amdhsa-code-object-version=2 -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
+# RUN: llvm-readobj --file-headers %t.so | FileCheck -check-prefix=FIRSTLINK %s
-# CHECK: Flags [
-# CHECK: EF_AMDGPU_MACH_AMDGCN_GFX803 (0x2A)
-# CHECK: ]
+## Try to link again where there are no object file inputs, only a shared library. Issue 47690
+# RUN: ld.lld -shared %t.so -o - | llvm-readobj -h - | FileCheck -check-prefix=SECONDLINK %s
+
+
+# FIRSTLINK: Flags [
+# FIRSTLINK-NEXT: EF_AMDGPU_MACH_AMDGCN_GFX803 (0x2A)
+# FIRSTLINK-NEXT: ]
+
+# SECONDLINK: Flags [ (0x0)
+# SECONDLINK-NEXT: ]
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.421591.patch
Type: text/x-patch
Size: 1965 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220408/d02847d9/attachment.bin>
More information about the llvm-commits
mailing list