Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
rcmaniac25
Posts: 1,804
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.2.1.2174, Z10 (STL100-3)-10.3.0.700 Dev OS, Z30 (STA100-5)-10.3.0.700 Dev OS, PlayBook (16GB)-2.1.0.1917
My Carrier: Verizon
Accepted Solution

Stack guard and PIC

[ Edited ]

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?

---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.
Please use plain text.
BlackBerry Development Advisor (Retired)
selom
Posts: 60
Registered: ‎05-10-2012
My Device: Blackberry 10 Alpha
My Carrier: none

Re: Stack guard and PIC

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

Please use plain text.
Developer
rcmaniac25
Posts: 1,804
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.2.1.2174, Z10 (STL100-3)-10.3.0.700 Dev OS, Z30 (STA100-5)-10.3.0.700 Dev OS, PlayBook (16GB)-2.1.0.1917
My Carrier: Verizon

Re: Stack guard and PIC

I understand that. What I am interested in knowing is what might have caused me to get the error I specified in my original post, like what kind of code.

I mentioned in an edit in my original post that I found I needed to specify it on the static library. Is specifying -fPIC on the static library the only way to get around this error short of a code rewrite (if it is even caused by some code).
---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.
Please use plain text.
BlackBerry Development Advisor (Retired)
selom
Posts: 60
Registered: ‎05-10-2012
My Device: Blackberry 10 Alpha
My Carrier: none

Re: Stack guard and PIC

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

Please use plain text.
Developer
rcmaniac25
Posts: 1,804
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.2.1.2174, Z10 (STL100-3)-10.3.0.700 Dev OS, Z30 (STA100-5)-10.3.0.700 Dev OS, PlayBook (16GB)-2.1.0.1917
My Carrier: Verizon

Re: Stack guard and PIC

Ok, so it "just is" and I should always use -fPIC for a static library.

---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.
Please use plain text.
BlackBerry Development Advisor (Retired)
selom
Posts: 60
Registered: ‎05-10-2012
My Device: Blackberry 10 Alpha
My Carrier: none

Re: Stack guard and PIC

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

Please use plain text.
Developer
rcmaniac25
Posts: 1,804
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.2.1.2174, Z10 (STL100-3)-10.3.0.700 Dev OS, Z30 (STA100-5)-10.3.0.700 Dev OS, PlayBook (16GB)-2.1.0.1917
My Carrier: Verizon

Re: Stack guard and PIC

Extra security for free? Why disable it? :smileytongue:

---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.
Please use plain text.