Skip to content

Instantly share code, notes, and snippets.

@dvanhorn
Created January 20, 2021 03:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dvanhorn/d4ccb7c43464d2070f7032086c80b6e8 to your computer and use it in GitHub Desktop.
Save dvanhorn/d4ccb7c43464d2070f7032086c80b6e8 to your computer and use it in GitHub Desktop.
can't link an external call in a shared library
int f () {
return 42;
}
default rel
extern f
global g:function
g:
call f
ret
$ gcc -fPIC -c f.c
$ nasm -f elf64 g.s
$ gcc -shared f.o g.o
/usr/bin/ld: g.o: relocation R_X86_64_PC32 against symbol `f' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Bad value
collect2: error: ld returned 1 exit status
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment