Mail Archives: cygwin/1998/11/11/22:26:59
> 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 AT cygnus DOT com" with one line of text: "help".
- Raw text -