[lld] r354086 - LLD/AMDGPU: Preserve ABI version during linking ELF for AMDGPU
Konstantin Zhuravlyov via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 14 15:59:44 PST 2019
Author: kzhuravl
Date: Thu Feb 14 15:59:44 2019
New Revision: 354086
URL: http://llvm.org/viewvc/llvm-project?rev=354086&view=rev
Log:
LLD/AMDGPU: Preserve ABI version during linking ELF for AMDGPU
Differential Revision: https://reviews.llvm.org/D58026
Added:
lld/trunk/test/ELF/amdgpu-abi-version-err.s
lld/trunk/test/ELF/amdgpu-abi-version.s
Modified:
lld/trunk/ELF/InputFiles.cpp
lld/trunk/ELF/InputFiles.h
lld/trunk/ELF/Writer.cpp
Modified: lld/trunk/ELF/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.cpp?rev=354086&r1=354085&r2=354086&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.cpp (original)
+++ lld/trunk/ELF/InputFiles.cpp Thu Feb 14 15:59:44 2019
@@ -239,6 +239,7 @@ ELFFileBase<ELFT>::ELFFileBase(Kind K, M
EMachine = getObj().getHeader()->e_machine;
OSABI = getObj().getHeader()->e_ident[llvm::ELF::EI_OSABI];
+ ABIVersion = getObj().getHeader()->e_ident[llvm::ELF::EI_ABIVERSION];
}
template <class ELFT>
Modified: lld/trunk/ELF/InputFiles.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.h?rev=354086&r1=354085&r2=354086&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.h (original)
+++ lld/trunk/ELF/InputFiles.h Thu Feb 14 15:59:44 2019
@@ -103,6 +103,7 @@ public:
ELFKind EKind = ELFNoneKind;
uint16_t EMachine = llvm::ELF::EM_NONE;
uint8_t OSABI = 0;
+ uint8_t ABIVersion = 0;
// Cache for toString(). Only toString() should use this member.
mutable std::string ToStringCache;
Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=354086&r1=354085&r2=354086&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Thu Feb 14 15:59:44 2019
@@ -2384,9 +2384,21 @@ static uint16_t getELFType() {
static uint8_t getAbiVersion() {
// MIPS non-PIC executable gets ABI version 1.
- if (Config->EMachine == EM_MIPS && getELFType() == ET_EXEC &&
- (Config->EFlags & (EF_MIPS_PIC | EF_MIPS_CPIC)) == EF_MIPS_CPIC)
- return 1;
+ if (Config->EMachine == EM_MIPS) {
+ if (getELFType() == ET_EXEC &&
+ (Config->EFlags & (EF_MIPS_PIC | EF_MIPS_CPIC)) == EF_MIPS_CPIC)
+ return 1;
+ return 0;
+ }
+
+ if (Config->EMachine == EM_AMDGPU) {
+ uint8_t Ver = ObjectFiles[0]->ABIVersion;
+ for (InputFile *File : makeArrayRef(ObjectFiles).slice(1))
+ if (File->ABIVersion != Ver)
+ error("incompatible ABI version: " + toString(File));
+ return Ver;
+ }
+
return 0;
}
Added: lld/trunk/test/ELF/amdgpu-abi-version-err.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/amdgpu-abi-version-err.s?rev=354086&view=auto
==============================================================================
--- lld/trunk/test/ELF/amdgpu-abi-version-err.s (added)
+++ lld/trunk/test/ELF/amdgpu-abi-version-err.s Thu Feb 14 15:59:44 2019
@@ -0,0 +1,10 @@
+# REQUIRES: amdgpu
+# RUN: llvm-mc -triple amdgcn-amd-amdhsa -mcpu=gfx900 -filetype=obj %s -o %t-0.o
+# RUN: llvm-mc -triple amdgcn-amd-amdhsa -mcpu=gfx900 -mattr=-code-object-v3 -filetype=obj %s -o %t-1.o
+# RUN: not ld.lld -shared %t-0.o %t-1.o -o %t.so 2>&1 | FileCheck %s
+
+# CHECK: ld.lld: error: incompatible ABI version: {{.*}}-1.o
+
+.text
+ s_nop 0x0
+ s_endpgm
Added: lld/trunk/test/ELF/amdgpu-abi-version.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/amdgpu-abi-version.s?rev=354086&view=auto
==============================================================================
--- lld/trunk/test/ELF/amdgpu-abi-version.s (added)
+++ lld/trunk/test/ELF/amdgpu-abi-version.s Thu Feb 14 15:59:44 2019
@@ -0,0 +1,11 @@
+# REQUIRES: amdgpu
+# RUN: llvm-mc -triple amdgcn-amd-amdhsa -mcpu=gfx900 -filetype=obj %s -o %t.o
+# RUN: ld.lld -shared %t.o -o %t.so
+# RUN: llvm-readobj -file-headers %t.so | FileCheck %s
+
+# CHECK: OS/ABI: AMDGPU_HSA (0x40)
+# CHECK: ABIVersion: 1
+
+.text
+ s_nop 0x0
+ s_endpgm
More information about the llvm-commits
mailing list