Here's a transcipt of something very similar that seems to result in an infinite loop on Linux. :(
dvanhorn@starburst:small $ cat f.c
int f() {
return 42;
}
int (*ptr_to_f)() = f;
dvanhorn@starburst:small $ cat try.s
global main
default rel
section .text
extern ptr_to_f
main:
sub rsp, 8
lea rax, [rel ptr_to_f wrt ..plt]
call [rax]
add rsp, 8
ret
dvanhorn@starburst:small $ cat ffi-f.rkt
#lang racket
(require ffi/unsafe)
(define libf (ffi-lib "f.so"))
(define asm-main
(get-ffi-obj "main" libf (_fun -> _int)))
(asm-main)
dvanhorn@starburst:small $ nasm -f elf64 try.s -o try.o
dvanhorn@starburst:small $ gcc -shared -fPIC f.c try.o -o f.so
dvanhorn@starburst:small $ racket ffi-f.rkt
Killed