I'm trying to execute a program compiled with my own library, but when i execute the program I get the following error:
./a.out
./a.out: error while loading shared libraries: ../../lib-arm/libCustomLibrary.so: unexpected reloc type 0x03
That just happens with the Release execution, with the Debug execution all works fine.
Where do you think that may be the problem?
The CustomLibrary Library is linked with the following arguments:
-lSubLibrary -fPIC -Wl,-Bstatic -lboost_system -lboost_filesystem -lboost_thread -lpthread -Wl,-Bdynamic -lrt
I attatch the lld unix library command output for my library.
ldd ../../lib-arm/libCustomLibrary.so
/usr/lib/arm-linux-gnueabihf/libcofi_rpi.so (0x76e5d000)
libSubLibrary.so => ../../lib-arm/libSubLibrary.so (0x76e2d000)
librt.so.1 => /lib/arm-linux-gnueabihf/librt.so.1 (0x76e10000)
libstdc++.so.6 => /usr/lib/arm-linux-gnueabihf/libstdc++.so.6 (0x76d3e000)
libm.so.6 => /lib/arm-linux-gnueabihf/libm.so.6 (0x76ccd000)
libgcc_s.so.1 => /lib/arm-linux-gnueabihf/libgcc_s.so.1 (0x76ca5000)
libc.so.6 => /lib/arm-linux-gnueabihf/libc.so.6 (0x76b75000)
libdl.so.2 => /lib/arm-linux-gnueabihf/libdl.so.2 (0x76b6a000)
libpthread.so.0 => /lib/arm-linux-gnueabihf/libpthread.so.0 (0x76b4b000)
/lib/ld-linux-armhf.so.3 (0x76f05000)
From https://lists.linaro.org/pipermail/linaro-toolchain/2012-November/002939.html :
Relocation type 3 is R_ARM_REL32 which is a static relocation not allowed in shared objects. How did you create the shared lib? Make sure you compile all the code going into it with -fPIC.
In other words, you are using -fPIC when linking your program, but perhaps not when building your shared library.
Regarding:
./a.out
./a.out: error while loading shared libraries: ../../lib-arm/libCustomLibrary.so: unexpected reloc type 0x03
I think you need to show the relevant source code for libCustomLibrary.so. You can see which symbol is causing the problem with:
LD_DEBUG=all ./a.out
After the verbose output, the last symbol mentioned will be the problem. For example, testing Cryptogams SHA, which is hand written asm, in a shared object results in:
10419: relocation processing: /home/test/libcryptopp-8.3.0.so.8 (lazy)
10419: symbol=CRYPTOGAMS_armcaps; lookup in file=/home/test/libcryptopp.so.8 [0]
10419: binding file /home/test/libcryptopp.so.8 [0]: normal symbol `CRYPTOGAMS_armcaps'
/home/test/: error while loading shared libraries: /home/test/libcryptopp.so.8: unexpected reloc type 0x03
So I know the problem is with the CRYPTOGAMS_armcaps symbol. You can confirm with objdump -r. R_ARM_REL32 is symbol type 0x03.
$ objdump -r sha1-armv4.o
sha1-armv4.o: file format elf32-littlearm
RELOCATION RECORDS FOR [.text]:
OFFSET TYPE VALUE
000004d0 R_ARM_REL32 CRYPTOGAMS_armcaps
Then you can go back to the source file and fix the problem with the symbol.
Also, from Crypto++ Issue 846, ARM and "unexpected reloc type 0x03" loading shared object, I know it is not as simple as using -fPIC. Everything was built with -fPIC and the problem still surfaced.
来源:https://stackoverflow.com/questions/33474070/unexpected-reloc-type-0x03