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 07:06 AM
export??? Justinkase Shell Programming and Scripting 1 12-03-2007 06:32 PM
nfs export permissions psimoes79 HP-UX 1 10-13-2007 05:12 AM
confusion with export kdipankar Shell Programming and Scripting 1 05-11-2006 06:07 AM
export variables srishan Shell Programming and Scripting 4 07-06-2004 01:53 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-29-2006
Hitori's Avatar
Hitori Hitori is offline Forum Advisor  
Registered User
  
 

Join Date: Jun 2006
Posts: 360
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.
  #2 (permalink)  
Old 06-29-2006
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,787
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?
  #3 (permalink)  
Old 06-30-2006
Hitori's Avatar
Hitori Hitori is offline Forum Advisor  
Registered User
  
 

Join Date: Jun 2006
Posts: 360
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)?
  #4 (permalink)  
Old 06-30-2006
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,787
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.
  #5 (permalink)  
Old 06-30-2006
Hitori's Avatar
Hitori Hitori is offline Forum Advisor  
Registered User
  
 

Join Date: Jun 2006
Posts: 360
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
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:35 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0