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

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


This revision was automatically updated to reflect the committed changes.
Closed by commit rL349738: [llvm-objcopy] - Do not drop the OS/ABI and ABIVersion fields of ELF header (authored by grimar, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D55886?vs=178886&id=179034#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D55886/new/

https://reviews.llvm.org/D55886

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


Index: llvm/trunk/test/tools/llvm-objcopy/ELF/copy-osabi.test
===================================================================
--- llvm/trunk/test/tools/llvm-objcopy/ELF/copy-osabi.test
+++ llvm/trunk/test/tools/llvm-objcopy/ELF/copy-osabi.test
@@ -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
Index: llvm/trunk/tools/llvm-objcopy/ELF/Object.cpp
===================================================================
--- llvm/trunk/tools/llvm-objcopy/ELF/Object.cpp
+++ llvm/trunk/tools/llvm-objcopy/ELF/Object.cpp
@@ -703,6 +703,8 @@
 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<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 @@
   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;
Index: llvm/trunk/tools/llvm-objcopy/ELF/Object.h
===================================================================
--- llvm/trunk/tools/llvm-objcopy/ELF/Object.h
+++ llvm/trunk/tools/llvm-objcopy/ELF/Object.h
@@ -733,6 +733,8 @@
   Segment ElfHdrSegment;
   Segment ProgramHdrSegment;
 
+  uint8_t OSABI;
+  uint8_t ABIVersion;
   uint64_t Entry;
   uint64_t SHOffset;
   uint32_t Type;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D55886.179034.patch
Type: text/x-patch
Size: 2258 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181220/3bdf6719/attachment.bin>


More information about the llvm-commits mailing list