Patch from Mandriva, done by pcpa. Rebased for 4.8.2 / tmb Signed-off-by: Thomas Backlund <tmb@mageia.org> gcc/config/i386/biarch64.h | 9 +++++++++ gcc/opts-common.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff -Nurp gcc-4.8-20130725/gcc/config/i386/biarch64.h gcc-4.8-20130725-linux32/gcc/config/i386/biarch64.h --- gcc-4.8-20130725/gcc/config/i386/biarch64.h 2013-01-10 22:38:27.000000000 +0200 +++ gcc-4.8-20130725-linux32/gcc/config/i386/biarch64.h 2013-07-29 18:56:22.560690959 +0300 @@ -27,3 +27,12 @@ see the files COPYING3 and COPYING.RUNTI #define TARGET_64BIT_DEFAULT (OPTION_MASK_ISA_64BIT | OPTION_MASK_ABI_64) #define TARGET_BI_ARCH 1 + +#if defined(__linux__) +#ifndef inhibit_libc +#include <sys/syscall.h> +#include <sys/personality.h> +#define TARGET_32BIT_PERSONALITY \ + ((syscall(SYS_personality, 0xffffffff) & PER_MASK) == PER_LINUX32) +#endif +#endif diff -Nurp gcc-4.8-20130725/gcc/opts-common.c gcc-4.8-20130725-linux32/gcc/opts-common.c --- gcc-4.8-20130725/gcc/opts-common.c 2013-03-05 08:01:13.000000000 +0200 +++ gcc-4.8-20130725-linux32/gcc/opts-common.c 2013-07-29 18:56:22.560690959 +0300 @@ -21,6 +21,7 @@ along with GCC; see the file COPYING3. #include "system.h" #include "intl.h" #include "coretypes.h" +#include "tm.h" #include "opts.h" #include "flags.h" #include "diagnostic.h" @@ -744,6 +745,10 @@ decode_cmdline_options_to_array (unsigne unsigned int n, i; struct cl_decoded_option *opt_array; unsigned int num_decoded_options; +#ifdef TARGET_32BIT_PERSONALITY + bool arch_flag = false; + bool arch_32bit = TARGET_32BIT_PERSONALITY; +#endif opt_array = XNEWVEC (struct cl_decoded_option, argc); @@ -773,11 +778,35 @@ decode_cmdline_options_to_array (unsigne continue; } +#ifdef TARGET_32BIT_PERSONALITY + if (!arch_flag && arch_32bit + && opt[1] == 'm' && ((opt[2] == '3' && opt[3] == '2') + || (opt[2] == '6' && opt[3] == '4')) + && opt[4] == '\0') + arch_flag = true; +#endif + n = decode_cmdline_option (argv + i, lang_mask, &opt_array[num_decoded_options]); num_decoded_options++; } +#ifdef TARGET_32BIT_PERSONALITY + if (!arch_flag && arch_32bit) + { + const char **argvec = XNEWVEC (const char *, 2); + + argvec[0] = "-m32"; + argvec[1] = NULL; + if (++num_decoded_options > argc) + opt_array = XRESIZEVEC (struct cl_decoded_option, + opt_array, num_decoded_options); + (void)decode_cmdline_option (argvec, lang_mask, + &opt_array[num_decoded_options - 1]); + free (argvec); + } +#endif + *decoded_options = opt_array; *decoded_options_count = num_decoded_options; prune_options (decoded_options, decoded_options_count);