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]

[csl-sol210] Patch to add -fno-jump-tables


This patch, for csl-sol210-3_4-branch, adds a compiler option 
-fno-jump-tables to disable the use of jump tables for switch statements.  
This is for the use of dynamic linker code before the GOT is set up, where 
the address of a jump table cannot be referenced.  A separate patch to 
disable constant pools (to the extent they occur for the relevant dynamic 
linker code and cause similar problems on SPARC Solaris) is under 
development.

Any comments on whether this would be a useful feature for mainline?

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-19  Joseph S. Myers  <joseph@codesourcery.com>

	* gcc/common.opt (fjump-tables): New.
	* gcc/doc/invoke.texi (-fno-jump-tables): Document.
	* gcc/flags.h (flag_jump_tables): New.
	* gcc/opts.c (common_handle_option): Handle OPT_fjump_tables.
	* gcc/toplev.c (flag_jump_tables): New.
	* gcc/stmt.c (expand_end_case_type): Do not emit jump tables
	unless flag_jump_tables.

diff -rupN GCC.orig/gcc/common.opt GCC/gcc/common.opt
--- GCC.orig/gcc/common.opt	2004-10-28 03:43:09.000000000 +0000
+++ GCC/gcc/common.opt	2005-05-06 02:33:13.000000000 +0000
@@ -408,6 +408,10 @@ finstrument-functions
 Common
 Instrument function entry and exit with profiling calls
 
+fjump-tables
+Common
+Use jump tables for sufficiently large switch statements
+
 fkeep-inline-functions
 Common
 Generate code for functions even if they are fully inlined
diff -rupN GCC.orig/gcc/doc/invoke.texi GCC/gcc/doc/invoke.texi
--- GCC.orig/gcc/doc/invoke.texi	2004-10-06 20:15:08.000000000 +0000
+++ GCC/gcc/doc/invoke.texi	2005-05-18 22:35:34.000000000 +0000
@@ -668,6 +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
 -freg-struct-return  -fshared-data  -fshort-enums @gol
 -fshort-double  -fshort-wchar @gol
 -fverbose-asm  -fpack-struct  -fstack-check @gol
@@ -11073,6 +11074,14 @@ generated position independent code can 
 Usually these options are used when @option{-pie} GCC option will be
 used during linking.
 
+@item -fno-jump-tables
+@opindex fno-jump-tables
+Do not use jump tables for switch statements even where it would be
+more efficient than other code generation strategies.  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 jump table.
+
 @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	2004-02-18 00:09:04.000000000 +0000
+++ GCC/gcc/flags.h	2005-05-06 02:34:14.000000000 +0000
@@ -492,6 +492,10 @@ extern int flag_pie;
 
 extern int flag_shlib;
 
+/* Nonzero if we may use jump tables for switch statements.  */
+
+extern int flag_jump_tables;
+
 /* 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	2004-02-18 00:09:04.000000000 +0000
+++ GCC/gcc/opts.c	2005-05-18 19:49:53.000000000 +0000
@@ -1075,6 +1075,10 @@ common_handle_option (size_t scode, cons
       flag_instrument_function_entry_exit = value;
       break;
 
+    case OPT_fjump_tables:
+      flag_jump_tables = value;
+      break;
+
     case OPT_fkeep_inline_functions:
       flag_keep_inline_functions =value;
       break;
diff -rupN GCC.orig/gcc/stmt.c GCC/gcc/stmt.c
--- GCC.orig/gcc/stmt.c	2004-05-06 23:32:47.000000000 +0000
+++ GCC/gcc/stmt.c	2005-05-06 02:38:01.000000000 +0000
@@ -5524,6 +5524,7 @@ expand_end_case_type (tree orig_index, t
 #ifndef ASM_OUTPUT_ADDR_DIFF_ELT
 	       || flag_pic
 #endif
+	       || !flag_jump_tables
 	       || TREE_CONSTANT (index_expr))
 	{
 	  index = expand_expr (index_expr, NULL_RTX, VOIDmode, 0);
diff -rupN GCC.orig/gcc/toplev.c GCC/gcc/toplev.c
--- GCC.orig/gcc/toplev.c	2004-07-26 14:42:11.000000000 +0000
+++ GCC/gcc/toplev.c	2005-05-06 02:34:31.000000000 +0000
@@ -777,6 +777,10 @@ int flag_pie;
 
 int flag_shlib;
 
+/* Nonzero if we may use jump tables for switch statements.  */
+
+int flag_jump_tables = 1;
+
 /* Set to the default thread-local storage (tls) model to use.  */
 
 enum tls_model flag_tls_default = TLS_MODEL_GLOBAL_DYNAMIC;


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