This is the mail archive of the binutils@sources.redhat.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: Bug in dynamic linker


   Date: Thu, 20 Jul 2000 10:16:12 -0700
   From: "H . J . Lu" <hjl@lucon.org>

   On Thu, Jul 20, 2000 at 07:10:48PM +0200, Mark Kettenis wrote:
   > symbol in libpthread.  That means that by walking the DT_NEEDED chain,
   > ld will prefer the definition in libpthread.  I believe that with your
   > patch foo will get a DT_NEEDED for libpthread.  The reason I believe
   > this is true, is that right now ld records the version information for
   > close in libpthread.  This was the exact scenario causing the
   > origional "bug".
   > 
   > So you see that there are cases where a program doesn't explicitly
   > reference a symbol in a particular library, it will nevertheless get
   > a DT_NEEDED for that library.

   Could you please spend a few minutes creating a testcase and sending
   to me? Call me dumb. I need to see it to really believe it. I really
   appreciate it.

Here it is (thanks for including the shar target :-)).  By the way,
looks like there's something wrong with the linker.  I get the
following output (with glibc 2.1.3):

delius:~/tmp/needed$ make
for f in threadtest test; do echo "Running: $f"; ./$f; \
  if [ $? != 0 ]; then echo Failed; fi; done
Running: threadtest
BUG IN DYNAMIC LINKER ld.so: dynamic-link.h: 57: elf_get_dynamic_info: Assertion `! "bad dynamic tag"' failed!
Failed
Running: test
./test: error in loading shared libraries: libthreadlib.so: cannot open shared object file: No such file or directory
Failed
for f in threadtest test; do echo "Running: ldd $f"; ldd ./$f; \
  if [ $? != 0 ]; then echo Failed; fi; done
Running: ldd threadtest
BUG IN DYNAMIC LINKER ld.so: dynamic-link.h: 57: elf_get_dynamic_info: Assertion `! "bad dynamic tag"' failed!
ldd: /lib/ld-linux.so.2 exited with unknown exit code (127)
Failed
Running: ldd test
       libthreadlib.so => not found
       libc.so.6 => /lib/libc.so.6 (0x40015000)
       libpthread.so.0 => /lib/libpthread.so.0 (0x400f8000)
       /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)
delius:~/tmp/needed$ make

Mark


#!/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 2000-07-20 19:46 CEST by <kettenis@delius.kettenis.local>.
# Source directory was `/home/kettenis/tmp/needed'.
#
# Existing files will *not* be overwritten unless `-c' is specified.
#
# This shar contains:
# length mode       name
# ------ ---------- ------------------------------------------
#    143 -rw-r--r-- test.c
#    218 -rw-r--r-- threadlib.c
#    207 -rw-r--r-- threadtest.c
#    696 -rw-r--r-- Makefile
#
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 _sh18434; then
  $echo 'x -' 'creating lock directory'
else
  $echo 'failed to create lock directory'
  exit 1
fi
# ============= test.c ==============
if test -f 'test.c' && test "$first_param" != -c; then
  $echo 'x -' SKIPPING 'test.c' '(file already exists)'
else
  $echo 'x -' extracting 'test.c' '(text)'
  sed 's/^X//' << 'SHAR_EOF' > 'test.c' &&
#include <stdio.h>
X  
extern int dummy(void);
X  
int main(int argc, char **argv) {
X  printf("spec = %d\n", dummy());
X  close(0);
X  return 0;
}
SHAR_EOF
  $shar_touch -am 07201943100 'test.c' &&
  chmod 0644 'test.c' ||
  $echo 'restore of' 'test.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 'test.c:' 'MD5 check failed'
eb8457ae81efd570cd91b1550570132d  test.c
SHAR_EOF
  else
    shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'test.c'`"
    test 143 -eq "$shar_count" ||
    $echo 'test.c:' 'original size' '143,' 'current size' "$shar_count!"
  fi
fi
# ============= threadlib.c ==============
if test -f 'threadlib.c' && test "$first_param" != -c; then
  $echo 'x -' SKIPPING 'threadlib.c' '(file already exists)'
else
  $echo 'x -' extracting 'threadlib.c' '(text)'
  sed 's/^X//' << 'SHAR_EOF' > 'threadlib.c' &&
#include <pthread.h>
X  
pthread_key_t mykey;
X  
int dummy(void) {
X  int spec;
X  
X  pthread_key_create(&mykey, NULL);
X  pthread_setspecific(mykey, (void *)10);
X  spec = (int)pthread_getspecific(mykey);
X  return spec;
}
SHAR_EOF
  $shar_touch -am 07181133100 'threadlib.c' &&
  chmod 0644 'threadlib.c' ||
  $echo 'restore of' 'threadlib.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 'threadlib.c:' 'MD5 check failed'
19ecddd05773202c443a249d7583bc47  threadlib.c
SHAR_EOF
  else
    shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'threadlib.c'`"
    test 218 -eq "$shar_count" ||
    $echo 'threadlib.c:' 'original size' '218,' 'current size' "$shar_count!"
  fi
fi
# ============= threadtest.c ==============
if test -f 'threadtest.c' && test "$first_param" != -c; then
  $echo 'x -' SKIPPING 'threadtest.c' '(file already exists)'
else
  $echo 'x -' extracting 'threadtest.c' '(text)'
  sed 's/^X//' << 'SHAR_EOF' > 'threadtest.c' &&
#include <pthread.h>
#include <stdio.h>
X  
extern int dummy(void);
X  
pthread_t *me;
X  
int main(int argc, char **argv) {
X  printf("spec = %d\n", dummy());
X  me = (pthread_t *) pthread_self();
X  return 0;
}
SHAR_EOF
  $shar_touch -am 07181136100 'threadtest.c' &&
  chmod 0644 'threadtest.c' ||
  $echo 'restore of' 'threadtest.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 'threadtest.c:' 'MD5 check failed'
b9df452c72adac53de184bc4effa931a  threadtest.c
SHAR_EOF
  else
    shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'threadtest.c'`"
    test 207 -eq "$shar_count" ||
    $echo 'threadtest.c:' 'original size' '207,' 'current size' "$shar_count!"
  fi
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 -B./
PIC=-fPIC
NODELETE=-Wl,-z,nodelete
X
PROGS= threadtest test
X
all: $(PROGS)
X	for f in $(PROGS); do echo "Running: $$f"; ./$$f; \
X	  if [ $$? != 0 ]; then echo Failed; fi; done
X	for f in $(PROGS); do echo "Running: ldd $$f"; ldd ./$$f; \
X	  if [ $$? != 0 ]; then echo Failed; fi; done
X
threadtest: threadtest.o libthreadlib.so
X	$(CC) -o $@ $(CFLAGS) threadtest.o -L. -lthreadlib -Wl,-rpath,.
X
test: test.o libthreadlib.so
X	$(CC) -o $@ $(CFLAGS) test.o -L. -lthreadlib #-Wl,-rpath,.
X
libthreadlib.so: threadlib.c
X	$(CC) $(NODELETE) -shared -o $@ $(CFLAGS) $(PIC) $^ -lpthread
X
X.c.o:
X	$(CC) $(CFLAGS) -c $<
X
clean:
X	rm -f $(PROGS) *.so* *.o *.s *.a
X
shar:
X	shar *.c Makefile > bug.shar
SHAR_EOF
  $shar_touch -am 07191433100 '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'
2b653f2c654e24704696aa1416274039  Makefile
SHAR_EOF
  else
    shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'Makefile'`"
    test 696 -eq "$shar_count" ||
    $echo 'Makefile:' 'original size' '696,' 'current size' "$shar_count!"
  fi
fi
rm -fr _sh18434
exit 0


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