Reputation: 107
I have closed-source shared library originally built for Android which I want to use on Raspberry Pi. The problem is this:
/usr/bin/ld: /usr/lib/libfoo.so: undefined reference to `__cxa_atexit@LIBC'
/usr/bin/ld: /usr/lib/libfoo.so: undefined reference to `calloc@LIBC'
/usr/bin/ld: /usr/lib/libfoo.so: undefined reference to `malloc@LIBC'
/usr/bin/ld: /usr/lib/libfoo.so: undefined reference to `free@LIBC'
/usr/bin/ld: /usr/lib/libfoo.so: undefined reference to `memset@LIBC'
/usr/bin/ld: /usr/lib/libfoo.so: undefined reference to `memcpy@LIBC'
/usr/bin/ld: /usr/lib/libfoo.so: undefined reference to `raise@LIBC'
/usr/bin/ld: /usr/lib/libfoo.so: undefined reference to `__cxa_finalize@LIBC'
/usr/bin/ld: /usr/lib/libfoo.so: undefined reference to `abort@LIBC'
This is most likely because there's no such symbols in glibc.
The simplest solution would (probably) be to create wrapper library with these functions which will just call glibc's ones. However, it's not clear how to create functions with @ in the middle of their names.
Other solution may be somehow modifying the libfoo.so itself (I tried replacing libc.so requirement to libc.so.6 using patchelf without any success).
Probably the best option (but the hardest and it will require much more work) will be reverse-engineering this library. I will probably do this in future, but for now I need simple solution which just works.
What should I do to make it work?
Upvotes: 2
Views: 331
Reputation: 694
This is most likely because there's no such symbols in glibc.
You're correct. Your wrapper library idea is plausible in theory. The way you create @LIBC symbols is with __asm__
directives in your C source.
void *malloc_like_bionic( size_t size)
{
return malloc( size);
}
__asm__(.symver malloc_like_bionic, malloc@LIBC);
That __asm__
statement uses the .symver
directive of the GNU assembler to rename the malloc_like_bionic
function as malloc@LIBC
. That lets you use a name that C doesn't like. The GNU assembler is run by GCC every time you use GCC to compile; it generates an object file from assembler source written by GCC.
The GCC Wiki's page on symbol versioning will show you many more tricks you can play with these tools.
Upvotes: 0