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]

Patch: Make PE-CFF "weak externals" behaviour consistent between GNU and MS linker.


Hello

In bfd/cofflink.c: _bfd_coff_generic_relocate_section a coment about
weak symbols on PE-COFF targets states (1) that currently PE-COFF weak
externals always have IMAGE_WEAK_EXTERN_SEARCH_LIBRARY charcteristic,
and (2) that is the only useful type of weak external for PE-COFF.

Neither of these statements are true. In fact, the current actual
behaviour of ld for PE_COFF weak externals, as determined by bfd/linker.c:
generic_link_check_archive_element is as specified by the SVR4 ABI and
that is equivalent to the PE-COFF characteristic
IMAGE_WEAK_EXTERN_SEARCH_NOLIBRARY.  I think this behaviour is just as
useful for PE-COFF as it is for other flavours of COFF, and should
remain the default.  

Now, currently gas writes the IMAGE_WEAK_EXTERN_SEARCH_LIBRARY aux info
into object files (in gas/config/obj-coff.c: obj_coff_weak). While ld
doesn't (yet) pay attention to this flag, the MS linker does. This means
that when the MS linker is given a GNU-toolchain produced object file
from:

extern int  __attribute__ ((weak)) atoi (const char* );
int foo()
{
  if (atoi)
   return atoi ("1");
  else
   return 0;
}

the MS linker will resolve atoi in the runtime import lib (a static
archive) and return 1. When GNU ld is given that same object file, and
the same MS runtime archive, foo will return 0, as expected from
SVR4/IMAGE_WEAK_EXTERN_SEARCH_NOLIBRARY behaviour.
 
This patch changes the comment in bfd/cofflink.c to reflect reality and
makes gas produce object files with IMAGE_WEAK_EXTERN_SEARCH_NOLIBRARY
characteristic set.

Danny

bfd/ChangeLog
2005-08-15  Danny Smith  <dannysmith@users.sourceforge.net>

	* cofflink.c (_bfd_coff_generic_relocate_section): Correct
	comment.

gas/ChangeLog
2005-08-15  Danny Smith  <dannysmith@users.sourceforge.net>

	* config/obj-coff.c (obj_coff_weak): Set auxiliary information
	of NT weak externals to IMAGE_WEAK_EXTERN_SEARCH_NOLIBRARY.

Index: bfd/cofflink.c
===================================================================
RCS file: /cvs/src/src/bfd/cofflink.c,v
retrieving revision 1.56
diff -c -3 -p -r1.56 cofflink.c
*** bfd/cofflink.c	4 May 2005 15:53:05 -0000	1.56
--- bfd/cofflink.c	14 Aug 2005 10:21:38 -0000
*************** _bfd_coff_generic_relocate_section (bfd 
*** 2937,2945 ****
  		     Note that weak symbols without aux records are a GNU
  		     extension.
  		     FIXME: All weak externals are treated as having
! 		     characteristics IMAGE_WEAK_EXTERN_SEARCH_LIBRARY (2).
! 		     There are no known uses of the other two types of
! 		     weak externals.  */
  		  asection *sec;
  		  struct coff_link_hash_entry *h2 =
  		    input_bfd->tdata.coff_obj_data->sym_hashes[
--- 2937,2947 ----
  		     Note that weak symbols without aux records are a GNU
  		     extension.
  		     FIXME: All weak externals are treated as having
! 		     characteristic IMAGE_WEAK_EXTERN_SEARCH_NOLIBRARY (1).
! 		     These behave as per SVR4 ABI:  A library member
! 		     will resolve a weak external only if a normal
! 		     external causes the library member to be linked.
! 		     See also linker.c: generic_link_check_archive_element. */
  		  asection *sec;
  		  struct coff_link_hash_entry *h2 =
  		    input_bfd->tdata.coff_obj_data->sym_hashes[
Index: gas/config/obj-coff.c
===================================================================
RCS file: /cvs/src/src/gas/config/obj-coff.c,v
retrieving revision 1.86
diff -c -3 -p -r1.86 obj-coff.c
*** gas/config/obj-coff.c	11 Aug 2005 01:25:24 -0000	1.86
--- gas/config/obj-coff.c	14 Aug 2005 10:22:05 -0000
*************** obj_coff_weak (int ignore ATTRIBUTE_UNUS
*** 1093,1099 ****
           the value of the weak symbol itself.  */
        S_SET_STORAGE_CLASS (symbolP, C_NT_WEAK);
        S_SET_NUMBER_AUXILIARY (symbolP, 1);
!       SA_SET_SYM_FSIZE (symbolP, IMAGE_WEAK_EXTERN_SEARCH_LIBRARY);
  
        alternateP = symbol_find_or_make (weak_name2altname (name));
        S_SET_EXTERNAL (alternateP);
--- 1093,1099 ----
           the value of the weak symbol itself.  */
        S_SET_STORAGE_CLASS (symbolP, C_NT_WEAK);
        S_SET_NUMBER_AUXILIARY (symbolP, 1);
!       SA_SET_SYM_FSIZE (symbolP, IMAGE_WEAK_EXTERN_SEARCH_NOLIBRARY);
  
        alternateP = symbol_find_or_make (weak_name2altname (name));
        S_SET_EXTERNAL (alternateP);

Send instant messages to your online friends http://au.messenger.yahoo.com 


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