Sunday, November 28, 2010

R_ARM_TLS_LE32 relocation not permitted in shared object

Environment: Linux, C, ARM, cross compile, Makefile

Friday I was taking two 3rd party static libraries, add an API layer around it, and repackage it into a shared library.  This shared library will allow us to be vendor agnostic and swap in and out with other implementations as necessary.

All was working as planned until I ran into the following compile warning: (The so library still compiled.)

libc.a(malloc.o)(.text+0xe0): R_ARM_TLS_LE32 
   relocation not permitted in shared object

When I tried to include library statically, it pulled in the static C library into my shared library.  The static C library contains relocations that cannot be used in a shared library.

Some online article suggested recompiling the gcc with the "--disable-libmudflap" will fix the problem.

For me, I just need to link the libc dynamic instead of shared.  So in my LDFLAGS, I added -Wl -Bstatic in front of my two static libs and -Wl -Bdynamic afterward.  Problem solved.