A -Bsymbolic patch for bfd

H.J. Lu hjl@varesearch.com
Wed Sep 1 11:31:00 GMT 1999


Hi, Ian,

I got a bug report. I have verified that with the native tools on
Solaris 7/Sparc/x86, no copy is made if an undefined symbol is
referenced via GOT from a DSO. This patch tries to implement it.

Thanks.


-- 
H.J. Lu (hjl@gnu.org)
---
Wed Sep  1 11:17:30 1999  H.J. Lu  <hjl@gnu.org>

	* elf-bfd.h (ELF_LINK_HASH_NEEDS_GOT): New.

	* elflink.h (elf_adjust_dynamic_symbol): Skip if a symbol is
	defined in a shared object and referenced in a regular object
	via GOT.

	* elf32-i386.c (elf_i386_check_relocs): If necessary, set
	ELF_LINK_HASH_NEEDS_GOT.
	* elf32-sparc.c (elf_i386_check_relocs): Likewise.

Index: elf-bfd.h
===================================================================
RCS file: /work/cvs/gnu/binutils/bfd/elf-bfd.h,v
retrieving revision 1.1.1.7
diff -u -p -r1.1.1.7 elf-bfd.h
--- elf-bfd.h	1999/08/02 01:02:25	1.1.1.7
+++ elf-bfd.h	1999/09/01 17:45:06
@@ -189,6 +189,8 @@ struct elf_link_hash_entry
 #define ELF_LINK_FORCED_LOCAL 02000
   /* Symbol was marked during garbage collection.  */
 #define ELF_LINK_HASH_MARK 04000
+  /* Symbol needs a global offset table entry.  */
+#define ELF_LINK_HASH_NEEDS_GOT 010000
 };
 
 /* Records local symbols to be emitted in the dynamic symbol table.  */
Index: elf32-i386.c
===================================================================
RCS file: /work/cvs/gnu/binutils/bfd/elf32-i386.c,v
retrieving revision 1.3
diff -u -p -r1.3 elf32-i386.c
--- elf32-i386.c	1999/07/19 16:46:14	1.3
+++ elf32-i386.c	1999/09/01 18:11:30
@@ -519,6 +519,9 @@ elf_i386_check_relocs (abfd, info, sec, 
 
 	  if (h != NULL)
 	    {
+	      if (!info->shared)
+		h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_GOT;
+
 	      if (h->got.offset != (bfd_vma) -1)
 		{
 		  /* We have already allocated space in the .got.  */
Index: elf32-sparc.c
===================================================================
RCS file: /work/cvs/gnu/binutils/bfd/elf32-sparc.c,v
retrieving revision 1.1.1.5
diff -u -p -r1.1.1.5 elf32-sparc.c
--- elf32-sparc.c	1999/08/09 16:22:03	1.1.1.5
+++ elf32-sparc.c	1999/09/01 18:12:07
@@ -421,6 +421,9 @@ elf32_sparc_check_relocs (abfd, info, se
 
 	  if (h != NULL)
 	    {
+	      if (!info->shared)
+		h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_GOT;
+
 	      if (h->got.offset != (bfd_vma) -1)
 		{
 		  /* We have already allocated space in the .got.  */
Index: elflink.h
===================================================================
RCS file: /work/cvs/gnu/binutils/bfd/elflink.h,v
retrieving revision 1.9
diff -u -p -r1.9 elflink.h
--- elflink.h	1999/08/31 17:17:49	1.9
+++ elflink.h	1999/09/01 17:58:09
@@ -3257,13 +3257,14 @@ elf_adjust_dynamic_symbol (h, data)
 
   /* If this symbol does not require a PLT entry, and it is not
      defined by a dynamic object, or is not referenced by a regular
-     object, ignore it.  We do have to handle a weak defined symbol,
-     even if no regular object refers to it, if we decided to add it
-     to the dynamic symbol table.  FIXME: Do we normally need to worry
-     about symbols which are defined by one dynamic object and
-     referenced by another one?  */
+     object, or requires a GOT entry, ignore it.  We do have to handle
+     a weak defined symbol, even if no regular object refers to it, if
+     we decided to add it to the dynamic symbol table.  FIXME: Do we
+     normally need to worry about symbols which are defined by one
+     dynamic object and referenced by another one?  */
   if ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) == 0
       && ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) != 0
+	  || (h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_GOT) != 0
 	  || (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) == 0
 	  || ((h->elf_link_hash_flags & ELF_LINK_HASH_REF_REGULAR) == 0
 	      && (h->weakdef == NULL || h->weakdef->dynindx == -1))))
----
#!/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-09-01 11:24 PDT by <hjl@osmium.su.varesearch.com>.
# Source directory was `/home/hjl/bugs/libc/symbolic'.
#
# Existing files will *not* be overwritten unless `-c' is specified.
#
# This shar contains:
# length mode       name
# ------ ---------- ------------------------------------------
#    521 -rw-r--r-- Makefile
#    213 -rw-r--r-- sotest.c
#    141 -rw-r--r-- solib.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 _sh29537; 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' &&
CC=gcc
CFLAGS=-O -g
LD=gcc
SHLIBS=solib.so
LIBS=$(SHLIBS) -Wl,-R,./
LDFLAGS=-Wl,-Bsymbolic
PIC_FLAGS=-fPIC
X
PROGS=sotest
X
all: $(SHLIBS) $(PROGS)
X	-for f in $(PROGS); do \
X	  if [ -x $$f ]; then $$f; echo $$?; fi; \
X	done
X
sotest: sotest.o
X	$(CC) -o $@ $^ $(LIBS)
X
sotest.o: sotest.c
X	$(CC) $(CFLAGS) $(PIC_FLAGS) -c -o $@ $^
X
%.o: %.c
X	$(CC) -c $(CFLAGS) -fPIC -o $@ $<
X
%.so: %.o
X	$(LD) $(LDFLAGS) -o $@ $< -shared -lc
X
clean:
X	$(RM) a.out core $(PROGS) *.o *.s *.so*
X
shar:
X	shar Makefile sotest.c solib.c  > bug.shar
SHAR_EOF
  $shar_touch -am 0901112499 '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'
38b359412ac255f81b62d88744f2532f  Makefile
SHAR_EOF
  else
    shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'Makefile'`"
    test 521 -eq "$shar_count" ||
    $echo 'Makefile:' 'original size' '521,' 'current size' "$shar_count!"
  fi
fi
# ============= sotest.c ==============
if test -f 'sotest.c' && test "$first_param" != -c; then
  $echo 'x -' SKIPPING 'sotest.c' '(file already exists)'
else
  $echo 'x -' extracting 'sotest.c' '(text)'
  sed 's/^X//' << 'SHAR_EOF' > 'sotest.c' &&
extern int lib_int;
X
#if 0
int lib_int = 13;
#endif
X
main()
{
X  extern void print_lib();
X  lib_int = 13;
X
X  print_lib();
X  printf("%s: lib_int = %d, address = %lx\n", __FILE__, lib_int, &lib_int);  
X  return 0;
}
SHAR_EOF
  $shar_touch -am 0901112099 'sotest.c' &&
  chmod 0644 'sotest.c' ||
  $echo 'restore of' 'sotest.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 'sotest.c:' 'MD5 check failed'
fd1491dfc7bed707a1577ced93f443d8  sotest.c
SHAR_EOF
  else
    shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'sotest.c'`"
    test 213 -eq "$shar_count" ||
    $echo 'sotest.c:' 'original size' '213,' 'current size' "$shar_count!"
  fi
fi
# ============= solib.c ==============
if test -f 'solib.c' && test "$first_param" != -c; then
  $echo 'x -' SKIPPING 'solib.c' '(file already exists)'
else
  $echo 'x -' extracting 'solib.c' '(text)'
  sed 's/^X//' << 'SHAR_EOF' > 'solib.c' &&
int lib_int = 13;
X
void print_lib()
{
X  lib_int = 26;
X  printf("%s: lib_int = %d, address = %lx\n", 
X        __FILE__, lib_int, &lib_int);
}
SHAR_EOF
  $shar_touch -am 0830073499 'solib.c' &&
  chmod 0644 'solib.c' ||
  $echo 'restore of' 'solib.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 'solib.c:' 'MD5 check failed'
0653b56e7a0768ad09efb2d27bc39ccf  solib.c
SHAR_EOF
  else
    shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'solib.c'`"
    test 141 -eq "$shar_count" ||
    $echo 'solib.c:' 'original size' '141,' 'current size' "$shar_count!"
  fi
fi
rm -fr _sh29537
exit 0


More information about the Binutils mailing list