I have a bunch of object files that have been compiled without the -fPIC
option. So the calls to the functions do not use @PLT
. (source code is C and is compiled with clang
).
I want to link these object files into a shared library that I can load at runtime using dlopen
. I need to do this because I have to do a lot of setup before the actual .so
is loaded.
But every time I try to link with the -shared
option, I get the error -
relocation
R_X86_64_PC32
against symbolsplay_tree_lookup
can not be used when making a shared object; recompile with-fPIC
I have no issues recompiling from source. But I don't want to use -fPIC
. This is part of a research project where we are working on a custom compiler. PIC wouldn't work for the type of guarantees we are trying to provide in the compiler.
Is there some flag I can use with ld
so that it generate load time relocating libraries. In fact I am okay with no relocations. I can provide a base address for the library and dlopen
can fail if the virtual address is not available.
The command I am using for compiling my c
files are equivalent to -
clang -m64 -c foo.c
and for linking I am using
clang -m64 -shared *.o -o foo.so
I say equivalent because it is a custom compiler (forked off clang
) and has some extra steps. But it is equivalent.