?
Solved

Multiple Loads of a shared library

Posted on 2003-02-20
4
Medium Priority
?
320 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

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

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
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…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

770 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