Skip to content

Commit a9962ed

Browse files
Statically linked AArch64 binaries crash at loading time.
Executing such a binary would result in: > Unexpected reloc type in static binary. > [1] 1234 abort (core dumped)
1 parent 587308c commit a9962ed

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Tests that statically linked AArch64 binaries do not crash at binary loading
2+
// time.
3+
//
4+
// Functions like `_init` do not appear in the `.text` section of the original
5+
// binary. For those cases, the BOLT'ed binary creates an alias (ie, `.init`),
6+
// which matches the address of the relevant function in the original binary.
7+
// If such function appears in the GOT and is patched, it leads to a runtime
8+
// crash.
9+
10+
REQUIRES: system-linux
11+
12+
RUN: %clang %p/../Inputs/main.c -o %t -Wl,-q -static
13+
RUN: llvm-bolt %t -o %t.bolt > /dev/null 2>&1
14+
RUN: not --crash %t.bolt 2>&1 | FileCheck %s
15+
CHECK: Unexpected reloc type in static binary.

bolt/test/Inputs/main.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// dummy function just for emitting relocations to the linker.
2+
int foo() { return 0; }
3+
int main(int argc, char **argv) { return foo() + 1; }

0 commit comments

Comments
 (0)