I tracked down what was causing the "./a.out: Symbol `fstat' causes overflow in R_X86_64_PC32 relocation" message (and I suppose the others as well).
My build script attempts to link my executables with my project's dynamic lib (unless directed otherwise) and then a static version of the same lib before linking in external libs (the idea is to have a generic recipe that provides for the possibility that some of my project's executables might want to refer to project symbols that aren't exported in the shared lib).
It seems it is this double linking ( `tcc something... liblib.so liblib.a` ), compounded with something in the glibc definition of
fstat, that causes the problem on tcc.
MCVE:
#!/bin/sh -eu
cat > liblib.c <<EOF
#include <sys/stat.h>
void f(void) { struct stat sb; fstat(0, &sb); }
EOF
cat > main.c <<EOF
int main() { extern void f(); f(); return 0; }
EOF
: ${CC:=tcc}
$CC liblib.c -fPIC -c; ar rcs liblib.a liblib.o; $CC -o liblib.so liblib.o -shared
$CC main.c $PWD/liblib.so liblib.a #uncommenting liblib.a removes the error
LD_LIBRARY_PATH=$PWD ./a.out
In the above reproducer, liblib.a should be ignored because it's not resolving any undefined references, but instead it appears to be causing the error message.
Regards,
Petr Skocik