On Sun, 23 Apr 2000, Omer Mussaev wrote:> Alexander Indenbaum wrote:
>
> > Hi!
> >
> > We develop product using Linux / GCC.
> >
> > We have problems with run time linking with dll ( .so ) using
> > dlopen/dlsym. The problem is that global symbols of program and library
> > with the same name are getting merged when dlopen() executed ( having
> > global symbols as a bad design is another question :{) ) As result API
> > function from dll call causes changing of internal data in main program
> > which is obviously is not desirable at all.
> >
> > How it can be prevented?
>
> by redefining symbols at make stage.
>What do you meen?
How?
1. you can specify Xlinker options to gcc, and redefine your functions.
For example:
let foo.c be:
---
#include <stdio.h>
int main (int c, char ** v )
{
printf ( "c and one is %d\n",
add1 ( c ) ) ;
return ( c + c ) ;
}
int add1 (int c)
{
return c + 1 ;
}
---
and let wraps.c be:
---
int __wrap_printf ( char * format, ... )
{
__real_printf ("hello, cruel
world\n") ;
}
---
gcc foo.c ; ./a.out
will give you
c and one is 2
but
gcc ./foo.c -Xlinker --wrap -Xlinker printf foo.c wraps.c ; ./a.out
will give you:
hello, cruel world
Thus, you are undeffing printf, and getting 2 funcs:
__wrap_printf
and
__real_printf
2.
you can use ld -defsym new_global_sym=addr,
where addr is address of old_global_sym
3.
you can write ld scripts to do just that.
Note that none of those touchs shared library, but only "trims" your
own code.
Well, there is 4th way - re-design your program to behave correctly.
> >
> >
> > Alexander Indenbaum
> > [EMAIL PROTECTED]
> >
> > =================================================================
> > To unsubscribe, send mail to [EMAIL PROTECTED] with
> > the word "unsubscribe" in the message body, e.g., run the command
> > echo unsubscribe | mail [EMAIL PROTECTED]
>
> --
> ---
> Omer Mussaev mailto:[EMAIL PROTECTED]
> 051-308-214 http://www.cs.bgu.ac.il/~omer
>
>
>Alexander Indenbaum
[EMAIL PROTECTED]
-- --- Omer Mussaev mailto:[EMAIL PROTECTED] 051-308-214 http://www.cs.bgu.ac.il/~omer