[PATCH] D58026: LLD: Preserve ABI version during linking ELF

Konstantin Zhuravlyov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 11 00:24:17 PST 2019


kzhuravl created this revision.
kzhuravl added a reviewer: ruiu.
Herald added subscribers: arichardson, nhaehnle, wdng, jvesely, emaste.
Herald added a reviewer: espindola.
kzhuravl added a parent revision: D57811: AMDGPU: Set ABI version to 1 for code object v3.

https://reviews.llvm.org/D58026

Files:
  ELF/Config.h
  ELF/Driver.cpp
  ELF/InputFiles.cpp
  ELF/InputFiles.h
  ELF/Writer.cpp
  test/ELF/amdgpu-abi-version.s


Index: test/ELF/amdgpu-abi-version.s
===================================================================
--- /dev/null
+++ test/ELF/amdgpu-abi-version.s
@@ -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
\ No newline at end of file
Index: ELF/Writer.cpp
===================================================================
--- ELF/Writer.cpp
+++ ELF/Writer.cpp
@@ -2403,7 +2403,8 @@
   EHdr->e_ident[EI_DATA] = Config->IsLE ? ELFDATA2LSB : ELFDATA2MSB;
   EHdr->e_ident[EI_VERSION] = EV_CURRENT;
   EHdr->e_ident[EI_OSABI] = Config->OSABI;
-  EHdr->e_ident[EI_ABIVERSION] = getAbiVersion();
+  EHdr->e_ident[EI_ABIVERSION] =
+      Config->ABIVersion == 0 ? getAbiVersion() : Config->ABIVersion;
   EHdr->e_type = getELFType();
   EHdr->e_machine = Config->EMachine;
   EHdr->e_version = EV_CURRENT;
Index: ELF/InputFiles.h
===================================================================
--- ELF/InputFiles.h
+++ ELF/InputFiles.h
@@ -103,6 +103,7 @@
   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;
Index: ELF/InputFiles.cpp
===================================================================
--- ELF/InputFiles.cpp
+++ ELF/InputFiles.cpp
@@ -239,6 +239,7 @@
 
   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>
Index: ELF/Driver.cpp
===================================================================
--- ELF/Driver.cpp
+++ ELF/Driver.cpp
@@ -1165,6 +1165,7 @@
     Config->EKind = F->EKind;
     Config->EMachine = F->EMachine;
     Config->OSABI = F->OSABI;
+    Config->ABIVersion = F->ABIVersion;
     Config->MipsN32Abi = Config->EMachine == EM_MIPS && isMipsN32Abi(F);
     return;
   }
Index: ELF/Config.h
===================================================================
--- ELF/Config.h
+++ ELF/Config.h
@@ -82,6 +82,7 @@
 // Most fields are initialized by the driver.
 struct Configuration {
   uint8_t OSABI = 0;
+  uint8_t ABIVersion = 0;
   llvm::CachePruningPolicy ThinLTOCachePolicy;
   llvm::StringMap<uint64_t> SectionStartMap;
   llvm::StringRef Chroot;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D58026.186188.patch
Type: text/x-patch
Size: 2576 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190211/1c6fd76c/attachment.bin>


More information about the llvm-commits mailing list