1# RUN: rm -rf %t && mkdir -p %t/armv4t && mkdir -p %t/armv6 && mkdir -p %t/armv7 2# 3# RUN: llvm-mc -triple=armv4t-linux-gnueabi -arm-add-build-attributes \ 4# RUN: -filetype=obj -o %t/armv4t/out.o %s 5# RUN: llvm-jitlink -noexec -slab-address 0x76ff0000 \ 6# RUN: -slab-allocate 10Kb -slab-page-size 4096 \ 7# RUN: -abs ext=0x76bbe880 -check %s %t/armv4t/out.o 8# 9# RUN: llvm-mc -triple=armv6-linux-gnueabi -arm-add-build-attributes \ 10# RUN: -filetype=obj -o %t/armv6/out.o %s 11# RUN: llvm-jitlink -noexec -slab-address 0x76ff0000 \ 12# RUN: -slab-allocate 10Kb -slab-page-size 4096 \ 13# RUN: -abs ext=0x76bbe880 -check %s %t/armv6/out.o 14# 15# RUN: llvm-mc -triple=armv7-linux-gnueabi -arm-add-build-attributes \ 16# RUN: -filetype=obj -o %t/armv7/out.o %s 17# RUN: llvm-jitlink -noexec -slab-address 0x76ff0000 \ 18# RUN: -slab-allocate 10Kb -slab-page-size 4096 \ 19# RUN: -abs ext=0x76bbe880 -check %s %t/armv7/out.o 20 21 .text 22 .syntax unified 23 24# Check that calls/jumps to external functions trigger the generation of 25# branch-range extension stubs. These stubs don't follow the default PLT model 26# where the branch-target address is loaded from a GOT entry. Instead, they 27# hard-code it in the immediate field. 28 29# The external function ext will return to the caller directly. 30# jitlink-check: decode_operand(test_arm_jump, 0) = stub_addr(out.o, ext) - next_pc(test_arm_jump) 31 .globl test_arm_jump 32 .type test_arm_jump,%function 33 .p2align 2 34test_arm_jump: 35 b ext 36 .size test_arm_jump, .-test_arm_jump 37 38# The branch-with-link sets the LR register so that the external function ext 39# returns to us. We have to save the register (push) and return to main manually 40# (pop). This adds the +4 offset for the bl instruction we decode: 41# jitlink-check: decode_operand(test_arm_call + 4, 0) = stub_addr(out.o, ext) - next_pc(test_arm_call) - 4 42 .globl test_arm_call 43 .type test_arm_call,%function 44 .p2align 2 45test_arm_call: 46 push {lr} 47 bl ext 48 pop {pc} 49 .size test_arm_call, .-test_arm_call 50 51# This test is executable with any Arm (and for v7+ also Thumb) `ext` functions. 52# It only has to return with `bx lr`. For example: 53# > echo "void ext() {}" | clang -target armv7-linux-gnueabihf -o ext.o -c -xc - 54# > llvm-jitlink ext.o out.o 55# 56 .globl main 57 .type main,%function 58 .p2align 2 59main: 60 push {lr} 61 bl test_arm_call 62 bl test_arm_jump 63 mov r0, #0 64 pop {pc} 65 .size main, .-main 66