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: Bug#62008: ld leaves hidden/internal symbols in the symbol table (Patch Included)


On Fri, Apr 07, 2000 at 06:19:27PM -0700, Chip Salzenberg wrote:
> Package: binutils
> Version: 2.9.5.0.31-1
> Severity: important
> 
> This bug is complex to explain, but the fix is very simple.
> It's severity "important" because it breaks libstdc++-v3 on
> i386-elf (and probably all other elf targets).
> 
> Index: bfd/elflink.c
> *************** _bfd_elf_link_record_dynamic_symbol (inf
> *** 239,243 ****
>   	  
>   	  h->elf_link_hash_flags |= ELF_LINK_FORCED_LOCAL;
> ! 	  break;
>   	  
>   	default:
> --- 239,243 ----
>   	  
>   	  h->elf_link_hash_flags |= ELF_LINK_FORCED_LOCAL;
> ! 	  return true;
>   	  
>   	default:
> 
> 
> Here's the long version:
> 
>   1.  When a symbol is marked '.hidden' or '.internal', it's not
>       supposed to be visible outside the given program / shared
>       object.
> 
>   2.  The context of the above patch is the forcing of hidden/internal
>       symbols to be considered "local" instead of "global".  This is a
>       kludge, but a required one, per this comment in elflink.c:
> 
>       /* XXX: The ABI draft says the linker must turn hidden and
>          internal symbols into STB_LOCAL symbols when producing the
>          DSO. However, if ld.so honors st_other in the dynamic table,
>          this would not be necessary.  */
> 
>   3.  The function in question is responsible for registering symbols
>       in the dynamic linkage symbol table.  It gets called because a
>       symbol that's hidden/internal will be global in the object file.
> 
>   4.  However, by definition, a hidden/internal symbol should _NEVER_
>       be in the dynamic linkage symbol table!
> 
>   5.  Without the patch, the function does its work, the linker
>       creates a reference to the now-local symbol, which (being local)
>       can never satisfy this reference.  Thus, the shared object is
>       thoroughly broken and unusable.
> 
>   6.  The Fix:  This patch forces an immediate return out of the
>       function, before the incorrect symbol registration.  This leaves
>       the hidden/internal symbol as it should be: 100% private.
> 
> I hope this is clear enough.  I'll provide test cases on request.

I am not sure it is the right patch. I am enclosing a testcase here.
It fails on Linux/ia32 with glibc 2.1.3.

# make
cc -S  -fPIC -O -B./ foo.c
cc: file path prefix `./' never used
echo ".hidden bar" >> foo.s
cc -c foo.s
cc -shared -o libfoo.so -O -B./ foo.o
cc: file path prefix `./' never used
cc -o foo -O -B./ libfoo.so main.c -Wl,-rpath,. -rdynamic
cc: file path prefix `./' never used
for f in foo; do echo "Running: $f"; ./$f; \
  if [ $? != 0 ]; then echo Failed; fi; done
Running: foo
./foo: error in loading shared libraries: ./libfoo.so: undefined symbol: bar
Failed


H.J.
----
#!/bin/sh
# This is a shell archive (produced by GNU sharutils 4.2.1).
# 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-04-07 21:10 PDT by <hjl@osmium.su.varesearch.com>.
# Source directory was `/home/hjl/bugs/gas/hidden'.
#
# Existing files will *not* be overwritten unless `-c' is specified.
#
# This shar contains:
# length mode       name
# ------ ---------- ------------------------------------------
#     65 -rw-r--r-- foo.c
#     54 -rw-r--r-- main.c
#    438 -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
if touch -am -t 200112312359.59 $$.touch >/dev/null 2>&1 && test ! -f 200112312359.59 -a -f $$.touch; then
  shar_touch='touch -am -t $1$2$3$4$5$6.$7 "$8"'
elif touch -am 123123592001.59 $$.touch >/dev/null 2>&1 && test ! -f 123123592001.59 -a ! -f 123123592001.5 -a -f $$.touch; then
  shar_touch='touch -am $3$4$5$6$1$2.$7 "$8"'
elif touch -am 1231235901 $$.touch >/dev/null 2>&1 && test ! -f 1231235901 -a -f $$.touch; then
  shar_touch='touch -am $3$4$5$6$2 "$8"'
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 200112312359.59 123123592001.59 123123592001.5 1231235901 $$.touch
#
if mkdir _sh00820; then
  $echo 'x -' 'creating lock directory'
else
  $echo 'failed to create lock directory'
  exit 1
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' &&
void
bar ()
{
X  printf ("Hello\n");
}
X
void
foo ()
{
X  bar ();
}
SHAR_EOF
  (set 20 00 04 07 21 10 28 'foo.c'; eval "$shar_touch") &&
  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'
dcc44729d5741c566699aea1f88e2b02  foo.c
SHAR_EOF
  else
    shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'foo.c'`"
    test 65 -eq "$shar_count" ||
    $echo 'foo.c:' 'original size' '65,' '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' &&
void foo ();
X
int
main ()
{
X
X  foo ();
X
X  return 0;
}
SHAR_EOF
  (set 20 00 04 07 20 11 37 'main.c'; eval "$shar_touch") &&
  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'
ffad46a6b66294bd257c1317767a44f6  main.c
SHAR_EOF
  else
    shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'main.c'`"
    test 54 -eq "$shar_count" ||
    $echo 'main.c:' 'original size' '54,' '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./
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
foo: libfoo.so main.c
X	$(CC) -o $@ $(CFLAGS) $^ -Wl,-rpath,. -rdynamic
X
libfoo.so: foo.o
X	$(CC) -shared -o $@ $(CFLAGS) $^
X
foo.o: foo.s
X	$(CC) -c $^
X
foo.s: foo.c
X	$(CC) -S  -fPIC $(CFLAGS) $^
X	echo ".hidden bar" >> $@
X
clean:
X	rm -f $(PROGS) *.so *.o *.s
X
X
shar:
X	shar *.c Makefile > bug.shar
SHAR_EOF
  (set 20 00 04 07 21 09 40 'Makefile'; eval "$shar_touch") &&
  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'
be6c034589a395c2b5be84245e795435  Makefile
SHAR_EOF
  else
    shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'Makefile'`"
    test 438 -eq "$shar_count" ||
    $echo 'Makefile:' 'original size' '438,' 'current size' "$shar_count!"
  fi
fi
rm -fr _sh00820
exit 0

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