From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Christian Jullien" To: "Gary V. Vaughan" , "Geoffrey Noer" Cc: "Jorrit Tyberghein" , Subject: RE: dlopen patch [was Re: dlopen] Date: Wed, 11 Nov 1998 04:22:00 -0000 Message-id: <000001be0d4d$16835060$020039c1@young> References: <364883FA.B4BB64EA@oranda.demon.co.uk> X-SW-Source: 1998-11/msg00485.html > Better late than never? Diffs attached. Interestingly, this doesn't > seem to fix my particular problem -- but unless there is funkiness with > casting from HMODULE (dlopen) to void* (dlsym) to HINSTANCE > (GetProcAddress), then by inspection it really ought to work, according > to the Borland Win32 API docs. > > I guess my implementation is awry somehow. > > Cheers, > Gary V. Vaughan Thank you for your post but the problem if (much ?) more complex. Your patch, the same I've already tested before, is not suffisent. dlsym supports a NULL handle (no needs to dlopen first), you can fix this with : void * dlsym (void *handle, const char *name) { - void * ret = (void *) GetProcAddress (handle, name); + void * ret = 0; + + if( handle ) + ret = (void *) GetProcAddress (handle, name); + else ret = (void *) GetProcAddress (GetModuleHandle(), name); if (!ret) set_dl_error ("dlsym"); debug_printf ("ret %p", ret); return ret; } But it does not work since all symbols MUST be exported (am I right ?). In my special case I can't export all symbols, I've also a lot (>= 50000) generated assembler lines. The HUGLY things I've made to work is to link my program 3 (THREE) times !! 1) 1st pass, I link my program with a dummy nlist.c file with : struct { unsigned long s_add; char* s_type; char* s_name; } _nlist_tab[] = { { 0x00000000, "?", (char*)0 } }; 2) then I make a 2nd link filling _nlist_tab[] with nm myapp.exe | sed -f C/nlist.sed | grep "0x0" >> nlist.c nlist.sed: s/^\([0-9A-Fa-f]*\) \([DT]\) *\([_A-Za-z0-9]*\).*$/ { 0x\1, "\2", "\3" },/g nlist.c becomes : struct { unsigned long s_add; char* s_type; char* s_name; } _nlist_tab[] = { { 0x0041adb8, "T", "_BnAdd" }, { 0x0041ad90, "T", "_BnAddCarry" }, { 0x0041acc8, "T", "_BnAndDigits" }, ... { 0x00000000, "?", (char*)0 } }; This second link makes my program have the good size with _nlist_tab 3) I make the final link with the same command again nm myapp.exe | sed -f C/nlist.sed | grep "0x0" >> nlist.c this time it fills _nlist_tab with the good address VALUES. In my case, the dlsym equivalent is simply (:-<) unsigned long my_dlsym( char* strg ) { extern struct { unsigned long s_add; char* s_type; char* s_name; } _nlist_tab[]; /* s_type is not used in my case, a dicotomic search could be used */ int i; for( i = 0 ; _nlist_tab[i].s_name != 0 ; i++ ) if( strcmp( _nlist_tab[i].s_name, strg ) == 0 ) return( _nlist_tab[i].s_add ); return 0; } I guess that the same result could be found by plugging a subset of nm tool but I had no time (or energy) to inspect this way yet. If you have a better solution I will be happy to test it (and/or to improve it). Thanks Christian Jullien - For help on using this list (especially unsubscribing), send a message to "gnu-win32-request@cygnus.com" with one line of text: "help".