[llvm] r349738 - [llvm-objcopy] - Do not drop the OS/ABI and ABIVersion fields of ELF header

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 20 02:51:42 PST 2018


Author: grimar
Date: Thu Dec 20 02:51:42 2018
New Revision: 349738

URL: http://llvm.org/viewvc/llvm-project?rev=349738&view=rev
Log:
[llvm-objcopy] - Do not drop the OS/ABI and ABIVersion fields of ELF header

This is https://bugs.llvm.org/show_bug.cgi?id=40005,

Patch teaches llvm-objcopy to preserve OS/ABI and ABIVersion fields of ELF header.
(Currently, it drops them to zero).

Differential revision: https://reviews.llvm.org/D55886

Added:
    llvm/trunk/test/tools/llvm-objcopy/ELF/copy-osabi.test
Modified:
    llvm/trunk/tools/llvm-objcopy/ELF/Object.cpp
    llvm/trunk/tools/llvm-objcopy/ELF/Object.h

Added: llvm/trunk/test/tools/llvm-objcopy/ELF/copy-osabi.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-objcopy/ELF/copy-osabi.test?rev=349738&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-objcopy/ELF/copy-osabi.test (added)
+++ llvm/trunk/test/tools/llvm-objcopy/ELF/copy-osabi.test Thu Dec 20 02:51:42 2018
@@ -0,0 +1,16 @@
+# RUN: yaml2obj %s > %t
+# RUN: llvm-objcopy %t %t2
+# RUN: llvm-readobj -file-headers %t2 | FileCheck %s
+
+## Check that llvm-objcopy preserves the OSABI and ABIVersion fields.
+# CHECK: OS/ABI: FreeBSD (0x9)
+# CHECK: ABIVersion: 1
+
+!ELF
+FileHeader:
+  Class:           ELFCLASS64
+  Data:            ELFDATA2LSB
+  OSABI:           ELFOSABI_FREEBSD
+  ABIVersion:      1
+  Type:            ET_REL
+  Machine:         EM_AARCH64

Modified: llvm/trunk/tools/llvm-objcopy/ELF/Object.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objcopy/ELF/Object.cpp?rev=349738&r1=349737&r2=349738&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-objcopy/ELF/Object.cpp (original)
+++ llvm/trunk/tools/llvm-objcopy/ELF/Object.cpp Thu Dec 20 02:51:42 2018
@@ -703,6 +703,8 @@ static bool compareSegmentsByPAddr(const
 template <class ELFT> void BinaryELFBuilder<ELFT>::initFileHeader() {
   Obj->Flags = 0x0;
   Obj->Type = ET_REL;
+  Obj->OSABI = 0;
+  Obj->ABIVersion = 0;
   Obj->Entry = 0x0;
   Obj->Machine = EMachine;
   Obj->Version = 1;
@@ -1086,6 +1088,8 @@ template <class ELFT> void ELFBuilder<EL
 template <class ELFT> void ELFBuilder<ELFT>::build() {
   const auto &Ehdr = *ElfFile.getHeader();
 
+  Obj.OSABI = Ehdr.e_ident[EI_OSABI];
+  Obj.ABIVersion = Ehdr.e_ident[EI_ABIVERSION];
   Obj.Type = Ehdr.e_type;
   Obj.Machine = Ehdr.e_machine;
   Obj.Version = Ehdr.e_version;
@@ -1162,8 +1166,8 @@ template <class ELFT> void ELFWriter<ELF
   Ehdr.e_ident[EI_DATA] =
       ELFT::TargetEndianness == support::big ? ELFDATA2MSB : ELFDATA2LSB;
   Ehdr.e_ident[EI_VERSION] = EV_CURRENT;
-  Ehdr.e_ident[EI_OSABI] = ELFOSABI_NONE;
-  Ehdr.e_ident[EI_ABIVERSION] = 0;
+  Ehdr.e_ident[EI_OSABI] = Obj.OSABI;
+  Ehdr.e_ident[EI_ABIVERSION] = Obj.ABIVersion;
 
   Ehdr.e_type = Obj.Type;
   Ehdr.e_machine = Obj.Machine;

Modified: llvm/trunk/tools/llvm-objcopy/ELF/Object.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objcopy/ELF/Object.h?rev=349738&r1=349737&r2=349738&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-objcopy/ELF/Object.h (original)
+++ llvm/trunk/tools/llvm-objcopy/ELF/Object.h Thu Dec 20 02:51:42 2018
@@ -733,6 +733,8 @@ public:
   Segment ElfHdrSegment;
   Segment ProgramHdrSegment;
 
+  uint8_t OSABI;
+  uint8_t ABIVersion;
   uint64_t Entry;
   uint64_t SHOffset;
   uint32_t Type;




More information about the llvm-commits mailing list