[patch]: flag to store uninitialized const vars in rodata

Diego Novillo dnovillo@cygnus.com
Wed Nov 17 16:12:00 GMT 1999


The following patch adds a new target-specific switch that used
together with -membedded-data, causes uninitialized const
variable declarations to be placed in the read-only section.

The patch has been approved by Jim Wilson. Is it OK to check-in?

Thanks. Diego.

Wed Nov 17 17:08:59 MST 1999	Diego Novillo <dnovillo@cygnus.com>

	* invoke.texi: Add documentation for -muninit-const-in-rodata.
	* mips.h (MASK_UNINIT_CONST_IN_RODATA): Define.
	(TARGET_UNINIT_CONST_IN_RODATA): Define.
	(text_section): Add switches -munint-const-in-rodata and
	-mno-uninit-const-in-rodata.
	(ASM_OUTPUT_COMMON): Remove.
	(ASM_OUTPUT_ALIGNED_DECL_COMMON): Define. Check if uninitialized
	const objects should be placed in read-only data. Otherwise declare
	them in common.


Index: invoke.texi
===================================================================
RCS file: /cvs/gcc/egcs/gcc/invoke.texi,v
retrieving revision 1.150
diff -c -p -r1.150 invoke.texi
*** invoke.texi	1999/11/10 07:53:20	1.150
--- invoke.texi	1999/11/18 00:04:15
*************** in the following sections.
*** 334,345 ****
  -mminimum-fp-blocks  -mnohc-struct-return
  
  @emph{MIPS Options}
! -mabicalls  -mcpu=@var{cpu type}  -membedded-data
  -membedded-pic  -mfp32  -mfp64  -mgas  -mgp32  -mgp64
  -mgpopt  -mhalf-pic  -mhard-float  -mint64  -mips1
  -mips2  -mips3 -mips4 -mlong64  -mlong32 -mlong-calls  -mmemcpy
  -mmips-as  -mmips-tfile  -mno-abicalls
! -mno-embedded-data  -mno-embedded-pic
  -mno-gpopt  -mno-long-calls
  -mno-memcpy  -mno-mips-tfile  -mno-rnames  -mno-stats
  -mrnames  -msoft-float
--- 334,345 ----
  -mminimum-fp-blocks  -mnohc-struct-return
  
  @emph{MIPS Options}
! -mabicalls  -mcpu=@var{cpu type}  -membedded-data -muninit-const-in-rodata
  -membedded-pic  -mfp32  -mfp64  -mgas  -mgp32  -mgp64
  -mgpopt  -mhalf-pic  -mhard-float  -mint64  -mips1
  -mips2  -mips3 -mips4 -mlong64  -mlong32 -mlong-calls  -mmemcpy
  -mmips-as  -mmips-tfile  -mno-abicalls
! -mno-embedded-data  -mno-uninit-const-in-rodata  -mno-embedded-pic
  -mno-gpopt  -mno-long-calls
  -mno-memcpy  -mno-mips-tfile  -mno-rnames  -mno-stats
  -mrnames  -msoft-float
*************** next in the small data section if possib
*** 5574,5579 ****
--- 5574,5584 ----
  slightly slower code than the default, but reduces the amount of RAM required
  when executing, and thus may be preferred for some embedded systems.
  
+ @item -muninit-const-in-rodata
+ @itemx -mno-uninit-const-in-rodata
+ When used together with -membedded-data, it will always store uninitialized
+ const variables in the read-only data section.
+   
  @item -msingle-float
  @itemx -mdouble-float
  The @samp{-msingle-float} switch tells gcc to assume that the floating
Index: config/mips/mips.h
===================================================================
RCS file: /cvs/gcc/egcs/gcc/config/mips/mips.h,v
retrieving revision 1.74
diff -c -p -r1.74 mips.h
*** mips.h	1999/10/26 20:29:34	1.74
--- mips.h	1999/11/18 00:04:20
*************** extern void		sbss_section PARAMS ((void)
*** 209,214 ****
--- 209,216 ----
  #define MASK_MIPS16	0x01000000	/* Generate mips16 code */
  #define MASK_NO_CHECK_ZERO_DIV 0x04000000	/* divide by zero checking */
  #define MASK_CHECK_RANGE_DIV 0x08000000	/* divide result range checking */
+ #define MASK_UNINIT_CONST_IN_RODATA 0x10000000	/* Store uninitialized
+ 						   consts in rodata */
  
  					/* Dummy switches used only in spec's*/
  #define MASK_MIPS_TFILE	0x00000000	/* flag for mips-tfile usage */
*************** extern void		sbss_section PARAMS ((void)
*** 288,293 ****
--- 290,300 ----
  					   fastest code.  */
  #define TARGET_EMBEDDED_DATA	(target_flags & MASK_EMBEDDED_DATA)
  
+ 					/* always store uninitialized const
+ 					   variables in rodata, requires
+ 					   TARGET_EMBEDDED_DATA. */
+ #define TARGET_UNINIT_CONST_IN_RODATA	(target_flags & MASK_UNINIT_CONST_IN_RODATA)
+ 
  					/* generate big endian code.  */
  #define TARGET_BIG_ENDIAN	(target_flags & MASK_BIG_ENDIAN)
  
*************** extern void		sbss_section PARAMS ((void)
*** 392,397 ****
--- 399,408 ----
       "Use ROM instead of RAM"},						\
    {"no-embedded-data",	 -MASK_EMBEDDED_DATA,				\
       "Don't use ROM instead of RAM"},					\
+   {"uninit-const-in-rodata", MASK_UNINIT_CONST_IN_RODATA,		\
+      "Put uninitialized constants in ROM (needs -membedded-data)"},	\
+   {"no-uninit-const-in-rodata", -MASK_UNINIT_CONST_IN_RODATA,		\
+      "Don't put uninitialized constants in ROM"},			\
    {"eb",		  MASK_BIG_ENDIAN,				\
       "Use big-endian byte order"},					\
    {"el",		 -MASK_BIG_ENDIAN,				\
*************** while (0)
*** 4187,4195 ****
    } while (0)
  
  /* This says how to define a global common symbol.  */
  
- #define ASM_OUTPUT_COMMON(STREAM, NAME, SIZE, ROUNDED)			\
-   mips_declare_object (STREAM, NAME, "\n\t.comm\t", ",%u\n", (SIZE))
  
  /* This says how to define a local common symbol (ie, not visible to
     linker).  */
--- 4198,4226 ----
    } while (0)
  
  /* This says how to define a global common symbol.  */
+ 
+ #define ASM_OUTPUT_ALIGNED_DECL_COMMON(STREAM, DECL, NAME, SIZE, ALIGN) \
+   do {									\
+     /* If the target wants uninitialized const declarations in		\
+        .rdata then don't put them in .comm */				\
+     if (TARGET_EMBEDDED_DATA && TARGET_UNINIT_CONST_IN_RODATA		\
+ 	&& TREE_CODE (DECL) == VAR_DECL && TREE_READONLY (DECL)		\
+ 	&& (DECL_INITIAL (DECL) == 0					\
+ 	    || DECL_INITIAL (DECL) == error_mark_node))			\
+       {									\
+ 	if (TREE_PUBLIC (DECL) && DECL_NAME (DECL))			\
+ 	  ASM_GLOBALIZE_LABEL (STREAM, NAME);				\
+ 	    								\
+ 	READONLY_DATA_SECTION ();					\
+ 	ASM_OUTPUT_ALIGN (STREAM, floor_log2 (ALIGN / BITS_PER_UNIT));	\
+ 	mips_declare_object (STREAM, NAME, "", ":\n\t.space\t%u\n",	\
+ 	    (SIZE));							\
+       }									\
+     else								\
+       mips_declare_object (STREAM, NAME, "\n\t.comm\t", ",%u\n",	\
+ 	  (SIZE));							\
+   } while (0)
  
  
  /* This says how to define a local common symbol (ie, not visible to
     linker).  */



More information about the Gcc-patches mailing list