In a project, my colleague create a static library, e.g liba.a, which linked with app.
In liba.a he overwrites the libc malloc() to his owner version.
I create a shared library libs.so which also linked with app.
The problem is when my libs.so linked with app, the malloc() used in my libs.so will be the one in liba.a, not the one in standard libc.so, this causes problems.
Then, I want static link the libc.a to my libs.so, I used -static -shared -fPIC flags for gcc.
But I always get arm-2012.03/bin/../lib/gcc/arm-none-linux-gnueabi/4.6.3/../../../../arm-none-linux-gnueabi/bin/ld: arm-2012.03/bin/../arm-none-linux-gnueabi/libc/usr/lib/libc.a(dl-tsd.o)(.text+0x14): R_ARM_TLS_LE32 relocation not permitted in shared object.
Does anyone have idea about it?
Thanks forward.
You can't, because code that goes in shared library must be compiled with -fPIC
and code in static libraries isn't. If you managed to do it, the resulting executable would end up linked with libc multiple times, which would be really fragile anyway and probably crash sooner or later, so you shouldn't do it anyway. Therefore:
Don't. Dynamic libraries have to link against system libraries dynamically and any executable that links against any dynamic libraries also has to link system libraries dynamically.
I would also like to remind you, that linking GNU libc against non-GPL application statically is illegal, since LGPL only excepts dynamically linked code. This is on purpose to allow bugfixing the library without recompiling the executable for which source may not be available. It's rather common in Linux to upgrade shared libraries with bugfixed version without recompiling dependent executables; libc developers know how to do that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With