Main Page | Report this Page
 
   
Linux Forum Index  »  Linux Development - Applications  »  symbol versioning...
Page 1 of 1    
Author Message
Sirius Black...
Posted: Fri Aug 01, 2008 7:26 pm
Guest
Hello,

I need to load multiple versions of a library in the same address
space. I cannot use dlopen because library dependency is not direct,
and because many parts of code link with this library. For ex., my
application depends on version M of library X, while a third party
library that we link with, depends on version N of library X, where
version M and N are incompatible.

I don't understand symbol versioning fully, but as per my
understanding, they solve this problem and allow us to load multiple
versions of same library in memory. I want to add version information
to all the symbols in our library X, so that both the versions can
reside in memory. I tried to search online for an user level
description of how to add version information to a shared library, but
I am unable to find a document that describes this.

I tried by writing a simple version script:

LIB1_1.0
{
global:
*;
};

I am building my library by passing this version script as an argument
to ld, using --version-script option. Using readelf, I am able to find
that the version information is added to the symbol in .dynsym symbol
table [and not in .symtab, unless I link with --export-dynamic].
However, when I link this library with my main program, I see that the
main program does not record its needed version information. Because
of this, it can work with any version of the library. How can I link
my main program so that it records its needed version information, and
makes use of that symbols alone?

Can some one please tell me whether this is the right way to load
multiple versions of same library? Is there any better way?

I am using 32 bit Intel C++ compiler on RHEL 4.0. Because gcc and
intel c++ are object compatible, please tell me even if the solution
is specific to gcc.

If this is not the right place to ask this question, kindly point out
the right news group.

Regards,
Sirius

[I will post this to some other news group too]
Paul Pluzhnikov...
Posted: Sat Aug 02, 2008 5:46 pm
Guest
Sirius Black <hari.usenet at (no spam) gmail.com> writes:

Quote:
I need to load multiple versions of a library in the same address
space.

Generally, this is a loosing proposition, and you'll likely be
better off rethinking your requirements.

Quote:
I cannot use dlopen because library dependency is not direct,
and because many parts of code link with this library. For ex., my
application depends on version M of library X, while a third party
library that we link with, depends on version N of library X, where
version M and N are incompatible.

You are SOL.

Quote:
I don't understand symbol versioning fully, but as per my
understanding, they solve this problem and allow us to load multiple
versions of same library in memory.

No, they don't. They solve a different problem: that of providing
two or more incompatible implementations of the same function in
a *single* library.

Quote:
I am building my library by passing this version script as an argument
to ld, using --version-script option. Using readelf, I am able to find
that the version information is added to the symbol in .dynsym symbol
table [and not in .symtab, unless I link with --export-dynamic].
However, when I link this library with my main program, I see that the
main program does not record its needed version information.

That's not what is supposed to happen, but it is hard to tell
exactly what is happening, since you didn't provide relevant details
(e.g. command line actually used to link the main program; the names
of the libraries; the output from 'readelf -s' for the libraries
that are used during linking of the main program).

Quote:
How can I link
my main program so that it records its needed version information, and
makes use of that symbols alone?

Even if you manage to do that, you'd still be SOL: since the
third-party library uses unversioned symbols, it will bind to the
first symbol with the same name (versioned or not), which likely
will be the wrong one.

Quote:
Can some one please tell me whether this is the right way to load
multiple versions of same library? Is there any better way?

There isn't the right way. Don't do it.

Quote:
If this is not the right place to ask this question, kindly point out
the right news group.

You've multi-posted this to many groups, which is quite annoying.
Please learn to cross-post instead.

You may also wish to come up with a simple test case illustrating
the problem you are trying to solve.

Cheers,
--
In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.
John Reiser...
Posted: Tue Aug 05, 2008 9:10 am
Guest
Quote:
If I understand it correctly, each of these module branches maintain
their own symbol table. If the symbols are not available in a module
symbol table, does it load the required libraries? Like libc, stdc++,
etc., If we assume that the library that we are going to load is not
going to depend as much on the libraries that are already loaded,
should we bother about controlling communication?

The symbol tables ({DT_HASH, DT_GNU_HASH} + DT_SYMTAB + DT_STRTAB) are
the ones in each module (.so, main). What turns them into "one" table
is the search order for resolving a reference: which symbol tables are
consulted, and in which order. Under dlmopen the [basic] search order
is the path to the root along the branch containing the referring module,
except that each node contains a list of modules that were loaded at
the same time by one call to dlopen/dlmopen.

Get the source code to glibc, and consult include/link.h for the internal
definition of struct link_map. The public definition in <link.h> is only
a small prefix of the real thing. Note the various "struct r_scope_elem"
which contain lists of struct link_map * to be searched. Of course
these fields may not be referenced except internally by glibc (they *do*
change from release to release) but understanding their purpose and uses
is reasonably necessary for effective use of dlmopen.

--
Sirius Black...
Posted: Mon Aug 11, 2008 6:59 pm
Guest
On Aug 5, 7:10 pm, John Reiser <jrei... at (no spam) BitWagon.com> wrote:
Quote:
If I understand it correctly, each of these module branches maintain
their own symbol table. If the symbols are not available in a module
symbol table, does it load the required libraries? Like libc, stdc++,
etc., If we assume that the library that we are going to load is not
going to depend as much on the libraries that are already loaded,
should we bother about controlling communication?

The symbol tables ({DT_HASH, DT_GNU_HASH} + DT_SYMTAB + DT_STRTAB) are
the ones in each module (.so, main).  What turns them into "one" table
is the search order for resolving a reference: which symbol tables are
consulted, and in which order.  Under dlmopen the [basic] search order
is the path to the root along the branch containing the referring module,
except that each node contains a list of modules that were loaded at
the same time by one call to dlopen/dlmopen.


Thanks for the reply. I am able to test load my library by making use
of dlmopen, and it appears to work fine.

Quote:
Get the source code to glibc, and consult include/link.h for the internal
definition of struct link_map.  The public definition in <link.h> is only
a small prefix of the real thing.  Note the various "struct r_scope_elem"
which contain lists of struct link_map * to be searched.  Of course
these fields may not be referenced except internally by glibc (they *do*
change from release to release) but understanding their purpose and uses
is reasonably necessary for effective use of dlmopen.


I will do this.

Quote:
--

Best Regards,
Sirius
 
Page 1 of 1       All times are GMT - 5 Hours
The time now is Sat Nov 22, 2008 11:27 am