Sophie

Sophie

distrib > Mandriva > current > i586 > media > contrib-release-src > by-pkgid > d582d52b3e7c1700ea6c527e039f75bd > files > 27

cross-avr-gcc-4.4.3-7mnb2.src.rpm

From 02bff8a1522534a9e5f467b1794b2e49c687335b Mon Sep 17 00:00:00 2001
From: unknown author <cooker@mandrivalinux.org>
Date: Tue, 10 Feb 2009 15:47:49 +0000
Subject: gcc40 linux32

2005-01-12  Gwenole Beauchesne  <gbeauchesne@mandrakesoft.com>

	* gcc/gcc.c (biarch_specific_options): New. Disable 64-bit code
	generation if running under a 32-bit personality.
	(process_command): Use biarch_specific_options.
	* gcc/config/i386/biarch64.h (TARGET_32BIT_PERSONALITY): Define.
---
 gcc/config/i386/biarch64.h |    9 +++++
 gcc/gcc.c                  |   87 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 96 insertions(+), 0 deletions(-)

diff --git a/gcc/config/i386/biarch64.h b/gcc/config/i386/biarch64.h
index 629ec98..76843e8 100644
--- a/gcc/config/i386/biarch64.h
+++ b/gcc/config/i386/biarch64.h
@@ -27,3 +27,12 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 
 #define TARGET_64BIT_DEFAULT OPTION_MASK_ISA_64BIT
 #define TARGET_BI_ARCH 1
+
+#if defined(__linux__)
+#ifndef inhibit_libc
+#include <sys/syscall.h>
+#include <sys/personality.h>
+#define TARGET_32BIT_PERSONALITY \
+		((syscall(SYS_personality, 0xffffffff) & PER_MASK) == PER_LINUX32)
+#endif
+#endif
diff --git a/gcc/gcc.c b/gcc/gcc.c
index ee95366..88cd291 100644
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -1413,6 +1413,90 @@ translate_options (int *argcp, const char *const **argvp)
   *argvp = newv;
   *argcp = newindex;
 }
+
+/* On biarch platforms, scan the options described by *ARGCP and *ARGVP.
+   If gcc is running under a 32-bit personality and no -m32/-m64
+   appeared on the command line, switch gcc to generate 32-bit code
+   instead of 64-bit code.  */
+
+static void
+biarch_specific_options (int *argcp, const char *const **argvp)
+{
+#ifdef TARGET_32BIT_PERSONALITY
+  if (TARGET_32BIT_PERSONALITY)
+    {
+      int i;
+
+      /* If nonzero, the user gave us the `-m32' or `-m64' flag.  */
+      int saw_mode_flag = 0;
+
+      /* Used to track options that take arguments, so we don't go wrapping
+	 those with -xc++/-xnone.  */
+      const char *quote = NULL;
+
+      /* The new argument list will be contained in this.  */
+      const char **arglist;
+
+      /* The total number of arguments with the new stuff.  */
+      int argc;
+
+      /* The argument list.  */
+      const char *const *argv;
+
+      argc = *argcp;
+      argv = *argvp;
+      for (i = 1; i < argc; i++)
+	{
+	  /* If the previous option took an argument, we swallow it here.  */
+	  if (quote)
+	    {
+	      quote = NULL;
+	      continue;
+	    }
+
+	  /* We don't do this anymore, since we don't get them with minus
+	     signs on them.  */
+	  if (argv[i][0] == '\0' || argv[i][1] == '\0')
+	    continue;
+
+	  if (argv[i][0] == '-')
+	    {
+	      if (strcmp (argv[i], "-m32") == 0
+		  || strcmp (argv[i], "-m64") == 0)
+		saw_mode_flag = 1;
+	      else if (((argv[i][2] == '\0'
+			 && strchr ("bBVDUoeTuIYmLiA", argv[i][1]) != NULL)
+			|| strcmp (argv[i], "-Xlinker") == 0
+			|| strcmp (argv[i], "-Tdata") == 0))
+		quote = argv[i];
+	      else
+		/* Pass other options through.  */
+		continue;
+	    }
+	}
+
+      if (quote)
+	fatal ("argument to `%s' missing\n", quote);
+
+      /* If we know we don't have to do anything, bail now.  */
+      if (saw_mode_flag)
+	return;
+
+      /* Make sure to have room for the trailing NULL argument.  */
+      arglist = xmalloc ((argc + 2) * sizeof (char *));
+
+      /* Copy the arguments and add new -m32 argument.  */
+      for (i = 0; i < argc; i++)
+	arglist[i] = argv[i];
+      arglist[i++] = "-m32";
+      arglist[i] = NULL;
+
+      *argcp = i;
+      *argvp = arglist;
+    }
+#endif
+}
+
 
 static char *
 skip_whitespace (char *p)
@@ -3611,6 +3695,9 @@ process_command (int argc, const char **argv)
   /* Do language-specific adjustment/addition of flags.  */
   lang_specific_driver (&argc, (const char *const **) &argv, &added_libraries);
 
+  /* Do biarch-specific adjustment/addition of flags.  */
+  biarch_specific_options (&argc, (const char *const **) &argv);
+
   /* Scan argv twice.  Here, the first time, just count how many switches
      there will be in their vector, and how many input files in theirs.
      Here we also parse the switches that cc itself uses (e.g. -v).  */
-- 
1.6.2.4