This is the mail archive of the binutils@sources.redhat.com 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]

[Patch] Fix section flags in dlltool



The stub ds*.o files created by dlltool.c have different section
attributes for .text, .data and .bss sections than those generated
by gas.  This cause the Microsoft linker to generate warning
messages when linking against import libraries created by dlltool
under cygwin.

Warning LNK4078: multiple ".bss" sections found with different attributes.

The "obvious" patch below ensures that bfd_set_section_flags are
called with identical values to those in used in gas/as.c.  Whilst
I was there, I also fixed a variable may be used uninitialized warning
in the same function.

Alas no copyright assignment, but the fix is both obvious and taken
directly from the gas source code in binutils.  Tested on i686-pc-cygwin
and with LINK.EXE from MSVC 5.0 and 6.0.



*** ChangeLog.orig	Wed Mar 28 13:10:53 2001
--- ChangeLog	Wed Mar 28 13:18:18 2001
***************
*** 1,3 ****
--- 1,9 ----
+ 2001-03-28  Roger Sayle <roger@metaphorics.com>
+ 
+ 	* dlltool.c (make_one_lib_file): Fix section flags for
+ 	.text, .data and .bss in stub ds*.o files to match those
+ 	generated by gas.
+ 
  2001-03-26  Andreas Jaeger  <aj@suse.de>
  
  	* binutils.texi (nm): Fix texi syntax.
*** dlltool.c.orig	Wed Mar 28 12:38:05 2001
--- dlltool.c	Wed Mar 28 17:44:30 2001
*************** typedef struct
*** 2076,2091 ****
  
  #define NSECS 7
  
! #define INIT_SEC_DATA(id, name, flags, align) { id, name, flags, align, NULL, NULL, NULL, 0, NULL }
  static sinfo secdata[NSECS] =
  {
!   INIT_SEC_DATA (TEXT,   ".text",    SEC_CODE | SEC_HAS_CONTENTS, 2),
!   INIT_SEC_DATA (DATA,   ".data",    SEC_DATA,                    2),
!   INIT_SEC_DATA (BSS,    ".bss",     0,                           2),
!   INIT_SEC_DATA (IDATA7, ".idata$7", SEC_HAS_CONTENTS,            2),
!   INIT_SEC_DATA (IDATA5, ".idata$5", SEC_HAS_CONTENTS,            2),
!   INIT_SEC_DATA (IDATA4, ".idata$4", SEC_HAS_CONTENTS,            2),
!   INIT_SEC_DATA (IDATA6, ".idata$6", SEC_HAS_CONTENTS,            1)
  };
  
  #else
--- 2076,2097 ----
  
  #define NSECS 7
  
! #define TEXT_SEC_FLAGS   \
!         (SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_READONLY | SEC_HAS_CONTENTS)
! #define DATA_SEC_FLAGS   (SEC_ALLOC | SEC_LOAD | SEC_DATA)
! #define BSS_SEC_FLAGS     SEC_ALLOC
! 
! #define INIT_SEC_DATA(id, name, flags, align) \
!         { id, name, flags, align, NULL, NULL, NULL, 0, NULL }
  static sinfo secdata[NSECS] =
  {
!   INIT_SEC_DATA (TEXT,   ".text",    TEXT_SEC_FLAGS,   2),
!   INIT_SEC_DATA (DATA,   ".data",    DATA_SEC_FLAGS,   2),
!   INIT_SEC_DATA (BSS,    ".bss",     BSS_SEC_FLAGS,    2),
!   INIT_SEC_DATA (IDATA7, ".idata$7", SEC_HAS_CONTENTS, 2),
!   INIT_SEC_DATA (IDATA5, ".idata$5", SEC_HAS_CONTENTS, 2),
!   INIT_SEC_DATA (IDATA4, ".idata$4", SEC_HAS_CONTENTS, 2),
!   INIT_SEC_DATA (IDATA6, ".idata$6", SEC_HAS_CONTENTS, 1)
  };
  
  #else
*************** make_one_lib_file (exp, i)
*** 2231,2237 ****
      {
        bfd *      abfd;
        asymbol *  exp_label;
!       asymbol *  iname;
        asymbol *  iname2;
        asymbol *  iname_lab;
        asymbol ** iname_lab_pp;
--- 2237,2243 ----
      {
        bfd *      abfd;
        asymbol *  exp_label;
!       asymbol *  iname = 0;
        asymbol *  iname2;
        asymbol *  iname_lab;
        asymbol ** iname_lab_pp;
*************** make_one_lib_file (exp, i)
*** 2245,2250 ****
--- 2251,2257 ----
  #define EXTRA    0
  #endif
        asymbol *  ptrs[NSECS + 4 + EXTRA + 1];
+       flagword   applicable;
  
        char *     outname = xmalloc (10);
        int        oidx = 0;
*************** make_one_lib_file (exp, i)
*** 2269,2274 ****
--- 2276,2283 ----
  	bfd_set_private_flags (abfd, F_INTERWORK);
  #endif
        
+       applicable = bfd_applicable_section_flags (abfd);
+  
        /* First make symbols for the sections */
        for (i = 0; i < NSECS; i++)
  	{
*************** make_one_lib_file (exp, i)
*** 2278,2284 ****
  	  si->sec = bfd_make_section_old_way (abfd, si->name);
  	  bfd_set_section_flags (abfd,
  				 si->sec,
! 				 si->flags);
  
  	  bfd_set_section_alignment(abfd, si->sec, si->align);
  	  si->sec->output_section = si->sec;
--- 2287,2293 ----
  	  si->sec = bfd_make_section_old_way (abfd, si->name);
  	  bfd_set_section_flags (abfd,
  				 si->sec,
! 				 si->flags & applicable);
  
  	  bfd_set_section_alignment(abfd, si->sec, si->align);
  	  si->sec->output_section = si->sec;

Roger
--
Roger Sayle,                         E-mail: roger@metaphorics.com
Bioinformatics Group, Metaphorics,   WWW: http://www.metaphorics.com/
Office 104, 441 Greg Avenue,         Tel: (+1) 505-954-3281
Santa Fe, New Mexico, 87501.         Fax: (+1) 505-989-1200


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