The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM


High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to export jisha BSD 4 01-21-2008 03:06 AM
export??? Justinkase Shell Programming and Scripting 1 12-03-2007 02:32 PM
nfs export permissions psimoes79 HP-UX 1 10-13-2007 01:12 AM
confusion with export kdipankar Shell Programming and Scripting 1 05-11-2006 02:07 AM
export variables srishan Shell Programming and Scripting 4 07-06-2004 09:53 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-29-2006
Hitori's Avatar
Registered User
 

Join Date: Jun 2006
Posts: 356
export-dynamic

I load some dynamic libraries from main module (with dlopen). These libraries use 1 function from main module, therefore in Makefile I must use

gcc -g -Wl,--export-dynamic,-rpath,./lib -o not not.o db.o -ldl -ldb -lpcap

Note option --export-dynamic that is passed to the ELF linker.

The question is how can I determine which symbols must be put to the dynamic symbol table. I do not want to put all symbols, but putting only used once the function called by dynamically loaded libraries is not visible for these libraries.
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 06-29-2006
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 3,858
If I understand your question:
dynamic loading means you know the symbol names and the libraries names ahead of time - for the all the entrypoints you are going to map dynamically by calling dlopen yourself...

Right?

Code:
nm myexcutablefile
will list all of the external symbols your program uses. There will be a lot of them that are part of __start and the general C support runtime. Your special symbols need to be mapped by a call to dlopen.

Am I on track so far?
Reply With Quote
  #3 (permalink)  
Old 06-30-2006
Hitori's Avatar
Registered User
 

Join Date: Jun 2006
Posts: 356
This is not what I meant
Suppose I have 2 files: main.c, lib.c
Function func1() is defined in main.c, and lib.so is loaded from main.c: dlopen("lib.so", RTLD_LAZY)
Then func1() is called from lib.c. Becouse of this I need to put all symbols to the dynamic symbol table:
gcc -g -Wl,--export-dynamic,-rpath,. -o main main.o -ldl
How can put only func1() to the dynamic symbol table (omitting other symbols)?
Reply With Quote
  #4 (permalink)  
Old 06-30-2006
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 3,858
Sorry. I did not understand.

Since you are in a GNU development environment do you know about libltdl?
This allows you to handle what you are doing. See:
http://www.gnu.org/software/libtool/...#Using-libltdl

If you don't like that - what you have to do in code: do not directly reference the module you want by name, this is how you "hide" it from ld.

Example:
Code:
#include <stdlib.h>
#include <stdio.h>
#include <dlfcn.h>

int main(int argc, char **argv) {
    void *libhandle=NULL;
    double (*myfunc)(double);
    char *errormsg=NULL;

    libhandle = dlopen ("/lib/libwhatever.so.1", RTLD_LAZY);
    if (!libhandle) {
        fputs (dlerror(), stderr);
        exit(EXIT_FAILURE);
    }

    myfunc = dlsym(libhandle, "myfunction");
    if ((errormsg = dlerror()) != NULL)  {
        fputs(errormsg, stderr);
        exit(EXIT_FAILURE);
    }

    printf ("%f\n", (*myfunc)(1.0));
    dlclose(libhandle);
    return 0;
}
You cannot hide fully qualified symbols from ld - it will try to link against each one, or generate an error.

Again, this is what I think you are saying: you have not "hidden" all the symbols. Correct me if I'm wrong. You can't play mix-n-match, some hidden, some not.
Reply With Quote
  #5 (permalink)  
Old 06-30-2006
Hitori's Avatar
Registered User
 

Join Date: Jun 2006
Posts: 356
Tanks a lot for a reply
I've solve my problem by moving the 'visible' functions (func1() in above example) from main module to another library that is linked at runtime
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 08:15 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0