PowerpC pointer_equality_needed optimisation

Alan Modra amodra@bigpond.net.au
Sun Feb 24 03:15:00 GMT 2008


On Sat, Feb 23, 2008 at 03:53:09PM -0800, H.J. Lu wrote:
> Yes, it is a weak and hidden with shared library. How do you make
> the pointer to a weak hidden symbol in a shared library to NULL
> at the runtime? Do you modify the instruction addressing mode?

In the executable, we load the address of f via the got.  ld.so is
responsible for resolving f and returns zero.

Here's another problem case.

cat > weakref.c <<EOF
#include <stdio.h>

extern int __attribute__ ((weak)) foo (void);
extern int (*fooptr) (void);

int main (void)
{
  if (fooptr)
    printf ("fooptr = %p, foo returns %d\n", fooptr, foo ());
  else
    printf ("fooptr = null\n");
  return 0;
}
EOF
cat > weakptr.c <<EOF
extern int __attribute__ ((weak)) foo (void);
int (*fooptr) (void) = &foo;
EOF
cat > weakreflib.c <<EOF
extern int (*fooptr) (void);
int foo (void)
{
  return &foo == fooptr;
}
EOF
echo -n > empty.o
gcc -O -fpic -shared -o deflib.so weakreflib.c -Wl,-soname,weak.so
gcc -O -fpic -shared -o nodeflib.so empty.o -Wl,-soname,weak.so
gcc -O -fpic -o weakref weakref.c weakptr.c
LD_LIBRARY_PATH=. ./weakref
gcc -O -fpic -o weakref weakref.c weakptr.c deflib.so
ln -sfn deflib.so weak.so
LD_LIBRARY_PATH=. ./weakref
ln -sfn nodeflib.so weak.so
LD_LIBRARY_PATH=. ./weakref

The last weakref run fails with a segfault because we don't emit a
dynamic reloc on the fooptr initialisation.

-- 
Alan Modra
Australia Development Lab, IBM



More information about the Binutils mailing list