LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-27-2011, 06:46 PM   #1
debuser123
Member
 
Registered: Nov 2006
Distribution: Ubuntu Hardy
Posts: 69

Rep: Reputation: 15
Question Linking PIC and non-PIC code...into a shared library


Note: I am on Solaris

The final output of what I have to put together must be a shared library (.so) that will be loaded by another executable.

To keep it simple, let's say I have two C files which are compiled into their respective object files. The problem is that one of those C files use functions from a static library. So when creating the shared library, I have to specify -L/directory/of/libsomestuff.a -lsomestuff. I also must specify "-z text" which spawns a fatal link error if there are relocations against the text(non-writable) section...which is the problem I am running into.

The (expected) error I get is: “relocations remain against allocatable but non-writable sections”

Is there any way around this? Is there some way I can make the referenced code in the static library somehow PIC at link-time (or even compile-time)? I don't control the static library and cannot modify it, nor do I have the source to recompile it. Suggestions?
 
Old 03-27-2011, 06:58 PM   #2
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Hi -

I tried to look up the old Solaris "Linkers and Libraries Guide" (which used to be online, at docs.sun.com), but Oracle has completed ****'ed it up. Sorry

Anyway, I believe the answer to your question is to add "-mimpure-text" to your ld command.

Things you might want to Google for (perhaps you'll have more luck than I did) are:

Solaris linker and libraries guide

Solaris how to link stdc++ and libgcc

Last edited by paulsm4; 03-27-2011 at 07:00 PM.
 
Old 03-27-2011, 09:50 PM   #3
debuser123
Member
 
Registered: Nov 2006
Distribution: Ubuntu Hardy
Posts: 69

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by paulsm4 View Post
Hi -

I tried to look up the old Solaris "Linkers and Libraries Guide" (which used to be online, at docs.sun.com), but Oracle has completed ****'ed it up. Sorry

Anyway, I believe the answer to your question is to add "-mimpure-text" to your ld command.

Things you might want to Google for (perhaps you'll have more luck than I did) are:

Solaris linker and libraries guide

Solaris how to link stdc++ and libgcc
Hi paulsm4, and thanks for your reply. I had came across the -mimpure-text option but it seems what that does is not send "-z text" to the linker. And based on some trial/error, this option doesn't seem to have an effect if "-z text" is on the linker's command line (makes sense).

I guess, is the bottom line that there is no way around linking non PIC code from a static lib into a shared object without forcing the linker to ignore relocation messages? In other words, just telling the linker, "it's ok, I know what I'm doing" is the only way? If that's true, then I guess what I need to create isn't possible, as my final link command must have "-z text" in it (it's the "rules").
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Writing code for picture management (slide show with varying times for each pic.) mmmojojojo Programming 3 09-11-2012 02:18 AM
Where do I start? to create slide show thru code, varying time each pic is shown. mmmojojojo Linux - Newbie 2 07-08-2008 08:19 AM
LINUX - linking archive (static library) with shared (dynamic) library gurkama Programming 5 03-04-2007 11:11 PM
PIC files/library? ashlesha Linux - Newbie 1 11-08-2006 02:13 PM
Non-PIC code a security vulnerability..How?? kingkhan2006 Linux - Security 1 03-31-2006 04:58 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:29 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration