RFC: Desupport -fwritable-strings

Zack Weinberg zack@codesourcery.com
Mon Apr 21 01:08:00 GMT 2003


-fwritable-strings is a crutch for pre-C89 code.  It seems unlikely,
to me, that anyone needs it anymore.  And it's got tentacles into
rather a lot of backend code.  So I would like to propose that we
deprecate it in 3.3 and remove it from 3.4.

The appended patches have not even been compiled; they are for
illustration.  If we like the idea I will do proper testing.

zw

for webpage:
===================================================================
Index: gcc-3.3/changes.html
--- gcc-3.3/changes.html	15 Apr 2003 21:27:20 -0000	1.23
+++ gcc-3.3/changes.html	21 Apr 2003 01:07:56 -0000
@@ -57,6 +57,9 @@
         <code><varargs.h></code> header, used for writing
 	variadic functions in traditional C, still exists but will
 	produce an error message if used.</li>
+
+   <li>The <code>-fwritable-strings</code> C compiler option has been
+       deprecated and will be removed in GCC 3.4.</li>
   </ul>
 
 
===================================================================
Index: gcc-3.4/changes.html
--- gcc-3.4/changes.html	15 Apr 2003 21:27:20 -0000	1.20
+++ gcc-3.4/changes.html	21 Apr 2003 01:07:56 -0000
@@ -24,6 +24,9 @@
 	It is unlikely that they worked correctly in any 3.x release.</li>
     <li>GCC no longer ships <code><varargs.h></code>.  Use
         <code><stdarg.h></code> instead.</li>
+    <li>GCC no longer accepts the <code>-fwritable-strings</code>
+        option.  Use named character arrays when you need a writable
+        string.</li>
   </ul>
 
 <h2>General Optimizer Improvements</h2>


for 3.3:
===================================================================
Index: toplev.c
--- toplev.c	2 Apr 2003 07:14:28 -0000	1.690.2.15
+++ toplev.c	21 Apr 2003 01:05:02 -0000
@@ -4985,6 +4985,9 @@ parse_options_and_default_flags (argc, a
 	}
     }
 
+  if (flag_writable_strings)
+    warning ("-fwritable-strings is deprecated and will be removed in GCC 3.4");
+
   if (flag_no_inline == 2)
     flag_no_inline = 0;
   else


for 3.4:
===================================================================
Index: c-common.c
--- c-common.c	14 Apr 2003 03:13:03 -0000	1.410
+++ c-common.c	21 Apr 2003 00:53:18 -0000
@@ -1208,7 +1208,7 @@ fix_string_type (value)
      -Wwrite-strings says make the string constant an array of const char
      so that copying it to a non-const pointer will get a warning.
      For C++, this is the standard behavior.  */
-  if (flag_const_strings && ! flag_writable_strings)
+  if (flag_const_strings)
     {
       tree elements
 	= build_type_variant (wide_flag ? wchar_type_node : char_type_node,
@@ -1223,7 +1223,7 @@ fix_string_type (value)
 			  build_index_type (build_int_2 (nchars - 1, 0)));
 
   TREE_CONSTANT (value) = 1;
-  TREE_READONLY (value) = ! flag_writable_strings;
+  TREE_READONLY (value) = 1;
   TREE_STATIC (value) = 1;
   return value;
 }
===================================================================
Index: c-opts.c
--- c-opts.c	20 Mar 2003 16:46:17 -0000	1.40
+++ c-opts.c	21 Apr 2003 00:53:19 -0000
@@ -1874,7 +1874,6 @@ set_std_c89 (c94, iso)
   flag_noniso_default_format_attributes = !iso;
   flag_isoc94 = c94;
   flag_isoc99 = 0;
-  flag_writable_strings = 0;
 }
 
 /* Set the C 99 standard (without GNU extensions if ISO).  */
@@ -1889,7 +1888,6 @@ set_std_c99 (iso)
   flag_iso = iso;
   flag_isoc99 = 1;
   flag_isoc94 = 1;
-  flag_writable_strings = 0;
 }
 
 /* Set the C++ 98 standard (without GNU extensions if ISO).  */
===================================================================
Index: flags.h
--- flags.h	12 Apr 2003 02:16:45 -0000	1.105
+++ flags.h	21 Apr 2003 00:53:19 -0000
@@ -320,11 +320,6 @@ extern int flag_cse_skip_blocks;
    perform miscellaneous relatively-expensive optimizations.  */
 extern int flag_expensive_optimizations;
 
-/* Nonzero for -fwritable-strings:
-   store string constants in data segment and don't uniquize them.  */
-
-extern int flag_writable_strings;
-
 /* Nonzero means don't put addresses of constant functions in registers.
    Used for compiling the Unix kernel, where strange substitutions are
    done on the assembly output.  */
===================================================================
Index: toplev.c
--- toplev.c	17 Apr 2003 23:18:49 -0000	1.742
+++ toplev.c	21 Apr 2003 00:53:20 -0000
@@ -561,11 +561,6 @@ int flag_reduce_all_givs = 0;
 
 int flag_regmove = 0;
 
-/* Nonzero for -fwritable-strings:
-   store string constants in data segment and don't uniquize them.  */
-
-int flag_writable_strings = 0;
-
 /* Nonzero means don't put addresses of constant functions in registers.
    Used for compiling the Unix kernel, where strange substitutions are
    done on the assembly output.  */
@@ -1053,8 +1048,6 @@ static const lang_independent_options f_
    N_("Force all loop invariant computations out of loops") },
   {"reduce-all-givs", &flag_reduce_all_givs, 1,
    N_("Strength reduce all loop general induction variables") },
-  {"writable-strings", &flag_writable_strings, 1,
-   N_("Store strings in writable data section") },
   {"peephole", &flag_no_peephole, 0,
    N_("Enable machine specific peephole optimizations") },
   {"force-mem", &flag_force_mem, 1,
===================================================================
Index: varasm.c
--- varasm.c	20 Apr 2003 22:43:59 -0000	1.342
+++ varasm.c	21 Apr 2003 00:53:21 -0000
@@ -2345,9 +2345,6 @@ compare_constant (t1, t2)
       return REAL_VALUES_IDENTICAL (TREE_REAL_CST (t1), TREE_REAL_CST (t2));
 
     case STRING_CST:
-      if (flag_writable_strings)
-	return 0;
-
       if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2)))
 	return 0;
 
@@ -2652,8 +2649,7 @@ output_constant_def (exp, defer)
      output it.  Do no output if -fsyntax-only.  */
   if (! found && ! flag_syntax_only)
     {
-      if (!defer || TREE_CODE (exp) != STRING_CST
-	  || flag_writable_strings)
+      if (!defer || TREE_CODE (exp) != STRING_CST)
 	output_constant_def_contents (exp, reloc, labelno);
       else
 	{
@@ -4912,7 +4908,7 @@ default_select_section (decl, reloc, ali
 	readonly = true;
     }
   else if (TREE_CODE (decl) == STRING_CST)
-    readonly = !flag_writable_strings;
+    readonly = true;
   else if (! (flag_pic && reloc))
     readonly = true;
 
@@ -4973,12 +4969,7 @@ categorize_decl_for_section (decl, reloc
   if (TREE_CODE (decl) == FUNCTION_DECL)
     return SECCAT_TEXT;
   else if (TREE_CODE (decl) == STRING_CST)
-    {
-      if (flag_writable_strings)
-	return SECCAT_DATA;
-      else
-	return SECCAT_RODATA_MERGE_STR;
-    }
+    return SECCAT_RODATA_MERGE_STR;
   else if (TREE_CODE (decl) == VAR_DECL)
     {
       if (DECL_INITIAL (decl) == NULL
===================================================================
Index: config/darwin.c
--- config/darwin.c	20 Apr 2003 18:20:37 -0000	1.36
+++ config/darwin.c	21 Apr 2003 00:53:22 -0000
@@ -1153,10 +1153,8 @@ machopic_select_section (exp, reloc, ali
 {
   if (TREE_CODE (exp) == STRING_CST)
     {
-      if (flag_writable_strings)
-	data_section ();
-      else if ((size_t) TREE_STRING_LENGTH (exp) !=
-	       strlen (TREE_STRING_POINTER (exp)) + 1)
+      if ((size_t) TREE_STRING_LENGTH (exp) !=
+	  strlen (TREE_STRING_POINTER (exp)) + 1)
 	readonly_data_section ();
       else
 	cstring_section ();
===================================================================
Index: config/arm/arm.c
--- config/arm/arm.c	20 Apr 2003 18:20:37 -0000	1.269
+++ config/arm/arm.c	21 Apr 2003 00:53:24 -0000
@@ -12160,8 +12160,7 @@ arm_encode_section_info (decl, rtl, firs
   /* This doesn't work with AOF syntax, since the string table may be in
      a different AREA.  */
 #ifndef AOF_ASSEMBLER
-  if (optimize > 0 && TREE_CONSTANT (decl)
-      && (!flag_writable_strings || TREE_CODE (decl) != STRING_CST))
+  if (optimize > 0 && TREE_CONSTANT (decl))
     SYMBOL_REF_FLAG (XEXP (rtl, 0)) = 1;
 #endif
 
===================================================================
Index: config/arm/pe.c
--- config/arm/pe.c	20 Apr 2003 18:20:37 -0000	1.20
+++ config/arm/pe.c	21 Apr 2003 00:53:24 -0000
@@ -213,8 +213,7 @@ arm_pe_encode_section_info (decl, rtl, f
      int first ATTRIBUTE_UNUSED;
 {
   /* This bit is copied from arm_encode_section_info.  */
-  if (optimize > 0 && TREE_CONSTANT (decl)
-      && (!flag_writable_strings || TREE_CODE (decl) != STRING_CST))
+  if (optimize > 0 && TREE_CONSTANT (decl))
     SYMBOL_REF_FLAG (XEXP (rtl, 0)) = 1;
 
   /* Mark the decl so we can tell from the rtl whether the object is
===================================================================
Index: config/m88k/m88k.c
--- config/m88k/m88k.c	20 Apr 2003 18:20:37 -0000	1.72
+++ config/m88k/m88k.c	21 Apr 2003 00:53:25 -0000
@@ -3280,14 +3280,7 @@ m88k_select_section (decl, reloc, align)
      unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED;
 {
   if (TREE_CODE (decl) == STRING_CST)
-    {
-      if (! flag_writable_strings)
-	readonly_data_section ();
-      else if (TREE_STRING_LENGTH (decl) <= m88k_gp_threshold)
-	sdata_section ();
-      else
-	data_section ();
-    }
+    readonly_data_section ();
   else if (TREE_CODE (decl) == VAR_DECL)
     {
       if (SYMBOL_REF_FLAG (XEXP (DECL_RTL (decl), 0)))
@@ -3340,21 +3333,13 @@ m88k_encode_section_info (decl, rtl, fir
      rtx rtl;
      int first ATTRIBUTE_UNUSED;
 {
-  if (m88k_gp_threshold > 0)
+  if (m88k_gp_threshold > 0
+      && TREE_CODE (decl) == VAR_DECL
+      && (!TREE_READONLY (decl) || TREE_SIDE_EFFECTS (decl)))
     {
-      if (TREE_CODE (decl) == VAR_DECL)
-	{
-	  if (!TREE_READONLY (decl) || TREE_SIDE_EFFECTS (decl))
-	    {
-	      int size = int_size_in_bytes (TREE_TYPE (decl));
-
-	      if (size > 0 && size <= m88k_gp_threshold)
-		SYMBOL_REF_FLAG (XEXP (rtl, 0)) = 1;
-	    }
-	}
-      else if (TREE_CODE (decl) == STRING_CST
-	       && flag_writable_strings
-	       && TREE_STRING_LENGTH (decl) <= m88k_gp_threshold)
+      int size = int_size_in_bytes (TREE_TYPE (decl));
+      
+      if (size > 0 && size <= m88k_gp_threshold)
 	SYMBOL_REF_FLAG (XEXP (rtl, 0)) = 1;
     }
 }
===================================================================
Index: config/mips/mips.c
--- config/mips/mips.c	20 Apr 2003 18:20:38 -0000	1.256
+++ config/mips/mips.c	21 Apr 2003 00:53:28 -0000
@@ -8442,8 +8442,7 @@ mips_select_section (decl, reloc, align)
   int size = int_size_in_bytes (TREE_TYPE (decl));
 
   if ((TARGET_EMBEDDED_PIC || TARGET_MIPS16)
-      && TREE_CODE (decl) == STRING_CST
-      && !flag_writable_strings)
+      && TREE_CODE (decl) == STRING_CST)
     /* For embedded position independent code, put constant strings in the
        text section, because the data section is limited to 64K in size.
        For mips16 code, put strings in the text section so that a PC
@@ -8454,15 +8453,11 @@ mips_select_section (decl, reloc, align)
       /* For embedded applications, always put an object in read-only data
 	 if possible, in order to reduce RAM usage.  */
 
-      if (((TREE_CODE (decl) == VAR_DECL
-	    && TREE_READONLY (decl) && !TREE_SIDE_EFFECTS (decl)
-	    && DECL_INITIAL (decl)
-	    && (DECL_INITIAL (decl) == error_mark_node
-		|| TREE_CONSTANT (DECL_INITIAL (decl))))
-	   /* Deal with calls from output_constant_def_contents.  */
-	   || (TREE_CODE (decl) != VAR_DECL
-	       && (TREE_CODE (decl) != STRING_CST
-		   || !flag_writable_strings)))
+      if ((TREE_CODE (decl) != VAR_DECL
+	   || (TREE_READONLY (decl) && !TREE_SIDE_EFFECTS (decl)
+	       && DECL_INITIAL (decl)
+	       && (DECL_INITIAL (decl) == error_mark_node
+		   || TREE_CONSTANT (DECL_INITIAL (decl)))))
 	  && ! (flag_pic && reloc))
 	readonly_data_section ();
       else if (size > 0 && size <= mips_section_threshold)
@@ -8477,15 +8472,11 @@ mips_select_section (decl, reloc, align)
 
       if (size > 0 && size <= mips_section_threshold)
 	SMALL_DATA_SECTION ();
-      else if (((TREE_CODE (decl) == VAR_DECL
-		 && TREE_READONLY (decl) && !TREE_SIDE_EFFECTS (decl)
-		 && DECL_INITIAL (decl)
-		 && (DECL_INITIAL (decl) == error_mark_node
-		     || TREE_CONSTANT (DECL_INITIAL (decl))))
-		/* Deal with calls from output_constant_def_contents.  */
-		|| (TREE_CODE (decl) != VAR_DECL
-		    && (TREE_CODE (decl) != STRING_CST
-			|| !flag_writable_strings)))
+      else if ((TREE_CODE (decl) != VAR_DECL
+		|| (TREE_READONLY (decl) && !TREE_SIDE_EFFECTS (decl)
+		    && DECL_INITIAL (decl)
+		    && (DECL_INITIAL (decl) == error_mark_node
+			|| TREE_CONSTANT (DECL_INITIAL (decl)))))
 	       && ! (flag_pic && reloc))
 	readonly_data_section ();
       else
@@ -8529,7 +8520,6 @@ mips_encode_section_info (decl, rtl, fir
   if (TARGET_MIPS16)
     {
       if (first && TREE_CODE (decl) == STRING_CST
-	  && ! flag_writable_strings
 	  /* If this string is from a function, and the function will
 	     go in a gnu linkonce section, then we can't directly
 	     access the string.  This gets an assembler error
@@ -8568,9 +8558,6 @@ mips_encode_section_info (decl, rtl, fir
 	SYMBOL_REF_FLAG (XEXP (rtl, 0)) = 1;
       else if (TREE_CODE (decl) == FUNCTION_DECL)
 	SYMBOL_REF_FLAG (XEXP (rtl, 0)) = 0;
-      else if (TREE_CODE (decl) == STRING_CST
-	       && ! flag_writable_strings)
-	SYMBOL_REF_FLAG (XEXP (rtl, 0)) = 0;
       else
 	SYMBOL_REF_FLAG (XEXP (rtl, 0)) = 1;
     }
@@ -10871,8 +10858,7 @@ mips_unique_section (decl, reloc)
            || DECL_INITIAL (decl) == error_mark_node)
     sec = 2;
   else if ((TARGET_EMBEDDED_PIC || TARGET_MIPS16)
-      && TREE_CODE (decl) == STRING_CST
-      && !flag_writable_strings)
+	   && TREE_CODE (decl) == STRING_CST)
     {
       /* For embedded position independent code, put constant
 	 strings in the text section, because the data section
===================================================================
Index: config/pa/pa.c
--- config/pa/pa.c	20 Apr 2003 18:20:38 -0000	1.207
+++ config/pa/pa.c	21 Apr 2003 00:53:29 -0000
@@ -8507,7 +8507,6 @@ pa_select_section (exp, reloc, align)
       && !reloc)
     readonly_data_section ();
   else if (TREE_CODE_CLASS (TREE_CODE (exp)) == 'c'
-	   && !(TREE_CODE (exp) == STRING_CST && flag_writable_strings)
 	   && !reloc)
     readonly_data_section ();
   else
===================================================================
Index: config/pa/pa.h
--- config/pa/pa.h	17 Apr 2003 23:18:57 -0000	1.189
+++ config/pa/pa.h	21 Apr 2003 00:53:30 -0000
@@ -1536,8 +1536,7 @@ do { 									\
        && TREE_READONLY (DECL) && ! TREE_SIDE_EFFECTS (DECL)		\
        && (! DECL_INITIAL (DECL) || ! reloc_needed (DECL_INITIAL (DECL))) \
        && !flag_pic)							\
-   || (TREE_CODE_CLASS (TREE_CODE (DECL)) == 'c'			\
-       && !(TREE_CODE (DECL) == STRING_CST && flag_writable_strings)))
+   || (TREE_CODE_CLASS (TREE_CODE (DECL)) == 'c'))
 
 #define FUNCTION_NAME_P(NAME)  (*(NAME) == '@')
 
===================================================================
Index: config/v850/v850.c
--- config/v850/v850.c	20 Apr 2003 18:20:39 -0000	1.75
+++ config/v850/v850.c	21 Apr 2003 00:53:31 -0000
@@ -3472,13 +3472,6 @@ v850_select_section (exp, reloc, align)
 	  break;
         }
     }
-  else if (TREE_CODE (exp) == STRING_CST)
-    {
-      if (! flag_writable_strings)
-	readonly_data_section ();
-      else
-	data_section ();
-    }
   else
     readonly_data_section ();
 }
===================================================================
Index: cp/decl.c
--- cp/decl.c	17 Apr 2003 21:27:34 -0000	1.1037
+++ cp/decl.c	21 Apr 2003 00:53:34 -0000
@@ -6355,11 +6355,6 @@ cxx_init_decl_processing (void)
 
   /* Show we use EH for cleanups.  */
   using_eh_for_cleanups ();
-
-  /* Maintain consistency.  Perhaps we should just complain if they
-     say -fwritable-strings?  */
-  if (flag_writable_strings)
-    flag_const_strings = 0;
 }
 
 /* Generate an initializer for a function naming variable from
===================================================================
Index: doc/invoke.texi
--- doc/invoke.texi	19 Apr 2003 11:43:31 -0000	1.269
+++ doc/invoke.texi	21 Apr 2003 00:53:37 -0000
@@ -166,8 +166,7 @@ in the following sections.
 -trigraphs  -no-integrated-cpp  -traditional  -traditional-cpp @gol
 -fallow-single-precision  -fcond-mismatch @gol
 -fsigned-bitfields  -fsigned-char @gol
--funsigned-bitfields  -funsigned-char @gol
--fwritable-strings}
+-funsigned-bitfields  -funsigned-char}
 
 @item C++ Language Options
 @xref{C++ Dialect Options,,Options Controlling C++ Dialect}.
@@ -1227,14 +1226,6 @@ declaration does not use either @code{si
 default, such a bit-field is signed, because this is consistent: the
 basic integer types such as @code{int} are signed types.
 
-@item -fwritable-strings
-@opindex fwritable-strings
-Store string constants in the writable data segment and don't uniquize
-them.  This is for compatibility with old programs which assume they can
-write into string constants.
-
-Writing into string constants is a very bad idea; ``constants'' should
-be constant.
 @end table
 
 @node C++ Dialect Options
@@ -1305,8 +1296,7 @@ been added for putting variables into BS
 Give string constants type @code{char *} instead of type @code{const
 char *}.  By default, G++ uses type @code{const char *} as required by
 the standard.  Even if you use @option{-fno-const-strings}, you cannot
-actually modify the value of a string constant, unless you also use
-@option{-fwritable-strings}.
+actually modify the value of a string constant.
 
 This option might be removed in a future release of G++.  For maximum
 portability, you should structure your code so that it works with
===================================================================
Index: doc/trouble.texi
--- doc/trouble.texi	7 Feb 2003 23:12:03 -0000	1.15
+++ doc/trouble.texi	21 Apr 2003 00:53:38 -0000
@@ -431,17 +431,14 @@ string its argument points to.
 @cindex @code{sscanf}, and constant strings
 @cindex @code{fscanf}, and constant strings
 @cindex @code{scanf}, and constant strings
-Another consequence is that @code{sscanf} does not work on some systems
-when passed a string constant as its format control string or input.
-This is because @code{sscanf} incorrectly tries to write into the string
-constant.  Likewise @code{fscanf} and @code{scanf}.
+Another consequence is that @code{sscanf} does not work on some very
+old systems when passed a string constant as its format control string
+or input.  This is because @code{sscanf} incorrectly tries to write
+into the string constant.  Likewise @code{fscanf} and @code{scanf}.
 
-@opindex fwritable-strings
-The best solution to these problems is to change the program to use
+The solution to these problems is to change the program to use
 @code{char}-array variables with initialization strings for these
-purposes instead of string constants.  But if this is not possible,
-you can use the @option{-fwritable-strings} flag, which directs GCC
-to handle string constants the same way most C compilers do.
+purposes instead of string constants.
 
 @item
 @code{-2147483648} is positive.



More information about the Gcc-patches mailing list