Sophie

Sophie

distrib > Mandriva > current > i586 > media > contrib-release-src > by-pkgid > 9fc823f579365b59d3b038e400844f43 > files > 4

cross-mipsel-binutils-2.19.51.0.2-1mnb2.src.rpm

diff -p -up binutils-2.19.50.0.1/gas/config/tc-i386.c.linux32 binutils-2.19.50.0.1/gas/config/tc-i386.c
--- binutils-2.19.50.0.1/gas/config/tc-i386.c.linux32	2008-10-06 22:19:26.000000000 +0200
+++ binutils-2.19.50.0.1/gas/config/tc-i386.c	2008-12-23 22:33:04.000000000 +0100
@@ -35,6 +35,13 @@
 #include "elf/x86-64.h"
 #include "opcodes/i386-init.h"
 
+#if defined(__linux__) && defined(__x86_64__)
+#include <sys/syscall.h>
+#include <sys/personality.h>
+
+#define is_linux32() ((syscall(SYS_personality, 0xffffffff) & PER_MASK) == PER_LINUX32)
+#endif
+
 #ifndef REGISTER_WARNINGS
 #define REGISTER_WARNINGS 1
 #endif
@@ -220,7 +227,16 @@ static void s_bss (int);
 static void handle_large_common (int small ATTRIBUTE_UNUSED);
 #endif
 
-static const char *default_arch = DEFAULT_ARCH;
+enum x86_arch
+  {
+    ARCH_default,
+    ARCH_i386,
+    ARCH_x86_64
+  };
+
+static enum x86_arch g_default_arch = ARCH_default;
+static enum x86_arch get_default_arch PARAMS ((void));
+static INLINE void set_default_arch PARAMS ((enum x86_arch arch));
 
 /* VEX prefix.  */
 typedef struct
@@ -2035,15 +2051,46 @@ set_cpu_arch (int dummy ATTRIBUTE_UNUSED
   demand_empty_rest_of_line ();
 }
 
+static enum x86_arch
+get_default_arch ()
+{
+  const char *default_arch_str = DEFAULT_ARCH;
+
+  if (g_default_arch != ARCH_default)
+    return g_default_arch;
+
+#ifdef is_linux32
+  if (is_linux32 ())
+    default_arch_str = "i386";
+#endif
+
+  if (!strcmp (default_arch_str, "x86_64"))
+    g_default_arch = ARCH_x86_64;
+  else if (!strcmp (default_arch_str, "i386"))
+    g_default_arch = ARCH_i386;
+
+  return g_default_arch;
+}
+
+static INLINE void
+set_default_arch (arch)
+     enum x86_arch arch;
+{
+  g_default_arch = arch;
+}
+
 unsigned long
 i386_mach ()
 {
-  if (!strcmp (default_arch, "x86_64"))
-    return bfd_mach_x86_64;
-  else if (!strcmp (default_arch, "i386"))
-    return bfd_mach_i386_i386;
-  else
-    as_fatal (_("Unknown architecture"));
+  switch (get_default_arch ())
+    {
+    case ARCH_x86_64:
+      return bfd_mach_x86_64;
+    case ARCH_i386:
+      return bfd_mach_i386_i386;
+    default:
+      as_fatal (_("Unknown architecture"));
+    }
 }
 
 void
@@ -8076,7 +8123,7 @@ md_parse_option (int c, char *arg)
 	      || strcmp (*l, "pe-x86-64") == 0
 	      || strcmp (*l, "pei-x86-64") == 0)
 	    {
-	      default_arch = "x86_64";
+	      set_default_arch (ARCH_x86_64);
 	      break;
 	    }
 	if (*l == NULL)
@@ -8087,7 +8134,7 @@ md_parse_option (int c, char *arg)
 #endif
 
     case OPTION_32:
-      default_arch = "i386";
+      set_default_arch (ARCH_i386);
       break;
 
     case OPTION_DIVIDE:
@@ -8304,8 +8351,9 @@ md_show_usage (stream)
 const char *
 i386_target_format (void)
 {
-  if (!strcmp (default_arch, "x86_64"))
+  switch (get_default_arch ())
     {
+    case ARCH_x86_64:
       set_code_flag (CODE_64BIT);
       if (cpu_flags_all_zero (&cpu_arch_isa_flags))
 	{
@@ -8333,9 +8381,8 @@ i386_target_format (void)
 	  cpu_arch_tune_flags.bitfield.cpusse = 1;
 	  cpu_arch_tune_flags.bitfield.cpusse2 = 1;
 	}
-    }
-  else if (!strcmp (default_arch, "i386"))
-    {
+      break;
+    case ARCH_i386:
       set_code_flag (CODE_32BIT);
       if (cpu_flags_all_zero (&cpu_arch_isa_flags))
 	{
@@ -8349,9 +8396,11 @@ i386_target_format (void)
 	  cpu_arch_tune_flags.bitfield.cpui286 = 1;
 	  cpu_arch_tune_flags.bitfield.cpui386 = 1;
 	}
+      break;
+    default:
+      as_fatal (_("Unknown architecture"));
+      break;
     }
-  else
-    as_fatal (_("Unknown architecture"));
   switch (OUTPUT_FLAVOR)
     {
 #ifdef TE_PEP
diff -p -up binutils-2.19.50.0.1/gas/config/tc-ppc.c.linux32 binutils-2.19.50.0.1/gas/config/tc-ppc.c
--- binutils-2.19.50.0.1/gas/config/tc-ppc.c.linux32	2008-10-06 22:19:26.000000000 +0200
+++ binutils-2.19.50.0.1/gas/config/tc-ppc.c	2008-12-23 22:33:04.000000000 +0100
@@ -35,6 +35,10 @@
 #include "coff/pe.h"
 #endif
 
+#if defined(__linux__) && defined(__powerpc64__)
+#include <sys/utsname.h>
+#endif
+
 /* This is the assembler for the PowerPC or POWER (RS/6000) chips.  */
 
 /* Tell the main code what the endianness is.  */
@@ -87,6 +91,8 @@ static bfd_boolean reg_names_p = TARGET_
 static void ppc_macro (char *, const struct powerpc_macro *);
 static void ppc_byte (int);
 
+static void ppc_set_obj64 PARAMS ((int));
+
 #if defined (OBJ_XCOFF) || defined (OBJ_ELF)
 static void ppc_tc (int);
 static void ppc_machine (int);
@@ -704,7 +710,7 @@ ppc_parse_name (const char *name, expres
 /* Local variables.  */
 
 /* Whether to target xcoff64/elf64.  */
-static unsigned int ppc_obj64 = BFD_DEFAULT_TARGET_SIZE == 64;
+static int g_ppc_obj64 = -1;
 
 /* Opcode hash table.  */
 static struct hash_control *ppc_hash;
@@ -1025,13 +1031,13 @@ md_parse_option (int c, char *arg)
       if (strcmp (arg, "64") == 0)
 	{
 #ifdef BFD64
-	  ppc_obj64 = 1;
+	  ppc_set_obj64 (1);
 #else
 	  as_fatal (_("%s unsupported"), "-a64");
 #endif
 	}
       else if (strcmp (arg, "32") == 0)
-	ppc_obj64 = 0;
+	ppc_set_obj64 (0);
       else
 	return 0;
       break;
@@ -1183,6 +1189,37 @@ PowerPC options:\n\
 #endif
 }
 
+/* Set ppc_obj64 if it is not already set.  */
+
+#define ppc_obj64 (ppc_get_obj64 ())
+
+static unsigned int
+ppc_get_obj64 (void)
+{
+  if (g_ppc_obj64 < 0)
+    {
+      g_ppc_obj64 = BFD_DEFAULT_TARGET_SIZE == 64;
+
+#if defined(__linux__) && defined(__powerpc64__)
+      /* Determine if we are running under a 32-bit personality. Don't
+	 use plain personality(0xffffffff) syscall because the kernel lies.  */
+      {
+	struct utsname buf;
+	if (uname(&buf) == 0 && strcmp(buf.machine, "ppc") == 0)
+	  g_ppc_obj64 = 0;
+      }
+#endif
+    }
+
+  return g_ppc_obj64;
+}
+
+static void
+ppc_set_obj64 (int obj64)
+{
+  g_ppc_obj64 = obj64;
+}
+
 /* Set ppc_cpu if it is not already set.  */
 
 static void