clang, -fPIC & R_PPC_REL24

I’m getting the following error when running a ppc (32 bit) exe on a linux-ppc board.

./testPocsn

./testPocsn: error while loading shared libraries: /usr/lib/libc++.so.3: R_PPC_REL24 relocation at 0x0fbd7928 for symbol `__cxa_guard_acquire’ out of range

A bunch of digging online suggests that the solution to this problem for the shared lib to be compiled with ‘-fPIC’. I checked the build logs on libc++ and it is already compiled with -fPIC.

I also understand that if -fPIC is issued, then the shared lib should not contain any relative addressing entries (R_PPC_REL24), but

powerpc-unknown-linux-readelf -D -r libc++.so

reveals…

00051928 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
0005e48c 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
0005e57c 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
0005e8c4 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
0005eb14 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
0005effc 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
0005f310 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
0005f5e8 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
0005f7a4 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
0005f970 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
0005fb18 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
0005fc08 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
0005fe28 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
00060148 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
00060324 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
00060508 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
000606f4 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
000608dc 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
00060b34 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
00060df0 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
000612ac 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
00061580 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
000617a4 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
000619d4 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
00061c04 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
00062110 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
000622f4 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
00062610 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
0006281c 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
000629d8 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
00062bc4 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
00062d80 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
00062f6c 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
00063b14 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
00064660 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
00076e74 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
0007848c 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
0007a280 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
0007a488 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
0007add4 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
0007af08 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
0007b254 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
0007c0f0 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
0007eb48 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
0007ec54 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
0007eccc 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
000808f8 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
000809f8 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
00080b44 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
00080cc0 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
00080e2c 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
00080f58 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
00081044 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
00081184 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
000812b8 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
000813a4 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
000814e4 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
00081730 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
000818fc 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
00081a30 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
00081b58 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
00081c8c 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
00081ec4 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
0008212c 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
00082c04 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
0008372c 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
0008382c 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
00088d68 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
00088de4 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
00089014 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
00089090 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
000892c0 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
0008933c 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
00089634 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
000896b0 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
000899a8 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
00089a24 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
00089b64 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
00089be0 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
00089d20 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
00089e2c 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
00089f44 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
0008a050 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
0008a168 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
0008a274 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
0008a38c 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
0008a498 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
0008d434 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
00092ed0 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
00098614 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
00099eb0 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
0009a91c 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
0009abec 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
0009aeb8 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
0009b1fc 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
0009b2f8 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
0009b908 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
0009b9f4 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
0009bfc4 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
0009c138 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
0009c4e0 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
0009ce8c 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
0009d808 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
0009dad8 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
0009dda4 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
0009e0e8 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
0009e1e4 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
0009e6f8 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
0009e7e4 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
0009edc8 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
0009ef3c 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
0009f2e0 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
000a6184 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
000a6294 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
000a6790 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
000a6898 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
000a69a0 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
000a6dd0 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
000a6ee0 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
000a73e8 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
000a74f0 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
000a75f8 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
000a7c04 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
000a7d0c 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
000a7e14 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
000a8124 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
000a822c 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
000a8334 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
000affac 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
000b18f0 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
000b3ecc 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
000b3fe4 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
000b40fc 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
000b50ac 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
000b524c 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
000b536c 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
000b558c 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
000b5744 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
000b5978 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
000b5b24 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
000b5ce8 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
000b5e7c 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
000b6014 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
000b61ac 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
000b6348 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
000b6500 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
000b7054 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
000cdca8 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
000cde78 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
000cdf58 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
000ceca0 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0
000cf164 0000db0a R_PPC_REL24 00000000 __cxa_guard_acquire + 0

questions….

Is this correct behavior for clang? If you specify the -fPIC, is ok to have R_PPC_REL24 references? If the behavior is correct, then why is the library loading failing?

further info…

this issue is resolved by building the final exe with -pie. I’m not sure why the final exe has to be position independent just because some of the libraries are shared libs.