public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* PATCH [1/n]: Add initial -x32 support
@ 2011-06-05 19:55 H.J. Lu
  2011-06-06 15:47 ` Uros Bizjak
                   ` (4 more replies)
  0 siblings, 5 replies; 26+ messages in thread
From: H.J. Lu @ 2011-06-05 19:55 UTC (permalink / raw)
  To: gcc-patches; +Cc: Uros Bizjak

Hi,

I'd like to start submitting a series of patches to enable x32:

https://sites.google.com/site/x32abi/

The GCC x32 branch is very stable. There are no unexpected failures in
C, C++, Fortran and Objective C testsuites.  SPEC CPU 2K/2006 compile
and run correctly at -O2 and -O3. 

More than 90% of changes are in x86 backend.  This is the first patch to
support x32.  By default, x32 is disabled and x32 run-time support
isn't required.  OK for trunk?

Thanks.


H.J.
---
2011-06-05  H.J. Lu  <hongjiu.lu@intel.com>

	* config.gcc: Support --enable-x32/--enable-ia32 for x86 Linux
	targets.

	* configure.ac: Support --enable-x32/--enable-ia32.
	* configure: Regenerated.

	* config/i386/gnu-user64.h (ASM_SPEC): Support x32.
	(LINK_SPEC): Likewise.
	(TARGET_THREAD_SSP_OFFSET): Likewise.
	(TARGET_THREAD_SPLIT_STACK_OFFSET): Likewise.

	* config/i386/i386.h (TARGET_X32): New.
	(TARGET_LP64): New.
	(LONG_TYPE_SIZE): Likewise.
	(POINTER_SIZE): Likewise.
	(POINTERS_EXTEND_UNSIGNED): Likewise.

	* config/i386/i386.opt (mx32): New.

	* config/i386/linux64.h (GLIBC_DYNAMIC_LINKERX32): New.

	* config/i386/t-linux64-x32: New.
	* config/i386/t-linuxx32: Likewise.

	* config/linux.h (UCLIBC_DYNAMIC_LINKERX32): New.
	(BIONIC_DYNAMIC_LINKERX32): Likewise.
	(GNU_USER_DYNAMIC_LINKERX32): Likewise.

	* doc/invoke.texi: Document -mx32.

diff --git a/gcc/config.gcc b/gcc/config.gcc
index 624129b..24b4a57 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -1232,7 +1232,17 @@ i[34567]86-*-linux* | i[34567]86-*-kfreebsd*-gnu | i[34567]86-*-knetbsd*-gnu | i
 		if test x$enable_targets = xall; then
 			tm_file="${tm_file} i386/x86-64.h i386/gnu-user64.h i386/linux64.h"
 			tm_defines="${tm_defines} TARGET_BI_ARCH=1"
-			tmake_file="${tmake_file} i386/t-linux64"
+			case x${enable_x32}${enable_ia32} in
+			xyesyes)
+				tmake_file="${tmake_file} i386/t-linuxx32"
+				;;
+			xyesno)
+				tmake_file="${tmake_file} i386/t-linux64-x32"
+				;;
+			*)
+				tmake_file="${tmake_file} i386/t-linux64"
+				;;
+			esac
 			need_64bit_hwint=yes
 			need_64bit_isa=yes
 			case X"${with_cpu}" in
@@ -1270,7 +1280,18 @@ x86_64-*-linux* | x86_64-*-kfreebsd*-gnu | x86_64-*-knetbsd*-gnu)
 	x86_64-*-kfreebsd*-gnu) tm_file="${tm_file} kfreebsd-gnu.h i386/kfreebsd-gnu.h" ;;
 	x86_64-*-knetbsd*-gnu) tm_file="${tm_file} knetbsd-gnu.h" ;;
 	esac
-	tmake_file="${tmake_file} i386/t-linux64 i386/t-crtstuff i386/t-crtpc i386/t-crtfm t-dfprules"
+	case x${enable_x32}${enable_ia32} in
+	xyesyes)
+		tmake_file="${tmake_file} i386/t-linuxx32"
+		;;
+	xyesno)
+		tmake_file="${tmake_file} i386/t-linux64-x32"
+		;;
+	*)
+		tmake_file="${tmake_file} i386/t-linux64"
+		;;
+	esac
+	tmake_file="${tmake_file} i386/t-crtstuff i386/t-crtpc i386/t-crtfm t-dfprules"
 	;;
 i[34567]86-pc-msdosdjgpp*)
 	xm_file=i386/xm-djgpp.h
diff --git a/gcc/config/i386/gnu-user64.h b/gcc/config/i386/gnu-user64.h
index 3ece0fa..b99fb13 100644
--- a/gcc/config/i386/gnu-user64.h
+++ b/gcc/config/i386/gnu-user64.h
@@ -65,17 +65,20 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #endif
 
 #undef ASM_SPEC
-#define ASM_SPEC "%{" SPEC_32 ":--32} %{" SPEC_64 ":--64} \
+#define ASM_SPEC "%{" SPEC_32 ":%{!mx32:--32}} %{" \
+ SPEC_64 ":%{!mx32:--64}} %{mx32:--x32} \
  %{!mno-sse2avx:%{mavx:-msse2avx}} %{msse2avx:%{!mavx:-msse2avx}}"
 
 #undef	LINK_SPEC
-#define LINK_SPEC "%{" SPEC_64 ":-m elf_x86_64} %{" SPEC_32 ":-m elf_i386} \
+#define LINK_SPEC "%{" SPEC_64 ":%{!mx32:-m elf_x86_64}} %{" \
+  SPEC_32 ":%{!mx32:-m elf_i386}} %{mx32:-m elf32_x86_64} \
   %{shared:-shared} \
   %{!shared: \
     %{!static: \
       %{rdynamic:-export-dynamic} \
-      %{" SPEC_32 ":-dynamic-linker " GNU_USER_DYNAMIC_LINKER32 "} \
-      %{" SPEC_64 ":-dynamic-linker " GNU_USER_DYNAMIC_LINKER64 "}} \
+      %{" SPEC_32 ":%{!mx32:-dynamic-linker " GNU_USER_DYNAMIC_LINKER32 "}} \
+      %{" SPEC_64 ":%{!mx32:-dynamic-linker " GNU_USER_DYNAMIC_LINKER64 "}} \
+      %{mx32:-dynamic-linker " GNU_USER_DYNAMIC_LINKERX32 "}} \
     %{static:-static}}"
 
 /* Similar to standard GNU userspace, but adding -ffast-math support.  */
@@ -109,10 +112,13 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 
 #ifdef TARGET_LIBC_PROVIDES_SSP
 /* i386 glibc provides __stack_chk_guard in %gs:0x14,
+   x32 glibc provides it in %fs:0x18. 
    x86_64 glibc provides it in %fs:0x28.  */
-#define TARGET_THREAD_SSP_OFFSET	(TARGET_64BIT ? 0x28 : 0x14)
+#define TARGET_THREAD_SSP_OFFSET \
+  (TARGET_64BIT ? (TARGET_X32 ? 0x18 : 0x28) : 0x14)
 
 /* We steal the last transactional memory word.  */
 #define TARGET_CAN_SPLIT_STACK
-#define TARGET_THREAD_SPLIT_STACK_OFFSET (TARGET_64BIT ? 0x70 : 0x30)
+#define TARGET_THREAD_SPLIT_STACK_OFFSET \
+  (TARGET_64BIT ? (TARGET_X32 ? 0x40 : 0x70) : 0x30)
 #endif
diff --git a/gcc/config/i386/i386.h b/gcc/config/i386/i386.h
index 8badcbb..f9270de 100644
--- a/gcc/config/i386/i386.h
+++ b/gcc/config/i386/i386.h
@@ -42,6 +42,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 /* Redefines for option macros.  */
 
 #define TARGET_64BIT	OPTION_ISA_64BIT
+#define TARGET_X32	OPTION_ISA_X32
 #define TARGET_MMX	OPTION_ISA_MMX
 #define TARGET_3DNOW	OPTION_ISA_3DNOW
 #define TARGET_3DNOW_A	OPTION_ISA_3DNOW_A
@@ -72,6 +73,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #define TARGET_RDRND	OPTION_ISA_RDRND
 #define TARGET_F16C	OPTION_ISA_F16C
 
+#define TARGET_LP64	(TARGET_64BIT && !TARGET_X32)
 
 /* SSE4.1 defines round instructions */
 #define	OPTION_MASK_ISA_ROUND	OPTION_MASK_ISA_SSE4_1
@@ -638,6 +640,8 @@ enum target_cpu_default
 
 #define SHORT_TYPE_SIZE 16
 #define INT_TYPE_SIZE 32
+#define LONG_TYPE_SIZE (TARGET_X32 ? 32 : BITS_PER_WORD)
+#define POINTER_SIZE (TARGET_X32 ? 32 : BITS_PER_WORD)
 #define LONG_LONG_TYPE_SIZE 64
 #define FLOAT_TYPE_SIZE 32
 #define DOUBLE_TYPE_SIZE 64
@@ -1743,6 +1747,13 @@ do {							\
    between pointers and any other objects of this machine mode.  */
 #define Pmode (TARGET_64BIT ? DImode : SImode)
 
+/* A C expression whose value is zero if pointers that need to be extended
+   from being `POINTER_SIZE' bits wide to `Pmode' are sign-extended and
+   greater then zero if they are zero-extended and less then zero if the
+   ptr_extend instruction should be used.  */
+
+#define POINTERS_EXTEND_UNSIGNED 1
+
 /* A function address in a call instruction
    is a byte address (for indexing purposes)
    so give the MEM rtx a byte's mode.  */
diff --git a/gcc/config/i386/i386.opt b/gcc/config/i386/i386.opt
index 21e0def..2c8fe8f 100644
--- a/gcc/config/i386/i386.opt
+++ b/gcc/config/i386/i386.opt
@@ -398,9 +398,13 @@ Target RejectNegative Negative(m64) Report InverseMask(ISA_64BIT) Var(ix86_isa_f
 Generate 32bit i386 code
 
 m64
-Target RejectNegative Negative(m32) Report Mask(ISA_64BIT) Var(ix86_isa_flags) Save
+Target RejectNegative Negative(mx32) Report Mask(ISA_64BIT) Var(ix86_isa_flags) Save
 Generate 64bit x86-64 code
 
+mx32
+Target RejectNegative Negative(m32) Report Mask(ISA_X32) Var(ix86_isa_flags) Save
+Generate 32bit x86-64 code
+
 mmmx
 Target Report Mask(ISA_MMX) Var(ix86_isa_flags) Save
 Support MMX built-in functions
diff --git a/gcc/config/i386/linux64.h b/gcc/config/i386/linux64.h
index 9bf7eab..78c9c8e 100644
--- a/gcc/config/i386/linux64.h
+++ b/gcc/config/i386/linux64.h
@@ -26,3 +26,4 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 
 #define GLIBC_DYNAMIC_LINKER32 "/lib/ld-linux.so.2"
 #define GLIBC_DYNAMIC_LINKER64 "/lib64/ld-linux-x86-64.so.2"
+#define GLIBC_DYNAMIC_LINKERX32 "/libx32/ld-linux-x32.so.2"
diff --git a/gcc/config/i386/t-linux64-x32 b/gcc/config/i386/t-linux64-x32
new file mode 100644
index 0000000..3a4d1de
--- /dev/null
+++ b/gcc/config/i386/t-linux64-x32
@@ -0,0 +1,34 @@
+# Copyright (C) 2011 Free Software Foundation, Inc.
+#
+# This file is part of GCC.
+#
+# GCC is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GCC is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GCC; see the file COPYING3.  If not see
+# <http://www.gnu.org/licenses/>.
+
+# To support x86-64 and x32 libraries, the directory structrue
+# should be:
+#
+# 	/lib64 has x86-64 libraries.
+# 	/libx32 has x32 libraries.
+#
+MULTILIB_OPTIONS = m64/mx32
+MULTILIB_DIRNAMES = 64 x32
+MULTILIB_OSDIRNAMES = ../lib64 ../libx32
+
+LIBGCC = stmp-multilib
+INSTALL_LIBGCC = install-multilib
+
+EXTRA_MULTILIB_PARTS=crtbegin.o crtend.o crtbeginS.o crtendS.o \
+		     crtbeginT.o crtprec32.o crtprec64.o crtprec80.o \
+		     crtfastmath.o
diff --git a/gcc/config/i386/t-linuxx32 b/gcc/config/i386/t-linuxx32
new file mode 100644
index 0000000..92acf91
--- /dev/null
+++ b/gcc/config/i386/t-linuxx32
@@ -0,0 +1,42 @@
+# Copyright (C) 2011 Free Software Foundation, Inc.
+#
+# This file is part of GCC.
+#
+# GCC is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GCC is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GCC; see the file COPYING3.  If not see
+# <http://www.gnu.org/licenses/>.
+
+# On Debian, Ubuntu and other derivative distributions, the 32bit libraries
+# are found in /lib32 and /usr/lib32, /lib64 and /usr/lib64 are symlinks to
+# /lib and /usr/lib, while other distributions install libraries into /lib64
+# and /usr/lib64.  The LSB does not enforce the use of /lib64 and /usr/lib64,
+# it doesn't tell anything about the 32bit libraries on those systems.  Set
+# MULTILIB_OSDIRNAMES according to what is found on the target.
+
+# To support i386, x86-64 and x32 libraries, the directory structrue
+# should be:
+#
+# 	/lib has i386 libraries.
+# 	/lib64 has x86-64 libraries.
+# 	/libx32 has x32 libraries.
+#
+MULTILIB_OPTIONS = m64/m32/mx32
+MULTILIB_DIRNAMES = 64 32 x32
+MULTILIB_OSDIRNAMES = ../lib64 $(if $(wildcard $(shell echo $(SYSTEM_HEADER_DIR))/../../usr/lib32),../lib32,../lib) ../libx32
+
+LIBGCC = stmp-multilib
+INSTALL_LIBGCC = install-multilib
+
+EXTRA_MULTILIB_PARTS=crtbegin.o crtend.o crtbeginS.o crtendS.o \
+		     crtbeginT.o crtprec32.o crtprec64.o crtprec80.o \
+		     crtfastmath.o
diff --git a/gcc/config/linux.h b/gcc/config/linux.h
index fc897b1..dbbeea5 100644
--- a/gcc/config/linux.h
+++ b/gcc/config/linux.h
@@ -77,9 +77,11 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #define UCLIBC_DYNAMIC_LINKER "/lib/ld-uClibc.so.0"
 #define UCLIBC_DYNAMIC_LINKER32 "/lib/ld-uClibc.so.0"
 #define UCLIBC_DYNAMIC_LINKER64 "/lib/ld64-uClibc.so.0"
+#define UCLIBC_DYNAMIC_LINKERX32 "/lib/ldx32-uClibc.so.0"
 #define BIONIC_DYNAMIC_LINKER "/system/bin/linker"
 #define BIONIC_DYNAMIC_LINKER32 "/system/bin/linker"
 #define BIONIC_DYNAMIC_LINKER64 "/system/bin/linker64"
+#define BIONIC_DYNAMIC_LINKERX32 "/system/bin/linkerx32"
 
 #define GNU_USER_DYNAMIC_LINKER						\
   CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER, UCLIBC_DYNAMIC_LINKER,	\
@@ -90,6 +92,9 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #define GNU_USER_DYNAMIC_LINKER64					\
   CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER64, UCLIBC_DYNAMIC_LINKER64, \
 			 BIONIC_DYNAMIC_LINKER64)
+#define GNU_USER_DYNAMIC_LINKERX32					\
+  CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKERX32, UCLIBC_DYNAMIC_LINKERX32, \
+			 BIONIC_DYNAMIC_LINKERX32)
 
 /* Determine whether the entire c99 runtime
    is present in the runtime library.  */
diff --git a/gcc/configure.ac b/gcc/configure.ac
index 5e41479..a421746 100644
--- a/gcc/configure.ac
+++ b/gcc/configure.ac
@@ -611,6 +611,16 @@ AC_ARG_ENABLE(multilib,
 [], [enable_multilib=yes])
 AC_SUBST(enable_multilib)
 
+# With x32 support
+AC_ARG_ENABLE(x32,
+[  --enable-x32            enable x32 library support for multiple ABIs],
+[], [enable_x32=no])
+
+# With ia32 support
+AC_ARG_ENABLE(ia32,
+[  --enable-ia32           enable ia32 library support for multiple ABIs],
+[], [enable_ia32=yes])
+
 # Enable __cxa_atexit for C++.
 AC_ARG_ENABLE(__cxa_atexit,
 [AS_HELP_STRING([--enable-__cxa_atexit], [enable __cxa_atexit for C++])],
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index a069042..12080ca 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -609,7 +609,7 @@ Objective-C and Objective-C++ Dialects}.
 -mpc32 -mpc64 -mpc80 -mstackrealign @gol
 -momit-leaf-frame-pointer  -mno-red-zone -mno-tls-direct-seg-refs @gol
 -mcmodel=@var{code-model} -mabi=@var{name} @gol
--m32  -m64 -mlarge-data-threshold=@var{num} @gol
+-m32 -m64 -mx32 -mlarge-data-threshold=@var{num} @gol
 -msse2avx -mfentry -m8bit-idiv @gol
 -mavx256-split-unaligned-load -mavx256-split-unaligned-store}
 
@@ -12824,14 +12824,18 @@ on AMD x86-64 processors in 64-bit environments.
 @table @gcctabopt
 @item -m32
 @itemx -m64
+@itemx -mx32
 @opindex m32
 @opindex m64
+@opindex mx32
 Generate code for a 32-bit or 64-bit environment.
-The 32-bit environment sets int, long and pointer to 32 bits and
+The -m32 option sets int, long and pointer to 32 bits and
 generates code that runs on any i386 system.
-The 64-bit environment sets int to 32 bits and long and pointer
-to 64 bits and generates code for AMD's x86-64 architecture. For
-darwin only the -m64 option turns off the @option{-fno-pic} and
+The -m64 option sets int to 32 bits and long and pointer
+to 64 bits and generates code for AMD's x86-64 architecture.
+The -mx32 option sets int, long and pointer to 32 bits and generates
+code for AMD's x86-64 architecture.
+For darwin only the -m64 option turns off the @option{-fno-pic} and
 @option{-mdynamic-no-pic} options.
 
 @item -mno-red-zone

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: PATCH [1/n]: Add initial -x32 support
  2011-06-05 19:55 PATCH [1/n]: Add initial -x32 support H.J. Lu
@ 2011-06-06 15:47 ` Uros Bizjak
  2011-06-07 15:47 ` Joseph S. Myers
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 26+ messages in thread
From: Uros Bizjak @ 2011-06-06 15:47 UTC (permalink / raw)
  To: H.J. Lu; +Cc: gcc-patches

On Sun, Jun 5, 2011 at 9:54 PM, H.J. Lu <hongjiu.lu@intel.com> wrote:

> I'd like to start submitting a series of patches to enable x32:
>
> https://sites.google.com/site/x32abi/
>
> The GCC x32 branch is very stable. There are no unexpected failures in
> C, C++, Fortran and Objective C testsuites.  SPEC CPU 2K/2006 compile
> and run correctly at -O2 and -O3.
>
> More than 90% of changes are in x86 backend.  This is the first patch to
> support x32.  By default, x32 is disabled and x32 run-time support
> isn't required.  OK for trunk?

I'd suggest to first post for review and later commit target
independent fixes in the middle-end, then fixes/improvements in
generic i386 parts and at last strict x32 target stuff. IIRC, ther are
many inconsistencies w.r.t. ptr_size != size of Pmode in both,
middle-end and generic i386 parts, and this way I hope we will avoid
problems if change in lower layers is based on wrong assumptions.

I also suggest to rename t-linuxx32 to t-linux-x32.

Thanks,
Uros.

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: PATCH [1/n]: Add initial -x32 support
  2011-06-05 19:55 PATCH [1/n]: Add initial -x32 support H.J. Lu
  2011-06-06 15:47 ` Uros Bizjak
@ 2011-06-07 15:47 ` Joseph S. Myers
  2011-06-07 18:54   ` H.J. Lu
  2011-06-07 15:59 ` Joseph S. Myers
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 26+ messages in thread
From: Joseph S. Myers @ 2011-06-07 15:47 UTC (permalink / raw)
  To: H.J. Lu; +Cc: gcc-patches, Uros Bizjak

On Sun, 5 Jun 2011, H.J. Lu wrote:

> 	* config.gcc: Support --enable-x32/--enable-ia32 for x86 Linux
> 	targets.
> 
> 	* configure.ac: Support --enable-x32/--enable-ia32.
> 	* configure: Regenerated.

New configure options need documenting in install.texi.

>  #undef ASM_SPEC
> -#define ASM_SPEC "%{" SPEC_32 ":--32} %{" SPEC_64 ":--64} \
> +#define ASM_SPEC "%{" SPEC_32 ":%{!mx32:--32}} %{" \
> + SPEC_64 ":%{!mx32:--64}} %{mx32:--x32} \
>   %{!mno-sse2avx:%{mavx:-msse2avx}} %{msse2avx:%{!mavx:-msse2avx}}"

This looks wrong.  You should define SPEC_32, SPEC_64 and SPEC_X32 to be 
the three mutually exclusive cases, then use those three here and in other 
specs without any nesting.

>  Generate code for a 32-bit or 64-bit environment.
> -The 32-bit environment sets int, long and pointer to 32 bits and
> +The -m32 option sets int, long and pointer to 32 bits and

@option{-m32}.  Likewise later in this paragraph for various option names.

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: PATCH [1/n]: Add initial -x32 support
  2011-06-05 19:55 PATCH [1/n]: Add initial -x32 support H.J. Lu
  2011-06-06 15:47 ` Uros Bizjak
  2011-06-07 15:47 ` Joseph S. Myers
@ 2011-06-07 15:59 ` Joseph S. Myers
  2011-06-07 19:11   ` H.J. Lu
  2011-06-14 17:52 ` H.J. Lu
  2011-07-05 14:42 ` PATCH [1/n] X32: " H.J. Lu
  4 siblings, 1 reply; 26+ messages in thread
From: Joseph S. Myers @ 2011-06-07 15:59 UTC (permalink / raw)
  To: H.J. Lu; +Cc: gcc-patches, Uros Bizjak

An additional comment on the specs: OPTION_DEFAULT_SPECS needs updating 
(-mx32 should use the --with-arch-64 etc. settings).

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: PATCH [1/n]: Add initial -x32 support
  2011-06-07 15:47 ` Joseph S. Myers
@ 2011-06-07 18:54   ` H.J. Lu
  2011-06-07 19:19     ` Joseph S. Myers
  0 siblings, 1 reply; 26+ messages in thread
From: H.J. Lu @ 2011-06-07 18:54 UTC (permalink / raw)
  To: Joseph S. Myers; +Cc: gcc-patches, Uros Bizjak

On Tue, Jun 7, 2011 at 8:47 AM, Joseph S. Myers <joseph@codesourcery.com> wrote:
> On Sun, 5 Jun 2011, H.J. Lu wrote:
>
>>       * config.gcc: Support --enable-x32/--enable-ia32 for x86 Linux
>>       targets.
>>
>>       * configure.ac: Support --enable-x32/--enable-ia32.
>>       * configure: Regenerated.
>
> New configure options need documenting in install.texi.

I will fix it.

>>  #undef ASM_SPEC
>> -#define ASM_SPEC "%{" SPEC_32 ":--32} %{" SPEC_64 ":--64} \
>> +#define ASM_SPEC "%{" SPEC_32 ":%{!mx32:--32}} %{" \
>> + SPEC_64 ":%{!mx32:--64}} %{mx32:--x32} \
>>   %{!mno-sse2avx:%{mavx:-msse2avx}} %{msse2avx:%{!mavx:-msse2avx}}"
>
> This looks wrong.  You should define SPEC_32, SPEC_64 and SPEC_X32 to be
> the three mutually exclusive cases, then use those three here and in other
> specs without any nesting.

I thought about it when I started working on it.  But I couldn't find a way
to do it properly.  What we have are

#if TARGET_64BIT_DEFAULT
#define SPEC_32 "m32"
#define SPEC_64 "!m32"
#else
#define SPEC_32 "!m64"
#define SPEC_64 "m64"
#endif

I don't know how  to make -mx32, -m32 and -m64 mutually exclusive with
GCC spec processing in GCC driver.

>>  Generate code for a 32-bit or 64-bit environment.
>> -The 32-bit environment sets int, long and pointer to 32 bits and
>> +The -m32 option sets int, long and pointer to 32 bits and
>
> @option{-m32}.  Likewise later in this paragraph for various option names.
>

I will fix it.

Thanks.


-- 
H.J.

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: PATCH [1/n]: Add initial -x32 support
  2011-06-07 15:59 ` Joseph S. Myers
@ 2011-06-07 19:11   ` H.J. Lu
  2011-06-07 19:20     ` Joseph S. Myers
  0 siblings, 1 reply; 26+ messages in thread
From: H.J. Lu @ 2011-06-07 19:11 UTC (permalink / raw)
  To: Joseph S. Myers; +Cc: gcc-patches, Uros Bizjak

On Tue, Jun 7, 2011 at 8:59 AM, Joseph S. Myers <joseph@codesourcery.com> wrote:
> An additional comment on the specs: OPTION_DEFAULT_SPECS needs updating
> (-mx32 should use the --with-arch-64 etc. settings).
>

The current x32 branch works like this:

[hjl@gnu-6 gcc]$  ./xgcc -B./ -v -O /tmp/x.i -S
Reading specs from ./specs
COLLECT_GCC=./xgcc
COLLECT_LTO_WRAPPER=./lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: /export/gnu/import/git/gcc-x32/configure
--enable-languages=c --disable-bootstrap --prefix=/usr/gcc-4.7.0-x32
--with-local-prefix=/usr/local --enable-gnu-indirect-function
--enable-x32 --with-arch-32=atom --with-cpu-64=corei7
--enable-cloog-backend=isl --with-ppl-include=/opt/gnu/include
--with-ppl-lib=/opt/gnu/lib64 --with-cloog-include=/opt/gnu/include
--with-cloog-lib=/opt/gnu/lib64 --with-fpmath=sse
Thread model: posix
gcc version 4.7.0 20110607 (experimental) (GCC)
COLLECT_GCC_OPTIONS='-B' './' '-v' '-O' '-S' '-mtune=corei7' '-march=x86-64'
 ./cc1 -fpreprocessed /tmp/x.i -quiet -dumpbase x.i -mtune=corei7
-march=x86-64 -auxbase x -O -version -o x.s
GNU C (GCC) version 4.7.0 20110607 (experimental) (x86_64-unknown-linux-gnu)
	compiled by GNU C version 4.6.0 20110509 (Red Hat 4.6.0-7), GMP
version 4.3.2, MPFR version 3.0.0, MPC version 0.8.3-dev
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
GNU C (GCC) version 4.7.0 20110607 (experimental) (x86_64-unknown-linux-gnu)
	compiled by GNU C version 4.6.0 20110509 (Red Hat 4.6.0-7), GMP
version 4.3.2, MPFR version 3.0.0, MPC version 0.8.3-dev
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
Compiler executable checksum: 4ce06b87a1cd6526b31d62b0b2a64ecd
COMPILER_PATH=./
LIBRARY_PATH=./:/lib/../lib64/:/usr/lib/../lib64/:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-B' './' '-v' '-O' '-S' '-mtune=corei7' '-march=x86-64'
[hjl@gnu-6 gcc]$  ./xgcc -B./ -v -O /tmp/x.i -S -mx32
Reading specs from ./specs
COLLECT_GCC=./xgcc
COLLECT_LTO_WRAPPER=./lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: /export/gnu/import/git/gcc-x32/configure
--enable-languages=c --disable-bootstrap --prefix=/usr/gcc-4.7.0-x32
--with-local-prefix=/usr/local --enable-gnu-indirect-function
--enable-x32 --with-arch-32=atom --with-cpu-64=corei7
--enable-cloog-backend=isl --with-ppl-include=/opt/gnu/include
--with-ppl-lib=/opt/gnu/lib64 --with-cloog-include=/opt/gnu/include
--with-cloog-lib=/opt/gnu/lib64 --with-fpmath=sse
Thread model: posix
gcc version 4.7.0 20110607 (experimental) (GCC)
COLLECT_GCC_OPTIONS='-B' './' '-v' '-O' '-S' '-mx32' '-mtune=corei7'
'-march=x86-64'
 ./cc1 -fpreprocessed /tmp/x.i -quiet -dumpbase x.i -mx32
-mtune=corei7 -march=x86-64 -auxbase x -O -version -o x.s
GNU C (GCC) version 4.7.0 20110607 (experimental) (x86_64-unknown-linux-gnu)
	compiled by GNU C version 4.6.0 20110509 (Red Hat 4.6.0-7), GMP
version 4.3.2, MPFR version 3.0.0, MPC version 0.8.3-dev
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
GNU C (GCC) version 4.7.0 20110607 (experimental) (x86_64-unknown-linux-gnu)
	compiled by GNU C version 4.6.0 20110509 (Red Hat 4.6.0-7), GMP
version 4.3.2, MPFR version 3.0.0, MPC version 0.8.3-dev
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
Compiler executable checksum: 4ce06b87a1cd6526b31d62b0b2a64ecd
COMPILER_PATH=./
LIBRARY_PATH=./x32/:/lib/../libx32/:/usr/lib/../libx32/:./:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-B' './' '-v' '-O' '-S' '-mx32' '-mtune=corei7'
'-march=x86-64'
[hjl@gnu-6 gcc]$  ./xgcc -B./ -v -O /tmp/x.i -S -m32
Reading specs from ./specs
COLLECT_GCC=./xgcc
COLLECT_LTO_WRAPPER=./lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: /export/gnu/import/git/gcc-x32/configure
--enable-languages=c --disable-bootstrap --prefix=/usr/gcc-4.7.0-x32
--with-local-prefix=/usr/local --enable-gnu-indirect-function
--enable-x32 --with-arch-32=atom --with-cpu-64=corei7
--enable-cloog-backend=isl --with-ppl-include=/opt/gnu/include
--with-ppl-lib=/opt/gnu/lib64 --with-cloog-include=/opt/gnu/include
--with-cloog-lib=/opt/gnu/lib64 --with-fpmath=sse
Thread model: posix
gcc version 4.7.0 20110607 (experimental) (GCC)
COLLECT_GCC_OPTIONS='-B' './' '-v' '-O' '-S' '-m32' '-mtune=generic'
'-march=atom'
 ./cc1 -fpreprocessed /tmp/x.i -quiet -dumpbase x.i -m32
-mtune=generic -march=atom -auxbase x -O -version -o x.s
GNU C (GCC) version 4.7.0 20110607 (experimental) (x86_64-unknown-linux-gnu)
	compiled by GNU C version 4.6.0 20110509 (Red Hat 4.6.0-7), GMP
version 4.3.2, MPFR version 3.0.0, MPC version 0.8.3-dev
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
GNU C (GCC) version 4.7.0 20110607 (experimental) (x86_64-unknown-linux-gnu)
	compiled by GNU C version 4.6.0 20110509 (Red Hat 4.6.0-7), GMP
version 4.3.2, MPFR version 3.0.0, MPC version 0.8.3-dev
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
Compiler executable checksum: 4ce06b87a1cd6526b31d62b0b2a64ecd
COMPILER_PATH=./
LIBRARY_PATH=./32/:/lib/../lib/:/usr/lib/../lib/:./:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-B' './' '-v' '-O' '-S' '-m32' '-mtune=generic'
'-march=atom'
[hjl@gnu-6 gcc]$

That is -mx32 takes the same default as -m64. It is the correct
behavior for -mx32.


-- 
H.J.

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: PATCH [1/n]: Add initial -x32 support
  2011-06-07 18:54   ` H.J. Lu
@ 2011-06-07 19:19     ` Joseph S. Myers
  0 siblings, 0 replies; 26+ messages in thread
From: Joseph S. Myers @ 2011-06-07 19:19 UTC (permalink / raw)
  To: H.J. Lu; +Cc: gcc-patches, Uros Bizjak

On Tue, 7 Jun 2011, H.J. Lu wrote:

> I thought about it when I started working on it.  But I couldn't find a way
> to do it properly.  What we have are
> 
> #if TARGET_64BIT_DEFAULT
> #define SPEC_32 "m32"
> #define SPEC_64 "!m32"
> #else
> #define SPEC_32 "!m64"
> #define SPEC_64 "m64"
> #endif
> 
> I don't know how  to make -mx32, -m32 and -m64 mutually exclusive with
> GCC spec processing in GCC driver.

The use of Negative in the .opt file means that only one such option will 
be visible for specs.  So you define specs such as "m64|mx32:;" to mean 
"neither -m64 nor -mx32 is passed (see the MIPS definitions of OPT_ARCH64 
and OPT_ARCH32, for example).

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: PATCH [1/n]: Add initial -x32 support
  2011-06-07 19:11   ` H.J. Lu
@ 2011-06-07 19:20     ` Joseph S. Myers
  2011-06-07 22:02       ` H.J. Lu
  0 siblings, 1 reply; 26+ messages in thread
From: Joseph S. Myers @ 2011-06-07 19:20 UTC (permalink / raw)
  To: H.J. Lu; +Cc: gcc-patches, Uros Bizjak

On Tue, 7 Jun 2011, H.J. Lu wrote:

> That is -mx32 takes the same default as -m64. It is the correct
> behavior for -mx32.

I think it's only right in the case where -m64 is the default, and the 
specs for the case where -m32 is the default need changing to handle -mx32 
properly.

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: PATCH [1/n]: Add initial -x32 support
  2011-06-07 19:20     ` Joseph S. Myers
@ 2011-06-07 22:02       ` H.J. Lu
  0 siblings, 0 replies; 26+ messages in thread
From: H.J. Lu @ 2011-06-07 22:02 UTC (permalink / raw)
  To: Joseph S. Myers; +Cc: gcc-patches, Uros Bizjak

On Tue, Jun 7, 2011 at 12:17 PM, Joseph S. Myers
<joseph@codesourcery.com> wrote:
> On Tue, 7 Jun 2011, H.J. Lu wrote:
>
>> That is -mx32 takes the same default as -m64. It is the correct
>> behavior for -mx32.
>
> I think it's only right in the case where -m64 is the default, and the
> specs for the case where -m32 is the default need changing to handle -mx32
> properly.
>

I checked this patch into x32 branch.

Thanks.

-- 
H.J.
---
commit bf324611c9c9dcd844ecc883486f580fda114ffc
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Tue Jun 7 13:05:57 2011 -0700

    Pass proper x32 options to as, ld and compilers.

diff --git a/gcc/ChangeLog.x32 b/gcc/ChangeLog.x32
index 5655c61..38d63d8 100644
--- a/gcc/ChangeLog.x32
+++ b/gcc/ChangeLog.x32
@@ -1,5 +1,16 @@
 2011-06-07  H.J. Lu  <hongjiu.lu@intel.com>

+	* config/i386/gnu-user64.h (SPEC_64): Support x32.
+	(SPEC_32): Likewise.
+	(SPEC_X32): New.
+	(ASM_SPEC): Use SPEC_X32.
+	(LINK_SPEC): Likewise.
+
+	* config/i386/i386.h (OPT_ARCH64): Support x32.
+	(OPT_ARCH32): Likewise.
+
+2011-06-07  H.J. Lu  <hongjiu.lu@intel.com>
+
 	* doc/invoke.texi: Use @option{} on -mx32, -m64 and -mx32.

 2011-06-07  H.J. Lu  <hongjiu.lu@intel.com>
diff --git a/gcc/config/i386/gnu-user64.h b/gcc/config/i386/gnu-user64.h
index b99fb13..bb4b8da 100644
--- a/gcc/config/i386/gnu-user64.h
+++ b/gcc/config/i386/gnu-user64.h
@@ -58,15 +58,18 @@ see the files COPYING3 and COPYING.RUNTIME
respectively.  If not, see

 #if TARGET_64BIT_DEFAULT
 #define SPEC_32 "m32"
-#define SPEC_64 "!m32"
+#define SPEC_64 "m32|mx32:;"
+#define SPEC_X32 "mx32"
 #else
-#define SPEC_32 "!m64"
+#define SPEC_32 "m64|mx32:;"
 #define SPEC_64 "m64"
+#define SPEC_X32 "mx32"
 #endif

 #undef ASM_SPEC
-#define ASM_SPEC "%{" SPEC_32 ":%{!mx32:--32}} %{" \
- SPEC_64 ":%{!mx32:--64}} %{mx32:--x32} \
+#define ASM_SPEC "%{" SPEC_32 ":--32} \
+ %{" SPEC_64 ":--64} \
+ %{" SPEC_X32 ":--x32} \
  %{!mno-sse2avx:%{mavx:-msse2avx}} %{msse2avx:%{!mavx:-msse2avx}}"

 #undef	LINK_SPEC
@@ -76,9 +79,9 @@ see the files COPYING3 and COPYING.RUNTIME
respectively.  If not, see
   %{!shared: \
     %{!static: \
       %{rdynamic:-export-dynamic} \
-      %{" SPEC_32 ":%{!mx32:-dynamic-linker " GNU_USER_DYNAMIC_LINKER32 "}} \
-      %{" SPEC_64 ":%{!mx32:-dynamic-linker " GNU_USER_DYNAMIC_LINKER64 "}} \
-      %{mx32:-dynamic-linker " GNU_USER_DYNAMIC_LINKERX32 "}} \
+      %{" SPEC_32 ":-dynamic-linker " GNU_USER_DYNAMIC_LINKER32 "} \
+      %{" SPEC_64 ":-dynamic-linker " GNU_USER_DYNAMIC_LINKER64 "} \
+      %{" SPEC_X32 ":-dynamic-linker " GNU_USER_DYNAMIC_LINKERX32 "}} \
     %{static:-static}}"

 /* Similar to standard GNU userspace, but adding -ffast-math support.  */
diff --git a/gcc/config/i386/i386.h b/gcc/config/i386/i386.h
index f9270de..ec86e74 100644
--- a/gcc/config/i386/i386.h
+++ b/gcc/config/i386/i386.h
@@ -519,8 +519,8 @@ extern const char *host_detect_local_cpu (int
argc, const char **argv);
 #define OPT_ARCH64 "!m32"
 #define OPT_ARCH32 "m32"
 #else
-#define OPT_ARCH64 "m64"
-#define OPT_ARCH32 "!m64"
+#define OPT_ARCH64 "m64|mx32"
+#define OPT_ARCH32 "m64|mx32:;"
 #endif

 /* Support for configure-time defaults of some command line options.

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: PATCH [1/n]: Add initial -x32 support
  2011-06-05 19:55 PATCH [1/n]: Add initial -x32 support H.J. Lu
                   ` (2 preceding siblings ...)
  2011-06-07 15:59 ` Joseph S. Myers
@ 2011-06-14 17:52 ` H.J. Lu
  2011-07-05 14:42 ` PATCH [1/n] X32: " H.J. Lu
  4 siblings, 0 replies; 26+ messages in thread
From: H.J. Lu @ 2011-06-14 17:52 UTC (permalink / raw)
  To: gcc-patches, Uros Bizjak

On Sun, Jun 05, 2011 at 12:54:41PM -0700, H.J. Lu wrote:
> Hi,
> 
> I'd like to start submitting a series of patches to enable x32:
> 
> https://sites.google.com/site/x32abi/
> 
> The GCC x32 branch is very stable. There are no unexpected failures in
> C, C++, Fortran and Objective C testsuites.  SPEC CPU 2K/2006 compile
> and run correctly at -O2 and -O3. 
> 
> More than 90% of changes are in x86 backend.  This is the first patch to
> support x32.  By default, x32 is disabled and x32 run-time support
> isn't required.  OK for trunk?
> 
> Thanks.
> 
> 

Here is the updated patch based on the feedbacks.

Thanks.


H.J.
---
2011-06-14  H.J. Lu  <hongjiu.lu@intel.com>

	* config.gcc: Support --enable-x32/--enable-ia32 for x86 Linux
	targets.

	* configure.ac: Support --enable-x32/--enable-ia32.
	* configure: Regenerated.

	* config/i386/gnu-user64.h (SPEC_64): Support x32.
	(SPEC_32): Likewise.
	(ASM_SPEC): Likewise.
	(LINK_SPEC): Likewise.
	(TARGET_THREAD_SSP_OFFSET): Likewise.
	(TARGET_THREAD_SPLIT_STACK_OFFSET): Likewise.
	(SPEC_X32): New.

	* config/i386/i386.h (TARGET_X32): New.
	(TARGET_LP64): New.
	(LONG_TYPE_SIZE): Likewise.
	(POINTER_SIZE): Likewise.
	(POINTERS_EXTEND_UNSIGNED): Likewise.
	(OPT_ARCH64): Support x32.
	(OPT_ARCH32): Likewise.

	* config/i386/i386.opt (mx32): New.

	* config/i386/kfreebsd-gnu64.h (GNU_USER_LINK_EMULATIONX32): New.
	(GLIBC_DYNAMIC_LINKERX32): Likewise.
	* config/i386/linux64.h (GNU_USER_LINK_EMULATIONX32): Likewise.
	(GLIBC_DYNAMIC_LINKERX32): Likewise.

	* config/i386/t-linux-x32: New.
	* config/i386/t-linux64-x32: Likewise.

	* config/linux.h (UCLIBC_DYNAMIC_LINKERX32): New.
	(BIONIC_DYNAMIC_LINKERX32): Likewise.
	(GNU_USER_DYNAMIC_LINKERX32): Likewise.

	* doc/install.texi: Document --enable-ia32 and --enable-x32.

	* doc/invoke.texi: Document -mx32.

diff --git a/gcc/config.gcc b/gcc/config.gcc
index e9704f3..e2b72df 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -1232,7 +1232,17 @@ i[34567]86-*-linux* | i[34567]86-*-kfreebsd*-gnu | i[34567]86-*-knetbsd*-gnu | i
 		if test x$enable_targets = xall; then
 			tm_file="${tm_file} i386/x86-64.h i386/gnu-user64.h i386/linux64.h"
 			tm_defines="${tm_defines} TARGET_BI_ARCH=1"
-			tmake_file="${tmake_file} i386/t-linux64"
+			case x${enable_x32}${enable_ia32} in
+			xyesyes)
+				tmake_file="${tmake_file} i386/t-linux-x32"
+				;;
+			xyesno)
+				tmake_file="${tmake_file} i386/t-linux64-x32"
+				;;
+			*)
+				tmake_file="${tmake_file} i386/t-linux64"
+				;;
+			esac
 			need_64bit_hwint=yes
 			need_64bit_isa=yes
 			case X"${with_cpu}" in
@@ -1270,7 +1280,18 @@ x86_64-*-linux* | x86_64-*-kfreebsd*-gnu | x86_64-*-knetbsd*-gnu)
 	x86_64-*-kfreebsd*-gnu) tm_file="${tm_file} kfreebsd-gnu.h i386/kfreebsd-gnu64.h" ;;
 	x86_64-*-knetbsd*-gnu) tm_file="${tm_file} knetbsd-gnu.h" ;;
 	esac
-	tmake_file="${tmake_file} i386/t-linux64 i386/t-crtstuff i386/t-crtpc i386/t-crtfm t-dfprules"
+	case x${enable_x32}${enable_ia32} in
+	xyesyes)
+		tmake_file="${tmake_file} i386/t-linux-x32"
+		;;
+	xyesno)
+		tmake_file="${tmake_file} i386/t-linux64-x32"
+		;;
+	*)
+		tmake_file="${tmake_file} i386/t-linux64"
+		;;
+	esac
+	tmake_file="${tmake_file} i386/t-crtstuff i386/t-crtpc i386/t-crtfm t-dfprules"
 	;;
 i[34567]86-pc-msdosdjgpp*)
 	xm_file=i386/xm-djgpp.h
diff --git a/gcc/config/i386/gnu-user64.h b/gcc/config/i386/gnu-user64.h
index b069975..954f3b2 100644
--- a/gcc/config/i386/gnu-user64.h
+++ b/gcc/config/i386/gnu-user64.h
@@ -58,25 +58,31 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 
 #if TARGET_64BIT_DEFAULT
 #define SPEC_32 "m32"
-#define SPEC_64 "!m32"
+#define SPEC_64 "m32|mx32:;"
+#define SPEC_X32 "mx32"
 #else
-#define SPEC_32 "!m64"
+#define SPEC_32 "m64|mx32:;"
 #define SPEC_64 "m64"
+#define SPEC_X32 "mx32"
 #endif
 
 #undef ASM_SPEC
-#define ASM_SPEC "%{" SPEC_32 ":--32} %{" SPEC_64 ":--64} \
+#define ASM_SPEC "%{" SPEC_32 ":--32} \
+ %{" SPEC_64 ":--64} \
+ %{" SPEC_X32 ":--x32} \
  %{!mno-sse2avx:%{mavx:-msse2avx}} %{msse2avx:%{!mavx:-msse2avx}}"
 
 #undef	LINK_SPEC
 #define LINK_SPEC "%{" SPEC_64 ":-m " GNU_USER_LINK_EMULATION64 "} \
                    %{" SPEC_32 ":-m " GNU_USER_LINK_EMULATION32 "} \
+                   %{" SPEC_X32 ":-m " GNU_USER_LINK_EMULATIONX32 "} \
   %{shared:-shared} \
   %{!shared: \
     %{!static: \
       %{rdynamic:-export-dynamic} \
       %{" SPEC_32 ":-dynamic-linker " GNU_USER_DYNAMIC_LINKER32 "} \
-      %{" SPEC_64 ":-dynamic-linker " GNU_USER_DYNAMIC_LINKER64 "}} \
+      %{" SPEC_64 ":-dynamic-linker " GNU_USER_DYNAMIC_LINKER64 "} \
+      %{" SPEC_X32 ":-dynamic-linker " GNU_USER_DYNAMIC_LINKERX32 "}} \
     %{static:-static}}"
 
 /* Similar to standard GNU userspace, but adding -ffast-math support.  */
@@ -110,10 +116,13 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 
 #ifdef TARGET_LIBC_PROVIDES_SSP
 /* i386 glibc provides __stack_chk_guard in %gs:0x14,
+   x32 glibc provides it in %fs:0x18. 
    x86_64 glibc provides it in %fs:0x28.  */
-#define TARGET_THREAD_SSP_OFFSET	(TARGET_64BIT ? 0x28 : 0x14)
+#define TARGET_THREAD_SSP_OFFSET \
+  (TARGET_64BIT ? (TARGET_X32 ? 0x18 : 0x28) : 0x14)
 
 /* We steal the last transactional memory word.  */
 #define TARGET_CAN_SPLIT_STACK
-#define TARGET_THREAD_SPLIT_STACK_OFFSET (TARGET_64BIT ? 0x70 : 0x30)
+#define TARGET_THREAD_SPLIT_STACK_OFFSET \
+  (TARGET_64BIT ? (TARGET_X32 ? 0x40 : 0x70) : 0x30)
 #endif
diff --git a/gcc/config/i386/i386.h b/gcc/config/i386/i386.h
index 8badcbb..ec86e74 100644
--- a/gcc/config/i386/i386.h
+++ b/gcc/config/i386/i386.h
@@ -42,6 +42,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 /* Redefines for option macros.  */
 
 #define TARGET_64BIT	OPTION_ISA_64BIT
+#define TARGET_X32	OPTION_ISA_X32
 #define TARGET_MMX	OPTION_ISA_MMX
 #define TARGET_3DNOW	OPTION_ISA_3DNOW
 #define TARGET_3DNOW_A	OPTION_ISA_3DNOW_A
@@ -72,6 +73,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #define TARGET_RDRND	OPTION_ISA_RDRND
 #define TARGET_F16C	OPTION_ISA_F16C
 
+#define TARGET_LP64	(TARGET_64BIT && !TARGET_X32)
 
 /* SSE4.1 defines round instructions */
 #define	OPTION_MASK_ISA_ROUND	OPTION_MASK_ISA_SSE4_1
@@ -517,8 +519,8 @@ extern const char *host_detect_local_cpu (int argc, const char **argv);
 #define OPT_ARCH64 "!m32"
 #define OPT_ARCH32 "m32"
 #else
-#define OPT_ARCH64 "m64"
-#define OPT_ARCH32 "!m64"
+#define OPT_ARCH64 "m64|mx32"
+#define OPT_ARCH32 "m64|mx32:;"
 #endif
 
 /* Support for configure-time defaults of some command line options.
@@ -638,6 +640,8 @@ enum target_cpu_default
 
 #define SHORT_TYPE_SIZE 16
 #define INT_TYPE_SIZE 32
+#define LONG_TYPE_SIZE (TARGET_X32 ? 32 : BITS_PER_WORD)
+#define POINTER_SIZE (TARGET_X32 ? 32 : BITS_PER_WORD)
 #define LONG_LONG_TYPE_SIZE 64
 #define FLOAT_TYPE_SIZE 32
 #define DOUBLE_TYPE_SIZE 64
@@ -1743,6 +1747,13 @@ do {							\
    between pointers and any other objects of this machine mode.  */
 #define Pmode (TARGET_64BIT ? DImode : SImode)
 
+/* A C expression whose value is zero if pointers that need to be extended
+   from being `POINTER_SIZE' bits wide to `Pmode' are sign-extended and
+   greater then zero if they are zero-extended and less then zero if the
+   ptr_extend instruction should be used.  */
+
+#define POINTERS_EXTEND_UNSIGNED 1
+
 /* A function address in a call instruction
    is a byte address (for indexing purposes)
    so give the MEM rtx a byte's mode.  */
diff --git a/gcc/config/i386/i386.opt b/gcc/config/i386/i386.opt
index 21e0def..2c8fe8f 100644
--- a/gcc/config/i386/i386.opt
+++ b/gcc/config/i386/i386.opt
@@ -398,9 +398,13 @@ Target RejectNegative Negative(m64) Report InverseMask(ISA_64BIT) Var(ix86_isa_f
 Generate 32bit i386 code
 
 m64
-Target RejectNegative Negative(m32) Report Mask(ISA_64BIT) Var(ix86_isa_flags) Save
+Target RejectNegative Negative(mx32) Report Mask(ISA_64BIT) Var(ix86_isa_flags) Save
 Generate 64bit x86-64 code
 
+mx32
+Target RejectNegative Negative(m32) Report Mask(ISA_X32) Var(ix86_isa_flags) Save
+Generate 32bit x86-64 code
+
 mmmx
 Target Report Mask(ISA_MMX) Var(ix86_isa_flags) Save
 Support MMX built-in functions
diff --git a/gcc/config/i386/kfreebsd-gnu64.h b/gcc/config/i386/kfreebsd-gnu64.h
index c3798a5..2085ca5 100644
--- a/gcc/config/i386/kfreebsd-gnu64.h
+++ b/gcc/config/i386/kfreebsd-gnu64.h
@@ -21,6 +21,8 @@ along with GCC; see the file COPYING3.  If not see
 
 #define GNU_USER_LINK_EMULATION32 "elf_i386_fbsd"
 #define GNU_USER_LINK_EMULATION64 "elf_x86_64_fbsd"
+#define GNU_USER_LINK_EMULATIONX32 "elf32_x86_64_fbsd"
 
 #define GLIBC_DYNAMIC_LINKER32 "/lib/ld.so.1"
 #define GLIBC_DYNAMIC_LINKER64 "/lib/ld-kfreebsd-x86-64.so.1"
+#define GLIBC_DYNAMIC_LINKERX32 "/lib/ld-kfreebsd-x32.so.1"
diff --git a/gcc/config/i386/linux64.h b/gcc/config/i386/linux64.h
index 5d33224..5b0a212 100644
--- a/gcc/config/i386/linux64.h
+++ b/gcc/config/i386/linux64.h
@@ -26,6 +26,8 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 
 #define GNU_USER_LINK_EMULATION32 "elf_i386"
 #define GNU_USER_LINK_EMULATION64 "elf_x86_64"
+#define GNU_USER_LINK_EMULATIONX32 "elf32_x86_64"
 
 #define GLIBC_DYNAMIC_LINKER32 "/lib/ld-linux.so.2"
 #define GLIBC_DYNAMIC_LINKER64 "/lib64/ld-linux-x86-64.so.2"
+#define GLIBC_DYNAMIC_LINKERX32 "/libx32/ld-linux-x32.so.2"
diff --git a/gcc/config/i386/t-linux-x32 b/gcc/config/i386/t-linux-x32
new file mode 100644
index 0000000..92acf91
--- /dev/null
+++ b/gcc/config/i386/t-linux-x32
@@ -0,0 +1,42 @@
+# Copyright (C) 2011 Free Software Foundation, Inc.
+#
+# This file is part of GCC.
+#
+# GCC is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GCC is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GCC; see the file COPYING3.  If not see
+# <http://www.gnu.org/licenses/>.
+
+# On Debian, Ubuntu and other derivative distributions, the 32bit libraries
+# are found in /lib32 and /usr/lib32, /lib64 and /usr/lib64 are symlinks to
+# /lib and /usr/lib, while other distributions install libraries into /lib64
+# and /usr/lib64.  The LSB does not enforce the use of /lib64 and /usr/lib64,
+# it doesn't tell anything about the 32bit libraries on those systems.  Set
+# MULTILIB_OSDIRNAMES according to what is found on the target.
+
+# To support i386, x86-64 and x32 libraries, the directory structrue
+# should be:
+#
+# 	/lib has i386 libraries.
+# 	/lib64 has x86-64 libraries.
+# 	/libx32 has x32 libraries.
+#
+MULTILIB_OPTIONS = m64/m32/mx32
+MULTILIB_DIRNAMES = 64 32 x32
+MULTILIB_OSDIRNAMES = ../lib64 $(if $(wildcard $(shell echo $(SYSTEM_HEADER_DIR))/../../usr/lib32),../lib32,../lib) ../libx32
+
+LIBGCC = stmp-multilib
+INSTALL_LIBGCC = install-multilib
+
+EXTRA_MULTILIB_PARTS=crtbegin.o crtend.o crtbeginS.o crtendS.o \
+		     crtbeginT.o crtprec32.o crtprec64.o crtprec80.o \
+		     crtfastmath.o
diff --git a/gcc/config/i386/t-linux64-x32 b/gcc/config/i386/t-linux64-x32
new file mode 100644
index 0000000..3a4d1de
--- /dev/null
+++ b/gcc/config/i386/t-linux64-x32
@@ -0,0 +1,34 @@
+# Copyright (C) 2011 Free Software Foundation, Inc.
+#
+# This file is part of GCC.
+#
+# GCC is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GCC is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GCC; see the file COPYING3.  If not see
+# <http://www.gnu.org/licenses/>.
+
+# To support x86-64 and x32 libraries, the directory structrue
+# should be:
+#
+# 	/lib64 has x86-64 libraries.
+# 	/libx32 has x32 libraries.
+#
+MULTILIB_OPTIONS = m64/mx32
+MULTILIB_DIRNAMES = 64 x32
+MULTILIB_OSDIRNAMES = ../lib64 ../libx32
+
+LIBGCC = stmp-multilib
+INSTALL_LIBGCC = install-multilib
+
+EXTRA_MULTILIB_PARTS=crtbegin.o crtend.o crtbeginS.o crtendS.o \
+		     crtbeginT.o crtprec32.o crtprec64.o crtprec80.o \
+		     crtfastmath.o
diff --git a/gcc/config/linux.h b/gcc/config/linux.h
index fc897b1..dbbeea5 100644
--- a/gcc/config/linux.h
+++ b/gcc/config/linux.h
@@ -77,9 +77,11 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #define UCLIBC_DYNAMIC_LINKER "/lib/ld-uClibc.so.0"
 #define UCLIBC_DYNAMIC_LINKER32 "/lib/ld-uClibc.so.0"
 #define UCLIBC_DYNAMIC_LINKER64 "/lib/ld64-uClibc.so.0"
+#define UCLIBC_DYNAMIC_LINKERX32 "/lib/ldx32-uClibc.so.0"
 #define BIONIC_DYNAMIC_LINKER "/system/bin/linker"
 #define BIONIC_DYNAMIC_LINKER32 "/system/bin/linker"
 #define BIONIC_DYNAMIC_LINKER64 "/system/bin/linker64"
+#define BIONIC_DYNAMIC_LINKERX32 "/system/bin/linkerx32"
 
 #define GNU_USER_DYNAMIC_LINKER						\
   CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER, UCLIBC_DYNAMIC_LINKER,	\
@@ -90,6 +92,9 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #define GNU_USER_DYNAMIC_LINKER64					\
   CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER64, UCLIBC_DYNAMIC_LINKER64, \
 			 BIONIC_DYNAMIC_LINKER64)
+#define GNU_USER_DYNAMIC_LINKERX32					\
+  CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKERX32, UCLIBC_DYNAMIC_LINKERX32, \
+			 BIONIC_DYNAMIC_LINKERX32)
 
 /* Determine whether the entire c99 runtime
    is present in the runtime library.  */
diff --git a/gcc/configure.ac b/gcc/configure.ac
index 70b3dbc..4713264 100644
--- a/gcc/configure.ac
+++ b/gcc/configure.ac
@@ -611,6 +611,16 @@ AC_ARG_ENABLE(multilib,
 [], [enable_multilib=yes])
 AC_SUBST(enable_multilib)
 
+# With x32 support
+AC_ARG_ENABLE(x32,
+[  --enable-x32            enable x32 library support for multiple ABIs],
+[], [enable_x32=no])
+
+# With ia32 support
+AC_ARG_ENABLE(ia32,
+[  --enable-ia32           enable ia32 library support for multiple ABIs],
+[], [enable_ia32=yes])
+
 # Enable __cxa_atexit for C++.
 AC_ARG_ENABLE(__cxa_atexit,
 [AS_HELP_STRING([--enable-__cxa_atexit], [enable __cxa_atexit for C++])],
diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi
index 7ebcd92..f63094c 100644
--- a/gcc/doc/install.texi
+++ b/gcc/doc/install.texi
@@ -1155,6 +1155,16 @@ assumptions made by the configure test are incorrect.
 Specify that the target does not support TLS.
 This is an alias for @option{--enable-tls=no}.
 
+@item --enable-ia32
+This option enables ia32 library support for multiple ABIs.  By
+default, ia32 library support is enabled.  It is only supported for
+x86-64.
+
+@item --enable-x32
+This option enables x32 library support for multiple ABIs. By
+default, x32 library support is disabled.  It is only supported for
+x86-64.
+
 @item --with-cpu=@var{cpu}
 @itemx --with-cpu-32=@var{cpu}
 @itemx --with-cpu-64=@var{cpu}
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index e747f1d..a111236 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -610,7 +610,7 @@ Objective-C and Objective-C++ Dialects}.
 -mpc32 -mpc64 -mpc80 -mstackrealign @gol
 -momit-leaf-frame-pointer  -mno-red-zone -mno-tls-direct-seg-refs @gol
 -mcmodel=@var{code-model} -mabi=@var{name} @gol
--m32  -m64 -mlarge-data-threshold=@var{num} @gol
+-m32 -m64 -mx32 -mlarge-data-threshold=@var{num} @gol
 -msse2avx -mfentry -m8bit-idiv @gol
 -mavx256-split-unaligned-load -mavx256-split-unaligned-store}
 
@@ -12837,15 +12837,19 @@ on AMD x86-64 processors in 64-bit environments.
 @table @gcctabopt
 @item -m32
 @itemx -m64
+@itemx -mx32
 @opindex m32
 @opindex m64
+@opindex mx32
 Generate code for a 32-bit or 64-bit environment.
-The 32-bit environment sets int, long and pointer to 32 bits and
+The @option{-m32} option sets int, long and pointer to 32 bits and
 generates code that runs on any i386 system.
-The 64-bit environment sets int to 32 bits and long and pointer
-to 64 bits and generates code for AMD's x86-64 architecture. For
-darwin only the -m64 option turns off the @option{-fno-pic} and
-@option{-mdynamic-no-pic} options.
+The @option{-m64} option sets int to 32 bits and long and pointer
+to 64 bits and generates code for AMD's x86-64 architecture.
+The @option{-mx32} option sets int, long and pointer to 32 bits and
+generates code for AMD's x86-64 architecture.
+For darwin only the @option{-m64} option turns off the @option{-fno-pic}
+and @option{-mdynamic-no-pic} options.
 
 @item -mno-red-zone
 @opindex mno-red-zone

^ permalink raw reply	[flat|nested] 26+ messages in thread

* PATCH [1/n] X32: Add initial -x32 support
  2011-06-05 19:55 PATCH [1/n]: Add initial -x32 support H.J. Lu
                   ` (3 preceding siblings ...)
  2011-06-14 17:52 ` H.J. Lu
@ 2011-07-05 14:42 ` H.J. Lu
  2011-07-05 15:21   ` Uros Bizjak
  4 siblings, 1 reply; 26+ messages in thread
From: H.J. Lu @ 2011-07-05 14:42 UTC (permalink / raw)
  To: gcc-patches, Uros Bizjak

Hi,

I'd like to start submitting a series of patches to enable x32:

https://sites.google.com/site/x32abi/

The GCC x32 branch is very stable. There are no unexpected failures in
C, C++, Fortran and Objective C testsuites.  SPEC CPU 2K/2006 compile
and run correctly at -O2 and -O3. 

More than 90% of changes are in x86 backend.  I have submitted non-x86
backend patches.  Most of them have been reviewed and checked in.  Only
4 patches are pending for review/approval.

This is the first x86 backend patch to support x32.  By default, x32 is
disabled and x32 run-time support isn't required.  OK for trunk?

Thanks.


H.J.
---
2011-06-14  H.J. Lu  <hongjiu.lu@intel.com>

	* config.gcc: Support --enable-x32/--enable-ia32 for x86 Linux
	targets.

	* configure.ac: Support --enable-x32/--enable-ia32.
	* configure: Regenerated.

	* config/i386/gnu-user64.h (SPEC_64): Support x32.
	(SPEC_32): Likewise.
	(ASM_SPEC): Likewise.
	(LINK_SPEC): Likewise.
	(TARGET_THREAD_SSP_OFFSET): Likewise.
	(TARGET_THREAD_SPLIT_STACK_OFFSET): Likewise.
	(SPEC_X32): New.

	* config/i386/i386.h (TARGET_X32): New.
	(TARGET_LP64): New.
	(LONG_TYPE_SIZE): Likewise.
	(POINTER_SIZE): Likewise.
	(POINTERS_EXTEND_UNSIGNED): Likewise.
	(OPT_ARCH64): Support x32.
	(OPT_ARCH32): Likewise.

	* config/i386/i386.opt (mx32): New.

	* config/i386/kfreebsd-gnu64.h (GNU_USER_LINK_EMULATIONX32): New.
	(GLIBC_DYNAMIC_LINKERX32): Likewise.
	* config/i386/linux64.h (GNU_USER_LINK_EMULATIONX32): Likewise.
	(GLIBC_DYNAMIC_LINKERX32): Likewise.

	* config/i386/t-linux-x32: New.
	* config/i386/t-linux64-x32: Likewise.

	* config/linux.h (UCLIBC_DYNAMIC_LINKERX32): New.
	(BIONIC_DYNAMIC_LINKERX32): Likewise.
	(GNU_USER_DYNAMIC_LINKERX32): Likewise.

	* doc/install.texi: Document --enable-ia32 and --enable-x32.

	* doc/invoke.texi: Document -mx32.

diff --git a/gcc/config.gcc b/gcc/config.gcc
index e9704f3..e2b72df 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -1232,7 +1232,17 @@ i[34567]86-*-linux* | i[34567]86-*-kfreebsd*-gnu | i[34567]86-*-knetbsd*-gnu | i
 		if test x$enable_targets = xall; then
 			tm_file="${tm_file} i386/x86-64.h i386/gnu-user64.h i386/linux64.h"
 			tm_defines="${tm_defines} TARGET_BI_ARCH=1"
-			tmake_file="${tmake_file} i386/t-linux64"
+			case x${enable_x32}${enable_ia32} in
+			xyesyes)
+				tmake_file="${tmake_file} i386/t-linux-x32"
+				;;
+			xyesno)
+				tmake_file="${tmake_file} i386/t-linux64-x32"
+				;;
+			*)
+				tmake_file="${tmake_file} i386/t-linux64"
+				;;
+			esac
 			need_64bit_hwint=yes
 			need_64bit_isa=yes
 			case X"${with_cpu}" in
@@ -1270,7 +1280,18 @@ x86_64-*-linux* | x86_64-*-kfreebsd*-gnu | x86_64-*-knetbsd*-gnu)
 	x86_64-*-kfreebsd*-gnu) tm_file="${tm_file} kfreebsd-gnu.h i386/kfreebsd-gnu64.h" ;;
 	x86_64-*-knetbsd*-gnu) tm_file="${tm_file} knetbsd-gnu.h" ;;
 	esac
-	tmake_file="${tmake_file} i386/t-linux64 i386/t-crtstuff i386/t-crtpc i386/t-crtfm t-dfprules"
+	case x${enable_x32}${enable_ia32} in
+	xyesyes)
+		tmake_file="${tmake_file} i386/t-linux-x32"
+		;;
+	xyesno)
+		tmake_file="${tmake_file} i386/t-linux64-x32"
+		;;
+	*)
+		tmake_file="${tmake_file} i386/t-linux64"
+		;;
+	esac
+	tmake_file="${tmake_file} i386/t-crtstuff i386/t-crtpc i386/t-crtfm t-dfprules"
 	;;
 i[34567]86-pc-msdosdjgpp*)
 	xm_file=i386/xm-djgpp.h
diff --git a/gcc/config/i386/gnu-user64.h b/gcc/config/i386/gnu-user64.h
index b069975..954f3b2 100644
--- a/gcc/config/i386/gnu-user64.h
+++ b/gcc/config/i386/gnu-user64.h
@@ -58,25 +58,31 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 
 #if TARGET_64BIT_DEFAULT
 #define SPEC_32 "m32"
-#define SPEC_64 "!m32"
+#define SPEC_64 "m32|mx32:;"
+#define SPEC_X32 "mx32"
 #else
-#define SPEC_32 "!m64"
+#define SPEC_32 "m64|mx32:;"
 #define SPEC_64 "m64"
+#define SPEC_X32 "mx32"
 #endif
 
 #undef ASM_SPEC
-#define ASM_SPEC "%{" SPEC_32 ":--32} %{" SPEC_64 ":--64} \
+#define ASM_SPEC "%{" SPEC_32 ":--32} \
+ %{" SPEC_64 ":--64} \
+ %{" SPEC_X32 ":--x32} \
  %{!mno-sse2avx:%{mavx:-msse2avx}} %{msse2avx:%{!mavx:-msse2avx}}"
 
 #undef	LINK_SPEC
 #define LINK_SPEC "%{" SPEC_64 ":-m " GNU_USER_LINK_EMULATION64 "} \
                    %{" SPEC_32 ":-m " GNU_USER_LINK_EMULATION32 "} \
+                   %{" SPEC_X32 ":-m " GNU_USER_LINK_EMULATIONX32 "} \
   %{shared:-shared} \
   %{!shared: \
     %{!static: \
       %{rdynamic:-export-dynamic} \
       %{" SPEC_32 ":-dynamic-linker " GNU_USER_DYNAMIC_LINKER32 "} \
-      %{" SPEC_64 ":-dynamic-linker " GNU_USER_DYNAMIC_LINKER64 "}} \
+      %{" SPEC_64 ":-dynamic-linker " GNU_USER_DYNAMIC_LINKER64 "} \
+      %{" SPEC_X32 ":-dynamic-linker " GNU_USER_DYNAMIC_LINKERX32 "}} \
     %{static:-static}}"
 
 /* Similar to standard GNU userspace, but adding -ffast-math support.  */
@@ -110,10 +116,13 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 
 #ifdef TARGET_LIBC_PROVIDES_SSP
 /* i386 glibc provides __stack_chk_guard in %gs:0x14,
+   x32 glibc provides it in %fs:0x18. 
    x86_64 glibc provides it in %fs:0x28.  */
-#define TARGET_THREAD_SSP_OFFSET	(TARGET_64BIT ? 0x28 : 0x14)
+#define TARGET_THREAD_SSP_OFFSET \
+  (TARGET_64BIT ? (TARGET_X32 ? 0x18 : 0x28) : 0x14)
 
 /* We steal the last transactional memory word.  */
 #define TARGET_CAN_SPLIT_STACK
-#define TARGET_THREAD_SPLIT_STACK_OFFSET (TARGET_64BIT ? 0x70 : 0x30)
+#define TARGET_THREAD_SPLIT_STACK_OFFSET \
+  (TARGET_64BIT ? (TARGET_X32 ? 0x40 : 0x70) : 0x30)
 #endif
diff --git a/gcc/config/i386/i386.h b/gcc/config/i386/i386.h
index 8badcbb..ec86e74 100644
--- a/gcc/config/i386/i386.h
+++ b/gcc/config/i386/i386.h
@@ -42,6 +42,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 /* Redefines for option macros.  */
 
 #define TARGET_64BIT	OPTION_ISA_64BIT
+#define TARGET_X32	OPTION_ISA_X32
 #define TARGET_MMX	OPTION_ISA_MMX
 #define TARGET_3DNOW	OPTION_ISA_3DNOW
 #define TARGET_3DNOW_A	OPTION_ISA_3DNOW_A
@@ -72,6 +73,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #define TARGET_RDRND	OPTION_ISA_RDRND
 #define TARGET_F16C	OPTION_ISA_F16C
 
+#define TARGET_LP64	(TARGET_64BIT && !TARGET_X32)
 
 /* SSE4.1 defines round instructions */
 #define	OPTION_MASK_ISA_ROUND	OPTION_MASK_ISA_SSE4_1
@@ -517,8 +519,8 @@ extern const char *host_detect_local_cpu (int argc, const char **argv);
 #define OPT_ARCH64 "!m32"
 #define OPT_ARCH32 "m32"
 #else
-#define OPT_ARCH64 "m64"
-#define OPT_ARCH32 "!m64"
+#define OPT_ARCH64 "m64|mx32"
+#define OPT_ARCH32 "m64|mx32:;"
 #endif
 
 /* Support for configure-time defaults of some command line options.
@@ -638,6 +640,8 @@ enum target_cpu_default
 
 #define SHORT_TYPE_SIZE 16
 #define INT_TYPE_SIZE 32
+#define LONG_TYPE_SIZE (TARGET_X32 ? 32 : BITS_PER_WORD)
+#define POINTER_SIZE (TARGET_X32 ? 32 : BITS_PER_WORD)
 #define LONG_LONG_TYPE_SIZE 64
 #define FLOAT_TYPE_SIZE 32
 #define DOUBLE_TYPE_SIZE 64
@@ -1743,6 +1747,13 @@ do {							\
    between pointers and any other objects of this machine mode.  */
 #define Pmode (TARGET_64BIT ? DImode : SImode)
 
+/* A C expression whose value is zero if pointers that need to be extended
+   from being `POINTER_SIZE' bits wide to `Pmode' are sign-extended and
+   greater then zero if they are zero-extended and less then zero if the
+   ptr_extend instruction should be used.  */
+
+#define POINTERS_EXTEND_UNSIGNED 1
+
 /* A function address in a call instruction
    is a byte address (for indexing purposes)
    so give the MEM rtx a byte's mode.  */
diff --git a/gcc/config/i386/i386.opt b/gcc/config/i386/i386.opt
index 21e0def..2c8fe8f 100644
--- a/gcc/config/i386/i386.opt
+++ b/gcc/config/i386/i386.opt
@@ -398,9 +398,13 @@ Target RejectNegative Negative(m64) Report InverseMask(ISA_64BIT) Var(ix86_isa_f
 Generate 32bit i386 code
 
 m64
-Target RejectNegative Negative(m32) Report Mask(ISA_64BIT) Var(ix86_isa_flags) Save
+Target RejectNegative Negative(mx32) Report Mask(ISA_64BIT) Var(ix86_isa_flags) Save
 Generate 64bit x86-64 code
 
+mx32
+Target RejectNegative Negative(m32) Report Mask(ISA_X32) Var(ix86_isa_flags) Save
+Generate 32bit x86-64 code
+
 mmmx
 Target Report Mask(ISA_MMX) Var(ix86_isa_flags) Save
 Support MMX built-in functions
diff --git a/gcc/config/i386/kfreebsd-gnu64.h b/gcc/config/i386/kfreebsd-gnu64.h
index c3798a5..2085ca5 100644
--- a/gcc/config/i386/kfreebsd-gnu64.h
+++ b/gcc/config/i386/kfreebsd-gnu64.h
@@ -21,6 +21,8 @@ along with GCC; see the file COPYING3.  If not see
 
 #define GNU_USER_LINK_EMULATION32 "elf_i386_fbsd"
 #define GNU_USER_LINK_EMULATION64 "elf_x86_64_fbsd"
+#define GNU_USER_LINK_EMULATIONX32 "elf32_x86_64_fbsd"
 
 #define GLIBC_DYNAMIC_LINKER32 "/lib/ld.so.1"
 #define GLIBC_DYNAMIC_LINKER64 "/lib/ld-kfreebsd-x86-64.so.1"
+#define GLIBC_DYNAMIC_LINKERX32 "/lib/ld-kfreebsd-x32.so.1"
diff --git a/gcc/config/i386/linux64.h b/gcc/config/i386/linux64.h
index 5d33224..5b0a212 100644
--- a/gcc/config/i386/linux64.h
+++ b/gcc/config/i386/linux64.h
@@ -26,6 +26,8 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 
 #define GNU_USER_LINK_EMULATION32 "elf_i386"
 #define GNU_USER_LINK_EMULATION64 "elf_x86_64"
+#define GNU_USER_LINK_EMULATIONX32 "elf32_x86_64"
 
 #define GLIBC_DYNAMIC_LINKER32 "/lib/ld-linux.so.2"
 #define GLIBC_DYNAMIC_LINKER64 "/lib64/ld-linux-x86-64.so.2"
+#define GLIBC_DYNAMIC_LINKERX32 "/libx32/ld-linux-x32.so.2"
diff --git a/gcc/config/i386/t-linux-x32 b/gcc/config/i386/t-linux-x32
new file mode 100644
index 0000000..92acf91
--- /dev/null
+++ b/gcc/config/i386/t-linux-x32
@@ -0,0 +1,42 @@
+# Copyright (C) 2011 Free Software Foundation, Inc.
+#
+# This file is part of GCC.
+#
+# GCC is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GCC is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GCC; see the file COPYING3.  If not see
+# <http://www.gnu.org/licenses/>.
+
+# On Debian, Ubuntu and other derivative distributions, the 32bit libraries
+# are found in /lib32 and /usr/lib32, /lib64 and /usr/lib64 are symlinks to
+# /lib and /usr/lib, while other distributions install libraries into /lib64
+# and /usr/lib64.  The LSB does not enforce the use of /lib64 and /usr/lib64,
+# it doesn't tell anything about the 32bit libraries on those systems.  Set
+# MULTILIB_OSDIRNAMES according to what is found on the target.
+
+# To support i386, x86-64 and x32 libraries, the directory structrue
+# should be:
+#
+# 	/lib has i386 libraries.
+# 	/lib64 has x86-64 libraries.
+# 	/libx32 has x32 libraries.
+#
+MULTILIB_OPTIONS = m64/m32/mx32
+MULTILIB_DIRNAMES = 64 32 x32
+MULTILIB_OSDIRNAMES = ../lib64 $(if $(wildcard $(shell echo $(SYSTEM_HEADER_DIR))/../../usr/lib32),../lib32,../lib) ../libx32
+
+LIBGCC = stmp-multilib
+INSTALL_LIBGCC = install-multilib
+
+EXTRA_MULTILIB_PARTS=crtbegin.o crtend.o crtbeginS.o crtendS.o \
+		     crtbeginT.o crtprec32.o crtprec64.o crtprec80.o \
+		     crtfastmath.o
diff --git a/gcc/config/i386/t-linux64-x32 b/gcc/config/i386/t-linux64-x32
new file mode 100644
index 0000000..3a4d1de
--- /dev/null
+++ b/gcc/config/i386/t-linux64-x32
@@ -0,0 +1,34 @@
+# Copyright (C) 2011 Free Software Foundation, Inc.
+#
+# This file is part of GCC.
+#
+# GCC is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GCC is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GCC; see the file COPYING3.  If not see
+# <http://www.gnu.org/licenses/>.
+
+# To support x86-64 and x32 libraries, the directory structrue
+# should be:
+#
+# 	/lib64 has x86-64 libraries.
+# 	/libx32 has x32 libraries.
+#
+MULTILIB_OPTIONS = m64/mx32
+MULTILIB_DIRNAMES = 64 x32
+MULTILIB_OSDIRNAMES = ../lib64 ../libx32
+
+LIBGCC = stmp-multilib
+INSTALL_LIBGCC = install-multilib
+
+EXTRA_MULTILIB_PARTS=crtbegin.o crtend.o crtbeginS.o crtendS.o \
+		     crtbeginT.o crtprec32.o crtprec64.o crtprec80.o \
+		     crtfastmath.o
diff --git a/gcc/config/linux.h b/gcc/config/linux.h
index fc897b1..dbbeea5 100644
--- a/gcc/config/linux.h
+++ b/gcc/config/linux.h
@@ -77,9 +77,11 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #define UCLIBC_DYNAMIC_LINKER "/lib/ld-uClibc.so.0"
 #define UCLIBC_DYNAMIC_LINKER32 "/lib/ld-uClibc.so.0"
 #define UCLIBC_DYNAMIC_LINKER64 "/lib/ld64-uClibc.so.0"
+#define UCLIBC_DYNAMIC_LINKERX32 "/lib/ldx32-uClibc.so.0"
 #define BIONIC_DYNAMIC_LINKER "/system/bin/linker"
 #define BIONIC_DYNAMIC_LINKER32 "/system/bin/linker"
 #define BIONIC_DYNAMIC_LINKER64 "/system/bin/linker64"
+#define BIONIC_DYNAMIC_LINKERX32 "/system/bin/linkerx32"
 
 #define GNU_USER_DYNAMIC_LINKER						\
   CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER, UCLIBC_DYNAMIC_LINKER,	\
@@ -90,6 +92,9 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #define GNU_USER_DYNAMIC_LINKER64					\
   CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER64, UCLIBC_DYNAMIC_LINKER64, \
 			 BIONIC_DYNAMIC_LINKER64)
+#define GNU_USER_DYNAMIC_LINKERX32					\
+  CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKERX32, UCLIBC_DYNAMIC_LINKERX32, \
+			 BIONIC_DYNAMIC_LINKERX32)
 
 /* Determine whether the entire c99 runtime
    is present in the runtime library.  */
diff --git a/gcc/configure.ac b/gcc/configure.ac
index 70b3dbc..4713264 100644
--- a/gcc/configure.ac
+++ b/gcc/configure.ac
@@ -611,6 +611,16 @@ AC_ARG_ENABLE(multilib,
 [], [enable_multilib=yes])
 AC_SUBST(enable_multilib)
 
+# With x32 support
+AC_ARG_ENABLE(x32,
+[  --enable-x32            enable x32 library support for multiple ABIs],
+[], [enable_x32=no])
+
+# With ia32 support
+AC_ARG_ENABLE(ia32,
+[  --enable-ia32           enable ia32 library support for multiple ABIs],
+[], [enable_ia32=yes])
+
 # Enable __cxa_atexit for C++.
 AC_ARG_ENABLE(__cxa_atexit,
 [AS_HELP_STRING([--enable-__cxa_atexit], [enable __cxa_atexit for C++])],
diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi
index 7ebcd92..f63094c 100644
--- a/gcc/doc/install.texi
+++ b/gcc/doc/install.texi
@@ -1155,6 +1155,16 @@ assumptions made by the configure test are incorrect.
 Specify that the target does not support TLS.
 This is an alias for @option{--enable-tls=no}.
 
+@item --enable-ia32
+This option enables ia32 library support for multiple ABIs.  By
+default, ia32 library support is enabled.  It is only supported for
+x86-64.
+
+@item --enable-x32
+This option enables x32 library support for multiple ABIs. By
+default, x32 library support is disabled.  It is only supported for
+x86-64.
+
 @item --with-cpu=@var{cpu}
 @itemx --with-cpu-32=@var{cpu}
 @itemx --with-cpu-64=@var{cpu}
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index e747f1d..a111236 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -610,7 +610,7 @@ Objective-C and Objective-C++ Dialects}.
 -mpc32 -mpc64 -mpc80 -mstackrealign @gol
 -momit-leaf-frame-pointer  -mno-red-zone -mno-tls-direct-seg-refs @gol
 -mcmodel=@var{code-model} -mabi=@var{name} @gol
--m32  -m64 -mlarge-data-threshold=@var{num} @gol
+-m32 -m64 -mx32 -mlarge-data-threshold=@var{num} @gol
 -msse2avx -mfentry -m8bit-idiv @gol
 -mavx256-split-unaligned-load -mavx256-split-unaligned-store}
 
@@ -12837,15 +12837,19 @@ on AMD x86-64 processors in 64-bit environments.
 @table @gcctabopt
 @item -m32
 @itemx -m64
+@itemx -mx32
 @opindex m32
 @opindex m64
+@opindex mx32
 Generate code for a 32-bit or 64-bit environment.
-The 32-bit environment sets int, long and pointer to 32 bits and
+The @option{-m32} option sets int, long and pointer to 32 bits and
 generates code that runs on any i386 system.
-The 64-bit environment sets int to 32 bits and long and pointer
-to 64 bits and generates code for AMD's x86-64 architecture. For
-darwin only the -m64 option turns off the @option{-fno-pic} and
-@option{-mdynamic-no-pic} options.
+The @option{-m64} option sets int to 32 bits and long and pointer
+to 64 bits and generates code for AMD's x86-64 architecture.
+The @option{-mx32} option sets int, long and pointer to 32 bits and
+generates code for AMD's x86-64 architecture.
+For darwin only the @option{-m64} option turns off the @option{-fno-pic}
+and @option{-mdynamic-no-pic} options.
 
 @item -mno-red-zone
 @opindex mno-red-zone

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: PATCH [1/n] X32: Add initial -x32 support
  2011-07-05 14:42 ` PATCH [1/n] X32: " H.J. Lu
@ 2011-07-05 15:21   ` Uros Bizjak
  2011-07-05 17:59     ` H.J. Lu
  0 siblings, 1 reply; 26+ messages in thread
From: Uros Bizjak @ 2011-07-05 15:21 UTC (permalink / raw)
  To: H.J. Lu; +Cc: gcc-patches

On Tue, Jul 5, 2011 at 4:39 PM, H.J. Lu <hongjiu.lu@intel.com> wrote:

> I'd like to start submitting a series of patches to enable x32:
>
> https://sites.google.com/site/x32abi/
>
> The GCC x32 branch is very stable. There are no unexpected failures in
> C, C++, Fortran and Objective C testsuites.  SPEC CPU 2K/2006 compile
> and run correctly at -O2 and -O3.
>
> More than 90% of changes are in x86 backend.  I have submitted non-x86
> backend patches.  Most of them have been reviewed and checked in.  Only
> 4 patches are pending for review/approval.
>
> This is the first x86 backend patch to support x32.  By default, x32 is
> disabled and x32 run-time support isn't required.  OK for trunk?

Please strip out --enable-ia32 stuff, it complicates things ATM.  I
assume that --enable-x32 applies only to 64bit targets, so this part

> @@ -1232,7 +1232,17 @@ i[34567]86-*-linux* | i[34567]86-*-kfreebsd*-gnu | i[34567]86-*-knetbsd*-gnu | i
>                if test x$enable_targets = xall; then
>                        tm_file="${tm_file} i386/x86-64.h i386/gnu-user64.h i386/linux64.h"
>                        tm_defines="${tm_defines} TARGET_BI_ARCH=1"
> -                       tmake_file="${tmake_file} i386/t-linux64"
> +                       case x${enable_x32}${enable_ia32} in
> +                       xyesyes)
> +                               tmake_file="${tmake_file} i386/t-linux-x32"
> +                               ;;
> +                       xyesno)
> +                               tmake_file="${tmake_file} i386/t-linux64-x32"
> +                               ;;
> +                       *)
> +                               tmake_file="${tmake_file} i386/t-linux64"
> +                               ;;
> +                       esac

should be simplified to something:

if (enable_x32)
  tmake_file = "... i386/t-linux64-x32"
else
  tmake_file = "... i386/t-linux64"



> diff --git a/gcc/config/i386/gnu-user64.h b/gcc/config/i386/gnu-user64.h
> index b069975..954f3b2 100644
> --- a/gcc/config/i386/gnu-user64.h
> +++ b/gcc/config/i386/gnu-user64.h
> @@ -58,25 +58,31 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
>
>  #if TARGET_64BIT_DEFAULT
>  #define SPEC_32 "m32"
> -#define SPEC_64 "!m32"
> +#define SPEC_64 "m32|mx32:;"
> +#define SPEC_X32 "mx32"
>  #else
> -#define SPEC_32 "!m64"
> +#define SPEC_32 "m64|mx32:;"
>  #define SPEC_64 "m64"
> +#define SPEC_X32 "mx32"
>  #endif
>
>  #undef ASM_SPEC
> -#define ASM_SPEC "%{" SPEC_32 ":--32} %{" SPEC_64 ":--64} \
> +#define ASM_SPEC "%{" SPEC_32 ":--32} \
> + %{" SPEC_64 ":--64} \
> + %{" SPEC_X32 ":--x32} \
>  %{!mno-sse2avx:%{mavx:-msse2avx}} %{msse2avx:%{!mavx:-msse2avx}}"

Are you sure that above is correct? AFAICS, you are enabling SPEC_64
for m32 in case of TARGET_64BIT_DEFAULT.

>  /* SSE4.1 defines round instructions */
>  #define        OPTION_MASK_ISA_ROUND   OPTION_MASK_ISA_SSE4_1
> @@ -517,8 +519,8 @@ extern const char *host_detect_local_cpu (int argc, const char **argv);
>  #define OPT_ARCH64 "!m32"
>  #define OPT_ARCH32 "m32"
>  #else
> -#define OPT_ARCH64 "m64"
> -#define OPT_ARCH32 "!m64"
> +#define OPT_ARCH64 "m64|mx32"
> +#define OPT_ARCH32 "m64|mx32:;"
>  #endif

Same here.

Uros.

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: PATCH [1/n] X32: Add initial -x32 support
  2011-07-05 15:21   ` Uros Bizjak
@ 2011-07-05 17:59     ` H.J. Lu
  2011-07-05 18:18       ` Uros Bizjak
  0 siblings, 1 reply; 26+ messages in thread
From: H.J. Lu @ 2011-07-05 17:59 UTC (permalink / raw)
  To: Uros Bizjak; +Cc: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 4875 bytes --]

On Tue, Jul 5, 2011 at 8:16 AM, Uros Bizjak <ubizjak@gmail.com> wrote:
> On Tue, Jul 5, 2011 at 4:39 PM, H.J. Lu <hongjiu.lu@intel.com> wrote:
>
>> I'd like to start submitting a series of patches to enable x32:
>>
>> https://sites.google.com/site/x32abi/
>>
>> The GCC x32 branch is very stable. There are no unexpected failures in
>> C, C++, Fortran and Objective C testsuites.  SPEC CPU 2K/2006 compile
>> and run correctly at -O2 and -O3.
>>
>> More than 90% of changes are in x86 backend.  I have submitted non-x86
>> backend patches.  Most of them have been reviewed and checked in.  Only
>> 4 patches are pending for review/approval.
>>
>> This is the first x86 backend patch to support x32.  By default, x32 is
>> disabled and x32 run-time support isn't required.  OK for trunk?
>
> Please strip out --enable-ia32 stuff, it complicates things ATM.  I
> assume that --enable-x32 applies only to 64bit targets, so this part

Done.

>> @@ -1232,7 +1232,17 @@ i[34567]86-*-linux* | i[34567]86-*-kfreebsd*-gnu | i[34567]86-*-knetbsd*-gnu | i
>>                if test x$enable_targets = xall; then
>>                        tm_file="${tm_file} i386/x86-64.h i386/gnu-user64.h i386/linux64.h"
>>                        tm_defines="${tm_defines} TARGET_BI_ARCH=1"
>> -                       tmake_file="${tmake_file} i386/t-linux64"
>> +                       case x${enable_x32}${enable_ia32} in
>> +                       xyesyes)
>> +                               tmake_file="${tmake_file} i386/t-linux-x32"
>> +                               ;;
>> +                       xyesno)
>> +                               tmake_file="${tmake_file} i386/t-linux64-x32"
>> +                               ;;
>> +                       *)
>> +                               tmake_file="${tmake_file} i386/t-linux64"
>> +                               ;;
>> +                       esac
>
> should be simplified to something:
>
> if (enable_x32)
>  tmake_file = "... i386/t-linux64-x32"
> else
>  tmake_file = "... i386/t-linux64"

Done.

>
>
>> diff --git a/gcc/config/i386/gnu-user64.h b/gcc/config/i386/gnu-user64.h
>> index b069975..954f3b2 100644
>> --- a/gcc/config/i386/gnu-user64.h
>> +++ b/gcc/config/i386/gnu-user64.h
>> @@ -58,25 +58,31 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
>>
>>  #if TARGET_64BIT_DEFAULT
>>  #define SPEC_32 "m32"
>> -#define SPEC_64 "!m32"
>> +#define SPEC_64 "m32|mx32:;"
>> +#define SPEC_X32 "mx32"
>>  #else
>> -#define SPEC_32 "!m64"
>> +#define SPEC_32 "m64|mx32:;"
>>  #define SPEC_64 "m64"
>> +#define SPEC_X32 "mx32"
>>  #endif
>>
>>  #undef ASM_SPEC
>> -#define ASM_SPEC "%{" SPEC_32 ":--32} %{" SPEC_64 ":--64} \
>> +#define ASM_SPEC "%{" SPEC_32 ":--32} \
>> + %{" SPEC_64 ":--64} \
>> + %{" SPEC_X32 ":--x32} \
>>  %{!mno-sse2avx:%{mavx:-msse2avx}} %{msse2avx:%{!mavx:-msse2avx}}"
>
> Are you sure that above is correct? AFAICS, you are enabling SPEC_64
> for m32 in case of TARGET_64BIT_DEFAULT.

I have

#define SPEC_64 "m32|mx32:;"

There are ":;".  This is similar to "if then else".  SPEC_64 will be
false if -m32 or
-mx32 is used.

>>  /* SSE4.1 defines round instructions */
>>  #define        OPTION_MASK_ISA_ROUND   OPTION_MASK_ISA_SSE4_1
>> @@ -517,8 +519,8 @@ extern const char *host_detect_local_cpu (int argc, const char **argv);
>>  #define OPT_ARCH64 "!m32"
>>  #define OPT_ARCH32 "m32"
>>  #else
>> -#define OPT_ARCH64 "m64"
>> -#define OPT_ARCH32 "!m64"
>> +#define OPT_ARCH64 "m64|mx32"
>> +#define OPT_ARCH32 "m64|mx32:;"
>>  #endif
>
> Same here.
>

See above.

Here is the updated patch.  OK for trunk?

Thanks.

-- 
H.J.
---
2011-07-05  H.J. Lu  <hongjiu.lu@intel.com>

	* config.gcc: Support --enable-x32 for x86 Linux
	targets.

	* configure.ac: Support --enable-x32.
	* configure: Regenerated.

	* config/i386/gnu-user64.h (SPEC_64): Support x32.
	(SPEC_32): Likewise.
	(ASM_SPEC): Likewise.
	(LINK_SPEC): Likewise.
	(TARGET_THREAD_SSP_OFFSET): Likewise.
	(TARGET_THREAD_SPLIT_STACK_OFFSET): Likewise.
	(SPEC_X32): New.

	* config/i386/i386.h (TARGET_X32): New.
	(TARGET_LP64): New.
	(LONG_TYPE_SIZE): Likewise.
	(POINTER_SIZE): Likewise.
	(POINTERS_EXTEND_UNSIGNED): Likewise.
	(OPT_ARCH64): Support x32.
	(OPT_ARCH32): Likewise.

	* config/i386/i386.opt (mx32): New.

	* config/i386/kfreebsd-gnu64.h (GNU_USER_LINK_EMULATIONX32): New.
	(GLIBC_DYNAMIC_LINKERX32): Likewise.
	* config/i386/linux64.h (GNU_USER_LINK_EMULATIONX32): Likewise.
	(GLIBC_DYNAMIC_LINKERX32): Likewise.

	* config/i386/t-linux-x32: New.

	* config/linux.h (UCLIBC_DYNAMIC_LINKERX32): New.
	(BIONIC_DYNAMIC_LINKERX32): Likewise.
	(GNU_USER_DYNAMIC_LINKERX32): Likewise.

	* doc/install.texi: Document --enable-x32.

	* doc/invoke.texi: Document -mx32.

[-- Attachment #2: gcc-x32-3.patch --]
[-- Type: text/plain, Size: 14611 bytes --]

2011-07-05  H.J. Lu  <hongjiu.lu@intel.com>

	* config.gcc: Support --enable-x32 for x86 Linux
	targets.

	* configure.ac: Support --enable-x32.
	* configure: Regenerated.

	* config/i386/gnu-user64.h (SPEC_64): Support x32.
	(SPEC_32): Likewise.
	(ASM_SPEC): Likewise.
	(LINK_SPEC): Likewise.
	(TARGET_THREAD_SSP_OFFSET): Likewise.
	(TARGET_THREAD_SPLIT_STACK_OFFSET): Likewise.
	(SPEC_X32): New.

	* config/i386/i386.h (TARGET_X32): New.
	(TARGET_LP64): New.
	(LONG_TYPE_SIZE): Likewise.
	(POINTER_SIZE): Likewise.
	(POINTERS_EXTEND_UNSIGNED): Likewise.
	(OPT_ARCH64): Support x32.
	(OPT_ARCH32): Likewise.

	* config/i386/i386.opt (mx32): New.

	* config/i386/kfreebsd-gnu64.h (GNU_USER_LINK_EMULATIONX32): New.
	(GLIBC_DYNAMIC_LINKERX32): Likewise.
	* config/i386/linux64.h (GNU_USER_LINK_EMULATIONX32): Likewise.
	(GLIBC_DYNAMIC_LINKERX32): Likewise.

	* config/i386/t-linux-x32: New.

	* config/linux.h (UCLIBC_DYNAMIC_LINKERX32): New.
	(BIONIC_DYNAMIC_LINKERX32): Likewise.
	(GNU_USER_DYNAMIC_LINKERX32): Likewise.

	* doc/install.texi: Document --enable-x32.

	* doc/invoke.texi: Document -mx32.

diff --git a/gcc/config.gcc b/gcc/config.gcc
index c77f40b..4787d6b 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -1279,7 +1279,11 @@ i[34567]86-*-linux* | i[34567]86-*-kfreebsd*-gnu | i[34567]86-*-knetbsd*-gnu | i
 		if test x$enable_targets = xall; then
 			tm_file="${tm_file} i386/x86-64.h i386/gnu-user64.h i386/linux64.h"
 			tm_defines="${tm_defines} TARGET_BI_ARCH=1"
-			tmake_file="${tmake_file} i386/t-linux64"
+			if test x${enable_x32} = xyes; then
+				tmake_file="${tmake_file} i386/t-linux-x32"
+			else
+				tmake_file="${tmake_file} i386/t-linux64"
+			fi
 			need_64bit_hwint=yes
 			need_64bit_isa=yes
 			case X"${with_cpu}" in
@@ -1317,7 +1321,12 @@ x86_64-*-linux* | x86_64-*-kfreebsd*-gnu | x86_64-*-knetbsd*-gnu)
 	x86_64-*-kfreebsd*-gnu) tm_file="${tm_file} kfreebsd-gnu.h i386/kfreebsd-gnu64.h" ;;
 	x86_64-*-knetbsd*-gnu) tm_file="${tm_file} knetbsd-gnu.h" ;;
 	esac
-	tmake_file="${tmake_file} i386/t-linux64 i386/t-crtstuff i386/t-crtpc i386/t-crtfm t-dfprules"
+	if test x${enable_x32} = xyes; then
+		tmake_file="${tmake_file} i386/t-linux-x32"
+	else
+		tmake_file="${tmake_file} i386/t-linux64"
+	fi
+	tmake_file="${tmake_file} i386/t-crtstuff i386/t-crtpc i386/t-crtfm t-dfprules"
 	;;
 i[34567]86-pc-msdosdjgpp*)
 	xm_file=i386/xm-djgpp.h
@@ -2631,6 +2640,7 @@ esac
 case ${target} in
 i[34567]86-*-linux* | x86_64-*-linux*)
 	tmake_file="${tmake_file} i386/t-pmm_malloc i386/t-i386"
+	libgcc_tm_file="${libgcc_tm_file} i386/value-unwind.h"
 	;;
 i[34567]86-*-* | x86_64-*-*)
 	tmake_file="${tmake_file} i386/t-gmm_malloc i386/t-i386"
diff --git a/gcc/config/i386/gnu-user64.h b/gcc/config/i386/gnu-user64.h
index b069975..954f3b2 100644
--- a/gcc/config/i386/gnu-user64.h
+++ b/gcc/config/i386/gnu-user64.h
@@ -58,25 +58,31 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 
 #if TARGET_64BIT_DEFAULT
 #define SPEC_32 "m32"
-#define SPEC_64 "!m32"
+#define SPEC_64 "m32|mx32:;"
+#define SPEC_X32 "mx32"
 #else
-#define SPEC_32 "!m64"
+#define SPEC_32 "m64|mx32:;"
 #define SPEC_64 "m64"
+#define SPEC_X32 "mx32"
 #endif
 
 #undef ASM_SPEC
-#define ASM_SPEC "%{" SPEC_32 ":--32} %{" SPEC_64 ":--64} \
+#define ASM_SPEC "%{" SPEC_32 ":--32} \
+ %{" SPEC_64 ":--64} \
+ %{" SPEC_X32 ":--x32} \
  %{!mno-sse2avx:%{mavx:-msse2avx}} %{msse2avx:%{!mavx:-msse2avx}}"
 
 #undef	LINK_SPEC
 #define LINK_SPEC "%{" SPEC_64 ":-m " GNU_USER_LINK_EMULATION64 "} \
                    %{" SPEC_32 ":-m " GNU_USER_LINK_EMULATION32 "} \
+                   %{" SPEC_X32 ":-m " GNU_USER_LINK_EMULATIONX32 "} \
   %{shared:-shared} \
   %{!shared: \
     %{!static: \
       %{rdynamic:-export-dynamic} \
       %{" SPEC_32 ":-dynamic-linker " GNU_USER_DYNAMIC_LINKER32 "} \
-      %{" SPEC_64 ":-dynamic-linker " GNU_USER_DYNAMIC_LINKER64 "}} \
+      %{" SPEC_64 ":-dynamic-linker " GNU_USER_DYNAMIC_LINKER64 "} \
+      %{" SPEC_X32 ":-dynamic-linker " GNU_USER_DYNAMIC_LINKERX32 "}} \
     %{static:-static}}"
 
 /* Similar to standard GNU userspace, but adding -ffast-math support.  */
@@ -110,10 +116,13 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 
 #ifdef TARGET_LIBC_PROVIDES_SSP
 /* i386 glibc provides __stack_chk_guard in %gs:0x14,
+   x32 glibc provides it in %fs:0x18. 
    x86_64 glibc provides it in %fs:0x28.  */
-#define TARGET_THREAD_SSP_OFFSET	(TARGET_64BIT ? 0x28 : 0x14)
+#define TARGET_THREAD_SSP_OFFSET \
+  (TARGET_64BIT ? (TARGET_X32 ? 0x18 : 0x28) : 0x14)
 
 /* We steal the last transactional memory word.  */
 #define TARGET_CAN_SPLIT_STACK
-#define TARGET_THREAD_SPLIT_STACK_OFFSET (TARGET_64BIT ? 0x70 : 0x30)
+#define TARGET_THREAD_SPLIT_STACK_OFFSET \
+  (TARGET_64BIT ? (TARGET_X32 ? 0x40 : 0x70) : 0x30)
 #endif
diff --git a/gcc/config/i386/i386.h b/gcc/config/i386/i386.h
index a1ac6b6..8cef4e7 100644
--- a/gcc/config/i386/i386.h
+++ b/gcc/config/i386/i386.h
@@ -42,6 +42,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 /* Redefines for option macros.  */
 
 #define TARGET_64BIT	OPTION_ISA_64BIT
+#define TARGET_X32	OPTION_ISA_X32
 #define TARGET_MMX	OPTION_ISA_MMX
 #define TARGET_3DNOW	OPTION_ISA_3DNOW
 #define TARGET_3DNOW_A	OPTION_ISA_3DNOW_A
@@ -72,6 +73,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #define TARGET_RDRND	OPTION_ISA_RDRND
 #define TARGET_F16C	OPTION_ISA_F16C
 
+#define TARGET_LP64	(TARGET_64BIT && !TARGET_X32)
 
 /* SSE4.1 defines round instructions */
 #define	OPTION_MASK_ISA_ROUND	OPTION_MASK_ISA_SSE4_1
@@ -516,8 +518,8 @@ extern const char *host_detect_local_cpu (int argc, const char **argv);
 #define OPT_ARCH64 "!m32"
 #define OPT_ARCH32 "m32"
 #else
-#define OPT_ARCH64 "m64"
-#define OPT_ARCH32 "!m64"
+#define OPT_ARCH64 "m64|mx32"
+#define OPT_ARCH32 "m64|mx32:;"
 #endif
 
 /* Support for configure-time defaults of some command line options.
@@ -637,6 +639,8 @@ enum target_cpu_default
 
 #define SHORT_TYPE_SIZE 16
 #define INT_TYPE_SIZE 32
+#define LONG_TYPE_SIZE (TARGET_X32 ? 32 : BITS_PER_WORD)
+#define POINTER_SIZE (TARGET_X32 ? 32 : BITS_PER_WORD)
 #define LONG_LONG_TYPE_SIZE 64
 #define FLOAT_TYPE_SIZE 32
 #define DOUBLE_TYPE_SIZE 64
@@ -1742,6 +1746,13 @@ do {							\
    between pointers and any other objects of this machine mode.  */
 #define Pmode (TARGET_64BIT ? DImode : SImode)
 
+/* A C expression whose value is zero if pointers that need to be extended
+   from being `POINTER_SIZE' bits wide to `Pmode' are sign-extended and
+   greater then zero if they are zero-extended and less then zero if the
+   ptr_extend instruction should be used.  */
+
+#define POINTERS_EXTEND_UNSIGNED 1
+
 /* A function address in a call instruction
    is a byte address (for indexing purposes)
    so give the MEM rtx a byte's mode.  */
diff --git a/gcc/config/i386/i386.opt b/gcc/config/i386/i386.opt
index 9886b7b..8dea93e 100644
--- a/gcc/config/i386/i386.opt
+++ b/gcc/config/i386/i386.opt
@@ -398,9 +398,13 @@ Target RejectNegative Negative(m64) Report InverseMask(ISA_64BIT) Var(ix86_isa_f
 Generate 32bit i386 code
 
 m64
-Target RejectNegative Negative(m32) Report Mask(ISA_64BIT) Var(ix86_isa_flags) Save
+Target RejectNegative Negative(mx32) Report Mask(ISA_64BIT) Var(ix86_isa_flags) Save
 Generate 64bit x86-64 code
 
+mx32
+Target RejectNegative Negative(m32) Report Mask(ISA_X32) Var(ix86_isa_flags) Save
+Generate 32bit x86-64 code
+
 mmmx
 Target Report Mask(ISA_MMX) Var(ix86_isa_flags) Save
 Support MMX built-in functions
diff --git a/gcc/config/i386/kfreebsd-gnu64.h b/gcc/config/i386/kfreebsd-gnu64.h
index c3798a5..2085ca5 100644
--- a/gcc/config/i386/kfreebsd-gnu64.h
+++ b/gcc/config/i386/kfreebsd-gnu64.h
@@ -21,6 +21,8 @@ along with GCC; see the file COPYING3.  If not see
 
 #define GNU_USER_LINK_EMULATION32 "elf_i386_fbsd"
 #define GNU_USER_LINK_EMULATION64 "elf_x86_64_fbsd"
+#define GNU_USER_LINK_EMULATIONX32 "elf32_x86_64_fbsd"
 
 #define GLIBC_DYNAMIC_LINKER32 "/lib/ld.so.1"
 #define GLIBC_DYNAMIC_LINKER64 "/lib/ld-kfreebsd-x86-64.so.1"
+#define GLIBC_DYNAMIC_LINKERX32 "/lib/ld-kfreebsd-x32.so.1"
diff --git a/gcc/config/i386/linux64.h b/gcc/config/i386/linux64.h
index 5d33224..5b0a212 100644
--- a/gcc/config/i386/linux64.h
+++ b/gcc/config/i386/linux64.h
@@ -26,6 +26,8 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 
 #define GNU_USER_LINK_EMULATION32 "elf_i386"
 #define GNU_USER_LINK_EMULATION64 "elf_x86_64"
+#define GNU_USER_LINK_EMULATIONX32 "elf32_x86_64"
 
 #define GLIBC_DYNAMIC_LINKER32 "/lib/ld-linux.so.2"
 #define GLIBC_DYNAMIC_LINKER64 "/lib64/ld-linux-x86-64.so.2"
+#define GLIBC_DYNAMIC_LINKERX32 "/libx32/ld-linux-x32.so.2"
diff --git a/gcc/config/i386/t-linux-x32 b/gcc/config/i386/t-linux-x32
new file mode 100644
index 0000000..92acf91
--- /dev/null
+++ b/gcc/config/i386/t-linux-x32
@@ -0,0 +1,42 @@
+# Copyright (C) 2011 Free Software Foundation, Inc.
+#
+# This file is part of GCC.
+#
+# GCC is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GCC is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GCC; see the file COPYING3.  If not see
+# <http://www.gnu.org/licenses/>.
+
+# On Debian, Ubuntu and other derivative distributions, the 32bit libraries
+# are found in /lib32 and /usr/lib32, /lib64 and /usr/lib64 are symlinks to
+# /lib and /usr/lib, while other distributions install libraries into /lib64
+# and /usr/lib64.  The LSB does not enforce the use of /lib64 and /usr/lib64,
+# it doesn't tell anything about the 32bit libraries on those systems.  Set
+# MULTILIB_OSDIRNAMES according to what is found on the target.
+
+# To support i386, x86-64 and x32 libraries, the directory structrue
+# should be:
+#
+# 	/lib has i386 libraries.
+# 	/lib64 has x86-64 libraries.
+# 	/libx32 has x32 libraries.
+#
+MULTILIB_OPTIONS = m64/m32/mx32
+MULTILIB_DIRNAMES = 64 32 x32
+MULTILIB_OSDIRNAMES = ../lib64 $(if $(wildcard $(shell echo $(SYSTEM_HEADER_DIR))/../../usr/lib32),../lib32,../lib) ../libx32
+
+LIBGCC = stmp-multilib
+INSTALL_LIBGCC = install-multilib
+
+EXTRA_MULTILIB_PARTS=crtbegin.o crtend.o crtbeginS.o crtendS.o \
+		     crtbeginT.o crtprec32.o crtprec64.o crtprec80.o \
+		     crtfastmath.o
diff --git a/gcc/config/linux.h b/gcc/config/linux.h
index fc897b1..dbbeea5 100644
--- a/gcc/config/linux.h
+++ b/gcc/config/linux.h
@@ -77,9 +77,11 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #define UCLIBC_DYNAMIC_LINKER "/lib/ld-uClibc.so.0"
 #define UCLIBC_DYNAMIC_LINKER32 "/lib/ld-uClibc.so.0"
 #define UCLIBC_DYNAMIC_LINKER64 "/lib/ld64-uClibc.so.0"
+#define UCLIBC_DYNAMIC_LINKERX32 "/lib/ldx32-uClibc.so.0"
 #define BIONIC_DYNAMIC_LINKER "/system/bin/linker"
 #define BIONIC_DYNAMIC_LINKER32 "/system/bin/linker"
 #define BIONIC_DYNAMIC_LINKER64 "/system/bin/linker64"
+#define BIONIC_DYNAMIC_LINKERX32 "/system/bin/linkerx32"
 
 #define GNU_USER_DYNAMIC_LINKER						\
   CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER, UCLIBC_DYNAMIC_LINKER,	\
@@ -90,6 +92,9 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #define GNU_USER_DYNAMIC_LINKER64					\
   CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER64, UCLIBC_DYNAMIC_LINKER64, \
 			 BIONIC_DYNAMIC_LINKER64)
+#define GNU_USER_DYNAMIC_LINKERX32					\
+  CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKERX32, UCLIBC_DYNAMIC_LINKERX32, \
+			 BIONIC_DYNAMIC_LINKERX32)
 
 /* Determine whether the entire c99 runtime
    is present in the runtime library.  */
diff --git a/gcc/configure.ac b/gcc/configure.ac
index 5f3641b..bddabeb 100644
--- a/gcc/configure.ac
+++ b/gcc/configure.ac
@@ -611,6 +611,11 @@ AC_ARG_ENABLE(multilib,
 [], [enable_multilib=yes])
 AC_SUBST(enable_multilib)
 
+# With x32 support
+AC_ARG_ENABLE(x32,
+[  --enable-x32            enable x32 library support for multiple ABIs],
+[], [enable_x32=no])
+
 # Enable __cxa_atexit for C++.
 AC_ARG_ENABLE(__cxa_atexit,
 [AS_HELP_STRING([--enable-__cxa_atexit], [enable __cxa_atexit for C++])],
diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi
index 49aac95..e89c396 100644
--- a/gcc/doc/install.texi
+++ b/gcc/doc/install.texi
@@ -1161,6 +1161,11 @@ assumptions made by the configure test are incorrect.
 Specify that the target does not support TLS.
 This is an alias for @option{--enable-tls=no}.
 
+@item --enable-x32
+This option enables x32 library support for multiple ABIs. By
+default, x32 library support is disabled.  It is only supported for
+x86-64.
+
 @item --with-cpu=@var{cpu}
 @itemx --with-cpu-32=@var{cpu}
 @itemx --with-cpu-64=@var{cpu}
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 1fc4038..fd6711c 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -610,7 +610,7 @@ Objective-C and Objective-C++ Dialects}.
 -mpc32 -mpc64 -mpc80 -mstackrealign @gol
 -momit-leaf-frame-pointer  -mno-red-zone -mno-tls-direct-seg-refs @gol
 -mcmodel=@var{code-model} -mabi=@var{name} @gol
--m32  -m64 -mlarge-data-threshold=@var{num} @gol
+-m32 -m64 -mx32 -mlarge-data-threshold=@var{num} @gol
 -msse2avx -mfentry -m8bit-idiv @gol
 -mavx256-split-unaligned-load -mavx256-split-unaligned-store}
 
@@ -12851,15 +12851,19 @@ on AMD x86-64 processors in 64-bit environments.
 @table @gcctabopt
 @item -m32
 @itemx -m64
+@itemx -mx32
 @opindex m32
 @opindex m64
+@opindex mx32
 Generate code for a 32-bit or 64-bit environment.
-The 32-bit environment sets int, long and pointer to 32 bits and
+The @option{-m32} option sets int, long and pointer to 32 bits and
 generates code that runs on any i386 system.
-The 64-bit environment sets int to 32 bits and long and pointer
-to 64 bits and generates code for AMD's x86-64 architecture. For
-darwin only the -m64 option turns off the @option{-fno-pic} and
-@option{-mdynamic-no-pic} options.
+The @option{-m64} option sets int to 32 bits and long and pointer
+to 64 bits and generates code for AMD's x86-64 architecture.
+The @option{-mx32} option sets int, long and pointer to 32 bits and
+generates code for AMD's x86-64 architecture.
+For darwin only the @option{-m64} option turns off the @option{-fno-pic}
+and @option{-mdynamic-no-pic} options.
 
 @item -mno-red-zone
 @opindex mno-red-zone

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: PATCH [1/n] X32: Add initial -x32 support
  2011-07-05 17:59     ` H.J. Lu
@ 2011-07-05 18:18       ` Uros Bizjak
  2011-07-05 19:09         ` H.J. Lu
  0 siblings, 1 reply; 26+ messages in thread
From: Uros Bizjak @ 2011-07-05 18:18 UTC (permalink / raw)
  To: H.J. Lu; +Cc: gcc-patches, Joseph S. Myers, Paolo Bonzini

On Tue, Jul 5, 2011 at 7:54 PM, H.J. Lu <hjl.tools@gmail.com> wrote:

>>> I'd like to start submitting a series of patches to enable x32:
>>>
>>> https://sites.google.com/site/x32abi/
>>>
>>> The GCC x32 branch is very stable. There are no unexpected failures in
>>> C, C++, Fortran and Objective C testsuites.  SPEC CPU 2K/2006 compile
>>> and run correctly at -O2 and -O3.
>>>
>>> More than 90% of changes are in x86 backend.  I have submitted non-x86
>>> backend patches.  Most of them have been reviewed and checked in.  Only
>>> 4 patches are pending for review/approval.
>>>
>>> This is the first x86 backend patch to support x32.  By default, x32 is
>>> disabled and x32 run-time support isn't required.  OK for trunk?
>>
>> Please strip out --enable-ia32 stuff, it complicates things ATM.  I
>> assume that --enable-x32 applies only to 64bit targets, so this part


I think that better name of the file would be "t-linux64-x32".

@@ -2631,6 +2640,7 @@ esac
 case ${target} in
 i[34567]86-*-linux* | x86_64-*-linux*)
 	tmake_file="${tmake_file} i386/t-pmm_malloc i386/t-i386"
+	libgcc_tm_file="${libgcc_tm_file} i386/value-unwind.h"

Not yet.

@@ -58,25 +58,31 @@ see the files COPYING3 and COPYING.RUNTIME
respectively.  If not, see

 #if TARGET_64BIT_DEFAULT
 #define SPEC_32 "m32"
-#define SPEC_64 "!m32"
+#define SPEC_64 "m32|mx32:;"
+#define SPEC_X32 "mx32"
 #else
-#define SPEC_32 "!m64"
+#define SPEC_32 "m64|mx32:;"
 #define SPEC_64 "m64"
+#define SPEC_X32 "mx32"
 #endif

I really think that "!(m64|mx32)" is more descriptive and clear...

 #undef	LINK_SPEC
 #define LINK_SPEC "%{" SPEC_64 ":-m " GNU_USER_LINK_EMULATION64 "} \
                    %{" SPEC_32 ":-m " GNU_USER_LINK_EMULATION32 "} \
+                   %{" SPEC_X32 ":-m " GNU_USER_LINK_EMULATIONX32 "} \
   %{shared:-shared} \
   %{!shared: \
     %{!static: \
       %{rdynamic:-export-dynamic} \
       %{" SPEC_32 ":-dynamic-linker " GNU_USER_DYNAMIC_LINKER32 "} \
-      %{" SPEC_64 ":-dynamic-linker " GNU_USER_DYNAMIC_LINKER64 "}} \
+      %{" SPEC_64 ":-dynamic-linker " GNU_USER_DYNAMIC_LINKER64 "} \
+      %{" SPEC_X32 ":-dynamic-linker " GNU_USER_DYNAMIC_LINKERX32 "}} \
     %{static:-static}}"

On the border of bikesheding, GNU_USER_LINK_EMULATION64_X32 and
GNU_USER_DYNAMIC_LINKER64_X32 sounds better to me.

Same with the below:

+#define GLIBC_DYNAMIC_LINKERX32 "/libx32/ld-linux-x32.so.2"
+#define UCLIBC_DYNAMIC_LINKERX32 "/lib/ldx32-uClibc.so.0"
+#define BIONIC_DYNAMIC_LINKERX32 "/system/bin/linkerx32"

+++ b/gcc/config/i386/t-linux-x32

Please rename above file to t-linux64-x32.

With above small changes, the patch looks OK to me. Please also wait
for build and options maintainer (CC'd) approvals.

Thanks,
Uros.

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: PATCH [1/n] X32: Add initial -x32 support
  2011-07-05 18:18       ` Uros Bizjak
@ 2011-07-05 19:09         ` H.J. Lu
  2011-07-05 19:09           ` Joseph S. Myers
                             ` (2 more replies)
  0 siblings, 3 replies; 26+ messages in thread
From: H.J. Lu @ 2011-07-05 19:09 UTC (permalink / raw)
  To: Uros Bizjak; +Cc: gcc-patches, Joseph S. Myers, Paolo Bonzini

[-- Attachment #1: Type: text/plain, Size: 3443 bytes --]

On Tue, Jul 5, 2011 at 11:14 AM, Uros Bizjak <ubizjak@gmail.com> wrote:
> On Tue, Jul 5, 2011 at 7:54 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
>
>>>> I'd like to start submitting a series of patches to enable x32:
>>>>
>>>> https://sites.google.com/site/x32abi/
>>>>
>>>> The GCC x32 branch is very stable. There are no unexpected failures in
>>>> C, C++, Fortran and Objective C testsuites.  SPEC CPU 2K/2006 compile
>>>> and run correctly at -O2 and -O3.
>>>>
>>>> More than 90% of changes are in x86 backend.  I have submitted non-x86
>>>> backend patches.  Most of them have been reviewed and checked in.  Only
>>>> 4 patches are pending for review/approval.
>>>>
>>>> This is the first x86 backend patch to support x32.  By default, x32 is
>>>> disabled and x32 run-time support isn't required.  OK for trunk?
>>>
>>> Please strip out --enable-ia32 stuff, it complicates things ATM.  I
>>> assume that --enable-x32 applies only to 64bit targets, so this part
>
>
> I think that better name of the file would be "t-linux64-x32".
>
> @@ -2631,6 +2640,7 @@ esac
>  case ${target} in
>  i[34567]86-*-linux* | x86_64-*-linux*)
>        tmake_file="${tmake_file} i386/t-pmm_malloc i386/t-i386"
> +       libgcc_tm_file="${libgcc_tm_file} i386/value-unwind.h"
>
> Not yet.

Removed.

> @@ -58,25 +58,31 @@ see the files COPYING3 and COPYING.RUNTIME
> respectively.  If not, see
>
>  #if TARGET_64BIT_DEFAULT
>  #define SPEC_32 "m32"
> -#define SPEC_64 "!m32"
> +#define SPEC_64 "m32|mx32:;"
> +#define SPEC_X32 "mx32"
>  #else
> -#define SPEC_32 "!m64"
> +#define SPEC_32 "m64|mx32:;"
>  #define SPEC_64 "m64"
> +#define SPEC_X32 "mx32"
>  #endif
>
> I really think that "!(m64|mx32)" is more descriptive and clear...

I don't know if gcc spec supports it.  I just followed mips backend.

>  #undef LINK_SPEC
>  #define LINK_SPEC "%{" SPEC_64 ":-m " GNU_USER_LINK_EMULATION64 "} \
>                    %{" SPEC_32 ":-m " GNU_USER_LINK_EMULATION32 "} \
> +                   %{" SPEC_X32 ":-m " GNU_USER_LINK_EMULATIONX32 "} \
>   %{shared:-shared} \
>   %{!shared: \
>     %{!static: \
>       %{rdynamic:-export-dynamic} \
>       %{" SPEC_32 ":-dynamic-linker " GNU_USER_DYNAMIC_LINKER32 "} \
> -      %{" SPEC_64 ":-dynamic-linker " GNU_USER_DYNAMIC_LINKER64 "}} \
> +      %{" SPEC_64 ":-dynamic-linker " GNU_USER_DYNAMIC_LINKER64 "} \
> +      %{" SPEC_X32 ":-dynamic-linker " GNU_USER_DYNAMIC_LINKERX32 "}} \
>     %{static:-static}}"
>
> On the border of bikesheding, GNU_USER_LINK_EMULATION64_X32 and
> GNU_USER_DYNAMIC_LINKER64_X32 sounds better to me.
>
> Same with the below:
>
> +#define GLIBC_DYNAMIC_LINKERX32 "/libx32/ld-linux-x32.so.2"
> +#define UCLIBC_DYNAMIC_LINKERX32 "/lib/ldx32-uClibc.so.0"
> +#define BIONIC_DYNAMIC_LINKERX32 "/system/bin/linkerx32"
>
> +++ b/gcc/config/i386/t-linux-x32
>
> Please rename above file to t-linux64-x32.

X32 is the name of the psABI:

https://sites.google.com/site/x32abi/

We have -mx32, -m32 and -m64 command line options and
There are macros like TARGET_X32. I'd like to be consistent
and avoid "64" when referring to x32 if possible. But I won't
insist.  Please let me know that you really won't like x32 without
64.

> With above small changes, the patch looks OK to me. Please also wait
> for build and options maintainer (CC'd) approvals.
>
> Thanks,
> Uros.
>

Thanks.


-- 
H.J.

[-- Attachment #2: gcc-x32-3.patch --]
[-- Type: text/plain, Size: 14315 bytes --]

2011-07-05  H.J. Lu  <hongjiu.lu@intel.com>

	* config.gcc: Support --enable-x32 for x86 Linux
	targets.

	* configure.ac: Support --enable-x32.
	* configure: Regenerated.

	* config/i386/gnu-user64.h (SPEC_64): Support x32.
	(SPEC_32): Likewise.
	(ASM_SPEC): Likewise.
	(LINK_SPEC): Likewise.
	(TARGET_THREAD_SSP_OFFSET): Likewise.
	(TARGET_THREAD_SPLIT_STACK_OFFSET): Likewise.
	(SPEC_X32): New.

	* config/i386/i386.h (TARGET_X32): New.
	(TARGET_LP64): New.
	(LONG_TYPE_SIZE): Likewise.
	(POINTER_SIZE): Likewise.
	(POINTERS_EXTEND_UNSIGNED): Likewise.
	(OPT_ARCH64): Support x32.
	(OPT_ARCH32): Likewise.

	* config/i386/i386.opt (mx32): New.

	* config/i386/kfreebsd-gnu64.h (GNU_USER_LINK_EMULATIONX32): New.
	(GLIBC_DYNAMIC_LINKERX32): Likewise.
	* config/i386/linux64.h (GNU_USER_LINK_EMULATIONX32): Likewise.
	(GLIBC_DYNAMIC_LINKERX32): Likewise.

	* config/i386/t-linux-x32: New.

	* config/linux.h (UCLIBC_DYNAMIC_LINKERX32): New.
	(BIONIC_DYNAMIC_LINKERX32): Likewise.
	(GNU_USER_DYNAMIC_LINKERX32): Likewise.

	* doc/install.texi: Document --enable-x32.

	* doc/invoke.texi: Document -mx32.

diff --git a/gcc/config.gcc b/gcc/config.gcc
index c77f40b..4787d6b 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -1279,7 +1279,11 @@ i[34567]86-*-linux* | i[34567]86-*-kfreebsd*-gnu | i[34567]86-*-knetbsd*-gnu | i
 		if test x$enable_targets = xall; then
 			tm_file="${tm_file} i386/x86-64.h i386/gnu-user64.h i386/linux64.h"
 			tm_defines="${tm_defines} TARGET_BI_ARCH=1"
-			tmake_file="${tmake_file} i386/t-linux64"
+			if test x${enable_x32} = xyes; then
+				tmake_file="${tmake_file} i386/t-linux-x32"
+			else
+				tmake_file="${tmake_file} i386/t-linux64"
+			fi
 			need_64bit_hwint=yes
 			need_64bit_isa=yes
 			case X"${with_cpu}" in
@@ -1317,7 +1321,12 @@ x86_64-*-linux* | x86_64-*-kfreebsd*-gnu | x86_64-*-knetbsd*-gnu)
 	x86_64-*-kfreebsd*-gnu) tm_file="${tm_file} kfreebsd-gnu.h i386/kfreebsd-gnu64.h" ;;
 	x86_64-*-knetbsd*-gnu) tm_file="${tm_file} knetbsd-gnu.h" ;;
 	esac
-	tmake_file="${tmake_file} i386/t-linux64 i386/t-crtstuff i386/t-crtpc i386/t-crtfm t-dfprules"
+	if test x${enable_x32} = xyes; then
+		tmake_file="${tmake_file} i386/t-linux-x32"
+	else
+		tmake_file="${tmake_file} i386/t-linux64"
+	fi
+	tmake_file="${tmake_file} i386/t-crtstuff i386/t-crtpc i386/t-crtfm t-dfprules"
 	;;
 i[34567]86-pc-msdosdjgpp*)
 	xm_file=i386/xm-djgpp.h
diff --git a/gcc/config/i386/gnu-user64.h b/gcc/config/i386/gnu-user64.h
index b069975..954f3b2 100644
--- a/gcc/config/i386/gnu-user64.h
+++ b/gcc/config/i386/gnu-user64.h
@@ -58,25 +58,31 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 
 #if TARGET_64BIT_DEFAULT
 #define SPEC_32 "m32"
-#define SPEC_64 "!m32"
+#define SPEC_64 "m32|mx32:;"
+#define SPEC_X32 "mx32"
 #else
-#define SPEC_32 "!m64"
+#define SPEC_32 "m64|mx32:;"
 #define SPEC_64 "m64"
+#define SPEC_X32 "mx32"
 #endif
 
 #undef ASM_SPEC
-#define ASM_SPEC "%{" SPEC_32 ":--32} %{" SPEC_64 ":--64} \
+#define ASM_SPEC "%{" SPEC_32 ":--32} \
+ %{" SPEC_64 ":--64} \
+ %{" SPEC_X32 ":--x32} \
  %{!mno-sse2avx:%{mavx:-msse2avx}} %{msse2avx:%{!mavx:-msse2avx}}"
 
 #undef	LINK_SPEC
 #define LINK_SPEC "%{" SPEC_64 ":-m " GNU_USER_LINK_EMULATION64 "} \
                    %{" SPEC_32 ":-m " GNU_USER_LINK_EMULATION32 "} \
+                   %{" SPEC_X32 ":-m " GNU_USER_LINK_EMULATIONX32 "} \
   %{shared:-shared} \
   %{!shared: \
     %{!static: \
       %{rdynamic:-export-dynamic} \
       %{" SPEC_32 ":-dynamic-linker " GNU_USER_DYNAMIC_LINKER32 "} \
-      %{" SPEC_64 ":-dynamic-linker " GNU_USER_DYNAMIC_LINKER64 "}} \
+      %{" SPEC_64 ":-dynamic-linker " GNU_USER_DYNAMIC_LINKER64 "} \
+      %{" SPEC_X32 ":-dynamic-linker " GNU_USER_DYNAMIC_LINKERX32 "}} \
     %{static:-static}}"
 
 /* Similar to standard GNU userspace, but adding -ffast-math support.  */
@@ -110,10 +116,13 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 
 #ifdef TARGET_LIBC_PROVIDES_SSP
 /* i386 glibc provides __stack_chk_guard in %gs:0x14,
+   x32 glibc provides it in %fs:0x18. 
    x86_64 glibc provides it in %fs:0x28.  */
-#define TARGET_THREAD_SSP_OFFSET	(TARGET_64BIT ? 0x28 : 0x14)
+#define TARGET_THREAD_SSP_OFFSET \
+  (TARGET_64BIT ? (TARGET_X32 ? 0x18 : 0x28) : 0x14)
 
 /* We steal the last transactional memory word.  */
 #define TARGET_CAN_SPLIT_STACK
-#define TARGET_THREAD_SPLIT_STACK_OFFSET (TARGET_64BIT ? 0x70 : 0x30)
+#define TARGET_THREAD_SPLIT_STACK_OFFSET \
+  (TARGET_64BIT ? (TARGET_X32 ? 0x40 : 0x70) : 0x30)
 #endif
diff --git a/gcc/config/i386/i386.h b/gcc/config/i386/i386.h
index a1ac6b6..8cef4e7 100644
--- a/gcc/config/i386/i386.h
+++ b/gcc/config/i386/i386.h
@@ -42,6 +42,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 /* Redefines for option macros.  */
 
 #define TARGET_64BIT	OPTION_ISA_64BIT
+#define TARGET_X32	OPTION_ISA_X32
 #define TARGET_MMX	OPTION_ISA_MMX
 #define TARGET_3DNOW	OPTION_ISA_3DNOW
 #define TARGET_3DNOW_A	OPTION_ISA_3DNOW_A
@@ -72,6 +73,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #define TARGET_RDRND	OPTION_ISA_RDRND
 #define TARGET_F16C	OPTION_ISA_F16C
 
+#define TARGET_LP64	(TARGET_64BIT && !TARGET_X32)
 
 /* SSE4.1 defines round instructions */
 #define	OPTION_MASK_ISA_ROUND	OPTION_MASK_ISA_SSE4_1
@@ -516,8 +518,8 @@ extern const char *host_detect_local_cpu (int argc, const char **argv);
 #define OPT_ARCH64 "!m32"
 #define OPT_ARCH32 "m32"
 #else
-#define OPT_ARCH64 "m64"
-#define OPT_ARCH32 "!m64"
+#define OPT_ARCH64 "m64|mx32"
+#define OPT_ARCH32 "m64|mx32:;"
 #endif
 
 /* Support for configure-time defaults of some command line options.
@@ -637,6 +639,8 @@ enum target_cpu_default
 
 #define SHORT_TYPE_SIZE 16
 #define INT_TYPE_SIZE 32
+#define LONG_TYPE_SIZE (TARGET_X32 ? 32 : BITS_PER_WORD)
+#define POINTER_SIZE (TARGET_X32 ? 32 : BITS_PER_WORD)
 #define LONG_LONG_TYPE_SIZE 64
 #define FLOAT_TYPE_SIZE 32
 #define DOUBLE_TYPE_SIZE 64
@@ -1742,6 +1746,13 @@ do {							\
    between pointers and any other objects of this machine mode.  */
 #define Pmode (TARGET_64BIT ? DImode : SImode)
 
+/* A C expression whose value is zero if pointers that need to be extended
+   from being `POINTER_SIZE' bits wide to `Pmode' are sign-extended and
+   greater then zero if they are zero-extended and less then zero if the
+   ptr_extend instruction should be used.  */
+
+#define POINTERS_EXTEND_UNSIGNED 1
+
 /* A function address in a call instruction
    is a byte address (for indexing purposes)
    so give the MEM rtx a byte's mode.  */
diff --git a/gcc/config/i386/i386.opt b/gcc/config/i386/i386.opt
index 9886b7b..8dea93e 100644
--- a/gcc/config/i386/i386.opt
+++ b/gcc/config/i386/i386.opt
@@ -398,9 +398,13 @@ Target RejectNegative Negative(m64) Report InverseMask(ISA_64BIT) Var(ix86_isa_f
 Generate 32bit i386 code
 
 m64
-Target RejectNegative Negative(m32) Report Mask(ISA_64BIT) Var(ix86_isa_flags) Save
+Target RejectNegative Negative(mx32) Report Mask(ISA_64BIT) Var(ix86_isa_flags) Save
 Generate 64bit x86-64 code
 
+mx32
+Target RejectNegative Negative(m32) Report Mask(ISA_X32) Var(ix86_isa_flags) Save
+Generate 32bit x86-64 code
+
 mmmx
 Target Report Mask(ISA_MMX) Var(ix86_isa_flags) Save
 Support MMX built-in functions
diff --git a/gcc/config/i386/kfreebsd-gnu64.h b/gcc/config/i386/kfreebsd-gnu64.h
index c3798a5..2085ca5 100644
--- a/gcc/config/i386/kfreebsd-gnu64.h
+++ b/gcc/config/i386/kfreebsd-gnu64.h
@@ -21,6 +21,8 @@ along with GCC; see the file COPYING3.  If not see
 
 #define GNU_USER_LINK_EMULATION32 "elf_i386_fbsd"
 #define GNU_USER_LINK_EMULATION64 "elf_x86_64_fbsd"
+#define GNU_USER_LINK_EMULATIONX32 "elf32_x86_64_fbsd"
 
 #define GLIBC_DYNAMIC_LINKER32 "/lib/ld.so.1"
 #define GLIBC_DYNAMIC_LINKER64 "/lib/ld-kfreebsd-x86-64.so.1"
+#define GLIBC_DYNAMIC_LINKERX32 "/lib/ld-kfreebsd-x32.so.1"
diff --git a/gcc/config/i386/linux64.h b/gcc/config/i386/linux64.h
index 5d33224..5b0a212 100644
--- a/gcc/config/i386/linux64.h
+++ b/gcc/config/i386/linux64.h
@@ -26,6 +26,8 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 
 #define GNU_USER_LINK_EMULATION32 "elf_i386"
 #define GNU_USER_LINK_EMULATION64 "elf_x86_64"
+#define GNU_USER_LINK_EMULATIONX32 "elf32_x86_64"
 
 #define GLIBC_DYNAMIC_LINKER32 "/lib/ld-linux.so.2"
 #define GLIBC_DYNAMIC_LINKER64 "/lib64/ld-linux-x86-64.so.2"
+#define GLIBC_DYNAMIC_LINKERX32 "/libx32/ld-linux-x32.so.2"
diff --git a/gcc/config/i386/t-linux-x32 b/gcc/config/i386/t-linux-x32
new file mode 100644
index 0000000..92acf91
--- /dev/null
+++ b/gcc/config/i386/t-linux-x32
@@ -0,0 +1,42 @@
+# Copyright (C) 2011 Free Software Foundation, Inc.
+#
+# This file is part of GCC.
+#
+# GCC is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GCC is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GCC; see the file COPYING3.  If not see
+# <http://www.gnu.org/licenses/>.
+
+# On Debian, Ubuntu and other derivative distributions, the 32bit libraries
+# are found in /lib32 and /usr/lib32, /lib64 and /usr/lib64 are symlinks to
+# /lib and /usr/lib, while other distributions install libraries into /lib64
+# and /usr/lib64.  The LSB does not enforce the use of /lib64 and /usr/lib64,
+# it doesn't tell anything about the 32bit libraries on those systems.  Set
+# MULTILIB_OSDIRNAMES according to what is found on the target.
+
+# To support i386, x86-64 and x32 libraries, the directory structrue
+# should be:
+#
+# 	/lib has i386 libraries.
+# 	/lib64 has x86-64 libraries.
+# 	/libx32 has x32 libraries.
+#
+MULTILIB_OPTIONS = m64/m32/mx32
+MULTILIB_DIRNAMES = 64 32 x32
+MULTILIB_OSDIRNAMES = ../lib64 $(if $(wildcard $(shell echo $(SYSTEM_HEADER_DIR))/../../usr/lib32),../lib32,../lib) ../libx32
+
+LIBGCC = stmp-multilib
+INSTALL_LIBGCC = install-multilib
+
+EXTRA_MULTILIB_PARTS=crtbegin.o crtend.o crtbeginS.o crtendS.o \
+		     crtbeginT.o crtprec32.o crtprec64.o crtprec80.o \
+		     crtfastmath.o
diff --git a/gcc/config/linux.h b/gcc/config/linux.h
index fc897b1..dbbeea5 100644
--- a/gcc/config/linux.h
+++ b/gcc/config/linux.h
@@ -77,9 +77,11 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #define UCLIBC_DYNAMIC_LINKER "/lib/ld-uClibc.so.0"
 #define UCLIBC_DYNAMIC_LINKER32 "/lib/ld-uClibc.so.0"
 #define UCLIBC_DYNAMIC_LINKER64 "/lib/ld64-uClibc.so.0"
+#define UCLIBC_DYNAMIC_LINKERX32 "/lib/ldx32-uClibc.so.0"
 #define BIONIC_DYNAMIC_LINKER "/system/bin/linker"
 #define BIONIC_DYNAMIC_LINKER32 "/system/bin/linker"
 #define BIONIC_DYNAMIC_LINKER64 "/system/bin/linker64"
+#define BIONIC_DYNAMIC_LINKERX32 "/system/bin/linkerx32"
 
 #define GNU_USER_DYNAMIC_LINKER						\
   CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER, UCLIBC_DYNAMIC_LINKER,	\
@@ -90,6 +92,9 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #define GNU_USER_DYNAMIC_LINKER64					\
   CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER64, UCLIBC_DYNAMIC_LINKER64, \
 			 BIONIC_DYNAMIC_LINKER64)
+#define GNU_USER_DYNAMIC_LINKERX32					\
+  CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKERX32, UCLIBC_DYNAMIC_LINKERX32, \
+			 BIONIC_DYNAMIC_LINKERX32)
 
 /* Determine whether the entire c99 runtime
    is present in the runtime library.  */
diff --git a/gcc/configure.ac b/gcc/configure.ac
index 5f3641b..bddabeb 100644
--- a/gcc/configure.ac
+++ b/gcc/configure.ac
@@ -611,6 +611,11 @@ AC_ARG_ENABLE(multilib,
 [], [enable_multilib=yes])
 AC_SUBST(enable_multilib)
 
+# With x32 support
+AC_ARG_ENABLE(x32,
+[  --enable-x32            enable x32 library support for multiple ABIs],
+[], [enable_x32=no])
+
 # Enable __cxa_atexit for C++.
 AC_ARG_ENABLE(__cxa_atexit,
 [AS_HELP_STRING([--enable-__cxa_atexit], [enable __cxa_atexit for C++])],
diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi
index 49aac95..e89c396 100644
--- a/gcc/doc/install.texi
+++ b/gcc/doc/install.texi
@@ -1161,6 +1161,11 @@ assumptions made by the configure test are incorrect.
 Specify that the target does not support TLS.
 This is an alias for @option{--enable-tls=no}.
 
+@item --enable-x32
+This option enables x32 library support for multiple ABIs. By
+default, x32 library support is disabled.  It is only supported for
+x86-64.
+
 @item --with-cpu=@var{cpu}
 @itemx --with-cpu-32=@var{cpu}
 @itemx --with-cpu-64=@var{cpu}
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 1fc4038..fd6711c 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -610,7 +610,7 @@ Objective-C and Objective-C++ Dialects}.
 -mpc32 -mpc64 -mpc80 -mstackrealign @gol
 -momit-leaf-frame-pointer  -mno-red-zone -mno-tls-direct-seg-refs @gol
 -mcmodel=@var{code-model} -mabi=@var{name} @gol
--m32  -m64 -mlarge-data-threshold=@var{num} @gol
+-m32 -m64 -mx32 -mlarge-data-threshold=@var{num} @gol
 -msse2avx -mfentry -m8bit-idiv @gol
 -mavx256-split-unaligned-load -mavx256-split-unaligned-store}
 
@@ -12851,15 +12851,19 @@ on AMD x86-64 processors in 64-bit environments.
 @table @gcctabopt
 @item -m32
 @itemx -m64
+@itemx -mx32
 @opindex m32
 @opindex m64
+@opindex mx32
 Generate code for a 32-bit or 64-bit environment.
-The 32-bit environment sets int, long and pointer to 32 bits and
+The @option{-m32} option sets int, long and pointer to 32 bits and
 generates code that runs on any i386 system.
-The 64-bit environment sets int to 32 bits and long and pointer
-to 64 bits and generates code for AMD's x86-64 architecture. For
-darwin only the -m64 option turns off the @option{-fno-pic} and
-@option{-mdynamic-no-pic} options.
+The @option{-m64} option sets int to 32 bits and long and pointer
+to 64 bits and generates code for AMD's x86-64 architecture.
+The @option{-mx32} option sets int, long and pointer to 32 bits and
+generates code for AMD's x86-64 architecture.
+For darwin only the @option{-m64} option turns off the @option{-fno-pic}
+and @option{-mdynamic-no-pic} options.
 
 @item -mno-red-zone
 @opindex mno-red-zone

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: PATCH [1/n] X32: Add initial -x32 support
  2011-07-05 19:09         ` H.J. Lu
@ 2011-07-05 19:09           ` Joseph S. Myers
  2011-07-05 20:07           ` Uros Bizjak
  2011-07-06 14:50           ` H.J. Lu
  2 siblings, 0 replies; 26+ messages in thread
From: Joseph S. Myers @ 2011-07-05 19:09 UTC (permalink / raw)
  To: H.J. Lu; +Cc: Uros Bizjak, gcc-patches, Paolo Bonzini

On Tue, 5 Jul 2011, H.J. Lu wrote:

> > I really think that "!(m64|mx32)" is more descriptive and clear...
> 
> I don't know if gcc spec supports it.  I just followed mips backend.

Indeed, I don't think any such grouping construct exists in specs.

The .opt changes look fine to me.

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: PATCH [1/n] X32: Add initial -x32 support
  2011-07-05 19:09         ` H.J. Lu
  2011-07-05 19:09           ` Joseph S. Myers
@ 2011-07-05 20:07           ` Uros Bizjak
  2011-07-06 14:50           ` H.J. Lu
  2 siblings, 0 replies; 26+ messages in thread
From: Uros Bizjak @ 2011-07-05 20:07 UTC (permalink / raw)
  To: H.J. Lu; +Cc: gcc-patches, Joseph S. Myers, Paolo Bonzini

On Tue, Jul 5, 2011 at 8:49 PM, H.J. Lu <hjl.tools@gmail.com> wrote:

>>  #undef LINK_SPEC
>>  #define LINK_SPEC "%{" SPEC_64 ":-m " GNU_USER_LINK_EMULATION64 "} \
>>                    %{" SPEC_32 ":-m " GNU_USER_LINK_EMULATION32 "} \
>> +                   %{" SPEC_X32 ":-m " GNU_USER_LINK_EMULATIONX32 "} \
>>   %{shared:-shared} \
>>   %{!shared: \
>>     %{!static: \
>>       %{rdynamic:-export-dynamic} \
>>       %{" SPEC_32 ":-dynamic-linker " GNU_USER_DYNAMIC_LINKER32 "} \
>> -      %{" SPEC_64 ":-dynamic-linker " GNU_USER_DYNAMIC_LINKER64 "}} \
>> +      %{" SPEC_64 ":-dynamic-linker " GNU_USER_DYNAMIC_LINKER64 "} \
>> +      %{" SPEC_X32 ":-dynamic-linker " GNU_USER_DYNAMIC_LINKERX32 "}} \
>>     %{static:-static}}"
>>
>> On the border of bikesheding, GNU_USER_LINK_EMULATION64_X32 and
>> GNU_USER_DYNAMIC_LINKER64_X32 sounds better to me.
>>
>> Same with the below:
>>
>> +#define GLIBC_DYNAMIC_LINKERX32 "/libx32/ld-linux-x32.so.2"
>> +#define UCLIBC_DYNAMIC_LINKERX32 "/lib/ldx32-uClibc.so.0"
>> +#define BIONIC_DYNAMIC_LINKERX32 "/system/bin/linkerx32"
>>
>> +++ b/gcc/config/i386/t-linux-x32
>>
>> Please rename above file to t-linux64-x32.
>
> X32 is the name of the psABI:
>
> https://sites.google.com/site/x32abi/
>
> We have -mx32, -m32 and -m64 command line options and
> There are macros like TARGET_X32. I'd like to be consistent
> and avoid "64" when referring to x32 if possible. But I won't
> insist.  Please let me know that you really won't like x32 without
> 64.

I would like to point out that the base target is in fact 64 bit and a
subtarget is x32, so ...64-x32. I could read this as 64bit target with
x32 ABI. Perhaps we will have 64-xxx or whatever different ABIs that
all apply to the same 64bit hardware.

These are my personal preferences, so I will leave the final decision
about names of defines and file names to you.

Thanks,
Uros.

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: PATCH [1/n] X32: Add initial -x32 support
  2011-07-05 19:09         ` H.J. Lu
  2011-07-05 19:09           ` Joseph S. Myers
  2011-07-05 20:07           ` Uros Bizjak
@ 2011-07-06 14:50           ` H.J. Lu
  2011-07-06 15:03             ` Richard Guenther
  2 siblings, 1 reply; 26+ messages in thread
From: H.J. Lu @ 2011-07-06 14:50 UTC (permalink / raw)
  To: DJ Delorie, Alexandre Oliva, Paolo Bonzini, Ralf Wildenhues, neroden
  Cc: gcc-patches

Hi Paolo, DJ, Nathanael, Alexandre, Ralf,

Is the change
.
	* configure.ac: Support --enable-x32.
	* configure: Regenerated.

diff --git a/gcc/configure.ac b/gcc/configure.ac
index 5f3641b..bddabeb 100644
--- a/gcc/configure.ac
+++ b/gcc/configure.ac
@@ -611,6 +611,11 @@ AC_ARG_ENABLE(multilib,
 [], [enable_multilib=yes])
 AC_SUBST(enable_multilib)

+# With x32 support
+AC_ARG_ENABLE(x32,
+[  --enable-x32            enable x32 library support for multiple ABIs],
+[], [enable_x32=no])
+
 # Enable __cxa_atexit for C++.
 AC_ARG_ENABLE(__cxa_atexit,
 [AS_HELP_STRING([--enable-__cxa_atexit], [enable __cxa_atexit for C++])],

OK?

Thanks.

-- 
H.J.
---

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: PATCH [1/n] X32: Add initial -x32 support
  2011-07-06 14:50           ` H.J. Lu
@ 2011-07-06 15:03             ` Richard Guenther
  2011-07-06 16:40               ` H.J. Lu
  0 siblings, 1 reply; 26+ messages in thread
From: Richard Guenther @ 2011-07-06 15:03 UTC (permalink / raw)
  To: H.J. Lu
  Cc: DJ Delorie, Alexandre Oliva, Paolo Bonzini, Ralf Wildenhues,
	neroden, gcc-patches

On Wed, Jul 6, 2011 at 4:48 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
> Hi Paolo, DJ, Nathanael, Alexandre, Ralf,
>
> Is the change
> .
>        * configure.ac: Support --enable-x32.
>        * configure: Regenerated.
>
> diff --git a/gcc/configure.ac b/gcc/configure.ac
> index 5f3641b..bddabeb 100644
> --- a/gcc/configure.ac
> +++ b/gcc/configure.ac
> @@ -611,6 +611,11 @@ AC_ARG_ENABLE(multilib,
>  [], [enable_multilib=yes])
>  AC_SUBST(enable_multilib)
>
> +# With x32 support
> +AC_ARG_ENABLE(x32,
> +[  --enable-x32            enable x32 library support for multiple ABIs],

Looks like a very very generic switch for a global configury ... we already
have --with-multilib-list (SH only), why not extend that to also work
for x86_64?

Richard.

> +[], [enable_x32=no])
> +
>  # Enable __cxa_atexit for C++.
>  AC_ARG_ENABLE(__cxa_atexit,
>  [AS_HELP_STRING([--enable-__cxa_atexit], [enable __cxa_atexit for C++])],
>
> OK?
>
> Thanks.
>
> --
> H.J.
> ---
>

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: PATCH [1/n] X32: Add initial -x32 support
  2011-07-06 15:03             ` Richard Guenther
@ 2011-07-06 16:40               ` H.J. Lu
  2011-07-07 13:03                 ` H.J. Lu
  2011-07-07 13:27                 ` Paolo Bonzini
  0 siblings, 2 replies; 26+ messages in thread
From: H.J. Lu @ 2011-07-06 16:40 UTC (permalink / raw)
  To: Richard Guenther
  Cc: DJ Delorie, Alexandre Oliva, Paolo Bonzini, Ralf Wildenhues,
	neroden, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 4060 bytes --]

On Wed, Jul 6, 2011 at 8:02 AM, Richard Guenther
<richard.guenther@gmail.com> wrote:
> On Wed, Jul 6, 2011 at 4:48 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
>> Hi Paolo, DJ, Nathanael, Alexandre, Ralf,
>>
>> Is the change
>> .
>>        * configure.ac: Support --enable-x32.
>>        * configure: Regenerated.
>>
>> diff --git a/gcc/configure.ac b/gcc/configure.ac
>> index 5f3641b..bddabeb 100644
>> --- a/gcc/configure.ac
>> +++ b/gcc/configure.ac
>> @@ -611,6 +611,11 @@ AC_ARG_ENABLE(multilib,
>>  [], [enable_multilib=yes])
>>  AC_SUBST(enable_multilib)
>>
>> +# With x32 support
>> +AC_ARG_ENABLE(x32,
>> +[  --enable-x32            enable x32 library support for multiple ABIs],
>
> Looks like a very very generic switch for a global configury ... we already
> have --with-multilib-list (SH only), why not extend that to also work
> for x86_64?
>
> Richard.
>
>> +[], [enable_x32=no])
>> +
>>  # Enable __cxa_atexit for C++.
>>  AC_ARG_ENABLE(__cxa_atexit,
>>  [AS_HELP_STRING([--enable-__cxa_atexit], [enable __cxa_atexit for C++])],
>>
>> OK?
>>
>> Thanks.
>>

Here is the updated patch to use --with-multilib-list=x32.

Paolo, DJ, Nathanael, Alexandre, Ralf, Is the configure.ac change

---
	* configure.ac: Mention x86-64 for --with-multilib-list.
	* configure: Regenerated.

	* doc/install.texi: Document --with-multilib-list=x32.

diff --git a/gcc/configure.ac b/gcc/configure.ac
index 5f3641b..a73f758 100644
--- a/gcc/configure.ac
+++ b/gcc/configure.ac
@@ -795,7 +795,7 @@ esac],
 [enable_languages=c])

 AC_ARG_WITH(multilib-list,
-[AS_HELP_STRING([--with-multilib-list], [select multilibs (SH only)])],
+[AS_HELP_STRING([--with-multilib-list], [select multilibs (SH and
x86-64 only)])],
 :,
 with_multilib_list=default)

diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi
index 49aac95..a5d266c 100644
--- a/gcc/doc/install.texi
+++ b/gcc/doc/install.texi
@@ -1049,8 +1049,10 @@ sysv, aix.
 @item --with-multilib-list=@var{list}
 @itemx --without-multilib-list
 Specify what multilibs to build.
-Currently only implemented for sh*-*-*.
+Currently only implemented for sh*-*-* and x86-64-*-linux*.

+@table @code
+@item sh*-*-*
 @var{list} is a comma separated list of CPU names.  These must be of the
 form @code{sh*} or @code{m*} (in which case they match the compiler option
 for that processor).  The list should not contain any endian options -
@@ -1082,6 +1084,12 @@ only little endian SH4AL:
 --with-multilib-list=sh4al,!mb/m4al
 @end smallexample

+@item x86-64-*-linux*
+If @var{list} is @code{x32}, x32 run-time library will be enabled.  By
+default, x32 run-time library is disabled.
+
+@end table
+
 @item --with-endian=@var{endians}
 Specify what endians to use.
 Currently only implemented for sh*-*-*.
---

OK?

Thanks.

-- 
H.J.
---
2011-07-06  H.J. Lu  <hongjiu.lu@intel.com>

	* config.gcc: Support --with-multilib-list=x32 for x86 Linux
	targets.

	* configure.ac: Mention x86-64 for --with-multilib-list.
	* configure: Regenerated.

	* config/i386/gnu-user64.h (SPEC_64): Support x32.
	(SPEC_32): Likewise.
	(ASM_SPEC): Likewise.
	(LINK_SPEC): Likewise.
	(TARGET_THREAD_SSP_OFFSET): Likewise.
	(TARGET_THREAD_SPLIT_STACK_OFFSET): Likewise.
	(SPEC_X32): New.

	* config/i386/i386.h (TARGET_X32): New.
	(TARGET_LP64): New.
	(LONG_TYPE_SIZE): Likewise.
	(POINTER_SIZE): Likewise.
	(POINTERS_EXTEND_UNSIGNED): Likewise.
	(OPT_ARCH64): Support x32.
	(OPT_ARCH32): Likewise.

	* config/i386/i386.opt (mx32): New.

	* config/i386/kfreebsd-gnu64.h (GNU_USER_LINK_EMULATIONX32): New.
	(GLIBC_DYNAMIC_LINKERX32): Likewise.
	* config/i386/linux64.h (GNU_USER_LINK_EMULATIONX32): Likewise.
	(GLIBC_DYNAMIC_LINKERX32): Likewise.

	* config/i386/t-linux-x32: New.

	* config/linux.h (UCLIBC_DYNAMIC_LINKERX32): New.
	(BIONIC_DYNAMIC_LINKERX32): Likewise.
	(GNU_USER_DYNAMIC_LINKERX32): Likewise.

	* doc/install.texi: Document --with-multilib-list=x32.

	* doc/invoke.texi: Document -mx32.

[-- Attachment #2: gcc-x32-4.patch --]
[-- Type: text/plain, Size: 14702 bytes --]

2011-07-06  H.J. Lu  <hongjiu.lu@intel.com>

	* config.gcc: Support --with-multilib-list=x32 for x86 Linux
	targets.

	* configure.ac: Mention x86-64 for --with-multilib-list.
	* configure: Regenerated.

	* config/i386/gnu-user64.h (SPEC_64): Support x32.
	(SPEC_32): Likewise.
	(ASM_SPEC): Likewise.
	(LINK_SPEC): Likewise.
	(TARGET_THREAD_SSP_OFFSET): Likewise.
	(TARGET_THREAD_SPLIT_STACK_OFFSET): Likewise.
	(SPEC_X32): New.

	* config/i386/i386.h (TARGET_X32): New.
	(TARGET_LP64): New.
	(LONG_TYPE_SIZE): Likewise.
	(POINTER_SIZE): Likewise.
	(POINTERS_EXTEND_UNSIGNED): Likewise.
	(OPT_ARCH64): Support x32.
	(OPT_ARCH32): Likewise.

	* config/i386/i386.opt (mx32): New.

	* config/i386/kfreebsd-gnu64.h (GNU_USER_LINK_EMULATIONX32): New.
	(GLIBC_DYNAMIC_LINKERX32): Likewise.
	* config/i386/linux64.h (GNU_USER_LINK_EMULATIONX32): Likewise.
	(GLIBC_DYNAMIC_LINKERX32): Likewise.

	* config/i386/t-linux-x32: New.

	* config/linux.h (UCLIBC_DYNAMIC_LINKERX32): New.
	(BIONIC_DYNAMIC_LINKERX32): Likewise.
	(GNU_USER_DYNAMIC_LINKERX32): Likewise.

	* doc/install.texi: Document --with-multilib-list=x32.

	* doc/invoke.texi: Document -mx32.

diff --git a/gcc/config.gcc b/gcc/config.gcc
index c77f40b..2622046 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -1279,7 +1279,11 @@ i[34567]86-*-linux* | i[34567]86-*-kfreebsd*-gnu | i[34567]86-*-knetbsd*-gnu | i
 		if test x$enable_targets = xall; then
 			tm_file="${tm_file} i386/x86-64.h i386/gnu-user64.h i386/linux64.h"
 			tm_defines="${tm_defines} TARGET_BI_ARCH=1"
-			tmake_file="${tmake_file} i386/t-linux64"
+			if test x${with_multilib_list} = xx32; then
+				tmake_file="${tmake_file} i386/t-linux-x32"
+			else
+				tmake_file="${tmake_file} i386/t-linux64"
+			fi
 			need_64bit_hwint=yes
 			need_64bit_isa=yes
 			case X"${with_cpu}" in
@@ -1317,7 +1321,12 @@ x86_64-*-linux* | x86_64-*-kfreebsd*-gnu | x86_64-*-knetbsd*-gnu)
 	x86_64-*-kfreebsd*-gnu) tm_file="${tm_file} kfreebsd-gnu.h i386/kfreebsd-gnu64.h" ;;
 	x86_64-*-knetbsd*-gnu) tm_file="${tm_file} knetbsd-gnu.h" ;;
 	esac
-	tmake_file="${tmake_file} i386/t-linux64 i386/t-crtstuff i386/t-crtpc i386/t-crtfm t-dfprules"
+	if test x${with_multilib_list} = xx32; then
+		tmake_file="${tmake_file} i386/t-linux-x32"
+	else
+		tmake_file="${tmake_file} i386/t-linux64"
+	fi
+	tmake_file="${tmake_file} i386/t-crtstuff i386/t-crtpc i386/t-crtfm t-dfprules"
 	;;
 i[34567]86-pc-msdosdjgpp*)
 	xm_file=i386/xm-djgpp.h
diff --git a/gcc/config/i386/gnu-user64.h b/gcc/config/i386/gnu-user64.h
index b069975..954f3b2 100644
--- a/gcc/config/i386/gnu-user64.h
+++ b/gcc/config/i386/gnu-user64.h
@@ -58,25 +58,31 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 
 #if TARGET_64BIT_DEFAULT
 #define SPEC_32 "m32"
-#define SPEC_64 "!m32"
+#define SPEC_64 "m32|mx32:;"
+#define SPEC_X32 "mx32"
 #else
-#define SPEC_32 "!m64"
+#define SPEC_32 "m64|mx32:;"
 #define SPEC_64 "m64"
+#define SPEC_X32 "mx32"
 #endif
 
 #undef ASM_SPEC
-#define ASM_SPEC "%{" SPEC_32 ":--32} %{" SPEC_64 ":--64} \
+#define ASM_SPEC "%{" SPEC_32 ":--32} \
+ %{" SPEC_64 ":--64} \
+ %{" SPEC_X32 ":--x32} \
  %{!mno-sse2avx:%{mavx:-msse2avx}} %{msse2avx:%{!mavx:-msse2avx}}"
 
 #undef	LINK_SPEC
 #define LINK_SPEC "%{" SPEC_64 ":-m " GNU_USER_LINK_EMULATION64 "} \
                    %{" SPEC_32 ":-m " GNU_USER_LINK_EMULATION32 "} \
+                   %{" SPEC_X32 ":-m " GNU_USER_LINK_EMULATIONX32 "} \
   %{shared:-shared} \
   %{!shared: \
     %{!static: \
       %{rdynamic:-export-dynamic} \
       %{" SPEC_32 ":-dynamic-linker " GNU_USER_DYNAMIC_LINKER32 "} \
-      %{" SPEC_64 ":-dynamic-linker " GNU_USER_DYNAMIC_LINKER64 "}} \
+      %{" SPEC_64 ":-dynamic-linker " GNU_USER_DYNAMIC_LINKER64 "} \
+      %{" SPEC_X32 ":-dynamic-linker " GNU_USER_DYNAMIC_LINKERX32 "}} \
     %{static:-static}}"
 
 /* Similar to standard GNU userspace, but adding -ffast-math support.  */
@@ -110,10 +116,13 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 
 #ifdef TARGET_LIBC_PROVIDES_SSP
 /* i386 glibc provides __stack_chk_guard in %gs:0x14,
+   x32 glibc provides it in %fs:0x18. 
    x86_64 glibc provides it in %fs:0x28.  */
-#define TARGET_THREAD_SSP_OFFSET	(TARGET_64BIT ? 0x28 : 0x14)
+#define TARGET_THREAD_SSP_OFFSET \
+  (TARGET_64BIT ? (TARGET_X32 ? 0x18 : 0x28) : 0x14)
 
 /* We steal the last transactional memory word.  */
 #define TARGET_CAN_SPLIT_STACK
-#define TARGET_THREAD_SPLIT_STACK_OFFSET (TARGET_64BIT ? 0x70 : 0x30)
+#define TARGET_THREAD_SPLIT_STACK_OFFSET \
+  (TARGET_64BIT ? (TARGET_X32 ? 0x40 : 0x70) : 0x30)
 #endif
diff --git a/gcc/config/i386/i386.h b/gcc/config/i386/i386.h
index a1ac6b6..8cef4e7 100644
--- a/gcc/config/i386/i386.h
+++ b/gcc/config/i386/i386.h
@@ -42,6 +42,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 /* Redefines for option macros.  */
 
 #define TARGET_64BIT	OPTION_ISA_64BIT
+#define TARGET_X32	OPTION_ISA_X32
 #define TARGET_MMX	OPTION_ISA_MMX
 #define TARGET_3DNOW	OPTION_ISA_3DNOW
 #define TARGET_3DNOW_A	OPTION_ISA_3DNOW_A
@@ -72,6 +73,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #define TARGET_RDRND	OPTION_ISA_RDRND
 #define TARGET_F16C	OPTION_ISA_F16C
 
+#define TARGET_LP64	(TARGET_64BIT && !TARGET_X32)
 
 /* SSE4.1 defines round instructions */
 #define	OPTION_MASK_ISA_ROUND	OPTION_MASK_ISA_SSE4_1
@@ -516,8 +518,8 @@ extern const char *host_detect_local_cpu (int argc, const char **argv);
 #define OPT_ARCH64 "!m32"
 #define OPT_ARCH32 "m32"
 #else
-#define OPT_ARCH64 "m64"
-#define OPT_ARCH32 "!m64"
+#define OPT_ARCH64 "m64|mx32"
+#define OPT_ARCH32 "m64|mx32:;"
 #endif
 
 /* Support for configure-time defaults of some command line options.
@@ -637,6 +639,8 @@ enum target_cpu_default
 
 #define SHORT_TYPE_SIZE 16
 #define INT_TYPE_SIZE 32
+#define LONG_TYPE_SIZE (TARGET_X32 ? 32 : BITS_PER_WORD)
+#define POINTER_SIZE (TARGET_X32 ? 32 : BITS_PER_WORD)
 #define LONG_LONG_TYPE_SIZE 64
 #define FLOAT_TYPE_SIZE 32
 #define DOUBLE_TYPE_SIZE 64
@@ -1742,6 +1746,13 @@ do {							\
    between pointers and any other objects of this machine mode.  */
 #define Pmode (TARGET_64BIT ? DImode : SImode)
 
+/* A C expression whose value is zero if pointers that need to be extended
+   from being `POINTER_SIZE' bits wide to `Pmode' are sign-extended and
+   greater then zero if they are zero-extended and less then zero if the
+   ptr_extend instruction should be used.  */
+
+#define POINTERS_EXTEND_UNSIGNED 1
+
 /* A function address in a call instruction
    is a byte address (for indexing purposes)
    so give the MEM rtx a byte's mode.  */
diff --git a/gcc/config/i386/i386.opt b/gcc/config/i386/i386.opt
index 9886b7b..8dea93e 100644
--- a/gcc/config/i386/i386.opt
+++ b/gcc/config/i386/i386.opt
@@ -398,9 +398,13 @@ Target RejectNegative Negative(m64) Report InverseMask(ISA_64BIT) Var(ix86_isa_f
 Generate 32bit i386 code
 
 m64
-Target RejectNegative Negative(m32) Report Mask(ISA_64BIT) Var(ix86_isa_flags) Save
+Target RejectNegative Negative(mx32) Report Mask(ISA_64BIT) Var(ix86_isa_flags) Save
 Generate 64bit x86-64 code
 
+mx32
+Target RejectNegative Negative(m32) Report Mask(ISA_X32) Var(ix86_isa_flags) Save
+Generate 32bit x86-64 code
+
 mmmx
 Target Report Mask(ISA_MMX) Var(ix86_isa_flags) Save
 Support MMX built-in functions
diff --git a/gcc/config/i386/kfreebsd-gnu64.h b/gcc/config/i386/kfreebsd-gnu64.h
index c3798a5..2085ca5 100644
--- a/gcc/config/i386/kfreebsd-gnu64.h
+++ b/gcc/config/i386/kfreebsd-gnu64.h
@@ -21,6 +21,8 @@ along with GCC; see the file COPYING3.  If not see
 
 #define GNU_USER_LINK_EMULATION32 "elf_i386_fbsd"
 #define GNU_USER_LINK_EMULATION64 "elf_x86_64_fbsd"
+#define GNU_USER_LINK_EMULATIONX32 "elf32_x86_64_fbsd"
 
 #define GLIBC_DYNAMIC_LINKER32 "/lib/ld.so.1"
 #define GLIBC_DYNAMIC_LINKER64 "/lib/ld-kfreebsd-x86-64.so.1"
+#define GLIBC_DYNAMIC_LINKERX32 "/lib/ld-kfreebsd-x32.so.1"
diff --git a/gcc/config/i386/linux64.h b/gcc/config/i386/linux64.h
index 5d33224..5b0a212 100644
--- a/gcc/config/i386/linux64.h
+++ b/gcc/config/i386/linux64.h
@@ -26,6 +26,8 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 
 #define GNU_USER_LINK_EMULATION32 "elf_i386"
 #define GNU_USER_LINK_EMULATION64 "elf_x86_64"
+#define GNU_USER_LINK_EMULATIONX32 "elf32_x86_64"
 
 #define GLIBC_DYNAMIC_LINKER32 "/lib/ld-linux.so.2"
 #define GLIBC_DYNAMIC_LINKER64 "/lib64/ld-linux-x86-64.so.2"
+#define GLIBC_DYNAMIC_LINKERX32 "/libx32/ld-linux-x32.so.2"
diff --git a/gcc/config/i386/t-linux-x32 b/gcc/config/i386/t-linux-x32
new file mode 100644
index 0000000..92acf91
--- /dev/null
+++ b/gcc/config/i386/t-linux-x32
@@ -0,0 +1,42 @@
+# Copyright (C) 2011 Free Software Foundation, Inc.
+#
+# This file is part of GCC.
+#
+# GCC is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GCC is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GCC; see the file COPYING3.  If not see
+# <http://www.gnu.org/licenses/>.
+
+# On Debian, Ubuntu and other derivative distributions, the 32bit libraries
+# are found in /lib32 and /usr/lib32, /lib64 and /usr/lib64 are symlinks to
+# /lib and /usr/lib, while other distributions install libraries into /lib64
+# and /usr/lib64.  The LSB does not enforce the use of /lib64 and /usr/lib64,
+# it doesn't tell anything about the 32bit libraries on those systems.  Set
+# MULTILIB_OSDIRNAMES according to what is found on the target.
+
+# To support i386, x86-64 and x32 libraries, the directory structrue
+# should be:
+#
+# 	/lib has i386 libraries.
+# 	/lib64 has x86-64 libraries.
+# 	/libx32 has x32 libraries.
+#
+MULTILIB_OPTIONS = m64/m32/mx32
+MULTILIB_DIRNAMES = 64 32 x32
+MULTILIB_OSDIRNAMES = ../lib64 $(if $(wildcard $(shell echo $(SYSTEM_HEADER_DIR))/../../usr/lib32),../lib32,../lib) ../libx32
+
+LIBGCC = stmp-multilib
+INSTALL_LIBGCC = install-multilib
+
+EXTRA_MULTILIB_PARTS=crtbegin.o crtend.o crtbeginS.o crtendS.o \
+		     crtbeginT.o crtprec32.o crtprec64.o crtprec80.o \
+		     crtfastmath.o
diff --git a/gcc/config/linux.h b/gcc/config/linux.h
index fc897b1..dbbeea5 100644
--- a/gcc/config/linux.h
+++ b/gcc/config/linux.h
@@ -77,9 +77,11 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #define UCLIBC_DYNAMIC_LINKER "/lib/ld-uClibc.so.0"
 #define UCLIBC_DYNAMIC_LINKER32 "/lib/ld-uClibc.so.0"
 #define UCLIBC_DYNAMIC_LINKER64 "/lib/ld64-uClibc.so.0"
+#define UCLIBC_DYNAMIC_LINKERX32 "/lib/ldx32-uClibc.so.0"
 #define BIONIC_DYNAMIC_LINKER "/system/bin/linker"
 #define BIONIC_DYNAMIC_LINKER32 "/system/bin/linker"
 #define BIONIC_DYNAMIC_LINKER64 "/system/bin/linker64"
+#define BIONIC_DYNAMIC_LINKERX32 "/system/bin/linkerx32"
 
 #define GNU_USER_DYNAMIC_LINKER						\
   CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER, UCLIBC_DYNAMIC_LINKER,	\
@@ -90,6 +92,9 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #define GNU_USER_DYNAMIC_LINKER64					\
   CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER64, UCLIBC_DYNAMIC_LINKER64, \
 			 BIONIC_DYNAMIC_LINKER64)
+#define GNU_USER_DYNAMIC_LINKERX32					\
+  CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKERX32, UCLIBC_DYNAMIC_LINKERX32, \
+			 BIONIC_DYNAMIC_LINKERX32)
 
 /* Determine whether the entire c99 runtime
    is present in the runtime library.  */
diff --git a/gcc/configure.ac b/gcc/configure.ac
index 5f3641b..a73f758 100644
--- a/gcc/configure.ac
+++ b/gcc/configure.ac
@@ -795,7 +795,7 @@ esac],
 [enable_languages=c])
 
 AC_ARG_WITH(multilib-list,
-[AS_HELP_STRING([--with-multilib-list], [select multilibs (SH only)])],
+[AS_HELP_STRING([--with-multilib-list], [select multilibs (SH and x86-64 only)])],
 :,
 with_multilib_list=default)
 
diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi
index 49aac95..a5d266c 100644
--- a/gcc/doc/install.texi
+++ b/gcc/doc/install.texi
@@ -1049,8 +1049,10 @@ sysv, aix.
 @item --with-multilib-list=@var{list}
 @itemx --without-multilib-list
 Specify what multilibs to build.
-Currently only implemented for sh*-*-*.
+Currently only implemented for sh*-*-* and x86-64-*-linux*.
 
+@table @code
+@item sh*-*-*
 @var{list} is a comma separated list of CPU names.  These must be of the
 form @code{sh*} or @code{m*} (in which case they match the compiler option
 for that processor).  The list should not contain any endian options -
@@ -1082,6 +1084,12 @@ only little endian SH4AL:
 --with-multilib-list=sh4al,!mb/m4al
 @end smallexample
 
+@item x86-64-*-linux*
+If @var{list} is @code{x32}, x32 run-time library will be enabled.  By
+default, x32 run-time library is disabled.
+
+@end table
+
 @item --with-endian=@var{endians}
 Specify what endians to use.
 Currently only implemented for sh*-*-*.
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 1fc4038..fd6711c 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -610,7 +610,7 @@ Objective-C and Objective-C++ Dialects}.
 -mpc32 -mpc64 -mpc80 -mstackrealign @gol
 -momit-leaf-frame-pointer  -mno-red-zone -mno-tls-direct-seg-refs @gol
 -mcmodel=@var{code-model} -mabi=@var{name} @gol
--m32  -m64 -mlarge-data-threshold=@var{num} @gol
+-m32 -m64 -mx32 -mlarge-data-threshold=@var{num} @gol
 -msse2avx -mfentry -m8bit-idiv @gol
 -mavx256-split-unaligned-load -mavx256-split-unaligned-store}
 
@@ -12851,15 +12851,19 @@ on AMD x86-64 processors in 64-bit environments.
 @table @gcctabopt
 @item -m32
 @itemx -m64
+@itemx -mx32
 @opindex m32
 @opindex m64
+@opindex mx32
 Generate code for a 32-bit or 64-bit environment.
-The 32-bit environment sets int, long and pointer to 32 bits and
+The @option{-m32} option sets int, long and pointer to 32 bits and
 generates code that runs on any i386 system.
-The 64-bit environment sets int to 32 bits and long and pointer
-to 64 bits and generates code for AMD's x86-64 architecture. For
-darwin only the -m64 option turns off the @option{-fno-pic} and
-@option{-mdynamic-no-pic} options.
+The @option{-m64} option sets int to 32 bits and long and pointer
+to 64 bits and generates code for AMD's x86-64 architecture.
+The @option{-mx32} option sets int, long and pointer to 32 bits and
+generates code for AMD's x86-64 architecture.
+For darwin only the @option{-m64} option turns off the @option{-fno-pic}
+and @option{-mdynamic-no-pic} options.
 
 @item -mno-red-zone
 @opindex mno-red-zone

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: PATCH [1/n] X32: Add initial -x32 support
  2011-07-06 16:40               ` H.J. Lu
@ 2011-07-07 13:03                 ` H.J. Lu
  2011-07-07 13:08                   ` Uros Bizjak
  2011-07-07 13:27                 ` Paolo Bonzini
  1 sibling, 1 reply; 26+ messages in thread
From: H.J. Lu @ 2011-07-07 13:03 UTC (permalink / raw)
  To: Uros Bizjak, GCC Patches

On Wed, Jul 6, 2011 at 9:22 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Wed, Jul 6, 2011 at 8:02 AM, Richard Guenther
> <richard.guenther@gmail.com> wrote:
>> On Wed, Jul 6, 2011 at 4:48 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
>>> Hi Paolo, DJ, Nathanael, Alexandre, Ralf,
>>>
>>> Is the change
>>> .
>>>        * configure.ac: Support --enable-x32.
>>>        * configure: Regenerated.
>>>
>>> diff --git a/gcc/configure.ac b/gcc/configure.ac
>>> index 5f3641b..bddabeb 100644
>>> --- a/gcc/configure.ac
>>> +++ b/gcc/configure.ac
>>> @@ -611,6 +611,11 @@ AC_ARG_ENABLE(multilib,
>>>  [], [enable_multilib=yes])
>>>  AC_SUBST(enable_multilib)
>>>
>>> +# With x32 support
>>> +AC_ARG_ENABLE(x32,
>>> +[  --enable-x32            enable x32 library support for multiple ABIs],
>>
>> Looks like a very very generic switch for a global configury ... we already
>> have --with-multilib-list (SH only), why not extend that to also work
>> for x86_64?
>>
>> Richard.
>>
>>> +[], [enable_x32=no])
>>> +
>>>  # Enable __cxa_atexit for C++.
>>>  AC_ARG_ENABLE(__cxa_atexit,
>>>  [AS_HELP_STRING([--enable-__cxa_atexit], [enable __cxa_atexit for C++])],
>>>
>>> OK?
>>>
>>> Thanks.
>>>
>
> Here is the updated patch to use --with-multilib-list=x32.
>
> Paolo, DJ, Nathanael, Alexandre, Ralf, Is the configure.ac change
>
> ---
>        * configure.ac: Mention x86-64 for --with-multilib-list.
>        * configure: Regenerated.
>
>        * doc/install.texi: Document --with-multilib-list=x32.
>
> diff --git a/gcc/configure.ac b/gcc/configure.ac
> index 5f3641b..a73f758 100644
> --- a/gcc/configure.ac
> +++ b/gcc/configure.ac
> @@ -795,7 +795,7 @@ esac],
>  [enable_languages=c])
>
>  AC_ARG_WITH(multilib-list,
> -[AS_HELP_STRING([--with-multilib-list], [select multilibs (SH only)])],
> +[AS_HELP_STRING([--with-multilib-list], [select multilibs (SH and
> x86-64 only)])],
>  :,
>  with_multilib_list=default)
>
> diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi
> index 49aac95..a5d266c 100644
> --- a/gcc/doc/install.texi
> +++ b/gcc/doc/install.texi
> @@ -1049,8 +1049,10 @@ sysv, aix.
>  @item --with-multilib-list=@var{list}
>  @itemx --without-multilib-list
>  Specify what multilibs to build.
> -Currently only implemented for sh*-*-*.
> +Currently only implemented for sh*-*-* and x86-64-*-linux*.
>
> +@table @code
> +@item sh*-*-*
>  @var{list} is a comma separated list of CPU names.  These must be of the
>  form @code{sh*} or @code{m*} (in which case they match the compiler option
>  for that processor).  The list should not contain any endian options -
> @@ -1082,6 +1084,12 @@ only little endian SH4AL:
>  --with-multilib-list=sh4al,!mb/m4al
>  @end smallexample
>
> +@item x86-64-*-linux*
> +If @var{list} is @code{x32}, x32 run-time library will be enabled.  By
> +default, x32 run-time library is disabled.
> +
> +@end table
> +
>  @item --with-endian=@var{endians}
>  Specify what endians to use.
>  Currently only implemented for sh*-*-*.
> ---
>
> OK?
>
> Thanks.
>
> --
> H.J.
> ---
> 2011-07-06  H.J. Lu  <hongjiu.lu@intel.com>
>
>        * config.gcc: Support --with-multilib-list=x32 for x86 Linux
>        targets.
>
>        * configure.ac: Mention x86-64 for --with-multilib-list.
>        * configure: Regenerated.
>
>        * config/i386/gnu-user64.h (SPEC_64): Support x32.
>        (SPEC_32): Likewise.
>        (ASM_SPEC): Likewise.
>        (LINK_SPEC): Likewise.
>        (TARGET_THREAD_SSP_OFFSET): Likewise.
>        (TARGET_THREAD_SPLIT_STACK_OFFSET): Likewise.
>        (SPEC_X32): New.
>
>        * config/i386/i386.h (TARGET_X32): New.
>        (TARGET_LP64): New.
>        (LONG_TYPE_SIZE): Likewise.
>        (POINTER_SIZE): Likewise.
>        (POINTERS_EXTEND_UNSIGNED): Likewise.
>        (OPT_ARCH64): Support x32.
>        (OPT_ARCH32): Likewise.
>
>        * config/i386/i386.opt (mx32): New.
>
>        * config/i386/kfreebsd-gnu64.h (GNU_USER_LINK_EMULATIONX32): New.
>        (GLIBC_DYNAMIC_LINKERX32): Likewise.
>        * config/i386/linux64.h (GNU_USER_LINK_EMULATIONX32): Likewise.
>        (GLIBC_DYNAMIC_LINKERX32): Likewise.
>
>        * config/i386/t-linux-x32: New.
>
>        * config/linux.h (UCLIBC_DYNAMIC_LINKERX32): New.
>        (BIONIC_DYNAMIC_LINKERX32): Likewise.
>        (GNU_USER_DYNAMIC_LINKERX32): Likewise.
>
>        * doc/install.texi: Document --with-multilib-list=x32.
>
>        * doc/invoke.texi: Document -mx32.
>

Hi Uros,

This new version only adds a comment to configure.ac.  OK to install?

Thanks.

-- 
H.J.

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: PATCH [1/n] X32: Add initial -x32 support
  2011-07-07 13:03                 ` H.J. Lu
@ 2011-07-07 13:08                   ` Uros Bizjak
  0 siblings, 0 replies; 26+ messages in thread
From: Uros Bizjak @ 2011-07-07 13:08 UTC (permalink / raw)
  To: H.J. Lu; +Cc: GCC Patches

On Thu, Jul 7, 2011 at 2:59 PM, H.J. Lu <hjl.tools@gmail.com> wrote:

>>>> Hi Paolo, DJ, Nathanael, Alexandre, Ralf,
>>>>
>>>> Is the change
>>>> .
>>>>        * configure.ac: Support --enable-x32.
>>>>        * configure: Regenerated.
>>>>
>>>> diff --git a/gcc/configure.ac b/gcc/configure.ac
>>>> index 5f3641b..bddabeb 100644
>>>> --- a/gcc/configure.ac
>>>> +++ b/gcc/configure.ac
>>>> @@ -611,6 +611,11 @@ AC_ARG_ENABLE(multilib,
>>>>  [], [enable_multilib=yes])
>>>>  AC_SUBST(enable_multilib)
>>>>
>>>> +# With x32 support
>>>> +AC_ARG_ENABLE(x32,
>>>> +[  --enable-x32            enable x32 library support for multiple ABIs],
>>>
>>> Looks like a very very generic switch for a global configury ... we already
>>> have --with-multilib-list (SH only), why not extend that to also work
>>> for x86_64?
>>>
>>> Richard.
>>>
>>>> +[], [enable_x32=no])
>>>> +
>>>>  # Enable __cxa_atexit for C++.
>>>>  AC_ARG_ENABLE(__cxa_atexit,
>>>>  [AS_HELP_STRING([--enable-__cxa_atexit], [enable __cxa_atexit for C++])],
>>>>
>>>> OK?
>>>>
>>>> Thanks.
>>>>
>>
>> Here is the updated patch to use --with-multilib-list=x32.
>>
>> Paolo, DJ, Nathanael, Alexandre, Ralf, Is the configure.ac change
>>
>> ---
>>        * configure.ac: Mention x86-64 for --with-multilib-list.
>>        * configure: Regenerated.
>>
>>        * doc/install.texi: Document --with-multilib-list=x32.
>>
>> diff --git a/gcc/configure.ac b/gcc/configure.ac
>> index 5f3641b..a73f758 100644
>> --- a/gcc/configure.ac
>> +++ b/gcc/configure.ac
>> @@ -795,7 +795,7 @@ esac],
>>  [enable_languages=c])
>>
>>  AC_ARG_WITH(multilib-list,
>> -[AS_HELP_STRING([--with-multilib-list], [select multilibs (SH only)])],
>> +[AS_HELP_STRING([--with-multilib-list], [select multilibs (SH and
>> x86-64 only)])],
>>  :,
>>  with_multilib_list=default)
>>
>> diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi
>> index 49aac95..a5d266c 100644
>> --- a/gcc/doc/install.texi
>> +++ b/gcc/doc/install.texi
>> @@ -1049,8 +1049,10 @@ sysv, aix.
>>  @item --with-multilib-list=@var{list}
>>  @itemx --without-multilib-list
>>  Specify what multilibs to build.
>> -Currently only implemented for sh*-*-*.
>> +Currently only implemented for sh*-*-* and x86-64-*-linux*.
>>
>> +@table @code
>> +@item sh*-*-*
>>  @var{list} is a comma separated list of CPU names.  These must be of the
>>  form @code{sh*} or @code{m*} (in which case they match the compiler option
>>  for that processor).  The list should not contain any endian options -
>> @@ -1082,6 +1084,12 @@ only little endian SH4AL:
>>  --with-multilib-list=sh4al,!mb/m4al
>>  @end smallexample
>>
>> +@item x86-64-*-linux*
>> +If @var{list} is @code{x32}, x32 run-time library will be enabled.  By
>> +default, x32 run-time library is disabled.
>> +
>> +@end table
>> +
>>  @item --with-endian=@var{endians}
>>  Specify what endians to use.
>>  Currently only implemented for sh*-*-*.
>> ---
>>
>> OK?
>>
>> Thanks.
>>
>> --
>> H.J.
>> ---
>> 2011-07-06  H.J. Lu  <hongjiu.lu@intel.com>
>>
>>        * config.gcc: Support --with-multilib-list=x32 for x86 Linux
>>        targets.
>>
>>        * configure.ac: Mention x86-64 for --with-multilib-list.
>>        * configure: Regenerated.
>>
>>        * config/i386/gnu-user64.h (SPEC_64): Support x32.
>>        (SPEC_32): Likewise.
>>        (ASM_SPEC): Likewise.
>>        (LINK_SPEC): Likewise.
>>        (TARGET_THREAD_SSP_OFFSET): Likewise.
>>        (TARGET_THREAD_SPLIT_STACK_OFFSET): Likewise.
>>        (SPEC_X32): New.
>>
>>        * config/i386/i386.h (TARGET_X32): New.
>>        (TARGET_LP64): New.
>>        (LONG_TYPE_SIZE): Likewise.
>>        (POINTER_SIZE): Likewise.
>>        (POINTERS_EXTEND_UNSIGNED): Likewise.
>>        (OPT_ARCH64): Support x32.
>>        (OPT_ARCH32): Likewise.
>>
>>        * config/i386/i386.opt (mx32): New.
>>
>>        * config/i386/kfreebsd-gnu64.h (GNU_USER_LINK_EMULATIONX32): New.
>>        (GLIBC_DYNAMIC_LINKERX32): Likewise.
>>        * config/i386/linux64.h (GNU_USER_LINK_EMULATIONX32): Likewise.
>>        (GLIBC_DYNAMIC_LINKERX32): Likewise.
>>
>>        * config/i386/t-linux-x32: New.
>>
>>        * config/linux.h (UCLIBC_DYNAMIC_LINKERX32): New.
>>        (BIONIC_DYNAMIC_LINKERX32): Likewise.
>>        (GNU_USER_DYNAMIC_LINKERX32): Likewise.
>>
>>        * doc/install.texi: Document --with-multilib-list=x32.
>>
>>        * doc/invoke.texi: Document -mx32.
>>
>
> Hi Uros,
>
> This new version only adds a comment to configure.ac.  OK to install?

OK.

Thanks,
Uros.

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: PATCH [1/n] X32: Add initial -x32 support
  2011-07-06 16:40               ` H.J. Lu
  2011-07-07 13:03                 ` H.J. Lu
@ 2011-07-07 13:27                 ` Paolo Bonzini
  2011-07-07 15:10                   ` H.J. Lu
  1 sibling, 1 reply; 26+ messages in thread
From: Paolo Bonzini @ 2011-07-07 13:27 UTC (permalink / raw)
  To: H.J. Lu
  Cc: Richard Guenther, DJ Delorie, Alexandre Oliva, Ralf Wildenhues,
	neroden, gcc-patches

Did you even _think_ of looking at the sh configury, and do something
vaguely similar for x86?

You should not duplicate t-linux64 at all.  Instead, in config.gcc set
m64/m32 as the default value for with_multilib_list on i386 biarch and
x86_64.  Pass $with_multilib_list to t-linux64 using
TM_MULTILIB_CONFIG.  Then, do something like

comma=,
MULTILIB_OPTIONS    = $(subst $(comma),/,@TM_MULTILIB_CONFIG@)
MULTILIB_DIRNAMES   = $(patsubst m%, %, $(subst /, ,$(MULTILIB_OPTIONS)))
MULTILIB_OSDIRNAMES  = 64=../lib64
MULTILIB_OSDIRNAMES += 32=$(if $(wildcard $(shell echo
$(SYSTEM_HEADER_DIR))/../../usr/lib32),../lib32,../lib)
MULTILIB_OSDIRNAMES += x32=../libx32

in config/t-linux64.  (Each on one line, apologies for any wrapping)

The option will be used as --with-multilib-list=m64,m32,mx32 (allowing
the user to omit some of the variants, too).

Paolo

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: PATCH [1/n] X32: Add initial -x32 support
  2011-07-07 13:27                 ` Paolo Bonzini
@ 2011-07-07 15:10                   ` H.J. Lu
  2011-07-07 15:14                     ` Uros Bizjak
  0 siblings, 1 reply; 26+ messages in thread
From: H.J. Lu @ 2011-07-07 15:10 UTC (permalink / raw)
  To: Paolo Bonzini, Uros Bizjak
  Cc: Richard Guenther, DJ Delorie, Alexandre Oliva, Ralf Wildenhues,
	neroden, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 2433 bytes --]

On Thu, Jul 7, 2011 at 6:21 AM, Paolo Bonzini <bonzini@gnu.org> wrote:
> Did you even _think_ of looking at the sh configury, and do something
> vaguely similar for x86?
>
> You should not duplicate t-linux64 at all.  Instead, in config.gcc set
> m64/m32 as the default value for with_multilib_list on i386 biarch and
> x86_64.  Pass $with_multilib_list to t-linux64 using
> TM_MULTILIB_CONFIG.  Then, do something like
>
> comma=,
> MULTILIB_OPTIONS    = $(subst $(comma),/,@TM_MULTILIB_CONFIG@)
> MULTILIB_DIRNAMES   = $(patsubst m%, %, $(subst /, ,$(MULTILIB_OPTIONS)))
> MULTILIB_OSDIRNAMES  = 64=../lib64
> MULTILIB_OSDIRNAMES += 32=$(if $(wildcard $(shell echo
> $(SYSTEM_HEADER_DIR))/../../usr/lib32),../lib32,../lib)
> MULTILIB_OSDIRNAMES += x32=../libx32
>
> in config/t-linux64.  (Each on one line, apologies for any wrapping)
>
> The option will be used as --with-multilib-list=m64,m32,mx32 (allowing
> the user to omit some of the variants, too).
>

This is an excellent suggestion.  Here is the updated patch. It
uses TM_MULTILIB_CONFIG and removes config/i386/t-linux-x32.

Uros, is this OK for trunk to replace the patch you approved earlier?

Thanks.

-- 
H.J.
---
2011-07-07  H.J. Lu  <hongjiu.lu@intel.com>

	* config.gcc: Support --with-multilib-list for x86 Linux
	targets.

	* configure.ac: Mention x86-64 for --with-multilib-list.
	* configure: Regenerated.

	* config/i386/gnu-user64.h (SPEC_64): Support x32.
	(SPEC_32): Likewise.
	(ASM_SPEC): Likewise.
	(LINK_SPEC): Likewise.
	(TARGET_THREAD_SSP_OFFSET): Likewise.
	(TARGET_THREAD_SPLIT_STACK_OFFSET): Likewise.
	(SPEC_X32): New.

	* config/i386/i386.h (TARGET_X32): New.
	(TARGET_LP64): New.
	(LONG_TYPE_SIZE): Likewise.
	(POINTER_SIZE): Likewise.
	(POINTERS_EXTEND_UNSIGNED): Likewise.
	(OPT_ARCH64): Support x32.
	(OPT_ARCH32): Likewise.

	* config/i386/i386.opt (mx32): New.

	* config/i386/kfreebsd-gnu64.h (GNU_USER_LINK_EMULATIONX32): New.
	(GLIBC_DYNAMIC_LINKERX32): Likewise.
	* config/i386/linux64.h (GNU_USER_LINK_EMULATIONX32): Likewise.
	(GLIBC_DYNAMIC_LINKERX32): Likewise.

	* config/linux.h (UCLIBC_DYNAMIC_LINKERX32): New.
	(BIONIC_DYNAMIC_LINKERX32): Likewise.
	(GNU_USER_DYNAMIC_LINKERX32): Likewise.

	* config/i386/t-linux64: Support TM_MULTILIB_CONFIG.

	* doc/install.texi: Document --with-multilib-list for
	Linux/x86-64.

	* doc/invoke.texi: Document -mx32.

[-- Attachment #2: gcc-x32-5.patch --]
[-- Type: text/plain, Size: 14841 bytes --]

2011-07-07  H.J. Lu  <hongjiu.lu@intel.com>

	* config.gcc: Support --with-multilib-list for x86 Linux
	targets.

	* configure.ac: Mention x86-64 for --with-multilib-list.
	* configure: Regenerated.

	* config/i386/gnu-user64.h (SPEC_64): Support x32.
	(SPEC_32): Likewise.
	(ASM_SPEC): Likewise.
	(LINK_SPEC): Likewise.
	(TARGET_THREAD_SSP_OFFSET): Likewise.
	(TARGET_THREAD_SPLIT_STACK_OFFSET): Likewise.
	(SPEC_X32): New.

	* config/i386/i386.h (TARGET_X32): New.
	(TARGET_LP64): New.
	(LONG_TYPE_SIZE): Likewise.
	(POINTER_SIZE): Likewise.
	(POINTERS_EXTEND_UNSIGNED): Likewise.
	(OPT_ARCH64): Support x32.
	(OPT_ARCH32): Likewise.

	* config/i386/i386.opt (mx32): New.

	* config/i386/kfreebsd-gnu64.h (GNU_USER_LINK_EMULATIONX32): New.
	(GLIBC_DYNAMIC_LINKERX32): Likewise.
	* config/i386/linux64.h (GNU_USER_LINK_EMULATIONX32): Likewise.
	(GLIBC_DYNAMIC_LINKERX32): Likewise.

	* config/linux.h (UCLIBC_DYNAMIC_LINKERX32): New.
	(BIONIC_DYNAMIC_LINKERX32): Likewise.
	(GNU_USER_DYNAMIC_LINKERX32): Likewise.

	* config/i386/t-linux64: Support TM_MULTILIB_CONFIG.

	* doc/install.texi: Document --with-multilib-list for
	Linux/x86-64.

	* doc/invoke.texi: Document -mx32.

diff --git a/gcc/config.gcc b/gcc/config.gcc
index c77f40b..449409e 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -1280,6 +1280,22 @@ i[34567]86-*-linux* | i[34567]86-*-kfreebsd*-gnu | i[34567]86-*-knetbsd*-gnu | i
 			tm_file="${tm_file} i386/x86-64.h i386/gnu-user64.h i386/linux64.h"
 			tm_defines="${tm_defines} TARGET_BI_ARCH=1"
 			tmake_file="${tmake_file} i386/t-linux64"
+			x86_multilibs="${with_multilib_list}"
+			if test "$x86_multilibs" = "default"; then
+				x86_multilibs="m64,m32"
+			fi
+			x86_multilibs=`echo $x86_multilibs | sed -e 's/,/ /g'`
+			for x86_multilib in ${x86_multilibs}; do
+				case ${x86_multilib} in
+				m32 | m64 | mx32)
+					TM_MULTILIB_CONFIG="${TM_MULTILIB_CONFIG},${x86_multilib}"
+					;;
+				*)
+					echo "--with-multilib-list=${x86_with_multilib} not supported."
+					exit 1
+				esac
+			done
+			TM_MULTILIB_CONFIG=`echo $TM_MULTILIB_CONFIG | sed 's/^,//'`
 			need_64bit_hwint=yes
 			need_64bit_isa=yes
 			case X"${with_cpu}" in
@@ -1318,6 +1334,22 @@ x86_64-*-linux* | x86_64-*-kfreebsd*-gnu | x86_64-*-knetbsd*-gnu)
 	x86_64-*-knetbsd*-gnu) tm_file="${tm_file} knetbsd-gnu.h" ;;
 	esac
 	tmake_file="${tmake_file} i386/t-linux64 i386/t-crtstuff i386/t-crtpc i386/t-crtfm t-dfprules"
+	x86_multilibs="${with_multilib_list}"
+	if test "$x86_multilibs" = "default"; then
+		x86_multilibs="m64,m32"
+	fi
+	x86_multilibs=`echo $x86_multilibs | sed -e 's/,/ /g'`
+	for x86_multilib in ${x86_multilibs}; do
+		case ${x86_multilib} in
+		m32 | m64 | mx32)
+			TM_MULTILIB_CONFIG="${TM_MULTILIB_CONFIG},${x86_multilib}"
+			;;
+		*)
+			echo "--with-multilib-list=${x86_with_multilib} not supported."
+			exit 1
+		esac
+	done
+	TM_MULTILIB_CONFIG=`echo $TM_MULTILIB_CONFIG | sed 's/^,//'`
 	;;
 i[34567]86-pc-msdosdjgpp*)
 	xm_file=i386/xm-djgpp.h
diff --git a/gcc/config/i386/gnu-user64.h b/gcc/config/i386/gnu-user64.h
index b069975..954f3b2 100644
--- a/gcc/config/i386/gnu-user64.h
+++ b/gcc/config/i386/gnu-user64.h
@@ -58,25 +58,31 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 
 #if TARGET_64BIT_DEFAULT
 #define SPEC_32 "m32"
-#define SPEC_64 "!m32"
+#define SPEC_64 "m32|mx32:;"
+#define SPEC_X32 "mx32"
 #else
-#define SPEC_32 "!m64"
+#define SPEC_32 "m64|mx32:;"
 #define SPEC_64 "m64"
+#define SPEC_X32 "mx32"
 #endif
 
 #undef ASM_SPEC
-#define ASM_SPEC "%{" SPEC_32 ":--32} %{" SPEC_64 ":--64} \
+#define ASM_SPEC "%{" SPEC_32 ":--32} \
+ %{" SPEC_64 ":--64} \
+ %{" SPEC_X32 ":--x32} \
  %{!mno-sse2avx:%{mavx:-msse2avx}} %{msse2avx:%{!mavx:-msse2avx}}"
 
 #undef	LINK_SPEC
 #define LINK_SPEC "%{" SPEC_64 ":-m " GNU_USER_LINK_EMULATION64 "} \
                    %{" SPEC_32 ":-m " GNU_USER_LINK_EMULATION32 "} \
+                   %{" SPEC_X32 ":-m " GNU_USER_LINK_EMULATIONX32 "} \
   %{shared:-shared} \
   %{!shared: \
     %{!static: \
       %{rdynamic:-export-dynamic} \
       %{" SPEC_32 ":-dynamic-linker " GNU_USER_DYNAMIC_LINKER32 "} \
-      %{" SPEC_64 ":-dynamic-linker " GNU_USER_DYNAMIC_LINKER64 "}} \
+      %{" SPEC_64 ":-dynamic-linker " GNU_USER_DYNAMIC_LINKER64 "} \
+      %{" SPEC_X32 ":-dynamic-linker " GNU_USER_DYNAMIC_LINKERX32 "}} \
     %{static:-static}}"
 
 /* Similar to standard GNU userspace, but adding -ffast-math support.  */
@@ -110,10 +116,13 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 
 #ifdef TARGET_LIBC_PROVIDES_SSP
 /* i386 glibc provides __stack_chk_guard in %gs:0x14,
+   x32 glibc provides it in %fs:0x18. 
    x86_64 glibc provides it in %fs:0x28.  */
-#define TARGET_THREAD_SSP_OFFSET	(TARGET_64BIT ? 0x28 : 0x14)
+#define TARGET_THREAD_SSP_OFFSET \
+  (TARGET_64BIT ? (TARGET_X32 ? 0x18 : 0x28) : 0x14)
 
 /* We steal the last transactional memory word.  */
 #define TARGET_CAN_SPLIT_STACK
-#define TARGET_THREAD_SPLIT_STACK_OFFSET (TARGET_64BIT ? 0x70 : 0x30)
+#define TARGET_THREAD_SPLIT_STACK_OFFSET \
+  (TARGET_64BIT ? (TARGET_X32 ? 0x40 : 0x70) : 0x30)
 #endif
diff --git a/gcc/config/i386/i386.h b/gcc/config/i386/i386.h
index a1ac6b6..8cef4e7 100644
--- a/gcc/config/i386/i386.h
+++ b/gcc/config/i386/i386.h
@@ -42,6 +42,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 /* Redefines for option macros.  */
 
 #define TARGET_64BIT	OPTION_ISA_64BIT
+#define TARGET_X32	OPTION_ISA_X32
 #define TARGET_MMX	OPTION_ISA_MMX
 #define TARGET_3DNOW	OPTION_ISA_3DNOW
 #define TARGET_3DNOW_A	OPTION_ISA_3DNOW_A
@@ -72,6 +73,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #define TARGET_RDRND	OPTION_ISA_RDRND
 #define TARGET_F16C	OPTION_ISA_F16C
 
+#define TARGET_LP64	(TARGET_64BIT && !TARGET_X32)
 
 /* SSE4.1 defines round instructions */
 #define	OPTION_MASK_ISA_ROUND	OPTION_MASK_ISA_SSE4_1
@@ -516,8 +518,8 @@ extern const char *host_detect_local_cpu (int argc, const char **argv);
 #define OPT_ARCH64 "!m32"
 #define OPT_ARCH32 "m32"
 #else
-#define OPT_ARCH64 "m64"
-#define OPT_ARCH32 "!m64"
+#define OPT_ARCH64 "m64|mx32"
+#define OPT_ARCH32 "m64|mx32:;"
 #endif
 
 /* Support for configure-time defaults of some command line options.
@@ -637,6 +639,8 @@ enum target_cpu_default
 
 #define SHORT_TYPE_SIZE 16
 #define INT_TYPE_SIZE 32
+#define LONG_TYPE_SIZE (TARGET_X32 ? 32 : BITS_PER_WORD)
+#define POINTER_SIZE (TARGET_X32 ? 32 : BITS_PER_WORD)
 #define LONG_LONG_TYPE_SIZE 64
 #define FLOAT_TYPE_SIZE 32
 #define DOUBLE_TYPE_SIZE 64
@@ -1742,6 +1746,13 @@ do {							\
    between pointers and any other objects of this machine mode.  */
 #define Pmode (TARGET_64BIT ? DImode : SImode)
 
+/* A C expression whose value is zero if pointers that need to be extended
+   from being `POINTER_SIZE' bits wide to `Pmode' are sign-extended and
+   greater then zero if they are zero-extended and less then zero if the
+   ptr_extend instruction should be used.  */
+
+#define POINTERS_EXTEND_UNSIGNED 1
+
 /* A function address in a call instruction
    is a byte address (for indexing purposes)
    so give the MEM rtx a byte's mode.  */
diff --git a/gcc/config/i386/i386.opt b/gcc/config/i386/i386.opt
index 9886b7b..8dea93e 100644
--- a/gcc/config/i386/i386.opt
+++ b/gcc/config/i386/i386.opt
@@ -398,9 +398,13 @@ Target RejectNegative Negative(m64) Report InverseMask(ISA_64BIT) Var(ix86_isa_f
 Generate 32bit i386 code
 
 m64
-Target RejectNegative Negative(m32) Report Mask(ISA_64BIT) Var(ix86_isa_flags) Save
+Target RejectNegative Negative(mx32) Report Mask(ISA_64BIT) Var(ix86_isa_flags) Save
 Generate 64bit x86-64 code
 
+mx32
+Target RejectNegative Negative(m32) Report Mask(ISA_X32) Var(ix86_isa_flags) Save
+Generate 32bit x86-64 code
+
 mmmx
 Target Report Mask(ISA_MMX) Var(ix86_isa_flags) Save
 Support MMX built-in functions
diff --git a/gcc/config/i386/kfreebsd-gnu64.h b/gcc/config/i386/kfreebsd-gnu64.h
index c3798a5..2085ca5 100644
--- a/gcc/config/i386/kfreebsd-gnu64.h
+++ b/gcc/config/i386/kfreebsd-gnu64.h
@@ -21,6 +21,8 @@ along with GCC; see the file COPYING3.  If not see
 
 #define GNU_USER_LINK_EMULATION32 "elf_i386_fbsd"
 #define GNU_USER_LINK_EMULATION64 "elf_x86_64_fbsd"
+#define GNU_USER_LINK_EMULATIONX32 "elf32_x86_64_fbsd"
 
 #define GLIBC_DYNAMIC_LINKER32 "/lib/ld.so.1"
 #define GLIBC_DYNAMIC_LINKER64 "/lib/ld-kfreebsd-x86-64.so.1"
+#define GLIBC_DYNAMIC_LINKERX32 "/lib/ld-kfreebsd-x32.so.1"
diff --git a/gcc/config/i386/linux64.h b/gcc/config/i386/linux64.h
index 5d33224..5b0a212 100644
--- a/gcc/config/i386/linux64.h
+++ b/gcc/config/i386/linux64.h
@@ -26,6 +26,8 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 
 #define GNU_USER_LINK_EMULATION32 "elf_i386"
 #define GNU_USER_LINK_EMULATION64 "elf_x86_64"
+#define GNU_USER_LINK_EMULATIONX32 "elf32_x86_64"
 
 #define GLIBC_DYNAMIC_LINKER32 "/lib/ld-linux.so.2"
 #define GLIBC_DYNAMIC_LINKER64 "/lib64/ld-linux-x86-64.so.2"
+#define GLIBC_DYNAMIC_LINKERX32 "/libx32/ld-linux-x32.so.2"
diff --git a/gcc/config/i386/t-linux64 b/gcc/config/i386/t-linux64
index 5d5a476..ea8f5e9 100644
--- a/gcc/config/i386/t-linux64
+++ b/gcc/config/i386/t-linux64
@@ -1,4 +1,5 @@
-# Copyright (C) 2002, 2005, 2007, 2008 Free Software Foundation, Inc.
+# Copyright (C) 2002, 2005, 2007, 2008, 2011
+# Free Software Foundation, Inc.
 #
 # This file is part of GCC.
 #
@@ -23,9 +24,19 @@
 # it doesn't tell anything about the 32bit libraries on those systems.  Set
 # MULTILIB_OSDIRNAMES according to what is found on the target.
 
-MULTILIB_OPTIONS = m64/m32
-MULTILIB_DIRNAMES = 64 32 
-MULTILIB_OSDIRNAMES = ../lib64 $(if $(wildcard $(shell echo $(SYSTEM_HEADER_DIR))/../../usr/lib32),../lib32,../lib)
+# To support i386, x86-64 and x32 libraries, the directory structrue
+# should be:
+#
+# 	/lib has i386 libraries.
+# 	/lib64 has x86-64 libraries.
+# 	/libx32 has x32 libraries.
+#
+comma=,
+MULTILIB_OPTIONS    = $(subst $(comma),/,$(TM_MULTILIB_CONFIG))
+MULTILIB_DIRNAMES   = $(patsubst m%, %, $(subst /, ,$(MULTILIB_OPTIONS)))
+MULTILIB_OSDIRNAMES = m64=../lib64
+MULTILIB_OSDIRNAMES+= m32=$(if $(wildcard $(shell echo $(SYSTEM_HEADER_DIR))/../../usr/lib32),../lib32,../lib)
+MULTILIB_OSDIRNAMES+= mx32=../libx32
 
 LIBGCC = stmp-multilib
 INSTALL_LIBGCC = install-multilib
diff --git a/gcc/config/linux.h b/gcc/config/linux.h
index fc897b1..dbbeea5 100644
--- a/gcc/config/linux.h
+++ b/gcc/config/linux.h
@@ -77,9 +77,11 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #define UCLIBC_DYNAMIC_LINKER "/lib/ld-uClibc.so.0"
 #define UCLIBC_DYNAMIC_LINKER32 "/lib/ld-uClibc.so.0"
 #define UCLIBC_DYNAMIC_LINKER64 "/lib/ld64-uClibc.so.0"
+#define UCLIBC_DYNAMIC_LINKERX32 "/lib/ldx32-uClibc.so.0"
 #define BIONIC_DYNAMIC_LINKER "/system/bin/linker"
 #define BIONIC_DYNAMIC_LINKER32 "/system/bin/linker"
 #define BIONIC_DYNAMIC_LINKER64 "/system/bin/linker64"
+#define BIONIC_DYNAMIC_LINKERX32 "/system/bin/linkerx32"
 
 #define GNU_USER_DYNAMIC_LINKER						\
   CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER, UCLIBC_DYNAMIC_LINKER,	\
@@ -90,6 +92,9 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #define GNU_USER_DYNAMIC_LINKER64					\
   CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER64, UCLIBC_DYNAMIC_LINKER64, \
 			 BIONIC_DYNAMIC_LINKER64)
+#define GNU_USER_DYNAMIC_LINKERX32					\
+  CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKERX32, UCLIBC_DYNAMIC_LINKERX32, \
+			 BIONIC_DYNAMIC_LINKERX32)
 
 /* Determine whether the entire c99 runtime
    is present in the runtime library.  */
diff --git a/gcc/configure.ac b/gcc/configure.ac
index 5f3641b..a73f758 100644
--- a/gcc/configure.ac
+++ b/gcc/configure.ac
@@ -795,7 +795,7 @@ esac],
 [enable_languages=c])
 
 AC_ARG_WITH(multilib-list,
-[AS_HELP_STRING([--with-multilib-list], [select multilibs (SH only)])],
+[AS_HELP_STRING([--with-multilib-list], [select multilibs (SH and x86-64 only)])],
 :,
 with_multilib_list=default)
 
diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi
index 78a6ee8..f14ba0b 100644
--- a/gcc/doc/install.texi
+++ b/gcc/doc/install.texi
@@ -1049,8 +1049,10 @@ sysv, aix.
 @item --with-multilib-list=@var{list}
 @itemx --without-multilib-list
 Specify what multilibs to build.
-Currently only implemented for sh*-*-*.
+Currently only implemented for sh*-*-* and x86-64-*-linux*.
 
+@table @code
+@item sh*-*-*
 @var{list} is a comma separated list of CPU names.  These must be of the
 form @code{sh*} or @code{m*} (in which case they match the compiler option
 for that processor).  The list should not contain any endian options -
@@ -1082,6 +1084,16 @@ only little endian SH4AL:
 --with-multilib-list=sh4al,!mb/m4al
 @end smallexample
 
+@item x86-64-*-linux*
+@var{list} is a comma separated list of @code{m32}, @code{m64} and
+@code{mx32} to enable 32-bit, 64-bit and x32 run-time libraries,
+respectively.  If @var{list} is empty, then there will be no multilibs
+and only the default run-time library will be enabled.
+
+If @option{--with-multilib-list} is not given, then only 32-bit and
+64-bit run-time libraries will be enabled.
+@end table
+
 @item --with-endian=@var{endians}
 Specify what endians to use.
 Currently only implemented for sh*-*-*.
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 1fc4038..fd6711c 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -610,7 +610,7 @@ Objective-C and Objective-C++ Dialects}.
 -mpc32 -mpc64 -mpc80 -mstackrealign @gol
 -momit-leaf-frame-pointer  -mno-red-zone -mno-tls-direct-seg-refs @gol
 -mcmodel=@var{code-model} -mabi=@var{name} @gol
--m32  -m64 -mlarge-data-threshold=@var{num} @gol
+-m32 -m64 -mx32 -mlarge-data-threshold=@var{num} @gol
 -msse2avx -mfentry -m8bit-idiv @gol
 -mavx256-split-unaligned-load -mavx256-split-unaligned-store}
 
@@ -12851,15 +12851,19 @@ on AMD x86-64 processors in 64-bit environments.
 @table @gcctabopt
 @item -m32
 @itemx -m64
+@itemx -mx32
 @opindex m32
 @opindex m64
+@opindex mx32
 Generate code for a 32-bit or 64-bit environment.
-The 32-bit environment sets int, long and pointer to 32 bits and
+The @option{-m32} option sets int, long and pointer to 32 bits and
 generates code that runs on any i386 system.
-The 64-bit environment sets int to 32 bits and long and pointer
-to 64 bits and generates code for AMD's x86-64 architecture. For
-darwin only the -m64 option turns off the @option{-fno-pic} and
-@option{-mdynamic-no-pic} options.
+The @option{-m64} option sets int to 32 bits and long and pointer
+to 64 bits and generates code for AMD's x86-64 architecture.
+The @option{-mx32} option sets int, long and pointer to 32 bits and
+generates code for AMD's x86-64 architecture.
+For darwin only the @option{-m64} option turns off the @option{-fno-pic}
+and @option{-mdynamic-no-pic} options.
 
 @item -mno-red-zone
 @opindex mno-red-zone

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: PATCH [1/n] X32: Add initial -x32 support
  2011-07-07 15:10                   ` H.J. Lu
@ 2011-07-07 15:14                     ` Uros Bizjak
  2011-07-07 15:38                       ` Paolo Bonzini
  0 siblings, 1 reply; 26+ messages in thread
From: Uros Bizjak @ 2011-07-07 15:14 UTC (permalink / raw)
  To: H.J. Lu
  Cc: Paolo Bonzini, Richard Guenther, DJ Delorie, Alexandre Oliva,
	Ralf Wildenhues, neroden, gcc-patches

On Thu, Jul 7, 2011 at 5:02 PM, H.J. Lu <hjl.tools@gmail.com> wrote:

>> Did you even _think_ of looking at the sh configury, and do something
>> vaguely similar for x86?
>>
>> You should not duplicate t-linux64 at all.  Instead, in config.gcc set
>> m64/m32 as the default value for with_multilib_list on i386 biarch and
>> x86_64.  Pass $with_multilib_list to t-linux64 using
>> TM_MULTILIB_CONFIG.  Then, do something like
>>
>> comma=,
>> MULTILIB_OPTIONS    = $(subst $(comma),/,@TM_MULTILIB_CONFIG@)
>> MULTILIB_DIRNAMES   = $(patsubst m%, %, $(subst /, ,$(MULTILIB_OPTIONS)))
>> MULTILIB_OSDIRNAMES  = 64=../lib64
>> MULTILIB_OSDIRNAMES += 32=$(if $(wildcard $(shell echo
>> $(SYSTEM_HEADER_DIR))/../../usr/lib32),../lib32,../lib)
>> MULTILIB_OSDIRNAMES += x32=../libx32
>>
>> in config/t-linux64.  (Each on one line, apologies for any wrapping)
>>
>> The option will be used as --with-multilib-list=m64,m32,mx32 (allowing
>> the user to omit some of the variants, too).
>>
>
> This is an excellent suggestion.  Here is the updated patch. It
> uses TM_MULTILIB_CONFIG and removes config/i386/t-linux-x32.
>
> Uros, is this OK for trunk to replace the patch you approved earlier?

Er, the approval was fo x86 parts, I will leave approval for build
parts to Paolo.

Thanks,
Uros.

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: PATCH [1/n] X32: Add initial -x32 support
  2011-07-07 15:14                     ` Uros Bizjak
@ 2011-07-07 15:38                       ` Paolo Bonzini
  0 siblings, 0 replies; 26+ messages in thread
From: Paolo Bonzini @ 2011-07-07 15:38 UTC (permalink / raw)
  To: Uros Bizjak
  Cc: H.J. Lu, Richard Guenther, DJ Delorie, Alexandre Oliva,
	Ralf Wildenhues, neroden, gcc-patches

On Thu, Jul 7, 2011 at 17:12, Uros Bizjak <ubizjak@gmail.com> wrote:
> On Thu, Jul 7, 2011 at 5:02 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
>
>>> Did you even _think_ of looking at the sh configury, and do something
>>> vaguely similar for x86?
>>>
>>> You should not duplicate t-linux64 at all.  Instead, in config.gcc set
>>> m64/m32 as the default value for with_multilib_list on i386 biarch and
>>> x86_64.  Pass $with_multilib_list to t-linux64 using
>>> TM_MULTILIB_CONFIG.  Then, do something like
>>>
>>> comma=,
>>> MULTILIB_OPTIONS    = $(subst $(comma),/,@TM_MULTILIB_CONFIG@)
>>> MULTILIB_DIRNAMES   = $(patsubst m%, %, $(subst /, ,$(MULTILIB_OPTIONS)))
>>> MULTILIB_OSDIRNAMES  = 64=../lib64
>>> MULTILIB_OSDIRNAMES += 32=$(if $(wildcard $(shell echo
>>> $(SYSTEM_HEADER_DIR))/../../usr/lib32),../lib32,../lib)
>>> MULTILIB_OSDIRNAMES += x32=../libx32
>>>
>>> in config/t-linux64.  (Each on one line, apologies for any wrapping)
>>>
>>> The option will be used as --with-multilib-list=m64,m32,mx32 (allowing
>>> the user to omit some of the variants, too).
>>>
>>
>> This is an excellent suggestion.  Here is the updated patch. It
>> uses TM_MULTILIB_CONFIG and removes config/i386/t-linux-x32.
>>
>> Uros, is this OK for trunk to replace the patch you approved earlier?
>
> Er, the approval was fo x86 parts, I will leave approval for build
> parts to Paolo.

Yes, build parts are okay too.

Paolo

^ permalink raw reply	[flat|nested] 26+ messages in thread

end of thread, other threads:[~2011-07-07 15:19 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-06-05 19:55 PATCH [1/n]: Add initial -x32 support H.J. Lu
2011-06-06 15:47 ` Uros Bizjak
2011-06-07 15:47 ` Joseph S. Myers
2011-06-07 18:54   ` H.J. Lu
2011-06-07 19:19     ` Joseph S. Myers
2011-06-07 15:59 ` Joseph S. Myers
2011-06-07 19:11   ` H.J. Lu
2011-06-07 19:20     ` Joseph S. Myers
2011-06-07 22:02       ` H.J. Lu
2011-06-14 17:52 ` H.J. Lu
2011-07-05 14:42 ` PATCH [1/n] X32: " H.J. Lu
2011-07-05 15:21   ` Uros Bizjak
2011-07-05 17:59     ` H.J. Lu
2011-07-05 18:18       ` Uros Bizjak
2011-07-05 19:09         ` H.J. Lu
2011-07-05 19:09           ` Joseph S. Myers
2011-07-05 20:07           ` Uros Bizjak
2011-07-06 14:50           ` H.J. Lu
2011-07-06 15:03             ` Richard Guenther
2011-07-06 16:40               ` H.J. Lu
2011-07-07 13:03                 ` H.J. Lu
2011-07-07 13:08                   ` Uros Bizjak
2011-07-07 13:27                 ` Paolo Bonzini
2011-07-07 15:10                   ` H.J. Lu
2011-07-07 15:14                     ` Uros Bizjak
2011-07-07 15:38                       ` Paolo Bonzini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).