[PATCH] D13140: [ELF2] Fix binaries so they actually run on FreeBSD.

Davide Italiano via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 24 19:07:30 PDT 2015


This revision was automatically updated to reflect the committed changes.
Closed by commit rL248554: [ELF2] Fix binaries so they actually run on FreeBSD. (authored by davide).

Changed prior to commit:
  http://reviews.llvm.org/D13140?vs=35647&id=35693#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D13140

Files:
  lld/trunk/ELF/InputFiles.h
  lld/trunk/ELF/Writer.cpp
  lld/trunk/test/elf2/basic-freebsd.s

Index: lld/trunk/test/elf2/basic-freebsd.s
===================================================================
--- lld/trunk/test/elf2/basic-freebsd.s
+++ lld/trunk/test/elf2/basic-freebsd.s
@@ -0,0 +1,25 @@
+# Verify that OSABI is set to the correct value.
+
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-freebsd %s -o %t
+# RUN: lld -flavor gnu2 %t -o %t2
+# RUN: llvm-readobj -file-headers %t2 | FileCheck %s
+# REQUIRES: x86
+
+.globl _start
+_start:
+  mov $1, %rax
+  mov $42, %rdi
+  syscall
+
+# CHECK: ElfHeader {
+# CHECK-NEXT:   Ident {
+# CHECK-NEXT:     Magic: (7F 45 4C 46)
+# CHECK-NEXT:     Class: 64-bit (0x2)
+# CHECK-NEXT:     DataEncoding: LittleEndian (0x1)
+# CHECK-NEXT:     FileVersion: 1
+# CHECK-NEXT:     OS/ABI: FreeBSD (0x9)
+# CHECK-NEXT:     ABIVersion: 0
+# CHECK-NEXT:     Unused: (00 00 00 00 00 00 00)
+# CHECK-NEXT:   }
+# CHECK-NEXT:   Type: Executable (0x2)
+# CHECK-NEXT:   Machine: EM_X86_64 (0x3E)
Index: lld/trunk/ELF/Writer.cpp
===================================================================
--- lld/trunk/ELF/Writer.cpp
+++ lld/trunk/ELF/Writer.cpp
@@ -500,14 +500,15 @@
                                ? ELFDATA2LSB
                                : ELFDATA2MSB;
   EHdr->e_ident[EI_VERSION] = EV_CURRENT;
-  EHdr->e_ident[EI_OSABI] = ELFOSABI_NONE;
+
+  const SymbolTable &Symtab = SymTabSec.getSymTable();
+  auto &FirstObj = cast<ObjectFile<ELFT>>(*Symtab.getFirstELF());
+  EHdr->e_ident[EI_OSABI] = FirstObj.getOSABI();
 
   // FIXME: Generalize the segment construction similar to how we create
   // output sections.
-  const SymbolTable &Symtab = SymTabSec.getSymTable();
 
   EHdr->e_type = Config->Shared ? ET_DYN : ET_EXEC;
-  auto &FirstObj = cast<ObjectFile<ELFT>>(*Symtab.getFirstELF());
   EHdr->e_machine = FirstObj.getEMachine();
   EHdr->e_version = EV_CURRENT;
   SymbolBody *Entry = Symtab.getEntrySym();
Index: lld/trunk/ELF/InputFiles.h
===================================================================
--- lld/trunk/ELF/InputFiles.h
+++ lld/trunk/ELF/InputFiles.h
@@ -105,6 +105,9 @@
   llvm::object::ELFFile<ELFT> &getObj() { return ELFObj; }
 
   uint16_t getEMachine() const { return getObj().getHeader()->e_machine; }
+  uint8_t getOSABI() const {
+    return getObj().getHeader()->e_ident[llvm::ELF::EI_OSABI];
+  }
 
   StringRef getStringTable() const { return StringTable; }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D13140.35693.patch
Type: text/x-patch
Size: 2366 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150925/83e57ea8/attachment.bin>


More information about the llvm-commits mailing list