This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[vxworks] PLT to weak symbol


this patch fixes a problem that vxworks rtp has with weak symbols. Consider:

app.c
	void Weak (void);
	void (*const ptr) (void) = &Weak;

lib.c
	void __attribute__((weak)) Weak (void) {}

This is what you get with a C++ class that has no key virtual function. Weak is an inline virtual function.

The problem vxworks has is that .rodata (where 'ptr' resides) is relocated by the kernel loader, and that doesn't know anything about 'Weak'. It blithely *ignores* the relocation we emit, and we end up with a broken image.

The rtp dynamic loader is responsible for filling in relocs to Weak, but it doesn't relocate .rodata and the like.

We already have special code to deal with the non-weak case here, and change the reloc for ptr's initializer to refer to .plt, which the kernel loader does know about. This patch makes it do the same thing for weak definitions too.

ok?

nathan
--
Nathan Sidwell    ::   http://www.codesourcery.com   ::         CodeSourcery
nathan@codesourcery.com    ::     http://www.planetfall.pwp.blueyonder.co.uk

2007-04-11  Nathan Sidwell  <nathan@codesourcery.com>

	* elf-vxworks.c (elf_vxworks_emit_relocs): Remap weakdef PLT slot
	relocs too.

Index: elf-vxworks.c
===================================================================
RCS file: /cvs/src/src/bfd/elf-vxworks.c,v
retrieving revision 1.5
diff -c -3 -p -r1.5 elf-vxworks.c
*** elf-vxworks.c	4 Aug 2006 13:13:55 -0000	1.5
--- elf-vxworks.c	11 Apr 2007 09:46:46 -0000
*************** elf_vxworks_emit_relocs (bfd *output_bfd
*** 170,176 ****
  	  && *rel_hash
  	  && (*rel_hash)->def_dynamic
  	  && !(*rel_hash)->def_regular
! 	  && (*rel_hash)->root.type == bfd_link_hash_defined
  	  && (*rel_hash)->root.u.def.section->output_section != NULL)
  	{
  	  /* This is a relocation from an executable or shared library
--- 170,177 ----
  	  && *rel_hash
  	  && (*rel_hash)->def_dynamic
  	  && !(*rel_hash)->def_regular
! 	  && ((*rel_hash)->root.type == bfd_link_hash_defined
! 	      || (*rel_hash)->root.type == bfd_link_hash_weakdef)
  	  && (*rel_hash)->root.u.def.section->output_section != NULL)
  	{
  	  /* This is a relocation from an executable or shared library

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]