weak symbol sizing
Alan Modra
amodra@bigpond.net.au
Tue Jul 26 15:19:00 GMT 2005
This testcase shows a problem with the way the linker merges weak
symbols. The linker correctly uses the first "_start", but gives the
symbol the size of the second "_start".
cat > weak1.s <<EOF
.weak _start
.type _start@function
.size _start, 4
_start:
.long 1
EOF
cat > weak2.s <<EOF
.weak _start
.type _start@function
.size _start, 8
_start:
.long 2
.long 2
EOF
as -o weak1.o weak1.s
as -o weak2.o weak2.s
ld -o weak weak1.o weak2.o
readelf -Ss weak
[snip]
[ 1] .text PROGBITS 08048074 000074 00000c 00 AX 0 0 4
[snip]
5: 08048074 8 FUNC WEAK DEFAULT 1 _start
[snip]
Fixed as follows. Tested for binutils, gcc and glibc regression
checks.
* elflink.c (_bfd_elf_merge_symbol): Skip weak redefinition
regardless of strength of previous definition.
Index: bfd/elflink.c
===================================================================
RCS file: /cvs/src/src/bfd/elflink.c,v
retrieving revision 1.179
diff -u -p -r1.179 elflink.c
--- bfd/elflink.c 25 Jul 2005 15:35:37 -0000 1.179
+++ bfd/elflink.c 26 Jul 2005 10:58:51 -0000
@@ -1216,7 +1216,7 @@ _bfd_elf_merge_symbol (bfd *abfd,
}
/* Skip weak definitions of symbols that are already defined. */
- if (newdef && olddef && newweak && !oldweak)
+ if (newdef && olddef && newweak)
*skip = TRUE;
/* If the old symbol is from a dynamic object, and the new symbol is
--
Alan Modra
IBM OzLabs - Linux Technology Centre
More information about the Binutils
mailing list