public inbox for gas2@sourceware.org
 help / color / mirror / Atom feed
* A weak symbol bug in gas-950819
@ 1995-08-20 18:51 H.J. Lu
  1995-08-21  8:14 ` Ian Lance Taylor
  0 siblings, 1 reply; 2+ messages in thread
From: H.J. Lu @ 1995-08-20 18:51 UTC (permalink / raw)
  To: gas2; +Cc: Ian Lance Taylor

Hi,

There is a weak symbol bug in gas-950819. The old snapshots failed to
pick up the real definition under certain circumstances. gas-950819
failed to set the weak symbol to zero.

BTW, what an ELF linker should do with the symbol "xxx" in

ld .... -lfoo -lbar

where a real "xxx" is defined in libfoo.a, a weak one is defined in
libbar.a and "xxx" is referenced in libbar.a only?


-- 
H.J. Lu
NYNEX Science and Technology, Inc.			hjl@nynexst.com
----
#!/bin/sh
# This is a shell archive (produced by GNU sharutils 4.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 1995-08-20 21:43 EDT by <hjl@didi>.
# Source directory was `/home/hjl/bugs/ld/weak'.
#
# Existing files will *not* be overwritten unless `-c' is specified.
#
# This shar contains:
# length mode       name
# ------ ---------- ------------------------------------------
#    353 -rw-r--r-- Makefile
#     78 -rw-r--r-- bar.c
#    100 -rw-r--r-- foo.c
#     32 -rw-r--r-- main.c
#     45 -rw-r--r-- main1.c
#     17 -rw-r--r-- x.c
#
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
#
# ============= Makefile ==============
if test -f 'Makefile' && test X"$1" != X"-c"; then
  echo 'x - skipping Makefile (file already exists)'
else
  echo 'x - extracting Makefile (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'Makefile' &&
SRCS= foo.c x.c bar.c
OBJS=$(SRCS:.c=.o)
AR=ar
CFLAGS=
CC=gcc -ggdb
RANLIB =ranlib
X
X.c.o:
X	$(CC) $(CFLAGS) -c $<
X
all: f1 f2 f3
X
f1: libfoo.a
X	$(CC) -o $@ main.c -L. -lfoo
X
f2: libfoo.a
X	$(CC) -o $@ main.c x.o -L. -lfoo
X
f3: libfoo.a
X	$(CC) -o $@ main1.c -L. -lfoo
X
libfoo.a:$(OBJS)
X	$(AR) ucvr $@ $(OBJS)
X	$(RANLIB) $@
X
clean:
X	-rm -f *.o *.a f1 f2 f3
SHAR_EOF
  $shar_touch -am 0820213995 'Makefile' &&
  chmod 0644 'Makefile' ||
  echo 'restore of Makefile failed'
  shar_count="`wc -c < 'Makefile'`"
  test 353 -eq "$shar_count" ||
    echo "Makefile: original size 353, current size $shar_count"
fi
# ============= bar.c ==============
if test -f 'bar.c' && test X"$1" != X"-c"; then
  echo 'x - skipping bar.c (file already exists)'
else
  echo 'x - extracting bar.c (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'bar.c' &&
#include <stdio.h>
X
extern int weak_x;
X
bar ()
{
X  printf ("%d\n", weak_x);
}
SHAR_EOF
  $shar_touch -am 0421213795 'bar.c' &&
  chmod 0644 'bar.c' ||
  echo 'restore of bar.c failed'
  shar_count="`wc -c < 'bar.c'`"
  test 78 -eq "$shar_count" ||
    echo "bar.c: original size 78, current size $shar_count"
fi
# ============= foo.c ==============
if test -f 'foo.c' && test X"$1" != X"-c"; then
  echo 'x - skipping foo.c (file already exists)'
else
  echo 'x - extracting foo.c (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'foo.c' &&
#include <stdio.h>
X
#pragma weak weak_x
X
extern int  weak_x;
X
foo ()
{
X  printf ("%d\n", weak_x);
}
SHAR_EOF
  $shar_touch -am 0421213795 'foo.c' &&
  chmod 0644 'foo.c' ||
  echo 'restore of foo.c failed'
  shar_count="`wc -c < 'foo.c'`"
  test 100 -eq "$shar_count" ||
    echo "foo.c: original size 100, current size $shar_count"
fi
# ============= main.c ==============
if test -f 'main.c' && test X"$1" != X"-c"; then
  echo 'x - skipping main.c (file already exists)'
else
  echo 'x - extracting main.c (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'main.c' &&
main ()
{
X  foo ();
X  bar ();
}
SHAR_EOF
  $shar_touch -am 0420012595 'main.c' &&
  chmod 0644 'main.c' ||
  echo 'restore of main.c failed'
  shar_count="`wc -c < 'main.c'`"
  test 32 -eq "$shar_count" ||
    echo "main.c: original size 32, current size $shar_count"
fi
# ============= main1.c ==============
if test -f 'main1.c' && test X"$1" != X"-c"; then
  echo 'x - skipping main1.c (file already exists)'
else
  echo 'x - extracting main1.c (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'main1.c' &&
main ()
{
X  foo ();
#if 0
X  bar ();
#endif
}
SHAR_EOF
  $shar_touch -am 0421222395 'main1.c' &&
  chmod 0644 'main1.c' ||
  echo 'restore of main1.c failed'
  shar_count="`wc -c < 'main1.c'`"
  test 45 -eq "$shar_count" ||
    echo "main1.c: original size 45, current size $shar_count"
fi
# ============= x.c ==============
if test -f 'x.c' && test X"$1" != X"-c"; then
  echo 'x - skipping x.c (file already exists)'
else
  echo 'x - extracting x.c (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'x.c' &&
int weak_x = 20;
SHAR_EOF
  $shar_touch -am 0421213795 'x.c' &&
  chmod 0644 'x.c' ||
  echo 'restore of x.c failed'
  shar_count="`wc -c < 'x.c'`"
  test 17 -eq "$shar_count" ||
    echo "x.c: original size 17, current size $shar_count"
fi
exit 0

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: A weak symbol bug in gas-950819
  1995-08-20 18:51 A weak symbol bug in gas-950819 H.J. Lu
@ 1995-08-21  8:14 ` Ian Lance Taylor
  0 siblings, 0 replies; 2+ messages in thread
From: Ian Lance Taylor @ 1995-08-21  8:14 UTC (permalink / raw)
  To: hjl; +Cc: gas2

   From: hjl@nynexst.com (H.J. Lu)
   Date: Sun, 20 Aug 1995 21:50:49 -0400 (EDT)

   There is a weak symbol bug in gas-950819. The old snapshots failed to
   pick up the real definition under certain circumstances. gas-950819
   failed to set the weak symbol to zero.

I'm not sure what you mean when you say that it failed to set the weak
symbol to zero.

I do see from your test case that the linker has a bug in the way it
handles an undefined weak reference followed by a weak reference.
I've checked in the appended patch, which should fix the problem.

   BTW, what an ELF linker should do with the symbol "xxx" in

   ld .... -lfoo -lbar

   where a real "xxx" is defined in libfoo.a, a weak one is defined in
   libbar.a and "xxx" is referenced in libbar.a only?

The linker processes libraries sequentially.  Assuming that there is
no mention of "xxx" before libfoo.a, and assuming that the definition
of "xxx" is not brought in from libfoo.a for some other reason,
libfoo.a is irrelevant to this case.

Ian

Index: linker.c
===================================================================
RCS file: /rel/cvsfiles/devo/bfd/linker.c,v
retrieving revision 1.58
diff -p -r1.58 linker.c
*** linker.c	1995/07/13 18:14:17	1.58
--- linker.c	1995/08/21 15:09:20
*************** enum link_action
*** 1321,1327 ****
  static const enum link_action link_action[8][8] =
  {
    /* current\prev    new    undef  undefw def    defw   com    indr   warn  */
!   /* UNDEF_ROW 	*/  {UND,   NOACT, NOACT, REF,   REF,   NOACT, REFC,  WARNC },
    /* UNDEFW_ROW	*/  {WEAK,  NOACT, NOACT, REF,   REF,   NOACT, REFC,  WARNC },
    /* DEF_ROW 	*/  {DEF,   DEF,   DEF,   MDEF,  DEF,   CDEF,  MDEF,  CYCLE },
    /* DEFW_ROW 	*/  {DEFW,  DEFW,  DEFW,  NOACT, NOACT, NOACT, NOACT, CYCLE },
--- 1321,1327 ----
  static const enum link_action link_action[8][8] =
  {
    /* current\prev    new    undef  undefw def    defw   com    indr   warn  */
!   /* UNDEF_ROW 	*/  {UND,   NOACT, UND,   REF,   REF,   NOACT, REFC,  WARNC },
    /* UNDEFW_ROW	*/  {WEAK,  NOACT, NOACT, REF,   REF,   NOACT, REFC,  WARNC },
    /* DEF_ROW 	*/  {DEF,   DEF,   DEF,   MDEF,  DEF,   CDEF,  MDEF,  CYCLE },
    /* DEFW_ROW 	*/  {DEFW,  DEFW,  DEFW,  NOACT, NOACT, NOACT, NOACT, CYCLE },
Index: elflink.h
===================================================================
RCS file: /rel/cvsfiles/devo/bfd/elflink.h,v
retrieving revision 1.9
diff -p -r1.9 elflink.h
*** elflink.h	1995/08/14 15:57:17	1.9
--- elflink.h	1995/08/21 15:09:22
*************** elf_link_add_archive_symbols (abfd, info
*** 155,161 ****
  	    continue;
  	  if (h->root.type != bfd_link_hash_undefined)
  	    {
! 	      defined[i] = true;
  	      continue;
  	    }
  
--- 155,162 ----
  	    continue;
  	  if (h->root.type != bfd_link_hash_undefined)
  	    {
! 	      if (h->root.type != bfd_link_hash_undefweak)
! 		defined[i] = true;
  	      continue;
  	    }
  


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~1995-08-21  8:14 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1995-08-20 18:51 A weak symbol bug in gas-950819 H.J. Lu
1995-08-21  8:14 ` Ian Lance Taylor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).