Sponsored Content
Operating Systems Linux Linux Shared Library build question... Post 302566654 by jcossette on Thursday 20th of October 2011 07:13:32 PM
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.
 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
confstr(3C)						   Standard C Library Functions 					       confstr(3C)

NAME
confstr - get configurable variables SYNOPSIS
#include <unistd.h> size_t confstr(int name, char *buf, size_t len); DESCRIPTION
The confstr() function provides a method for applications to get configuration-defined string values. Its use and purpose are similar to the sysconf(3C) function, but it is used where string values rather than numeric values are returned. The name argument represents the system variable to be queried. If len is not 0, and if name has a configuration-defined value, confstr() copies that value into the len-byte buffer pointed to by buf. If the string to be returned is longer than len bytes, including the terminating null, then confstr() truncates the string to len-1 bytes and null-terminates the result. The application can detect that the string was truncated by comparing the value returned by confstr() with len. If len is 0, confstr() still returns the integer value as defined below, but does not return the string. The confstr() function supports the following values for name, defined in <unistd.h>, for both SPARC and x86: _CS_LFS64_CFLAGS If _LFS64_LARGEFILE is defined in <unistd.h>, this value is the set of initial options to be given to the cc and c89 utilities to build an application using the Large File Summit transitional compilation environment (see lfcompile64(5)). _CS_LFS64_LDFLAGS If _LFS64_LARGEFILE is defined in <unistd.h>, this value is the set of final options to be given to the cc and c89 utilities to build an application using the Large File Summit transitional compilation environment (see lfcompile64(5)). _CS_LFS64_LIBS If _LFS64_LARGEFILE is defined in <unistd.h>, this value is the set of libraries to be given to the cc and c89 utilities to build an application using the Large File Summit transitional compilation environment (see lfcompile64(5)). _CS_LFS64_LINTFLAGS If _LFS64_LARGEFILE is defined in <unistd.h>, this value is the set of options to be given to the lint utility to check application source using the Large File Summit transitional compilation environment (see lfcompile64(5)). _CS_LFS_CFLAGS If _LFS_LARGEFILE is defined in <unistd.h>, this value is the set of initial options to be given to the cc and c89 utilities to build an application using the Large File Summit large file compilation environment for 32-bit applications (see lfcompile(5)). _CS_LFS_LDFLAGS If _LFS_LARGEFILE is defined in <unistd.h>, this value is the set of final options to be given to the cc and c89 utilities to build an application using the Large File Summit large file compilation environment for 32-bit applications (see lfcompile(5)). _CS_LFS_LIBS If _LFS_LARGEFILE is defined in <unistd.h>, this value is the set of libraries to be given to the cc and c89 utilities to build an application using the Large File Summit large file compilation environment for 32-bit applications (see lfcompile(5)). _CS_LFS_LINTFLAGS If _LFS_LARGEFILE is defined in <unistd.h>, this value is the set of options to be given to the lint utility to check application source using the Large File Summit large file compilation environment for 32-bit applications (see lfcompile(5)). _CS_PATH If the ISO POSIX.2 standard is supported, this is the value for the PATH environment variable that finds all standard utilities. Oth- erwise the meaning of this value is unspecified. _CS_POSIX_V6_ILP32_OFF32_CFLAGS If sysconf(_SC_V6_ILP32_OFF32) returns -1, the meaning of this value is unspecified. Otherwise, this value is the set of initial options to be given to the c99 utility to build an application using a programming model with 32-bit int, long, pointer, and off_t types. _CS_POSIX_V6_ILP32_OFF32_LDFLAGS If sysconf(_SC_V6_ILP32_OFF32) returns -1, the meaning of this value is unspecified. Otherwise, this value is the set of final options to be given to the c99 utility to build an application using a programming model with 32-bit int, long, pointer, and off_t types. _CS_POSIX_V6_ILP32_OFF32_LIBS If sysconf(_SC_V6_ILP32_OFF32) returns -1, the meaning of this value is unspecified. Otherwise, this value is the set of libraries to be given to the c99 utility to build an application using a programming model with 32-bit int, long, pointer, and off_t types. _CS_POSIX_V6_ILP32_OFFBIG_CFLAGS If sysconf(_SC_V6_ILP32_OFFBIG) returns -1, the meaning of this value is unspecified. Otherwise, this value is the set of initial options to be given to the c99 utility to build an application using a programming model with 32-bit int, long, and pointer types, and an off_t type using at least 64 bits. _CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS If sysconf(_SC_V6_ILP32_OFFBIG) returns -1, the meaning of this value is unspecified. Otherwise, this value is the set of final options to be given to the c99 utility to build an application using a programming model with 32-bit int, long, and pointer types, and an off_t type using at least 64 bits. _CS_POSIX_V6_ILP32_OFFBIG_LIBS If sysconf(_SC_V6_ILP32_OFFBIG) returns -1, the meaning of this value is unspecified. Otherwise, this value is the set of libraries to be given to the c99 utility to build an application using a programming model with 32-bit int, long, and pointer types, and an off_t type using at least 64 bits. _CS_POSIX_V6_LP64_OFF64_CFLAGS If sysconf(_SC_V6_LP64_OFF64) returns -1, the meaning of this value is unspecified. Otherwise, this value is the set of initial options to be given to the c99 utility to build an application using a programming model with 64-bit int, long, pointer, and off_t types. _CS_POSIX_V6_LP64_OFF64_LDFLAGS If sysconf(_SC_V6_LP64_OFF64) returns -1, the meaning of this value is unspecified. Otherwise, this value is the set of final options to be given to the c99 utility to build an application using a programming model with 64-bit int, long, pointer, and off_t types. _CS_POSIX_V6_LP64_OFF64_LIBS If sysconf(_SC_V6_LP64_OFF64) returns -1, the meaning of this value is unspecified. Otherwise, this value is the set of libraries to be given to the c99 utility to build an application using a programming model with 64-bit int, long, pointer, and off_t types. _CS_POSIX_V6_LPBIG_OFFBIG_CFLAGS If sysconf(_SC_V6_LPBIG_OFFBIG) returns -1, the meaning of this value is unspecified. Otherwise, this value is the set of initial options to be given to the c99 utility to build an application using a programming model with an int type using at least 32 bits and long, pointer, and off_t types using at least 64 bits. _CS_POSIX_V6_LPBIG_OFFBIG_LDFLAGS If sysconf(_SC_V6_LPBIG_OFFBIG) returns -1, the meaning of this value is unspecified. Otherwise, this value is the set of final options to be given to the c99 utility to build an application using a programming model with an int type using at least 32 bits and long, pointer, and off_t types using at least 64 bits. _CS_POSIX_V6_LPBIG_OFFBIG_LIBS If sysconf(_SC_V6_LPBIG_OFFBIG) returns -1, the meaning of this value is unspecified. Otherwise, this value is the set of libraries to be given to the c99 utility to build an application using a programming model with an int type using at least 32 bits and long, pointer, and off_t types using at least 64 bits. _CS_POSIX_V6_WIDTH_RESTRICTED_ENVS This value is a <newline>-separated list of names of programming environments supported by the implementation in which the widths of the blksize_t, cc_t, mode_t, nfds_t, pid_t, ptrdiff_t, size_t, speed_t, ssize_t, suseconds_t, tcflag_t, useconds_t, wchar_t, and wint_t types are no greater than the width of type long. _CS_XBS5_ILP32_OFF32_CFLAGS If sysconf(_SC_XBS5_ILP32_OFF32) returns -1 the meaning of this value is unspecified. Otherwise, this value is the set of initial options to be given to the cc and c89 utilities to build an application using a programming model with 32-bit int, long, pointer, and off_t types. _CS_XBS5_ILP32_OFF32_LDFLAGS If sysconf(_SC_XBS5_ILP32_OFF32) returns -1 the meaning of this value is unspecified. Otherwise, this value is the set of final options to be given to the cc and c89 utilities to build an application using a programming model with 32-bit int, long, pointer, and off_t types. _CS_XBS5_ILP32_OFF32_LIBS If sysconf(_SC_XBS5_ILP32_OFF32) returns -1 the meaning of this value is unspecified. Otherwise, this value is the set of libraries to be given to the cc and c89 utilities to build an application using a programming model with 32-bit int, long, pointer, and off_t types. _CS_XBS5_ILP32_OFF32_LINTFLAGS If sysconf(_SC_XBS5_ILP32_OFF32) returns -1 the meaning of this value is unspecified. Otherwise, this value is the set of options to be given to the lint utility to check application source using a programming model with 32-bit int, long, pointer, and off_t types. _CS_XBS5_ILP32_OFFBIG_CFLAGS If sysconf(_SC_XBS5_ILP32_OFFBIG) returns -1 the meaning of this value is unspecified. Otherwise, this value is the set of initial options to be given to the cc and c89 utilities to build an application using a programming model with 32-bit int, long, and pointer types, and an off_t type using at least 64 bits. _CS_XBS5_ILP32_OFFBIG_LDFLAGS If sysconf(SC_XBS5_ILP32_OFFBIG) returns -1 the meaning of this value is unspecified. Otherwise, this value is the set of final options to be given to the cc and c89 utilities to build an application using a programming model with 32-bit int, long, and pointer types, and an off_t type using at least 64 bits. _CS_XBS5_ILP32_OFFBIG_LIBS If sysconf(_SC_XBS5_ILP32_OFFBIG) returns -1 the meaning of this value is unspecified. Otherwise, this value is the set of libraries to be given to the cc and c89 utilities to build an application using a programming model with 32-bit int, long, and pointer types, and an off_t type using at least 64 bits. _CS_XBS5_ILP32_OFFBIG_LINTFLAGS If sysconf(_SC_XBS5_ILP32_OFFBIG) returns -1 the meaning of this value is unspecified. Otherwise, this value is the set of options to be given to the lint utility to check an application using a programming model with 32-bit int, long, and pointer types, and an off_t type using at least 64 bits. The confstr() function supports the following values for name, defined in <unistd.h>, for SPARC only: _CS_XBS5_LP64_OFF64_CFLAGS If sysconf(_SC_XBS5_LP64_OFF64) returns -1 the meaning of this value is unspecified. Otherwise, this value is the set of initial options to be given to the cc and c89 utilities to build an application using a programming model with 64-bit int, long, pointer, and off_t types. _CS_XBS5_LP64_OFF64_LDFLAGS If sysconf(_SC_XBS5_LP64_OFF64) returns -1 the meaning of this value is unspecified. Otherwise, this value is the set of final options to be given to the cc and c89 utilities to build an application using a programming model with 64-bit int, long, pointer, and off_t types. _CS_XBS5_LP64_OFF64_LIBS If sysconf(_SC_XBS5_LP64_OFF64) returns -1 the meaning of this value is unspecified. Otherwise, this value is the set of libraries to be given to the cc and c89 utilities to build an application using a programming model with 64-bit int, long, pointer, and off_t types. _CS_XBS5_LP64_OFF64_LINTFLAGS If sysconf(_SC_XBS5_LP64_OFF64) returns -1 the meaning of this value is unspecified. Otherwise, this value is the set of options to be given to the lint utility to check application source using a programming model with 64-bit int, long, pointer, and off_t types. _CS_XBS5_LPBIG_OFFBIG_CFLAGS If sysconf(_SC_XBS5_LPBIG_OFFBIG) returns -1 the meaning of this value is unspecified. Otherwise, this value is the set of initial options to be given to the cc and c89 utilities to build an application using a programming model with an int type using at least 32 bits and long, pointer, and off_t types using at least 64 bits. _CS_XBS5_LPBIG_OFFBIG_LDFLAGS If sysconf(_SC_XBS5_LPBIG_OFFBIG) returns -1 the meaning of this value is unspecified. Otherwise, this value is the set of final options to be given to the cc and c89 utilities to build an application using a programming model with an int type using at least 32 bits and long, pointer, and off_t types using at least 64 bits. _CS_XBS5_LPBIG_OFFBIG_LIBS If sysconf(_SC_XBS5_LPBIG_OFFBIG) returns -1 the meaning of this value is unspecified. Otherwise, this value is the set of libraries to be given to the cc and c89 utilities to build an application using a programming model with an int type using at least 32 bits and long, pointer, and off_t types using at least 64 bits. _CS_XBS5_LPBIG_OFFBIG_LINTFLAGS If sysconf(_SC_XBS5_LPBIG_OFFBIG) returns -1 the meaning of this value is unspecified. Otherwise, this value is the set of options to be given to the lint utility to check application source using a programming model with an int type using at least 32 bits and long, pointer, and off_t types using at least 64 bits. RETURN VALUES
If name has a configuration-defined value, the confstr() function returns the size of buffer that would be needed to hold the entire con- figuration-defined value. If this return value is greater than len, the string returned in buf is truncated. If name is invalid, confstr() returns 0 and sets errno to indicate the error. If name does not have a configuration-defined value, confstr() returns 0 and leaves errno unchanged. ERRORS
The confstr() function will fail if: EINVAL The value of the name argument is invalid. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |Standard | +-----------------------------+-----------------------------+ |MT-Level |Mt-Safe | +-----------------------------+-----------------------------+ SEE ALSO
pathconf(2), sysconf(3C), attributes(5), lfcompile(5), lfcompile64(5), standards(5) SunOS 5.10 15 Dec 2003 confstr(3C)
All times are GMT -4. The time now is 04:58 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy