This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC 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]: Use .rdata section for initialized consts on mingw and cygwin


Hello,

Currently GCC puts initialised data constants  in .text section
Well, most of the time.  CC1PLUS  put artificial data consts
(vtables and such) .rdata$* sections. Likewise, -fdata-sections
puts initialized consts into .rdata$* sections.  But in neither
of these cases does it set the section flags correctly.


For instance:

/* rdata1.c */
const int foo = 3;


> gcc -S -fdata-sections rdata1.c

gives:

	.file	"rdata1.c"
.globl _foo
	.section	.rdata$foo,""  <<< section flag not set
	.align 4
_foo:
	.long	3


Without -fdata-sections foo goes into .text.

Other windows compilers put initialized constants into rdata.

One problem is that cygwin and mingw don't define
READONLY_DATA_SECTION_ASM_OP. The other is that the code the
handles named sections, doesn't handle case in_readonly_data


The following fixes.  Note, that the section flag "dr" should be
just "r".  But until recently, gas didn't handle "r" as data, so
we make it explicit.for compatability with older binutils.

Bootstrap and tested on i686-pc-mingw with binutils 2.13 and
CVS binutils.

I have _not_ tested with interix, which also uses winnt.c.  I don't
know what assembler interix uses, but I don't think it is gas.
Could an interix maintainer test please.  (I couldn't find an interix
maintainer in the MAINTAINERS file).


2003-10-06  Danny Smith  <dannysmith@users.sourceforge.net>

	* config/i386/cygming.h (READONLY_DATA_SECTION_ASM_OP): Define.
	(switch_to_section): Handle in_readonly_data.
	* config/i386/winnt.c (i386_pe_asm_named_section): Handle
	readonly data.


Index: config/i386/cygming.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/i386/cygming.h,v
retrieving revision 1.7
diff -c -3 -p -r1.7 cygming.h
*** config/i386/cygming.h	30 Sep 2003 21:28:09 -0000	1.7
--- config/i386/cygming.h	6 Oct 2003 22:11:46 -0000
*************** drectve_section (void)							\
*** 132,137 ****
--- 132,141 ----
  }
  void drectve_section (void);
  
+ /* Older versions of gas don't handle 'r' as data.
+    Explicitly set data flag with 'd'.  */  
+ #define READONLY_DATA_SECTION_ASM_OP "\t.section .rdata,\"dr\""
+ 
  /* Switch to SECTION (an `enum in_section').
  
     ??? This facility should be provided by GCC proper.
*************** switch_to_section (enum in_section secti
*** 147,152 ****
--- 151,157 ----
      {								\
        case in_text: text_section (); break;			\
        case in_data: data_section (); break;			\
+       case in_readonly_data: readonly_data_section (); break;	\
        case in_named: named_section (decl, NULL, 0); break;	\
        case in_drectve: drectve_section (); break;		\
        default: abort (); break;				\
Index: config/i386/winnt.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/i386/winnt.c,v
retrieving revision 1.57
diff -c -3 -p -r1.57 winnt.c
*** config/i386/winnt.c	30 Sep 2003 21:28:09 -0000	1.57
--- config/i386/winnt.c	6 Oct 2003 22:11:48 -0000
*************** i386_pe_asm_named_section (const char *n
*** 710,721 ****
  {
    char flagchars[8], *f = flagchars;
  
!   if (flags & SECTION_CODE)
!     *f++ = 'x';
!   if (flags & SECTION_WRITE)
!     *f++ = 'w';
!   if (flags & SECTION_PE_SHARED)
!     *f++ = 's';
    *f = '\0';
  
    fprintf (asm_out_file, "\t.section\t%s,\"%s\"\n", name, flagchars);
--- 710,731 ----
  {
    char flagchars[8], *f = flagchars;
  
!   if ((flags & (SECTION_CODE | SECTION_WRITE)) == 0)
!     /* readonly data */
!     {
!       *f++ ='d';  /* This is necessary for older versions of gas.  */
!       *f++ ='r';
!     }
!   else	
!   {
!     if (flags & SECTION_CODE)
!       *f++ = 'x';
!     if (flags & SECTION_WRITE)
!       *f++ = 'w';
!     if (flags & SECTION_PE_SHARED)
!       *f++ = 's';
!   }
! 
    *f = '\0';
  
    fprintf (asm_out_file, "\t.section\t%s,\"%s\"\n", name, flagchars);

http://search.yahoo.com.au - Yahoo! Search
- Looking for more? Try the new Yahoo! Search


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