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] S/390: Set ABI default based on uname


Currently the default ABI option for a GCC built on a 64 bit system is
always -m64.  This is inconvenient when e.g. building 32 bit libraries
on a 64 bit system.  The usual way to do this is to set the personality
to s390 (32 bit) and let the configure script do the right thing.
Having a GCC which defaults to -m64 also requires to get a -m31 somehow
into the option list.

With that patch the GCC driver checks the current personality setting in
order to figure out at runtime what the default is supposed to be.

Bootstrapped and regtested on s390x.

I will commit the patch after waiting a few days for comments.

gcc/ChangeLog:

2018-03-12  Andreas Krebbel  <krebbel@linux.vnet.ibm.com>

	* config/s390/driver-native.c (s390_host_detect_target_bits): New
	function.
	* config/s390/s390.h: Invoke s390_host_detect_target_bits if
	neither -m31 nor -m64 has been specified.
---
 gcc/config/s390/driver-native.c | 26 ++++++++++++++++++++++++++
 gcc/config/s390/s390.h          | 14 +++++---------
 2 files changed, 31 insertions(+), 9 deletions(-)

diff --git a/gcc/config/s390/driver-native.c b/gcc/config/s390/driver-native.c
index 3793f8a..666ae48 100644
--- a/gcc/config/s390/driver-native.c
+++ b/gcc/config/s390/driver-native.c
@@ -19,6 +19,8 @@ along with GCC; see the file COPYING3.  If not see
 
 #define IN_TARGET_CODE 1
 
+#include <sys/utsname.h>
+
 #include "config.h"
 #include "system.h"
 #include "coretypes.h"
@@ -184,3 +186,27 @@ s390_host_detect_local_cpu (int argc, const char **argv)
 
   return concat ("-m", argv[0], "=", cpu, options, NULL);
 }
+
+/* This function is invoked by the gcc spec parser via
+   target_bits_detect.  It returns either "64" or "31" depending on
+   the personality currently being used.  */
+
+const char *
+s390_host_detect_target_bits (int argc ATTRIBUTE_UNUSED,
+			      const char **argv ATTRIBUTE_UNUSED)
+{
+  struct utsname uname_struct;
+
+  if (uname (&uname_struct) == 0)
+    {
+      if (strcmp (uname_struct.machine, "s390x") == 0)
+	return "64";
+      else if (strcmp (uname_struct.machine, "s390") == 0)
+	return "31";
+    }
+#ifdef DEFAULT_TARGET_64BIT
+  return "64";
+#else
+  return "31";
+#endif
+}
diff --git a/gcc/config/s390/s390.h b/gcc/config/s390/s390.h
index de71fd9..eee6158 100644
--- a/gcc/config/s390/s390.h
+++ b/gcc/config/s390/s390.h
@@ -209,8 +209,10 @@ enum processor_flags
 
 #ifdef __s390__
 extern const char *s390_host_detect_local_cpu (int argc, const char **argv);
-# define EXTRA_SPEC_FUNCTIONS \
-  { "local_cpu_detect", s390_host_detect_local_cpu },
+extern const char *s390_host_detect_target_bits (int argc, const char **argv);
+# define EXTRA_SPEC_FUNCTIONS				\
+  { "local_cpu_detect", s390_host_detect_local_cpu },	\
+  { "target_bits_detect", s390_host_detect_target_bits },
 
 #define MARCH_MTUNE_NATIVE_SPECS				\
   "%{mtune=native:%<mtune=native %:local_cpu_detect(tune)} "	\
@@ -220,16 +222,10 @@ extern const char *s390_host_detect_local_cpu (int argc, const char **argv);
 # define MARCH_MTUNE_NATIVE_SPECS ""
 #endif
 
-#ifdef DEFAULT_TARGET_64BIT
-#define S390_TARGET_BITS_STRING "64"
-#else
-#define S390_TARGET_BITS_STRING "31"
-#endif
-
 /* Defaulting rules.  */
 #define DRIVER_SELF_SPECS					\
   MARCH_MTUNE_NATIVE_SPECS,					\
-  "%{!m31:%{!m64:-m" S390_TARGET_BITS_STRING "}}",		\
+  "%{!m31:%{!m64:-m%:target_bits_detect()}}",			\
   "%{!mesa:%{!mzarch:%{m31:-mesa}%{m64:-mzarch}}}",		\
   "%{!march=*:-march=z900}"
 
-- 
2.9.1


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