This is the mail archive of the 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]

[Patch]: Fix relocation of PE dll 's containing undefined weak symbols

The attached testcase illustrates a bug in ld/pe-dll.c caused by the
generation of relocs for undefined weak symbols in dll's. Normal
undefined symbols will cause build of a dll to fail with "undefined
reference" error since windows shared libraries are execultables
requiring all symbols to be resolved. Undefined weak symbols howver are
resolved via a [linker-generated] alias.

The executable created by the testcase fails to initialize with system
error STATUS_ACCESS_VIOLATION (0xC0000005L). If the dlls are built with
non-conflicting image bases, relocation is not necessary, so the executable

The following patch, extracted from a patch submitted to the mingw users
list by Takashi Ono, fixes.

2008-07-30  Takashi Ono  <>

	* pe-dll.c (generate_relocs): Don't generate relocs for undefined weak

Index: pe-dll.c
RCS file: /cvs/src/src/ld/pe-dll.c,v
retrieving revision 1.106
diff -c -3 -p -r1.106 pe-dll.c
*** pe-dll.c	9 Jul 2008 03:18:15 -0000	1.106
--- pe-dll.c	30 Jul 2008 08:10:00 -0000
*************** generate_reloc (bfd *abfd, struct bfd_li
*** 1256,1261 ****
--- 1256,1271 ----
  		  bfd_vma sym_vma;
  		  struct bfd_symbol *sym = *relocs[i]->sym_ptr_ptr;

+ 		  /* Don't create reloc for undefined weak symbols.  */
+ 		  if (sym->flags == BSF_WEAK)
+ 		    {
+ 		      struct bfd_link_hash_entry *blhe
+ 			= bfd_link_hash_lookup (info->hash, sym->name,
+ 		      if (!blhe || blhe->type != bfd_link_hash_defined)
+ 			continue;		
+ 		    }
  		  sym_vma = (relocs[i]->addend
  			     + sym->value
  			     + sym->section->vma

Attachment: weak_reloc.tar.gz
Description: GNU Zip compressed data

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