111 lines · plain
1# REQUIRES: x86_64-linux2# RUN: rm -rf %t && mkdir -p %t3# RUN: split-file %s %t4# RUN: llvm-mc -triple=x86_64-unknown-linux-gnu -filetype=obj -o %t/test_runner.o %t/test_runner.s5# RUN: llvm-mc -triple=x86_64-unknown-linux-gnu -filetype=obj -o %t/func_defs.o %t/func_defs.s6# RUN: llvm-rtdyld -triple=x86_64-unknown-linux-gnu -verify -check=%s %t/test_runner.o %t/func_defs.o7# RUN: llvm-rtdyld -triple=x86_64-unknown-linux-gnu -execute %t/test_runner.o %t/func_defs.o8 9#--- test_runner.s10 11# The _main function of this file contains calls to the two external functions12# "indirect_func" and "normal_func" that are not yet defined. They are called via13# the PLT to simulate how a compiler would emit a call to an external function.14# Eventually, indirect_func will resolve to a STT_GNU_IFUNC and normal_func to a15# regular function. We include calls to both types of functions in this test to16# test that both types of functions are executed correctly when their types are17# not known initially.18# It also contains a call to a locally defined indirect function. As RuntimeDyld19# treats local functions a bit differently than external functions, we also test20# that.21# Verify that the functions return the excpeted value. If the external indirect22# function call fails, this returns the error code 1. If the external normal23# function call fails, it's the error code 2. If the call to the locally24# defined indirect function fails, return the error code 3.25 26local_real_func:27 mov $0x56, %eax28 ret29 30local_indirect_func_resolver:31 lea local_real_func(%rip), %rax32 ret33 34 .type local_indirect_func, @gnu_indirect_function35 .set local_indirect_func, local_indirect_func_resolver36 37 .global _main38_main:39 call indirect_func@plt40 cmp $0x12, %eax41 je 1f42 mov $1, %eax43 ret441:45 46 call normal_func@plt47 cmp $0x34, %eax48 je 1f49 mov $2, %eax50 ret511:52 53 call local_indirect_func@plt54 cmp $0x56, %eax55 je 1f56 mov $3, %eax57 ret581:59 60 xor %eax, %eax61 ret62 63# Test that the indirect functions have the same addresses in both calls.64# rtdyld-check: decode_operand(test_indirect_func_address_1, 4) + next_pc(test_indirect_func_address_1) = decode_operand(test_indirect_func_address_2, 4) + next_pc(test_indirect_func_address_2)65test_indirect_func_address_1:66 lea indirect_func(%rip), %rax67 68test_indirect_func_address_2:69 lea indirect_func(%rip), %rax70 71# rtdyld-check: decode_operand(test_local_indirect_func_address_1, 4) + next_pc(test_indirect_func_address_1) = decode_operand(test_local_indirect_func_address_2, 4) + next_pc(test_indirect_func_address_2)72test_local_indirect_func_address_1:73 lea local_indirect_func(%rip), %rax74 75test_local_indirect_func_address_2:76 lea local_indirect_func(%rip), %rax77 78#--- func_defs.s79 80# This file contains the external functions that are called above. The type of81# the indirect function is set to @gnu_indirect_function and its value is set82# to the value of ifunc_resolver. This is what gcc emits when using83# __attribute__((ifunc("ifunc_resolver"))) in C. The resolver function just84# returns the address of the real function "real_func".85# To test that everyting works correctly, the indirect function returns 0x1286# and the direct function returns 0x23. This is verified in the _main function87# above.88 89real_func:90 mov $0x12, %eax91 ret92 93ifunc_resolver:94 lea real_func(%rip), %rax95 ret96 97 .global indirect_func98 .type indirect_func, @gnu_indirect_function99 .set indirect_func, ifunc_resolver100 101 .global normal_func102normal_func:103 mov $0x34, %eax104 ret105 106# Test that the address of the indirect function is equal even when it is107# defined in another object file.108# rtdyld-check: decode_operand(test_indirect_func_address_1, 4) + next_pc(test_indirect_func_address_1) = decode_operand(test_indirect_func_address_3, 4) + next_pc(test_indirect_func_address_3)109test_indirect_func_address_3:110 lea indirect_func(%rip), %rax111