Simpler Navigation for Servers and Operating Systems - Please Update Your Bookmarks
Completed: a much simpler Servers and Operating Systems section of the Community. We combined many of the older boards, so you won't have to click through so many levels to get at the information you need. Check the consolidated boards here as many sub-forums are now single boards.
If you have bookmarked forums or discussion boards in Servers and Operating Systems, we suggest you check and update them as needed.
cancel
Showing results for 
Search instead for 
Did you mean: 

shared objects

lara
Advisor

shared objects

Hi,

Is there a way to find whether an object(.o file ) is compiled with -pic or not.

Regards,
Lara
5 REPLIES
Stuart Browne
Honored Contributor

Re: shared objects

Not 100% sure I'm afriad, but by doing some tests locally, using '-fPIC' (as '-pic' using a modern gcc doesn't work), with the tool 'readelf', a -fPIC binary has references to "_GLOBAL_OFFSET_TABLE_", where as an object compiled without -fPIC doesn't..

I've not done enough programming to actually know what '-pic' or '-fPIC' are supposed to do..
One long-haired git at your service...
lara
Advisor

Re: shared objects

Seems to be not neccessarly true. Anyway thanks for your suggestion.

Lara
lara
Advisor

Re: shared objects

Seems to be not necessarly true. Anyway thanks for your suggestion.

Lara
Umapathy S
Honored Contributor

Re: shared objects

Lara,
I dont have a linux box nearby to test it. But in hpux the file command gives out "relocatable" for position independent code. As you might be aware for the shared libs you need to have PIC.
Just compile a c file both ways and test it on the box.

HTH,
Umapathy
Arise Awake and Stop NOT till the goal is Reached!
lara
Advisor

Re: shared objects

Umapathy,

relocatable need not necessarly mean the object file has position independent code.

Lara