Port-m68k archive

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

Patches to fix building m68k with CPUFLAGS



Hi all,

I've been spending some time getting reacquainted with NetBSD/amiga, thanks to
emulation, and I just fixed some annoying bugs that were preventing anyone from
setting CPUFLAGS in their NetBSD build (e.g. to optimize for m68060 or m68040.
I also switched my build to use GCC 8.4.0 and binutils 2.34.

The biggest problem with CPUFLAGS had to do with a whitespace bug in
external/gpl3/gcc/dist/gcc/config/m68k/m68k.h (and in "gcc.old"),
which is the last
patch in the email. The bug is still in GCC, so the fix can be
upstreamed right away.
The changes to now add CPUFLAGS to AFLAGS are because GAS doesn't
recognize, e.g. "-m68020-60", so we can't ever pass CPUFLAGS directly (on m68k).

The patch to libgcc/config/m68k/lb1sf68.S (in gcc and gcc.old) is
because otherwise
the linker fails trying to handle unsupported 16-bit relocations. I'm
not sure if wrapping
the unworking code with !defined("__ELF__") is the correct fix, or if
this is a bug
that's specific to NetBSD. Either way, it got me past the build break.

As for switching to the new GCC and binutils, I'm still testing that.
I'm seeing some
kernel panics in UVM, but I think they may be related to instability
in NetBSD-current.
I'll have to build a kernel with GCC 7 and compare, and also with the
older binutils.
I wanted to email the list with the patches I have so far, since I
know a lot of people
are blocked from making builds for their 68060 or 68040 because CPUFLAGS
has been broken on m68k. If the mailing list breaks any of the patches, I also
put a PR at: https://github.com/NetBSD/src/pull/13

I'll delete the GitHub PR after the patches get merged. Thanks for reviewing!

Subject: [PATCH 1/2] Switch m68k to new GCC and binutils, fix CPUFLAGS.

- Change m68k build to use GCC 8.4.0 and binutils 2.34.
- Update binutils config files to define TARGET_BYTES_BIG_ENDIAN.
- Fix libgcc/config/m68k/lb1sf68.S to work around linker error
  when using CPUFLAGS (normally masked by default CPU options).
- Don't add CPUFLAGS to AFLAGS, to fix several build failures:
  - Amiga kernel locore.s uses opcodes not present in 68040/060
  - Amiga bootblocks use custom make rule that calls gas directly,
    and gas doesn't understand all m68k CPUFLAGS recognized by GCC.
  - m68060 kernel support package also doesn't like CPUFLAGS.
---
 external/gpl3/binutils.old/usr.bin/gas/arch/m68k/config.h | 2 +-
 external/gpl3/binutils/usr.bin/gas/arch/m68k/config.h     | 2 +-
 external/gpl3/gcc.old/dist/libgcc/config/m68k/lb1sf68.S   | 4 ++--
 external/gpl3/gcc/dist/libgcc/config/m68k/lb1sf68.S       | 4 ++--
 share/mk/bsd.own.mk                                       | 5 +----
 share/mk/bsd.sys.mk                                       | 4 ++++
 6 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/external/gpl3/binutils.old/usr.bin/gas/arch/m68k/config.h
b/external/gpl3/binutils.old/usr.bin/gas/arch/m68k/config.h
index 63afe83d1be4..181f0bbe08fc 100644
--- a/external/gpl3/binutils.old/usr.bin/gas/arch/m68k/config.h
+++ b/external/gpl3/binutils.old/usr.bin/gas/arch/m68k/config.h
@@ -298,7 +298,7 @@
 #define TARGET_ALIAS "m68k--netbsdelf"

 /* Define as 1 if big endian. */
-/* #undef TARGET_BYTES_BIG_ENDIAN */
+#define TARGET_BYTES_BIG_ENDIAN 1

 /* Canonical target. */
 #define TARGET_CANONICAL "m68k--netbsdelf"
diff --git a/external/gpl3/binutils/usr.bin/gas/arch/m68k/config.h
b/external/gpl3/binutils/usr.bin/gas/arch/m68k/config.h
index eddab29535cb..c4087fdff09c 100644
--- a/external/gpl3/binutils/usr.bin/gas/arch/m68k/config.h
+++ b/external/gpl3/binutils/usr.bin/gas/arch/m68k/config.h
@@ -317,7 +317,7 @@
 #define TARGET_ALIAS "m68k--netbsdelf"

 /* Define as 1 if big endian. */
-/* #undef TARGET_BYTES_BIG_ENDIAN */
+#define TARGET_BYTES_BIG_ENDIAN 1

 /* Canonical target. */
 #define TARGET_CANONICAL "m68k--netbsdelf"
diff --git a/external/gpl3/gcc.old/dist/libgcc/config/m68k/lb1sf68.S
b/external/gpl3/gcc.old/dist/libgcc/config/m68k/lb1sf68.S
index 0c367428ceff..472f4d94a9da 100644
--- a/external/gpl3/gcc.old/dist/libgcc/config/m68k/lb1sf68.S
+++ b/external/gpl3/gcc.old/dist/libgcc/config/m68k/lb1sf68.S
@@ -172,7 +172,7 @@ see the files COPYING3 and COPYING.RUNTIME
respectively.  If not, see
  /* ISA C has no bra.l instruction, and since this assembly file
    gets assembled into multiple object files, we avoid the
    bra instruction entirely.  */
-#if defined (__mcoldfire__) && !defined (__mcfisab__)
+#if defined (__ELF__) || (defined (__mcoldfire__) && !defined (__mcfisab__))
  lea \addr-.-8,a0
  jmp pc@(a0)
 #else
@@ -211,7 +211,7 @@ see the files COPYING3 and COPYING.RUNTIME
respectively.  If not, see
  /* ISA C has no bra.l instruction, and since this assembly file
    gets assembled into multiple object files, we avoid the
    bra instruction entirely.  */
-#if defined (__mcoldfire__) && !defined (__mcfisab__)
+#if defined (__ELF__) || (defined (__mcoldfire__) && !defined (__mcfisab__))
  lea \addr-.-8,a0
  jmp pc@(a0)
 #else
diff --git a/external/gpl3/gcc/dist/libgcc/config/m68k/lb1sf68.S
b/external/gpl3/gcc/dist/libgcc/config/m68k/lb1sf68.S
index 3784f4323961..2b3ff490a2a1 100644
--- a/external/gpl3/gcc/dist/libgcc/config/m68k/lb1sf68.S
+++ b/external/gpl3/gcc/dist/libgcc/config/m68k/lb1sf68.S
@@ -172,7 +172,7 @@ see the files COPYING3 and COPYING.RUNTIME
respectively.  If not, see
  /* ISA C has no bra.l instruction, and since this assembly file
    gets assembled into multiple object files, we avoid the
    bra instruction entirely.  */
-#if defined (__mcoldfire__) && !defined (__mcfisab__)
+#if defined (__ELF__) || (defined (__mcoldfire__) && !defined (__mcfisab__))
  lea \addr-.-8,a0
  jmp pc@(a0)
 #else
@@ -211,7 +211,7 @@ see the files COPYING3 and COPYING.RUNTIME
respectively.  If not, see
  /* ISA C has no bra.l instruction, and since this assembly file
    gets assembled into multiple object files, we avoid the
    bra instruction entirely.  */
-#if defined (__mcoldfire__) && !defined (__mcfisab__)
+#if defined (__ELF__) || (defined (__mcoldfire__) && !defined (__mcfisab__))
  lea \addr-.-8,a0
  jmp pc@(a0)
 #else
diff --git a/share/mk/bsd.own.mk b/share/mk/bsd.own.mk
index 3d4850e22e52..efaadde72aaa 100644
--- a/share/mk/bsd.own.mk
+++ b/share/mk/bsd.own.mk
@@ -63,9 +63,6 @@ TOOLCHAIN_MISSING?= no
 #
 # What GCC is used?
 #
-.if ${MACHINE_CPU} == "m68k"
-HAVE_GCC?= 7
-.endif
 HAVE_GCC?= 8

 #
@@ -163,7 +160,7 @@ EXTERNAL_GDB_SUBDIR= /does/not/exist
     ${MACHINE_ARCH} == "powerpc64" || ${MACHINE_ARCH} == "powerpc" || \
     ${MACHINE_CPU} == "aarch64" || ${MACHINE_CPU} == "arm" || \
     ${MACHINE_ARCH} == "hppa" || ${MACHINE_ARCH} == "sparc64" || \
-    ${MACHINE} == "sun2" || ${MACHINE} == "alpha"
+    ${MACHINE_CPU} == "m68k" || ${MACHINE} == "alpha"
 HAVE_BINUTILS?= 234
 .else
 HAVE_BINUTILS?= 231
diff --git a/share/mk/bsd.sys.mk b/share/mk/bsd.sys.mk
index 758ab3485d4a..ba7f0f4d3cbc 100644
--- a/share/mk/bsd.sys.mk
+++ b/share/mk/bsd.sys.mk
@@ -234,7 +234,11 @@ CPUFLAGS+= -Wa,--fatal-warnings
 #CPUFLAGS+= -mno-abicalls -fno-PIC
 #.endif
 CFLAGS+= ${CPUFLAGS}
+
+# GNU assembler doesn't like some m68k flags, esp. for kernel locore.s, etc.
+.if ${MACHINE_CPU} != "m68k"
 AFLAGS+= ${CPUFLAGS}
+.endif

 .if ${KCOV:U0} > 0
 KCOVFLAGS= -fsanitize-coverage=trace-pc,trace-cmp

Subject: [PATCH 2/2] Insert missing whitespace for assembler flag rules.

Fixes assembler errors like "unrecognized option -m68040-mcpu=68040".
---
 external/gpl3/gcc/dist/gcc/config/m68k/m68k.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/external/gpl3/gcc/dist/gcc/config/m68k/m68k.h
b/external/gpl3/gcc/dist/gcc/config/m68k/m68k.h
index 506fa4e50e76..8c688a4156cc 100644
--- a/external/gpl3/gcc/dist/gcc/config/m68k/m68k.h
+++ b/external/gpl3/gcc/dist/gcc/config/m68k/m68k.h
@@ -36,9 +36,9 @@ along with GCC; see the file COPYING3.  If not see
    and .arch directives.  */

 #define ASM_CPU_SPEC "\
-%{m68851}%{mno-68851} %{m68881}%{mno-68881} %{msoft-float:-mno-float} \
-%{m68020-40:-m68040}%{m68020-60:-m68040}\
-%{mcpu=*:-mcpu=%*}%{march=*:-march=%*}\
+ %{m68851} %{mno-68851} %{m68881} %{mno-68881} %{msoft-float:-mno-float}\
+ %{m68020-40:-m68040} %{m68020-60:-m68040}\
+ %{mcpu=*:-mcpu=%*} %{march=*:-march=%*}\
 "
 #define ASM_PCREL_SPEC "%{" FPIE_OR_FPIC_SPEC ":--pcrel} \
  %{mpcrel:%{" NO_FPIE_AND_FPIC_SPEC ":--pcrel}} \


Home | Main Index | Thread Index | Old Index