This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
PATCH: Remember the symbol size if it isn't undefined
- From: "H. J. Lu" <hjl at lucon dot org>
- To: Sergei Poselenov <sposelenov at emcraft dot com>
- Cc: binutils at sourceware dot org
- Date: Thu, 28 Dec 2006 16:23:15 -0800
- Subject: PATCH: Remember the symbol size if it isn't undefined
- References: <45926C03.1020100@emcraft.com>
On Wed, Dec 27, 2006 at 03:50:11PM +0300, Sergei Poselenov wrote:
> Hello,
>
> We have run into this problem when building the Xenomai 2.3-rc2
> testsuite for ARM target using Gcc 4.0.0/binutils-2.16.1/uClibc-0.9.27
>
> We were able to create a simpler testcase and tried it on some
> x86-based systems.
>
>
> - When using binutils-2.17.50.0.3-6 (Fedora Core 6) the linker
> outputs:
> /usr/bin/ld: /usr/bin/ld: BFD 2.17.50.0.3-6 20060715 internal error,
> aborting at ../../bfd/bfd.c line 506 in _bfd_default_error_handler
>
> /usr/bin/ld: Please report this bug.
>
> collect2: ld returned 1 exit status
>
> - On old RedHat 9 (binutils-2.13.90.0.18-9) the linking went ok with
> warning:
> /usr/bin/ld: Warning: size of symbol `__wrap_pthread_getschedparam1'
> changed from 5 to 38 in ./libmy.so
>
> - On Fedore Core-5 (binutils-2.16.91.0.6-5), the test even
> segfaults:
> gcc -c wrap.c lib.c func.c pthread.c -g -fpic
> gcc -shared -o libpthread1.so pthread.o -g
> gcc -shared -o libmy.so lib.o wrap.o ./libpthread1.so -g
> gcc -c -o main.o main.c -g
> gcc -o main -Wl,--wrap -Wl,pthread_getschedparam1 main.o ./libmy.so
> ./libpthread1.so
> collect2: ld terminated with signal 11 [Segmentation fault]
> /usr/bin/ld: make: *** [all] Error 1
>
>
> Interstingly enough, the error is gone if the libmy.so DSO is linked
> without the reference to libpthread1.so, i.e.:
>
> gcc -shared -o libmy.so lib.o wrap.o -g
>
> The testcase tarball and proposed fix to bfd/elflink.c are attached.
>
The problem is we remember the symbol size for undefined symbol and
later we find out its size changes. Do we really care if an undefined
symble changes size? This patch fixes it.
H.J.
----
2006-12-28 H.J. Lu <hongjiu.lu@intel.com>
* elflink.c (elf_link_add_object_symbols): Remember the symbol
size only if it is defined.
--- bfd/elflink.c.common 2006-12-28 14:20:35.000000000 -0800
+++ bfd/elflink.c 2006-12-28 16:17:57.000000000 -0800
@@ -4058,11 +4058,13 @@ elf_link_add_object_symbols (bfd *abfd,
}
}
- /* Remember the symbol size and type. */
- if (isym->st_size != 0
+ /* Remember the symbol size if it isn't undefined. */
+ if ((isym->st_size != 0 && isym->st_shndx != SHN_UNDEF)
&& (definition || h->size == 0))
{
- if (h->size != 0 && h->size != isym->st_size && ! size_change_ok)
+ if (h->size != 0
+ && h->size != isym->st_size
+ && ! size_change_ok)
(*_bfd_error_handler)
(_("Warning: size of symbol `%s' changed"
" from %lu in %B to %lu in %B"),