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 to fix non-sun targets pretending to be sun-solaris2


As discussed previously,
http://gcc.gnu.org/ml/gcc-patches/2003-11/msg00195.html

several platforms are reusing config/sol2.h and this causes them to
erroneously define `sun' and misidentify themselves.  This causes
problems in user code when one checks "#ifdef sun" and makes any
assumptions based on that.

Perhaps the 'real' fix is to separate out the common elements of
sol2.h into yet another file, then disentangle the entire mess.  I
felt that was too invasive for 3.4 in stage3, but I still think we
should fix the macro problem.  The solution I propose is to undefine
sun in the right places.  These are easier to identify and edit rather
than pulling apart the config stuff.

I tested this via bootstrap on sparc-sun-solaris2.7, no regressions.
I also built xgcc and cc1 in cross-compilers targetted to the
following platforms and checked whether they defined any of sun, __sun
or __sun__ as appropriate:

i386-sun-solaris2.9 sparc-sun-solaris2.5 sparc-unknown-elf
sparc-unknown-rtems sparc64-sun-solaris2.8 sparc64-unknown-elf
sparc86x-unknown-elf sparclite-unknown-elf

I believe this catches all the stanzas in config.gcc that include
config/sol2.h.

Ok for mainline?

		Thanks,
		--Kaveh


2003-11-20  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>

	* c-cppbuiltin.c (builtin_define_undef_std): New, created from
	previous builtin_define_std function, accept a boolean
	define/undef flag.
	(builtin_undef_std, builtin_define_std): New, write in terms of
	builtin_define_undef_std.
	(builtin_undef): New.
	
	* config/sparc/elf.h, config/sparc/liteelf.h,
	config/sparc/rtemself.h, config/sparc/sp64-elf.h,
	config/sparc/sp86x-elf.h (TARGET_SUB_OS_CPP_BUILTINS): Undef sun.

diff -rup orig/egcc-CVS20031105/gcc/c-cppbuiltin.c egcc-CVS20031105/gcc/c-cppbuiltin.c
--- orig/egcc-CVS20031105/gcc/c-cppbuiltin.c	Mon Oct  6 20:01:06 2003
+++ egcc-CVS20031105/gcc/c-cppbuiltin.c	Thu Nov  6 21:25:58 2003
@@ -46,6 +46,7 @@ Software Foundation, 59 Temple Place - S
 
 /* Non-static as some targets don't use it.  */
 void builtin_define_std (const char *) ATTRIBUTE_UNUSED;
+void builtin_undef_std (const char *) ATTRIBUTE_UNUSED;
 static void builtin_define_with_value_n (const char *, const char *,
 					 size_t);
 static void builtin_define_with_int_value (const char *, HOST_WIDE_INT);
@@ -387,6 +388,7 @@ c_cpp_builtins (cpp_reader *pfile)
 # define preprocessing_asm_p() (cpp_get_options (pfile)->lang == CLK_ASM)
 # define preprocessing_trad_p() (cpp_get_options (pfile)->traditional)
 # define builtin_define(TXT) cpp_define (pfile, TXT)
+# define builtin_undef(TXT) cpp_undef (pfile, TXT)
 # define builtin_assert(TXT) cpp_assert (pfile, TXT)
   TARGET_CPU_CPP_BUILTINS ();
   TARGET_OS_CPP_BUILTINS ();
@@ -394,16 +396,17 @@ c_cpp_builtins (cpp_reader *pfile)
 }
 
 /* Pass an object-like macro.  If it doesn't lie in the user's
-   namespace, defines it unconditionally.  Otherwise define a version
-   with two leading underscores, and another version with two leading
-   and trailing underscores, and define the original only if an ISO
-   standard was not nominated.
+   namespace, defines/undefines it unconditionally.  Otherwise
+   define/undefine a version with two leading underscores, and another
+   version with two leading and trailing underscores, and
+   define/undefine the original only if an ISO standard was not
+   nominated.
 
    e.g. passing "unix" defines "__unix", "__unix__" and possibly
    "unix".  Passing "_mips" defines "__mips", "__mips__" and possibly
    "_mips".  */
-void
-builtin_define_std (const char *macro)
+static inline void
+builtin_define_undef_std (const char *macro, bool define)
 {
   size_t len = strlen (macro);
   char *buff = alloca (len + 5);
@@ -419,23 +422,46 @@ builtin_define_std (const char *macro)
       if (p[1] != '_')
 	*--p = '_';
     }
-  cpp_define (parse_in, p);
+  if (define)
+    cpp_define (parse_in, p);
+  else
+    cpp_undef (parse_in, p);
 
   /* If it was in user's namespace...  */
   if (p != buff + 2)
     {
-      /* Define the macro with leading and following __.  */
+      /* Define/undefine the macro with leading and following __.  */
       if (q[-1] != '_')
 	*q++ = '_';
       if (q[-2] != '_')
 	*q++ = '_';
       *q = '\0';
-      cpp_define (parse_in, p);
+      if (define)
+	cpp_define (parse_in, p);
+      else
+	cpp_undef (parse_in, p);
 
       /* Finally, define the original macro if permitted.  */
       if (!flag_iso)
-	cpp_define (parse_in, macro);
+       {
+	 if (define)
+	   cpp_define (parse_in, macro);
+	 else
+	   cpp_undef (parse_in, macro);
+       }
     }
+}
+
+void
+builtin_define_std (const char *macro)
+{
+  builtin_define_undef_std (macro, true);
+}
+
+void
+builtin_undef_std (const char *macro)
+{
+  builtin_define_undef_std (macro, false);
 }
 
 /* Pass an object-like macro and a value to define it to.  The third
diff -rup orig/egcc-CVS20031105/gcc/config/sparc/elf.h egcc-CVS20031105/gcc/config/sparc/elf.h
--- orig/egcc-CVS20031105/gcc/config/sparc/elf.h	Thu Oct  2 08:40:57 2003
+++ egcc-CVS20031105/gcc/config/sparc/elf.h	Fri Nov  7 02:04:39 2003
@@ -48,3 +48,12 @@ Boston, MA 02111-1307, USA.  */
 
 #undef SUN_INTEGER_MULTIPLY_64
 #define SUN_INTEGER_MULTIPLY_64 0
+
+/* Don't pretend to be Solaris2.  */
+#undef TARGET_SUB_OS_CPP_BUILTINS
+#define TARGET_SUB_OS_CPP_BUILTINS()		\
+  do						\
+    {						\
+	builtin_undef_std ("sun");		\
+    }						\
+  while (0)
diff -rup orig/egcc-CVS20031105/gcc/config/sparc/liteelf.h egcc-CVS20031105/gcc/config/sparc/liteelf.h
--- orig/egcc-CVS20031105/gcc/config/sparc/liteelf.h	Thu Oct  2 08:40:57 2003
+++ egcc-CVS20031105/gcc/config/sparc/liteelf.h	Thu Nov  6 21:35:29 2003
@@ -24,6 +24,7 @@ Boston, MA 02111-1307, USA.  */
   do						\
     {						\
 	builtin_define ("__sparclite__");	\
+	builtin_undef_std ("sun");	\
     }						\
   while (0)
 
diff -rup orig/egcc-CVS20031105/gcc/config/sparc/rtemself.h egcc-CVS20031105/gcc/config/sparc/rtemself.h
--- orig/egcc-CVS20031105/gcc/config/sparc/rtemself.h	Tue Jun 17 10:12:04 2003
+++ egcc-CVS20031105/gcc/config/sparc/rtemself.h	Thu Nov  6 21:32:27 2003
@@ -20,10 +20,12 @@ the Free Software Foundation, 59 Temple 
 Boston, MA 02111-1307, USA.  */
 
 /* Target OS builtins.  */
+#undef TARGET_SUB_OS_CPP_BUILTINS
 #define TARGET_SUB_OS_CPP_BUILTINS()		\
   do						\
     {						\
 	builtin_define_std ("sparc");		\
+	builtin_undef_std ("sun");		\
 	builtin_define ("__rtems__");		\
 	builtin_define ("__USE_INIT_FINI__");	\
 	builtin_assert ("system=rtems");	\
diff -rup orig/egcc-CVS20031105/gcc/config/sparc/sp64-elf.h egcc-CVS20031105/gcc/config/sparc/sp64-elf.h
--- orig/egcc-CVS20031105/gcc/config/sparc/sp64-elf.h	Tue Jun 17 10:12:07 2003
+++ egcc-CVS20031105/gcc/config/sparc/sp64-elf.h	Thu Nov  6 21:41:05 2003
@@ -44,6 +44,7 @@ Boston, MA 02111-1307, USA.  */
   do						\
     {						\
 	builtin_define_std ("sparc");		\
+	builtin_undef_std ("sun");		\
     }						\
   while (0)
 
diff -rup orig/egcc-CVS20031105/gcc/config/sparc/sp86x-elf.h egcc-CVS20031105/gcc/config/sparc/sp86x-elf.h
--- orig/egcc-CVS20031105/gcc/config/sparc/sp86x-elf.h	Thu Oct  2 08:40:58 2003
+++ egcc-CVS20031105/gcc/config/sparc/sp86x-elf.h	Thu Nov  6 21:38:09 2003
@@ -24,6 +24,7 @@ Boston, MA 02111-1307, USA.  */
   do						\
     {						\
 	builtin_define ("__sparclite86x__");	\
+	builtin_undef_std ("sun");		\
     }						\
   while (0)
 


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