[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: two instances of global from shared lib linked with -Bsymbolic

From: Ian Lance Taylor
Subject: Re: two instances of global from shared lib linked with -Bsymbolic
Date: 06 Apr 2004 15:41:52 -0400
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3

Rafal Dabrowa <address@hidden> writes:

> On Tuesday 06 of April 2004 18:22, Ian Lance Taylor wrote:

> > Why are you using -Bsymbolic?
> I want to have the following behavior. I have created a shared library with a 
> lot of functions and global variables exposed to others. But I don't want up 
> to anybody would override my functions. Suppose I have two functions in my 
> lib:
>       void fun1() { ... }
>       void fun2() { fun1(); ... }
> Function fun2 invokes fun1. I want up to fun2 would always invoke fun1 from 
> my 
> library. It is surprising for me, that if I create fun1 in main program, then 
> fun2 invokes fun1 from main program instead of library. From this reason I 
> have added -Bsymbolic option.
> But, this option caused that I can't access any global variable from library. 
> If a library function changes a global from library (e.g. MyErrno), I can't 
> see the varibale change in main program.
> Do you know any solution ?

It is normally considered to be a feature that you can define fun1 in
the main program and have fun2 call it.  It permits many useful
operations, such as overriding malloc in the main program.  It is also
similar to the way that ordinary archives behave.

If you want to guarantee that fun2 calls fun1, and you also want to
make it possible for programs linked against the shared library to
call fun1 in the shared library, then there is no simple way to do

One approach which will work is to create the function __fun1, make an
alias for it called fun1, have fun2 call __fun1, and use a version
script to make __fun1 a hidden symbol.

If it is not necessary for programs linked against the shared library
to call fun1, then you can simply use a version script to make fun1 a
hidden symbol.

-Bsymbolic will always cause the problem you are seeing with global
variables.  This is inevitable due to the way that ELF handles global
variables referenced in both the main program and in shared libraries.
The ELF technique is convenient--it's much simpler than, say, the
technique used on Windows NT, in which variables must be explicitly
marked as imported or exported from a DLL.  But the ELF technique is
broken by -Bsymbolic.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]