06-15-2012 08:38 PM - edited 06-15-2012 09:20 PM
One of the projects I'm working on involves a static library for a bunch of "boilerplate code", a shared library for specific functionality (uses static lib), and an executable for, well, execution (uses static lib and shared lib).
The static library compiler just fine. But when I try to compile the shared library, which links to the static library, I get the following error:
C:\bbndk-2.1.0-beta1\host\win32\x86\usr\bin\ntoarm-ld: {static lib path}.a({object file}.o): relocation R_ARM_MOVW_ABS_NC against `__stack_chk_guard' can not be used when making a shared object; recompile with -fPIC
Any knowledge of what has happened?
I know I can simply specify -fPIC and be done with it, but I admittidly don't know if I specify it for the static library or the shared library. I think shared.
Edit: Ok, I now know I need to specify it on the static library.
Regardless, does anyone know what might have caused something like this and is -fPIC the only way to fix it?
Solved! Go to Solution.
06-18-2012 11:45 AM
Hello,
-fpic and -fPIC generate position independent code, a requirement for shared libraries. If you were asking about what the __stack_check_guard is, you can find more information about it at http://wiki.osdev.org/GCC_Stack_Smashing_Protector
Cheers
Selom
06-18-2012 09:15 PM
06-19-2012 09:09 AM
Hello again,
it's not caused by your code. The stack smashing protector is automatically inserted by the compiler to prevent stack overflows, without -fPIC your lib cannot be loaded.
Cheers
Selom
06-19-2012 11:06 AM
Ok, so it "just is" and I should always use -fPIC for a static library.
06-19-2012 11:27 AM
Indeed, plus you get buffer overflow protection for free. I highly recommend it for all apps.
However if you're the tinkering type, you can try disabling that option in gcc by removing the -fstack-protector-all compile file in the project properties->c/c++ build->settings->tool settings->QCC Compiler->Output control and unchecking the "Enhanced Security" option.
Cheers
Selom
06-19-2012 03:07 PM
Extra security for free? Why disable it? ![]()