-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ELF2] Fix binaries so they actually run on FreeBSD.
Since FreeBSD 4.1, the kernel expects binaries to be marked with ELFOSABI_FREEBSD in the ELF header to exec() them. LLD unconditionally sets OSABI to ELF_OSABINONE, and everything linked with it won't run on FreeBSD (unless explicitly rebranded). Example: % ./aarch64-hello ELF binary type "0" not known. zsh: exec format error: ./aarch64-hello FreeBSD could be modified to accept ELF_OSABINONE, but that would break all existing binaries, so the kernel needs to support both ABINONE and ABIFREEBSD. I plan to push this change in FreeBSD one day, which, unfortunately, is not today. This code patches lld so it sets the header field correctly. For completeness, the rationale of this change is explained in the FreeBSD commit message, and it's apparently to pleasee binutils maintainers at the time. https://svnweb.freebsd.org/base?view=revision&revision=59342 Differential Revision: http://reviews.llvm.org/D13140 llvm-svn: 248554
- Loading branch information
Showing
3 changed files
with
32 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |