From mboxrd@z Thu Jan 1 00:00:00 1970 From: hjl@zoom.com (H.J. Lu) To: ian@cygnus.com (Ian Lance Taylor), eric@aib.com (Eric Youngdale) Cc: gas2@cygnus.com Subject: A patch for ld bug. Date: Sun, 28 Jan 1996 10:33:00 -0000 Message-id: X-SW-Source: 1996/msg00004.html I am enclosing a patch for the bug below. Does that look right? BTW, if is correct for x86, should other archs be fixed also? Thanks. Index: elf32-i386.c =================================================================== RCS file: /home/cvs/gnu/binutils/bfd/elf32-i386.c,v retrieving revision 1.9 diff -c -r1.9 elf32-i386.c *** elf32-i386.c 1996/01/19 06:22:23 1.9 --- elf32-i386.c 1996/01/28 18:25:41 *************** *** 559,569 **** real definition first, and we can just use the same value. */ if (h->weakdef != NULL) { BFD_ASSERT (h->weakdef->root.type == bfd_link_hash_defined || h->weakdef->root.type == bfd_link_hash_defweak); ! h->root.u.def.section = h->weakdef->root.u.def.section; ! h->root.u.def.value = h->weakdef->root.u.def.value; ! return true; } /* This is a reference to a symbol defined by a dynamic object which --- 559,580 ---- real definition first, and we can just use the same value. */ if (h->weakdef != NULL) { + struct elf_link_hash_entry *realdef; + BFD_ASSERT (h->weakdef->root.type == bfd_link_hash_defined || h->weakdef->root.type == bfd_link_hash_defweak); ! ! /* We need to find a real defined symbol. H.J. */ ! for (realdef = h->weakdef; ! realdef->weakdef && realdef != h; realdef = realdef->weakdef); ! ! /* We find a real definition. H.J. */ ! if (realdef->weakdef == NULL) ! { ! h->root.u.def.section = h->weakdef->root.u.def.section; ! h->root.u.def.value = h->weakdef->root.u.def.value; ! return true; ! } } /* This is a reference to a symbol defined by a dynamic object which *************** *** 627,632 **** --- 638,658 ---- /* Increment the section size to make room for the symbol. */ s->_raw_size += h->size; + + /* We just adjust a weak symbol. We need to check all the + * aliases. H.J. */ + if (h->weakdef != NULL) + { + struct elf_link_hash_entry *realdef; + + /* We need to find a real defined symbol. H.J. */ + for (realdef = h->weakdef; + realdef != h; realdef = realdef->weakdef) + { + realdef->root.u.def.section = h->root.u.def.section; + realdef->root.u.def.value = h->root.u.def.value; + } + } return true; } -- H.J. Lu (hjl@gnu.ai.mit.edu) ---- #!/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 1996-01-28 10:30 PST by . # Source directory was `/home/hjl/bugs/ld/weak2'. # # Existing files will *not* be overwritten unless `-c' is specified. # # This shar contains: # length mode name # ------ ---------- ------------------------------------------ # 207 -rw-r--r-- Makefile # 778 -rw------- bug.log # 132 -rw-r--r-- foo.c # 147 -rw-r--r-- main.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' && all: foo X libfoo.so: foo.o X $(CC) -shared -o $@ foo.o X foo.o: foo.c X $(CC) $(CFLAGS) -fPIC -c $? X foo: libfoo.so main.o X $(CC) -o $@ main.o -L. -lfoo X LD_LIBRARY_PATH=. foo X clean: X -rm -rf *.o *.so foo bar SHAR_EOF $shar_touch -am 0128092196 'Makefile' && chmod 0644 'Makefile' || echo 'restore of Makefile failed' shar_count="`wc -c < 'Makefile'`" test 207 -eq "$shar_count" || echo "Makefile: original size 207, current size $shar_count" fi # ============= bug.log ============== if test -f 'bug.log' && test X"$1" != X"-c"; then echo 'x - skipping bug.log (file already exists)' else echo 'x - extracting bug.log (binary)' sed 's/^X//' << 'SHAR_EOF' | uudecode && begin 600 bug.log M4F5A9&EN9R!S<&5C"\R+C&5C=71I;F<@9V-C('9E"]B:6XO;&0@+6T@96QF7VDS.#8@+61Y;F%M:6,M M;&EN:V5R("]L:6(O;&0M;&EN=7@N"]L:6(@;6%I;BYO("UL9F]O("UL9V-C("UL8R`M;&=C8R`O=7-R+VQI8B]G M8V,M;&EB+VDT.#8M;&EN=7@O,BXW+C(M.38P,3(V+V-R=&5N9"YO("]UF%T:6]N(&UA:V5S('!O:6YT97(@9G)O;2!I;G1E9V5R M('=I=&AO=70@82!C87-T"B]T;7`O8V-A,#4Q-#0N 'foo.c' && #pragma weak __foo X #if 1 #pragma weak foo = __foo #else #include elf_alias (__foo, foo); #endif X char **__foo = 100; SHAR_EOF $shar_touch -am 0128102996 'foo.c' && chmod 0644 'foo.c' || echo 'restore of foo.c failed' shar_count="`wc -c < 'foo.c'`" test 132 -eq "$shar_count" || echo "foo.c: original size 132, 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' && #include X extern char **__foo; extern char **foo; main () { X printf ("__foo: %x\n", __foo); X printf ("foo: %x\n", foo); X X return 0; } SHAR_EOF $shar_touch -am 0128102896 'main.c' && chmod 0644 'main.c' || echo 'restore of main.c failed' shar_count="`wc -c < 'main.c'`" test 147 -eq "$shar_count" || echo "main.c: original size 147, current size $shar_count" fi exit 0