Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Multiple Loads of a shared library

Posted on 2003-02-20
4
Medium Priority
?
328 Views
Last Modified: 2010-04-21
I am trying to write a daemon that accesses non-reentrant libraries that are dynamically loaded.  The job of these libraries is to go fetch and process data from various sources, then return the homogenized results when done.  I'm multi-threading the application to hopefully speed up data requests by reducing wait time.  The problem I'm having is trying to load the same reader library multiple times in the same process.  When I use the dlopen on the library twice, it returns exactly the same handle the second time as the previous.  I've attempted to use mmap on the file, but then I can't call dlsym.  This makes sense, but that implies that I need to parse for various executable file formats (aout, coff, elf, etc.).  Getting the file format isn't necessarily a problem, but is there a nice library created that I can just pass the memory that I've mapped to get the function pointers I need from the library?  Or is there a more elegant solution?  One idea I've been given is to create a temporary copy of the file, but that just seems kludgy.  I'd really like a nice elegant solution.

Thanks.  I know this isn't your typical 2 banana problem, so I've given the most the thing would allow me to submit it as.
0
Comment
Question by:ChefInnocent
4 Comments
 
LVL 51

Expert Comment

by:ahoffmann
ID: 7993718
beside I cannot follow your thought why a shared lib cannot be used twice or more, how about following:

 1. copy your shared lib to different locations, let's say directory a b c d ...
 2. write a shell wrapper like:
    #! /bin/sh
    LD_LIBRARY_PATH="/path/to/$1:${LD_LIBRARY_PATH}"
    export LD_LIBRARY_PATH
    /path/to/your-script
 3. call above wrapper like:
    wrapper a
    wrapper b
    wrapper c
    ...
0
 
LVL 1

Accepted Solution

by:
BernhardBrueck earned 1500 total points
ID: 7994430
bad news first:
Simple mapping the library multiple time into memory won't work. Even if you get the entrance points of the functions inside the library you can't simple call them. The library itself may call functions outside (e.g. C-libs) which need to be resolved as well. When the libs are not compiled as reentrant
you  would even end with multible c-libs etc.

better solution:
use processes and communicate through files or shared mem

tmp = create new tmpfile
if fork() {                         // child ?
            dlopen('broken_lib');
            init_lib;
     use_library;
     write result to tmp;
     exit;                          // end child
}
watifor child                     // parent
read result from tmp

Hope that help,
     Bernhard Brueck
0
 
LVL 9

Expert Comment

by:mglxxx
ID: 8025734
I agree with BernhardBrueck. His suggestion looks
much simpler than what you are trying to do and
will definitely work.
Even if you could simply 'parse' the library for
the entry points and jump to them, you'd also need
to find any static initialisers and call them
before using the library.
0
 

Author Comment

by:ChefInnocent
ID: 8028220
Although I have decided to attack the problem differently, it does appear that the answer BernhardBrueck gave does work.  Thanks.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Integration Management Part 2

577 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question