NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

port-powerpc/51366: kernel for powerpc/ibm4xx miscompiled by gcc >= 4.8.5



>Number:         51366
>Category:       port-powerpc
>Synopsis:       kernel for powerpc/ibm4xx miscompiled by gcc >= 4.8.5
>Confidential:   no
>Severity:       critical
>Priority:       high
>Responsible:    port-powerpc-maintainer
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Jul 27 15:00:00 +0000 2016
>Originator:     Rin Okuyama
>Release:        HEAD
>Organization:
Faculty of Science and Technology, Keio University
>Environment:
NetBSD obs266 7.99.34 NetBSD 7.99.34 (OPENBLOCKS266) #1: Wed Jul 27 22:09:26 JST 2016  rin@XXX:XXX evbppc
>Description:
Kernels for powerpc/ibm4xx (e.g., evbppc/OPENBLOCKS266) are miscompiled
by gcc both 5.4 and 4.8.5. As a result, copyout fails and system does not
boot:

====================
  NetBSD 7.99.34 (INSTALL_OPENBLOCKS266) #0: Thu Jul 21 20:05:55 JST 2016
          rin@XXX:XXX
  Model: OpenBlockS266 IBM PowerPC 405GPr Board
  total memory = 128 MB
  avail memory = 119 MB
  plb0 (root)
  ...snip...
  root file system type: ffs
  kern.module.path=/stand/powerpc-ibm4xx/7.99.34/modules
  init: copying out flags `-s' 3
  init: copying out path `/sbin/init' 11
  exec /sbin/init: error 13
  init: copying out flags `-s' 3
  init: copying out path `/sbin/oinit' 12
  exec /sbin/oinit: error 2
  ...snip...
====================

If kernel is compiled with gcc 4.8.4 distributed with NetBSD 7.0.1,
system boots up successfully, which suggests that this is a regression
introduced to gcc >= 4.8.5.
>How-To-Repeat:
Described above.
>Fix:
This is due to ".machine ppc" pseudo-op, which is passed to assembler by
gcc >= 4.8.5. It discards CPU type specified by "-mcpu=405" option. As a
result, inline aseembler codes are compiled into a wrong dialect of
machine language. The attached patch removes this pseudo-op. Then, kernel
is successfully compiled by gcc 5.4 and 4.8.5.

Note that ".machine" pseudo-op seems necessary for powerpc64, in which
the default CPU type is power4. Without it, gas cannot assemble codes
generated by gcc.

====================
--- src/external/gpl3/gcc/dist/gcc/config/rs6000/rs6000.c.orig	2016-07-26 20:35:20.391415369 +0900
+++ src/external/gpl3/gcc/dist/gcc/config/rs6000/rs6000.c	2016-07-26 21:07:17.973106045 +0900
@@ -5185,8 +5185,13 @@
     }
 
 #ifdef USING_ELFOS_H
-  if (rs6000_default_cpu == 0 || rs6000_default_cpu[0] == '\0'
-      || !global_options_set.x_rs6000_cpu_index)
+/*
+ * XXX .machine overrides CPU type specified by -mcpu or -Wa,-m options, which
+ * can result in corrupted output with inline assembler for ppc32.
+ */
+  if ((rs6000_default_cpu == 0 || rs6000_default_cpu[0] == '\0'
+	|| !global_options_set.x_rs6000_cpu_index)
+      && (rs6000_isa_flags & OPTION_MASK_POWERPC64) != 0)
     {
       fputs ("\t.machine ", asm_out_file);
       if ((rs6000_isa_flags & OPTION_MASK_DIRECT_MOVE) != 0)
@@ -5199,10 +5204,8 @@
 	fputs ("power5\n", asm_out_file);
       else if ((rs6000_isa_flags & OPTION_MASK_MFCRF) != 0)
 	fputs ("power4\n", asm_out_file);
-      else if ((rs6000_isa_flags & OPTION_MASK_POWERPC64) != 0)
-	fputs ("ppc64\n", asm_out_file);
       else
-	fputs ("ppc\n", asm_out_file);
+	fputs ("ppc64\n", asm_out_file);
     }
 #endif
 
--- src/external/gpl3/gcc.old/dist/gcc/config/rs6000/rs6000.c.orig	2016-07-26 20:35:21.497737069 +0900
+++ src/external/gpl3/gcc.old/dist/gcc/config/rs6000/rs6000.c	2016-07-26 21:09:00.819227210 +0900
@@ -4972,8 +4972,13 @@
     }
 
 #ifdef USING_ELFOS_H
-  if (rs6000_default_cpu == 0 || rs6000_default_cpu[0] == '\0'
-      || !global_options_set.x_rs6000_cpu_index)
+/*
+ * XXX .machine overrides CPU type specified by -mcpu or -Wa,-m options, which
+ * can result in corrupted output with inline assembler for ppc32.
+ */
+  if ((rs6000_default_cpu == 0 || rs6000_default_cpu[0] == '\0'
+	|| !global_options_set.x_rs6000_cpu_index)
+      && (rs6000_isa_flags & OPTION_MASK_POWERPC64) != 0)
     {
       fputs ("\t.machine ", asm_out_file);
       if ((rs6000_isa_flags & OPTION_MASK_DIRECT_MOVE) != 0)
@@ -4986,10 +4991,8 @@
 	fputs ("power5\n", asm_out_file);
       else if ((rs6000_isa_flags & OPTION_MASK_MFCRF) != 0)
 	fputs ("power4\n", asm_out_file);
-      else if ((rs6000_isa_flags & OPTION_MASK_POWERPC64) != 0)
-	fputs ("ppc64\n", asm_out_file);
       else
-	fputs ("ppc\n", asm_out_file);
+	fputs ("ppc64\n", asm_out_file);
     }
 #endif
 }
====================



Home | Main Index | Thread Index | Old Index