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

comparing function pointers fails on hppa-linux



>Submitter-Id:  net
>Originator:
>Organization:  GNU hackers
>Confidential:  no
>Synopsis:      two function pointers to the same function are not equal
>Severity:      non-critical
>Priority:      low
>Category:      c
>Class:         wrong-code
>Release:       3.0.4 (Debian testing/unstable)
>Environment:
System: Linux spe170 2.4.17-64 #1 Sat Mar 16 17:31:44 MST 2002 parisc64 unknown
Architecture: parisc64

        <machine, os, target, libraries (multiple lines)>
host: hppa-unknown-linux-gnu
build: hppa-unknown-linux-gnu
target: hppa-unknown-linux-gnu
configured with: ../src/configure -v --enable-languages=c,c++,f77,proto,objc --prefix=/usr --infodir=/share/info --mandir=/share/man --enable-shared --with-gnu-as --with-gnu-ld --with-system-zlib --enable-long-long --enable-nls --without-included-gettext --disable-checking --enable-threads=posix --with-cpp-install-dir=bin hppa-linux

gcc version 3.0.4 (generates 32-bit code)
as, ld version 2.12.90.0.1 20020307 Debian/GNU Linux
glibc-2.2.5

>Description:

Two function pointers to a function residing in a shared library, one fetched
from inside the library and the other from outside the library, compare as different,
i.e. == returns false.

>How-To-Repeat:

$ cat <<EOF > main.c
#include <stdio.h>

extern int shared_func ();
extern int (* shared_func_p ()) ();

int main()
{
  int ret = 0;
  if (shared_func != shared_func_p ())
    {
      printf ("Function address: %p !=  Function address from DSO: %p\n",
              shared_func, shared_func_p ());
      ret = 1;
    }
  return ret;
}
EOF

$ cat <<EOF > shared.c
int shared_func ()
{
  return 42;
}

int (* shared_func_p ()) ()
{
  return shared_func;
}
EOF

$ gcc -Wall -O -c main.c
$ gcc -Wall -O -fPIC -c shared.c
$ gcc -o foo  main.o libfoo.so
$ env LD_LIBRARY_PATH=. ./foo
Function address: 0x2091a !=  Function address from DSO: 0x400273ae

>Fix:

Generate different code for the comparison of function pointers. See
http://gcc.gnu.org/ml/gcc/2003-06/msg01283.html



Reply to: