OK, so the assembly code, when statically linked into a executable works both with the call to f
and the indirect call through ptr_to_f
.
When dynamically loaded, the call to f
works, but the call through ptr_to_f
seg faults.
dvanhorn@starburst:small $ nasm -f elf64 call_f.s -o call_f.o
dvanhorn@starburst:small $ gcc static.c f.c call_f.o -o static
dvanhorn@starburst:small $ gcc -ldl dynamic.c -o dynamic
dvanhorn@starburst:small $ gcc -shared f.c call_f.o -o f.so
dvanhorn@starburst:small $ ./static frog
42
dvanhorn@starburst:small $ ./static duck
42
dvanhorn@starburst:small $ ./dynamic frog
42
dvanhorn@starburst:small $ ./dynamic duck
Segmentation fault