gcj, shared libraries, and -Bsymbolic

Jakub Jelinek jakub@redhat.com
Tue Jan 25 15:17:00 GMT 2005


On Tue, Jan 25, 2005 at 02:58:03PM +0000, Andrew Haley wrote:
>  > On the other side, -Bsymbolic doesn't work at all together with C++
>  > semantics.  So if you link both Java and C++ code into a shared library
>  > and link with -Bsymbolic, C++ code will often misbehave.
> 
> Go on, give me a clue.  I'm not aware of the problem you describe.

Another example is e.g.
cat > foo.h <<EOF
extern int (*fn1) ();
extern int (*fn2) ();
inline int foo ()
{
  static int i;
  return ++i;
}
EOF
for i in 1 2; do
cat > foo$i.C <<EOF
#include "foo.h"
int (*fn$i) () = foo;
EOF
g++ -shared -O2 -fpic -o libfooN$i.so foo$i.C
g++ -shared -O2 -fpic -o libfooS$i.so foo$i.C -Wl,-Bsymbolic
done
cat > foo.C <<EOF
#include <cstdlib>
#include "foo.h"
int main ()
{
  if (fn1 () != 1 || fn2 () != 2 || fn1 () != 3 || fn2 () != 4)
    abort ();
}
EOF
g++ -O2 -o fooN foo.C ./libfooN{1,2}.so
g++ -O2 -o fooS foo.C ./libfooS{1,2}.so

and at least in my understanding ODR should guarantee there is just
one foo()::i variable in the whole program.

	Jakub



More information about the Gcc-patches mailing list