This is the mail archive of the binutils@sourceware.cygnus.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: A glibc dynamic linker or gld bug?


>    By "problem", I mean the same symbol will have different values in
>    executable and DSO. When you update one of them, you won't see the
>    change in the other. If you relink executable against the new DSO,
>    the symbol in executable will override the one in DSO.
> 
> I guess I don't understand.  The DSO should have relocations for all
> uses of the symbol, so it will wind up seeing the definition in the
> executable.  At runtime the symbol will not have different values.
> This is an ordinary case in which the executable overrides the DSO.

Here is the testcase.

> 
> As far as I know, the only way you can get a DSO to see a different
> value from the main executable is to use -Bsymbolic or version
> scripts.  Also, you have just reported a case in which it happens due
> to the use of weak defined symbols in the executable.  But there
> definitely should not be any way to make the DSO and the executable
> see a different value for a strong defined symbol.
> 

# make
cc -shared -o libfoo.so -fPIC -O -g foo.c
cc -o foo -O -g libfoo.so main.c -Wl,-rpath,.
for f in foo; do echo "Running: $f"; ./$f; \
  if [ $? != 0 ]; then echo Failed; fi; done
Running: foo
main: 0x8049670
DSO: (nil)
cc -shared -o libfoo.so -fPIC -O -g foo.c -DDEF
for f in foo; do echo "Running: $f"; ./$f; \
  if [ $? != 0 ]; then echo Failed; fi; done
Running: foo
main: 0x8049670
DSO: 0x2aac0634
Failed


-- 
H.J. Lu (hjl@gnu.org)
---
#!/bin/sh
# This is a shell archive (produced by GNU sharutils 4.2).
# To extract the files from this archive, save it to some FILE, remove
# everything before the `!/bin/sh' line above, then type `sh FILE'.
#
# Made on 1999-07-07 07:52 PDT by <hjl@osmium.su.varesearch.com>.
# Source directory was `/home/hjl/bugs/gas/shared4'.
#
# Existing files will *not* be overwritten unless `-c' is specified.
#
# This shar contains:
# length mode       name
# ------ ---------- ------------------------------------------
#    442 -rw-r--r-- Makefile
#    113 -rw-r--r-- foo.c
#    188 -rw-r--r-- main.c
#
save_IFS="${IFS}"
IFS="${IFS}:"
gettext_dir=FAILED
locale_dir=FAILED
first_param="$1"
for dir in $PATH
do
  if test "$gettext_dir" = FAILED && test -f $dir/gettext \
     && ($dir/gettext --version >/dev/null 2>&1)
  then
    set `$dir/gettext --version 2>&1`
    if test "$3" = GNU
    then
      gettext_dir=$dir
    fi
  fi
  if test "$locale_dir" = FAILED && test -f $dir/shar \
     && ($dir/shar --print-text-domain-dir >/dev/null 2>&1)
  then
    locale_dir=`$dir/shar --print-text-domain-dir`
  fi
done
IFS="$save_IFS"
if test "$locale_dir" = FAILED || test "$gettext_dir" = FAILED
then
  echo=echo
else
  TEXTDOMAINDIR=$locale_dir
  export TEXTDOMAINDIR
  TEXTDOMAIN=sharutils
  export TEXTDOMAIN
  echo="$gettext_dir/gettext -s"
fi
touch -am 1231235999 $$.touch >/dev/null 2>&1
if test ! -f 1231235999 && test -f $$.touch; then
  shar_touch=touch
else
  shar_touch=:
  echo
  $echo 'WARNING: not restoring timestamps.  Consider getting and'
  $echo "installing GNU \`touch', distributed in GNU File Utilities..."
  echo
fi
rm -f 1231235999 $$.touch
#
if mkdir _sh00601; then
  $echo 'x -' 'creating lock directory'
else
  $echo 'failed to create lock directory'
  exit 1
fi
# ============= Makefile ==============
if test -f 'Makefile' && test "$first_param" != -c; then
  $echo 'x -' SKIPPING 'Makefile' '(file already exists)'
else
  $echo 'x -' extracting 'Makefile' '(text)'
  sed 's/^X//' << 'SHAR_EOF' > 'Makefile' &&
CFLAGS=-O -g
X
PROGS= foo
X
all: $(PROGS)
X	for f in $(PROGS); do echo "Running: $$f"; ./$$f; \
X	  if [ $$? != 0 ]; then echo Failed; fi; done
X	cc -shared -o libfoo.so -fPIC -O -g foo.c -DDEF
X	for f in $(PROGS); do echo "Running: $$f"; ./$$f; \
X	  if [ $$? != 0 ]; then echo Failed; fi; done
X
foo: libfoo.so main.c
X	$(CC) -o $@ $(CFLAGS) $^ -Wl,-rpath,.
X
libfoo.so: foo.c
X	$(CC) -shared -o $@ -fPIC $(CFLAGS) $^
X
clean:
X	rm -f $(PROGS) *.so *.o
SHAR_EOF
  $shar_touch -am 0707075199 'Makefile' &&
  chmod 0644 'Makefile' ||
  $echo 'restore of' 'Makefile' 'failed'
  if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
  && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
    md5sum -c << SHAR_EOF >/dev/null 2>&1 \
    || $echo 'Makefile:' 'MD5 check failed'
f0c616a6b715ce3606b9d73421d5d107  Makefile
SHAR_EOF
  else
    shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'Makefile'`"
    test 442 -eq "$shar_count" ||
    $echo 'Makefile:' 'original size' '442,' 'current size' "$shar_count!"
  fi
fi
# ============= foo.c ==============
if test -f 'foo.c' && test "$first_param" != -c; then
  $echo 'x -' SKIPPING 'foo.c' '(file already exists)'
else
  $echo 'x -' extracting 'foo.c' '(text)'
  sed 's/^X//' << 'SHAR_EOF' > 'foo.c' &&
#ifdef DEF
int deallocate = 0;
X
int *
foo ()
{
X  return &deallocate;
}
#else
int *
foo ()
{
X  return 0;
}
#endif
SHAR_EOF
  $shar_touch -am 0707075199 'foo.c' &&
  chmod 0644 'foo.c' ||
  $echo 'restore of' 'foo.c' 'failed'
  if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
  && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
    md5sum -c << SHAR_EOF >/dev/null 2>&1 \
    || $echo 'foo.c:' 'MD5 check failed'
a31cb6bbe33929046ce845bca37bf145  foo.c
SHAR_EOF
  else
    shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'foo.c'`"
    test 113 -eq "$shar_count" ||
    $echo 'foo.c:' 'original size' '113,' 'current size' "$shar_count!"
  fi
fi
# ============= main.c ==============
if test -f 'main.c' && test "$first_param" != -c; then
  $echo 'x -' SKIPPING 'main.c' '(file already exists)'
else
  $echo 'x -' extracting 'main.c' '(text)'
  sed 's/^X//' << 'SHAR_EOF' > 'main.c' &&
int deallocate = 0;
X
int * foo ();
X
int
main ()
{
X  printf ("main: %p\n", &deallocate);
X  printf ("DSO: %p\n", foo ());
X  if (foo () && foo () != &deallocate)
X    abort ();
X
X  return 0;
}
SHAR_EOF
  $shar_touch -am 0707074999 'main.c' &&
  chmod 0644 'main.c' ||
  $echo 'restore of' 'main.c' 'failed'
  if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
  && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
    md5sum -c << SHAR_EOF >/dev/null 2>&1 \
    || $echo 'main.c:' 'MD5 check failed'
88c903c7c636b45c40506df740f4de01  main.c
SHAR_EOF
  else
    shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'main.c'`"
    test 188 -eq "$shar_count" ||
    $echo 'main.c:' 'original size' '188,' 'current size' "$shar_count!"
  fi
fi
rm -fr _sh00601
exit 0

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]