Question

I'm trying to cross-compile arm assembly code which is using shared library that's located in : /system/lib/libxyz.so (on host device), and using dynamic linker: /system/bin/linker - which is also located on host device.

So I compile:

arm-eabi-gcc -mcpu="cortex-a9"  -Wl,-dynamic-linker=/system/bin/linker -llibxyz.so -Wl,--unresolved-symbols=ignore-all -nostdlib topsecret.S -o topsecret

I also use:

-Wl,--unresolved-symbols=ignore-all

To ignore any undefined symbols as I dont really have them when compiling - I'm taking on the asm code the calling of right addresses.

The trivial error I'm getting is :

arm-eabi/bin/ld cannot find -llibxyz.so, collect2: ld returned 1 exit status

And I dont actally want to have the libxyz.so library, I want the compiler to ignore the error, and add the dependency to the ELF Header. I tried -Wl,--no-as-needed, -Wl,--as-needed arguments but that didn't help.

The question is if I can either ignore the error, fake the library, or any other solution which will give me good binary that has the dependency in the header.

Link shared library in gcc without file? This solution is not good because I dont want to change the asm code, only the compiling mechanism.

Was it helpful?

Solution

Sorry, but what you want to do is not possible. The linker wants to see the shared library so it knows which symbols are defined there and which are not; it needs to know that to understand how the linkage will work. You'll have to copy the target's shared library to your development system, or else use explicit loading as suggested in the answer you reference (dlopen etc.) and create the linkage yourself with dlsym(). – MadScientist

You can transfer the file from host to build. If you cann't do this, then there is no way for the linker to know which library an un-resolved symbol exists in. You can create a fake host library with shims for implementation. This will work even if you can not transfer the host library (host locked down or something). This will allow you to link on the build machine and it should patch to the full implementation on the host by its loader. – artless noise

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top