Linux Shared Library build question...


 
Thread Tools Search this Thread
Operating Systems Linux Linux Shared Library build question...
# 1  
Old 10-20-2011
Linux Shared Library build question...

I'm a bit new to Linux systems programming. I've been programming at the systems level for over 20 years on various other platforms, but I'm not as familiar with the GCC toolchain as I'd like to be (but I'm learning quickly)...Smilie...

Our target is an ARM-based Linux Embedded system. We're using NPTL in most processes.

When using GCC to build shared libraries composed of multiple objects does each .o file have to be compiled with Position Independent Code options, or is it ok to simply invoke GCC during the final stage to compile/link and combine all the objects together specifying Position Independent Code options at that time along with the -shared option as well?

The reason I ask is I'm doing Remote GDB debugging on an embedded target, and I'm dynamically loading a shared library from my process via dlopen(), getting a function entry point with dlsym() and then indirectly invoking the function in the shared library. Under the above build scenario when I look at the resultant disassembly, say in a call to memset(), it simply loads an immedate offset for the target of the memset(), and this traps. Coincidently, the offset value is the same value assigned to the symbol when I dump the library with OBJDUMP. If I examine the target address passed to memset() the debugger doesn't appear to be able to access this address (no doubt why it traps). If I compile all objects with PIC options prior to the final stage above than the assembly code looks like it calculates the target address before calling memset(), and it doesn't trap.

In reading the GCC documentation it mentions the GOT, and from the above it appears that the loader isn't properly fixing up the symbol in question when each individual object isn't compiled with PIC options.

It was difficult enough getting the remote GDB environment set up to properly debug symbolically under a threaded dynamically loaded library scenario, so I've gotta' ask "Is this just an artifact of this type of symbolic debugging?"

The reason I say this is that our whole build system is setup to produce all the shared libraries we've written in this manner and no other team members have reported any issues running without a debugger (most of them don't use a debugger at all). All programs that run against these libraries are linked against the shared libraries, they are not performing dlopen() calls to access them like I am. The build system has been set up by an experienced Linux Systems Administrator.

I'm trying to get to the bottom of this. If anyone knows anything about this I'd appreciate their input.

Thanks in advance.
# 2  
Old 10-20-2011
I see -fPIC used for nearly any libraries under Linux.

I suspect this is to do with remote debugging; what happens with local debugging?
# 3  
Old 10-21-2011
Not sure what happens with local debugging. Without GDB GUI interface debugging is quite tedious from the console only.

When you say -fPIC being used do you mean for all objects or just during the last phase of combining objects during the link stage?
# 4  
Old 10-27-2011
Sorry, missed your question.

Code is generated during the compilation phase, so if you want this code to be position independent, you have to tell the compilation phase...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

Add shared members from library to same library in a different directory

I'm trying to install libiconv to AIX 7.1 from an rpm off of the perzl site. The rpm appears to install but I get this error message. add shr4.o shared members from /usr/lib/libiconv.a to /opt/freeware/lib/libiconv.a add shr.o shared members from /usr/lib/libiconv.a to ... (5 Replies)
Discussion started by: kneemoe
5 Replies

2. Programming

Shared library with acces to shared memory.

Hello. I am new to this forum and I would like to ask for advice about low level POSIX programming. I have to implement a POSIX compliant C shared library. A file will have some variables and the shared library will have some functions which need those variables. There is one special... (5 Replies)
Discussion started by: iamjag
5 Replies

3. Shell Programming and Scripting

How to change a Makefile from building static library to shared library?

Hi: I have a library that it only offers Makefile for building static library. It built libxxx.a file. How do I in any way build a shared library? (either changin the Makefile or direct script or command to build shared library) Thanks. (1 Reply)
Discussion started by: cpthk
1 Replies

4. HP-UX

Shared Library Issue HP UX

I have never seen this issue before, but here is what is happening. I link an executable against two dynamic mlib libraries veclib and lapack. We place a newer version of these libraries in a write only directory and point the shlib_path at that directory. When the executable runs, it gets a... (3 Replies)
Discussion started by: sambarusty
3 Replies

5. Programming

Shared memory for shared library

I am writing a shared library in Linux (but compatible with other UNIXes) and I want to allow multiple instances to share a piece of memory -- 1 byte is enough. What's the "best" way to do this? I want to optimize for speed and portability. Obviously, I'll have to worry about mutual exclusion. (0 Replies)
Discussion started by: otheus
0 Replies

6. Programming

Using funcion in a shared library

Is there any way in C to access a function in C shared library. I have used dlopen to access /load the c shared library but unable to use the function in the shared object. Thanks in advance :b: (1 Reply)
Discussion started by: yhacks
1 Replies

7. Programming

Shared memory in shared library

I need to create a shared library to access an in memory DB. The DB is not huge, but big enough to make it cumbersome to carry around in every single process using the shared library. Luckily, it is pretty static information, so I don't need to worry much about synchronizing the data between... (12 Replies)
Discussion started by: DreamWarrior
12 Replies

8. UNIX for Advanced & Expert Users

shared library

What is the primary difference between static library and dynamic library? and how to write static shared library? (1 Reply)
Discussion started by: areef4u
1 Replies

9. SCO

Creation of Shared library

Hi all, I am new to sco unix. I would like to know abt the procedure to create shared library in Sco-unix. Is it differ from linux? any help?? Thanx in Advance!!!!! (0 Replies)
Discussion started by: sarangb
0 Replies

10. Programming

Shared Library

hello all I want to work in shared libraries how can i work in Linux Environment ? (2 Replies)
Discussion started by: rajashekaran
2 Replies
Login or Register to Ask a Question