This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: How to configure a bi-arch PowerPC GCC?


On 23/01/17 18:18, Segher Boessenkool wrote:
Hello again,

On Mon, Jan 23, 2017 at 09:19:04AM +0100, Sebastian Huber wrote:
I am flexible in terms of the ABI choice for the 64-bit PowerPC. I guess
the ABI_ELFv2 is the way to go?
It certainly is the most modern ABI.  It makes some requirements to what
Power ISA features are required, which may or may not be a problem for
your platform.  If you want to use BE, that should work with ELFv2 fine
(and it did in the past at least), but it doesn't get serious testing.
I use now the attached patch and get the following error types (for
several multilibs):

/home/EB/sebastian_h/archive/gcc-git/libgcc/config/rs6000/ibm-ldouble.c:374:0:
/home/EB/sebastian_h/archive/gcc-git/libgcc/soft-fp/quad.h:72:1: error:
unable to emulate 'TF'
  typedef float TFtype __attribute__ ((mode (TF)));
  ^~~~~~~
 From rs6000.c (rs6000_scalar_mode_supported_p):
   else if (TARGET_FLOAT128_TYPE && (mode == KFmode || mode == IFmode))
     return true;
   else
     return default_scalar_mode_supported_p (mode);
and the latter has
       if (precision == LONG_DOUBLE_TYPE_SIZE)
         return true;
       return false;

so you have no 128-bit FP type at all.  Maybe your TARGET_IEEEQUAD definition
is wrong, maybe something else...  What type *do* you want for float128?

I disabled the ibm-ldouble.c for RTEMS. Enabling the 128-bit FP support for the 32-bit powerpc-rtems resulted in a lot of ICEs.

https://gcc.gnu.org/ml/gcc/2017-01/msg00215.html

With -m64 I set now:

+      if (rs6000_isa_flags & OPTION_MASK_64BIT)                        \
+       {                                                       \
+         rs6000_long_double_type_size = 128;                   \
+         rs6000_elf_abi = 2;                                   \
+         rs6000_current_abi = ABI_ELFv2;                       \
+         rs6000_isa_flags &= ~OPTION_MASK_EABI; \



/home/EB/sebastian_h/archive/gcc-git/libgcc/unwind-dw2-fde.c: In
function 'search_object':
/home/EB/sebastian_h/archive/gcc-git/libgcc/unwind-dw2-fde.c:588:25:
internal compiler error: in emit_move_insn, at expr.c:3698
         v1->array[i1+i2] = v1->array[i1-1];
         ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
0x6c49bb emit_move_insn(rtx_def*, rtx_def*)
         /home/EB/sebastian_h/archive/gcc-git/gcc/expr.c:3697
0x6a5c2b force_reg
         /home/EB/sebastian_h/archive/gcc-git/gcc/explow.c:648
0xd61994 rs6000_legitimize_address
/home/EB/sebastian_h/archive/gcc-git/gcc/config/rs6000/rs6000.c:8873
rs6000_legitimize_address called force_reg which ICEs in emit_move_insn
because the source is not the same mode as the dest (or an immediate, etc.)

You'll have to debug this a bit more to see what is going on.

I still get a lot of ICEs with the attached two patches (examples):

/home/EB/sebastian_h/archive/gcc-git/libgcc/libgcc2.c: In function '__multc3': /home/EB/sebastian_h/archive/gcc-git/libgcc/libgcc2.c:2035:1: error: unrecognizable insn:
  }
  ^
(insn 59 58 60 2 (set (reg:CCFP 219)
         (compare:CCFP (reg/v:TF 193 [ x ])
(reg/v:TF 193 [ x ]))) "/home/EB/sebastian_h/archive/gcc-git/libgcc/libgcc2.c":1990 -1
      (nil))
/home/EB/sebastian_h/archive/gcc-git/libgcc/libgcc2.c:2035:1: internal compiler error: in extract_insn, at recog.c:2311 0x9945f5 _fatal_insn(char const*, rtx_def const*, char const*, int, char const*)
     /home/EB/sebastian_h/archive/gcc-git/gcc/rtl-error.c:108
0x994629 _fatal_insn_not_found(rtx_def const*, char const*, int, char const*)
     /home/EB/sebastian_h/archive/gcc-git/gcc/rtl-error.c:116
0x965ee7 extract_insn(rtx_insn*)
     /home/EB/sebastian_h/archive/gcc-git/gcc/recog.c:2311
0x7238c2 instantiate_virtual_regs_in_insn
     /home/EB/sebastian_h/archive/gcc-git/gcc/function.c:1589
0x7238c2 instantiate_virtual_regs
     /home/EB/sebastian_h/archive/gcc-git/gcc/function.c:1957
0x7238c2 execute
     /home/EB/sebastian_h/archive/gcc-git/gcc/function.c:2006
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <http://gcc.gnu.org/bugs.html> for instructions.

/home/EB/sebastian_h/archive/gcc-git/libgcc/unwind-dw2-fde.c: In function 'search_object': /home/EB/sebastian_h/archive/gcc-git/libgcc/unwind-dw2-fde.c:588:25: internal compiler error: in emit_move_insn, at expr.c:3698
         v1->array[i1+i2] = v1->array[i1-1];
         ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
0x6c54ab emit_move_insn(rtx_def*, rtx_def*)
     /home/EB/sebastian_h/archive/gcc-git/gcc/expr.c:3697
0x6a68eb force_reg
     /home/EB/sebastian_h/archive/gcc-git/gcc/explow.c:648
0xd6bbc4 rs6000_legitimize_address
/home/EB/sebastian_h/archive/gcc-git/gcc/config/rs6000/rs6000.c:8871
0x6a76e1 memory_address_addr_space(machine_mode, rtx_def*, unsigned char)
     /home/EB/sebastian_h/archive/gcc-git/gcc/explow.c:432
0x6c0551 expand_expr_real_1(tree_node*, rtx_def*, machine_mode, expand_modifier, rtx_def**, bool)
     /home/EB/sebastian_h/archive/gcc-git/gcc/expr.c:10054
0x6ce5cc expand_expr
     /home/EB/sebastian_h/archive/gcc-git/gcc/expr.h:276
0x6ce5cc expand_assignment(tree_node*, tree_node*, bool)
     /home/EB/sebastian_h/archive/gcc-git/gcc/expr.c:5257
0x5b3dcc expand_gimple_stmt_1
     /home/EB/sebastian_h/archive/gcc-git/gcc/cfgexpand.c:3641
0x5b3dcc expand_gimple_stmt
     /home/EB/sebastian_h/archive/gcc-git/gcc/cfgexpand.c:3737
0x5b5c29 expand_gimple_basic_block
     /home/EB/sebastian_h/archive/gcc-git/gcc/cfgexpand.c:5744
0x5bb686 execute
     /home/EB/sebastian_h/archive/gcc-git/gcc/cfgexpand.c:6357
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <http://gcc.gnu.org/bugs.html> for instructions.

/home/EB/sebastian_h/archive/gcc-git/libgcc/libgcc2.c: In function '__multc3': /home/EB/sebastian_h/archive/gcc-git/libgcc/libgcc2.c:2035:1: error: unable to generate reloads for:
  }
  ^
(insn 138 1211 139 16 (set (reg/v:TF 203 [ a ])
         (unspec:TF [
                 (reg:TF 237)
                 (reg/v:TF 203 [ a ])
                 (reg:TF 238)
] UNSPEC_COPYSIGN)) "/home/EB/sebastian_h/archive/gcc-git/libgcc/libgcc2.c":1998 940 {copysigntf3_soft}
      (expr_list:REG_DEAD (reg:TF 238)
         (nil)))
/home/EB/sebastian_h/archive/gcc-git/libgcc/libgcc2.c:2035:1: internal compiler error: in curr_insn_transform, at lra-constraints.c:3743 0x9945f5 _fatal_insn(char const*, rtx_def const*, char const*, int, char const*)
     /home/EB/sebastian_h/archive/gcc-git/gcc/rtl-error.c:108
0x892303 curr_insn_transform
     /home/EB/sebastian_h/archive/gcc-git/gcc/lra-constraints.c:3743
0x8931e6 lra_constraints(bool)
     /home/EB/sebastian_h/archive/gcc-git/gcc/lra-constraints.c:4699
0x87ce06 lra(_IO_FILE*)
     /home/EB/sebastian_h/archive/gcc-git/gcc/lra.c:2377
0x8337df do_reload
     /home/EB/sebastian_h/archive/gcc-git/gcc/ira.c:5400
0x8337df execute
     /home/EB/sebastian_h/archive/gcc-git/gcc/ira.c:5584
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <http://gcc.gnu.org/bugs.html> for instructions.

The libstdc++ build revealed this:

/home/EB/sebastian_h/archive/gcc-git/libstdc++-v3/src/c++98/mt_allocator.cc: In function 'void {anonymous}::_M_destroy_thread_key(void*)': /home/EB/sebastian_h/archive/gcc-git/libstdc++-v3/src/c++98/mt_allocator.cc:82:57: error: cast from 'void*' to 'uintptr_t {aka unsigned int}' loses precision [-fpermissive]
        uintptr_t _M_id = reinterpret_cast<uintptr_t>(__id);
                                                          ^
/home/EB/sebastian_h/archive/gcc-git/libstdc++-v3/src/c++98/mt_allocator.cc: In member function 'std::size_t __gnu_cxx::__pool<true>::_M_get_thread_id()': /home/EB/sebastian_h/archive/gcc-git/libstdc++-v3/src/c++98/mt_allocator.cc:635:31: error: cast from 'void*' to 'uintptr_t {aka unsigned int}' loses precision [-fpermissive]
   uintptr_t _M_id = (uintptr_t)v;
                                ^
/home/EB/sebastian_h/archive/gcc-git/libstdc++-v3/src/c++98/mt_allocator.cc:648:52: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
       __gthread_setspecific(freelist._M_key, (void*)_M_id);
                                                     ^~~~~



/home/EB/sebastian_h/archive/gcc-git/libgcc/emutls.c:171:13: note:
include '<stdlib.h>' or provide a declaration of 'realloc'
/tmp/ccoZ1J0W.s: Assembler messages:
/tmp/ccoZ1J0W.s:125: Error: can't resolve `.got' {.got section} -
`.LCTOC1' {*UND* section}
Your TLS is misconfigured.  Or something.

I compared the linux64.h and freebsd64.h and as a wild guess I added:

+#undef TARGET_AIX
+#define        TARGET_AIX TARGET_64BIT
+

This seems to fix this issue. I don't know why.



--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -2381,7 +2381,7 @@ powerpc-*-eabi*)
  	use_gcc_stdint=wrap
  	;;
  powerpc-*-rtems*)
-	tm_file="${tm_file} dbxelf.h elfos.h freebsd-spec.h newlib-stdint.h rs6000/sysv4.h rs6000/eabi.h rs6000/e500.h rs6000/rtems.h rtems.h"
+	tm_file="rs6000/biarch64.h ${tm_file} dbxelf.h elfos.h freebsd-spec.h newlib-stdint.h rs6000/sysv4.h rs6000/eabi.h rs6000/e500.h rs6000/rtems.h rtems.h"
  	extra_options="${extra_options} rs6000/sysv4.opt"
  	tmake_file="${tmake_file} rs6000/t-fprules rs6000/t-rtems rs6000/t-ppccomm"
  	;;
You might want to break this line into parts.  It isn't so easy to see what
you changed now :-)

I simply added rs6000/biarch64.h to the head of the list.


Have you checked if your generated files (say, those in libgcc) are
actually ELFv2 now, and if they look correct?

The resulting objects look not completely bad:

powerpc-rtems4.12-readelf -h ./powerpc-rtems4.12/me6500/m32/libgcc/tramp.o
ELF Header:
   Magic:   7f 45 4c 46 01 02 01 00 00 00 00 00 00 00 00 00
   Class:                             ELF32
   Data:                              2's complement, big endian
   Version:                           1 (current)
   OS/ABI:                            UNIX - System V
   ABI Version:                       0
   Type:                              REL (Relocatable file)
   Machine:                           PowerPC
   Version:                           0x1
   Entry point address:               0x0
   Start of program headers:          0 (bytes into file)
   Start of section headers:          1056 (bytes into file)
   Flags:                             0x0
   Size of this header:               52 (bytes)
   Size of program headers:           0 (bytes)
   Number of program headers:         0
   Size of section headers:           40 (bytes)
   Number of section headers:         15
   Section header string table index: 14

powerpc-rtems4.12-readelf -h ./powerpc-rtems4.12/me6500/m64/libgcc/tramp.o
ELF Header:
   Magic:   7f 45 4c 46 02 02 01 00 00 00 00 00 00 00 00 00
   Class:                             ELF64
   Data:                              2's complement, big endian
   Version:                           1 (current)
   OS/ABI:                            UNIX - System V
   ABI Version:                       0
   Type:                              REL (Relocatable file)
   Machine:                           PowerPC64
   Version:                           0x1
   Entry point address:               0x0
   Start of program headers:          0 (bytes into file)
   Start of section headers:          1472 (bytes into file)
   Flags:                             0x2, abiv2
   Size of this header:               64 (bytes)
   Size of program headers:           0 (bytes)
   Number of program headers:         0
   Size of section headers:           64 (bytes)
   Number of section headers:         17
   Section header string table index: 16

--
Sebastian Huber, embedded brains GmbH

Address : Dornierstr. 4, D-82178 Puchheim, Germany
Phone   : +49 89 189 47 41-16
Fax     : +49 89 189 47 41-09
E-Mail  : sebastian.huber@embedded-brains.de
PGP     : Public key available on request.

Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.


>From 7a35ba21fa00567a986461ca66dce58019c6de31 Mon Sep 17 00:00:00 2001
From: Sebastian Huber <sebastian.huber@embedded-brains.de>
Date: Tue, 24 Jan 2017 11:20:22 +0100
Subject: [PATCH 1/2] RTEMS: Define __powerpc__

---
 gcc/config/rs6000/rtems.h          | 1 +
 libgcc/config/rs6000/ibm-ldouble.c | 3 ++-
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/gcc/config/rs6000/rtems.h b/gcc/config/rs6000/rtems.h
index 54a36de..531379a 100644
--- a/gcc/config/rs6000/rtems.h
+++ b/gcc/config/rs6000/rtems.h
@@ -25,6 +25,7 @@
   do                                      \
     {                                     \
       builtin_define_std ("PPC");         \
+      builtin_define_std ("powerpc");     \
       builtin_define ("__rtems__");       \
       builtin_define ("__USE_INIT_FINI__"); \
       builtin_assert ("system=rtems");    \
diff --git a/libgcc/config/rs6000/ibm-ldouble.c b/libgcc/config/rs6000/ibm-ldouble.c
index 949b50c..e99652e 100644
--- a/libgcc/config/rs6000/ibm-ldouble.c
+++ b/libgcc/config/rs6000/ibm-ldouble.c
@@ -45,7 +45,8 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
    This code currently assumes the most significant double is in
    the lower numbered register or lower addressed memory.  */
 
-#if defined (__MACH__) || defined (__powerpc__) || defined (_AIX)
+#if (defined (__MACH__) || defined (__powerpc__) || defined (_AIX)) \
+    && !defined (__rtems__)
 
 #define fabs(x) __builtin_fabs(x)
 #define isless(x, y) __builtin_isless (x, y)
-- 
1.8.4.5


>From 17510dac36db4d9cd46a9b94492efb69b8457093 Mon Sep 17 00:00:00 2001
From: Sebastian Huber <sebastian.huber@embedded-brains.de>
Date: Fri, 20 Jan 2017 10:05:52 +0100
Subject: [PATCH 2/2] RTEMS: Add 64-bit PowerPC support

---
 gcc/config.gcc            |  2 +-
 gcc/config/rs6000/rtems.h | 72 +++++++++++++++++++++++++++++++++++++++--------
 gcc/config/rs6000/sysv4.h |  2 +-
 gcc/config/rs6000/t-rtems |  5 ++++
 4 files changed, 67 insertions(+), 14 deletions(-)

diff --git a/gcc/config.gcc b/gcc/config.gcc
index 03b1894..b293a2e 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -2381,7 +2381,7 @@ powerpc-*-eabi*)
 	use_gcc_stdint=wrap
 	;;
 powerpc-*-rtems*)
-	tm_file="${tm_file} dbxelf.h elfos.h freebsd-spec.h newlib-stdint.h rs6000/sysv4.h rs6000/eabi.h rs6000/e500.h rs6000/rtems.h rtems.h"
+	tm_file="rs6000/biarch64.h ${tm_file} dbxelf.h elfos.h freebsd-spec.h newlib-stdint.h rs6000/sysv4.h rs6000/eabi.h rs6000/e500.h rs6000/rtems.h rtems.h"
 	extra_options="${extra_options} rs6000/sysv4.opt"
 	tmake_file="${tmake_file} rs6000/t-fprules rs6000/t-rtems rs6000/t-ppccomm"
 	;;
diff --git a/gcc/config/rs6000/rtems.h b/gcc/config/rs6000/rtems.h
index 531379a..fbaf5d3 100644
--- a/gcc/config/rs6000/rtems.h
+++ b/gcc/config/rs6000/rtems.h
@@ -20,19 +20,33 @@
 
 /* Specify predefined symbols in preprocessor.  */
 
+#undef	TARGET_AIX
+#define	TARGET_AIX TARGET_64BIT
+
 #undef TARGET_OS_CPP_BUILTINS
-#define TARGET_OS_CPP_BUILTINS()          \
-  do                                      \
-    {                                     \
-      builtin_define_std ("PPC");         \
-      builtin_define_std ("powerpc");     \
-      builtin_define ("__rtems__");       \
-      builtin_define ("__USE_INIT_FINI__"); \
-      builtin_assert ("system=rtems");    \
-      builtin_assert ("cpu=powerpc");     \
-      builtin_assert ("machine=powerpc"); \
-      TARGET_OS_SYSV_CPP_BUILTINS ();     \
-    }                                     \
+#define TARGET_OS_CPP_BUILTINS()			\
+  do							\
+    {							\
+      builtin_define ("__rtems__");			\
+      builtin_define ("__USE_INIT_FINI__");		\
+      builtin_assert ("system=rtems");			\
+      if (TARGET_64BIT)					\
+	{						\
+	  builtin_define ("__PPC__");			\
+	  builtin_define ("__PPC64__");			\
+	  builtin_define ("__powerpc64__");		\
+	  builtin_assert ("cpu=powerpc64");		\
+	  builtin_assert ("machine=powerpc64");		\
+	}						\
+      else						\
+	{						\
+	  builtin_define_std ("PPC");			\
+	  builtin_define_std ("powerpc");		\
+	  builtin_assert ("cpu=powerpc");		\
+	  builtin_assert ("machine=powerpc");		\
+	  TARGET_OS_SYSV_CPP_BUILTINS ();		\
+	}						\
+    }							\
   while (0)
 
 #undef TARGET_LIBGCC_SDATA_SECTION
@@ -59,3 +73,37 @@
 #undef  SUBSUBTARGET_EXTRA_SPECS
 #define SUBSUBTARGET_EXTRA_SPECS \
   { "cpp_os_rtems",		CPP_OS_RTEMS_SPEC }
+
+#define INVALID_64BIT "-m%s not supported in this configuration"
+
+#undef	SUBSUBTARGET_OVERRIDE_OPTIONS
+#define	SUBSUBTARGET_OVERRIDE_OPTIONS				\
+  do								\
+    {								\
+      if (rs6000_isa_flags & OPTION_MASK_64BIT)			\
+	{							\
+	  rs6000_long_double_type_size = 128;			\
+	  rs6000_elf_abi = 2;					\
+	  rs6000_current_abi = ABI_ELFv2;			\
+	  rs6000_isa_flags &= ~OPTION_MASK_EABI;		\
+	  if (rs6000_isa_flags & OPTION_MASK_RELOCATABLE)	\
+	    {							\
+	      rs6000_isa_flags &= ~OPTION_MASK_RELOCATABLE;	\
+	      error (INVALID_64BIT, "relocatable");		\
+	    }							\
+	  if (TARGET_PROTOTYPE)					\
+	    {							\
+	      target_prototype = 0;				\
+	      error (INVALID_64BIT, "prototype");		\
+	    }							\
+	  if ((rs6000_isa_flags & OPTION_MASK_POWERPC64) == 0)	\
+	    {							\
+	      rs6000_isa_flags |= OPTION_MASK_POWERPC64;	\
+	      error ("-m64 requires a PowerPC64 cpu");		\
+	    }							\
+	}							\
+    }								\
+  while (0)
+
+#undef TARGET_IEEEQUAD
+#define TARGET_IEEEQUAD 1
diff --git a/gcc/config/rs6000/sysv4.h b/gcc/config/rs6000/sysv4.h
index a5abeee..fccb1f0 100644
--- a/gcc/config/rs6000/sysv4.h
+++ b/gcc/config/rs6000/sysv4.h
@@ -533,7 +533,7 @@ extern int fixuplabelno;
 #define DEFAULT_ASM_ENDIAN " -mbig"
 
 #undef	ASM_SPEC
-#define	ASM_SPEC "%(asm_cpu) \
+#define	ASM_SPEC "%{!m64:-a32}%{m64:-a64} %(asm_cpu) \
 %{,assembler|,assembler-with-cpp: %{mregnames} %{mno-regnames}} \
 %{mrelocatable} %{mrelocatable-lib} %{" FPIE_OR_FPIC_SPEC ":-K PIC} \
 %{memb|msdata=eabi: -memb}" \
diff --git a/gcc/config/rs6000/t-rtems b/gcc/config/rs6000/t-rtems
index 7c7637d..8ff0656 100644
--- a/gcc/config/rs6000/t-rtems
+++ b/gcc/config/rs6000/t-rtems
@@ -30,6 +30,9 @@ MULTILIB_DIRNAMES += m403 m505 m603e m604 m860 m7400 m8540 me6500
 MULTILIB_OPTIONS += m32
 MULTILIB_DIRNAMES += m32
 
+MULTILIB_OPTIONS += m64
+MULTILIB_DIRNAMES += m64
+
 MULTILIB_OPTIONS += msoft-float/mfloat-gprs=double
 MULTILIB_DIRNAMES += nof gprsdouble
 
@@ -77,3 +80,5 @@ MULTILIB_REQUIRED += mcpu=8540/mfloat-gprs=double
 MULTILIB_REQUIRED += mcpu=860
 MULTILIB_REQUIRED += mcpu=e6500/m32
 MULTILIB_REQUIRED += mcpu=e6500/m32/msoft-float/mno-altivec
+MULTILIB_REQUIRED += mcpu=e6500/m64
+MULTILIB_REQUIRED += mcpu=e6500/m64/msoft-float/mno-altivec
-- 
1.8.4.5



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