[csl-sol210] Patch to disable constant pools

Joseph S. Myers joseph@codesourcery.com
Fri May 20 22:34:00 GMT 2005


This patch, for csl-sol210-3_4-branch, adds a compiler option 
-fno-constant-pools to disable the use of constant pools, for the use of 
dynamic linker code before the GOT is set up, where the address of a 
constant pool cannot be referenced.  This patch achieves the aim of 
preventing the use of a constant pool for the specific dynamic linker code 
on SPARC Solaris for which it was written; a more general feature along 
these lines would probably need more changes.

Any comments on whether this, as-is or in a more general form, would be a 
useful feature for mainline?  There already exists the target-specific 
alpha option -mbuild-constants to do something like this, with the same 
documented reason, and in general target-specific code would be needed to 
implement this option for many targets.  However, I wouldn't expect to be 
able to contribute much more than an updated version of this patch to 
mainline, given that this patch as-is satisfies customer requirements of 
building a specific source file without a GOT.

Bootstrapped with no regressions on sparc-sun-solaris2.10.1.  Applied
to csl-sol210-3_4-branch.

-- 
Joseph S. Myers               http://www.srcf.ucam.org/~jsm28/gcc/
    jsm@polyomino.org.uk (personal mail)
    joseph@codesourcery.com (CodeSourcery mail)
    jsm28@gcc.gnu.org (Bugzilla assignments and CCs)

2005-05-20  Joseph S. Myers  <joseph@codesourcery.com>

	* gcc/common.opt (fconstant-pools): New.
	* gcc/doc/invoke.texi (-fno-constant-pools): Document.
	* gcc/flags.h (flag_constant_pools): New.
	* gcc/opts.c (common_handle_option): Handle OPT_fconstant_pools.
	* gcc/toplev.c (flag_constant_pools): New.
	* gcc/varasm.c (force_const_mem): Return NULL_RTX for
	-fno-constant-pools.
	* gcc/reload.c (find_reloads): Do not try reloading a constant
	from a constant pool if -fno-constant-pools.

diff -rupN GCC.orig/gcc/common.opt GCC/gcc/common.opt
--- GCC.orig/gcc/common.opt	2005-05-06 02:33:13.000000000 +0000
+++ GCC/gcc/common.opt	2005-05-18 19:46:30.000000000 +0000
@@ -262,6 +262,10 @@ fcommon
 Common
 Do not put uninitialized globals in the common section
 
+fconstant-pools
+Common
+Put constants in pools in read-only memory if convenient
+
 fcprop-registers
 Common
 Perform a register copy-propagation optimization pass
diff -rupN GCC.orig/gcc/doc/invoke.texi GCC/gcc/doc/invoke.texi
--- GCC.orig/gcc/doc/invoke.texi	2005-05-19 20:38:46.000000000 +0000
+++ GCC/gcc/doc/invoke.texi	2005-05-19 20:38:39.000000000 +0000
@@ -668,7 +668,7 @@ in the following sections.
 -finhibit-size-directive  -finstrument-functions @gol
 -fno-common  -fno-ident @gol
 -fpcc-struct-return  -fpic  -fPIC -fpie -fPIE @gol
--fno-jump-tables @gol
+-fno-jump-tables  -fno-constant-pools @gol
 -freg-struct-return  -fshared-data  -fshort-enums @gol
 -fshort-double  -fshort-wchar @gol
 -fverbose-asm  -fpack-struct  -fstack-check @gol
@@ -11082,6 +11082,16 @@ of use in conjunction with @option{-fpic
 building code which forms part of a dynamic linker and cannot
 reference the address of a jump table.
 
+@item -fno-constant-pools
+@opindex fno-constant-pools
+Do not put constants other than user-declared constant variables in
+pools in read-only memory even if this requires constants to be built
+up in registers and spilled to the stack.  This option is of use in
+conjunction with @option{-fpic} or @option{-fPIC} for building code
+which forms part of a dynamic linker and cannot reference the address
+of a constant pool.  It may not work reliably for all code or on all
+targets.
+
 @item -ffixed-@var{reg}
 @opindex ffixed
 Treat the register named @var{reg} as a fixed register; generated code
diff -rupN GCC.orig/gcc/flags.h GCC/gcc/flags.h
--- GCC.orig/gcc/flags.h	2005-05-06 02:34:14.000000000 +0000
+++ GCC/gcc/flags.h	2005-05-18 19:49:06.000000000 +0000
@@ -496,6 +496,10 @@ extern int flag_shlib;
 
 extern int flag_jump_tables;
 
+/* Nonzero if we may use constant pools.  */
+
+extern int flag_constant_pools;
+
 /* Nonzero means generate extra code for exception handling and enable
    exception handling.  */
 
diff -rupN GCC.orig/gcc/opts.c GCC/gcc/opts.c
--- GCC.orig/gcc/opts.c	2005-05-18 19:49:53.000000000 +0000
+++ GCC/gcc/opts.c	2005-05-18 19:51:07.000000000 +0000
@@ -938,6 +938,10 @@ common_handle_option (size_t scode, cons
       flag_cse_skip_blocks = value;
       break;
 
+    case OPT_fconstant_pools:
+      flag_constant_pools = value;
+      break;
+
     case OPT_fdata_sections:
       flag_data_sections = value;
       break;
diff -rupN GCC.orig/gcc/reload.c GCC/gcc/reload.c
--- GCC.orig/gcc/reload.c	2004-09-14 18:48:29.000000000 +0000
+++ GCC/gcc/reload.c	2005-05-19 21:28:53.000000000 +0000
@@ -3130,6 +3130,7 @@ find_reloads (rtx insn, int replace, int
 			&& reg_renumber[REGNO (operand)] < 0))
 		  win = 1;
 		if (CONSTANT_P (operand)
+		    && flag_constant_pools
 		    /* force_const_mem does not accept HIGH.  */
 		    && GET_CODE (operand) != HIGH)
 		  badop = 0;
@@ -3194,7 +3195,8 @@ find_reloads (rtx insn, int replace, int
 			    || (reg_equiv_address[REGNO (operand)] != 0))))
 		  win = 1;
 		/* force_const_mem does not accept HIGH.  */
-		if ((CONSTANT_P (operand) && GET_CODE (operand) != HIGH)
+		if ((CONSTANT_P (operand) && flag_constant_pools
+		     && GET_CODE (operand) != HIGH)
 		    || GET_CODE (operand) == MEM)
 		  badop = 0;
 		constmemok = 1;
@@ -3314,7 +3316,8 @@ find_reloads (rtx insn, int replace, int
 			/* If we didn't already win, we can reload
 			   constants via force_const_mem, and other
 			   MEMs by reloading the address like for 'o'.  */
-			if ((CONSTANT_P (operand) && GET_CODE (operand) != HIGH)
+			if ((CONSTANT_P (operand) && flag_constant_pools
+			     && GET_CODE (operand) != HIGH)
 			    || GET_CODE (operand) == MEM)
 			  badop = 0;
 			constmemok = 1;
@@ -3391,6 +3394,7 @@ find_reloads (rtx insn, int replace, int
 		 precisely the same as in the code below that calls
 		 force_const_mem.  */
 	      if (CONSTANT_P (operand)
+		  && flag_constant_pools
 		  /* force_const_mem does not accept HIGH.  */
 		  && GET_CODE (operand) != HIGH
 		  && ((PREFERRED_RELOAD_CLASS (operand,
@@ -3773,6 +3777,7 @@ find_reloads (rtx insn, int replace, int
   for (i = 0; i < noperands; i++)
     if (! goal_alternative_win[i]
 	&& CONSTANT_P (recog_data.operand[i])
+	&& flag_constant_pools
 	/* force_const_mem does not accept HIGH.  */
 	&& GET_CODE (recog_data.operand[i]) != HIGH
 	&& ((PREFERRED_RELOAD_CLASS (recog_data.operand[i],
diff -rupN GCC.orig/gcc/toplev.c GCC/gcc/toplev.c
--- GCC.orig/gcc/toplev.c	2005-05-06 02:34:31.000000000 +0000
+++ GCC/gcc/toplev.c	2005-05-18 19:51:28.000000000 +0000
@@ -781,6 +781,10 @@ int flag_shlib;
 
 int flag_jump_tables = 1;
 
+/* Nonzero if we may use constant pools.  */
+
+int flag_constant_pools = 1;
+
 /* Set to the default thread-local storage (tls) model to use.  */
 
 enum tls_model flag_tls_default = TLS_MODEL_GLOBAL_DYNAMIC;
diff -rupN GCC.orig/gcc/varasm.c GCC/gcc/varasm.c
--- GCC.orig/gcc/varasm.c	2004-10-31 09:10:03.000000000 +0000
+++ GCC/gcc/varasm.c	2005-05-18 19:51:51.000000000 +0000
@@ -2937,7 +2937,7 @@ force_const_mem (enum machine_mode mode,
   unsigned int align;
 
   /* If we're not allowed to drop X into the constant pool, don't.  */
-  if ((*targetm.cannot_force_const_mem) (x))
+  if (!flag_constant_pools || (*targetm.cannot_force_const_mem) (x))
     return NULL_RTX;
 
   /* Compute hash code of X.  Search the descriptors for that hash code



More information about the Gcc-patches mailing list