Skip to content

Commit

Permalink
[ELF] Set EF_ARM_EABI_VER5 for ARM
Browse files Browse the repository at this point in the history
Without this flag set, an AArch64 Linux kernel won't try to load the executable
(even if a 32 bit arm kernel will run the binary just fine).

Patch by Martin Storsjö!

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

llvm-svn: 281394
  • Loading branch information
rui314 committed Sep 13, 2016
1 parent ea26504 commit 1e2e8ea
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lld/ELF/Writer.cpp
Expand Up @@ -1262,7 +1262,12 @@ template <class ELFT> void Writer<ELFT>::writeHeader() {
EHdr->e_shnum = OutputSections.size() + 1;
EHdr->e_shstrndx = Out<ELFT>::ShStrTab->SectionIndex;

if (Config->EMachine == EM_MIPS)
if (Config->EMachine == EM_ARM)
// We don't currently use any features incompatible with EF_ARM_EABI_VER5,
// but we don't have any firm guarantees of conformance. Linux AArch64
// kernels (as of 2016) require an EABI version to be set.
EHdr->e_flags = EF_ARM_EABI_VER5;
else if (Config->EMachine == EM_MIPS)
EHdr->e_flags = getMipsEFlags<ELFT>();

if (!Config->Relocatable) {
Expand Down
14 changes: 14 additions & 0 deletions lld/test/ELF/arm-eabi-version.s
@@ -0,0 +1,14 @@
// RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %s -o %t.o
// RUN: ld.lld -static %t.o -o %tout
// RUN: llvm-readobj -file-headers %tout | FileCheck %s
// REQUIRES: arm
.syntax unified
.text
.globl _start
_start:
bx lr

// CHECK: Flags [
// CHECK-NEXT: 0x1000000
// CHECK-NEXT: 0x4000000
// CHECK-NEXT: ]

0 comments on commit 1e2e8ea

Please sign in to comment.