Port-amiga archive

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

Re: Patches to fix building m68k with CPUFLAGS



Hi again,

My initial approach to patch the libgcc/config/m68k/lb1sf68.S file to
avoid 16-bit branches was a hack and not the right way to fix it, but
it wasn't until I made a linux-m68k cross compiler and looked at the
symbols with "nm -n" that I figured out why Linux isn't running into
build failures if you use "-m68030" or higher, while NetBSD is. If you
build for m68k-linux, the linker is placing "$_exception_handler"
exactly in the middle of the math functions that use it, while on
NetBSD, the same function is placed at the end, so the math functions
at the very beginning are >32KB away from it.

So it seems the correct fix to enable the use of any m68k CPUFLAGS
(with GCC 7 or 8, and with GCC 10, presumably) will be to modify the
build scripts to match whatever m68k-Linux is doing to lay out the
functions in the order that they can be linked with all branches <32KB
in size. I don't know how to do that, but I will try to figure it out.

On a related note, I can't build "m68k-netbsdelf" with GCC 10 (or
top-of-tree) for a different reason: it gives an internal compiler
error trying to build a floating-point rounding routine:

/home/jhamby/Projects/Toolchain/gcc-netbsd-m68k-gcc11/./gcc/xgcc
-B/home/jhamby/Projects/Toolchain/gcc-netbsd-m68k-gcc11/./gcc/
-B/home/jhamby/Projects/Toolchain/cross-netbsd-m68k/m68k--netbsdelf/bin/
-B/home/jhamby/Projects/Toolchain/cross-netbsd-m68k/m68k--netbsdelf/lib/
-isystem /home/jhamby/Projects/Toolchain/cross-netbsd-m68k/m68k--netbsdelf/include
-isystem /home/jhamby/Projects/Toolchain/cross-netbsd-m68k/m68k--netbsdelf/sys-include
   -g -O2 -O2  -g -O2 -DIN_GCC  -DCROSS_DIRECTORY_STRUCTURE  -W -Wall
-Wno-narrowing -Wwrite-strings -Wcast-qual -Wstrict-prototypes
-Wmissing-prototypes -Wold-style-definition  -isystem ./include
-fPIC -g -DIN_LIBGCC2 -fbuilding-libgcc -fno-stack-protector
-Dinhibit_libc  -fPIC -I. -I. -I../.././gcc -I../../../gcc/libgcc
-I../../../gcc/libgcc/. -I../../../gcc/libgcc/../gcc
-I../../../gcc/libgcc/../include  -DHAVE_CC_TLS  -o _fixunsxfdi.o -MT
_fixunsxfdi.o -MD -MP -MF _fixunsxfdi.dep -DL_fixunsxfdi -c
../../../gcc/libgcc/libgcc2.c -fvisibility=hidden -DHIDE_EXPORTS
during RTL pass: expand
../../../gcc/libgcc/libgcc2.c: In function ‘__fixunsxfdi’:
../../../gcc/libgcc/libgcc2.c:1412:5: internal compiler error:
Segmentation fault
 1412 |   a -= (XFtype)v;
      |   ~~^~~~~~~~~~~~
0xdb4eb3 crash_signal
../../gcc/gcc/toplev.c:328
0xa88015 assign_temp(tree_node*, int, int)
../../gcc/gcc/function.c:972
0xa2733d emit_push_insn(rtx_def*, machine_mode, tree_node*, rtx_def*,
unsigned int, int, rtx_def*, poly_int<1u, long>, rtx_def*, rtx_def*,
int, rtx_def*, bool)
../../gcc/gcc/expr.c:4515
0x8ed493 emit_library_call_value_1(int, rtx_def*, rtx_def*,
libcall_type, machine_mode, int, std::pair<rtx_def*, machine_mode>*)
../../gcc/gcc/calls.c:5480
0xca3d85 emit_library_call_value(rtx_def*, rtx_def*, libcall_type,
machine_mode, rtx_def*, machine_mode)
../../gcc/gcc/rtl.h:4245
0xca3d85 expand_float(rtx_def*, rtx_def*, int)
../../gcc/gcc/optabs.c:4940
0xa3033e expand_expr_real_2(separate_ops*, rtx_def*, machine_mode,
expand_modifier)
../../gcc/gcc/expr.c:9269
0xa1fea4 expand_expr_real_1(tree_node*, rtx_def*, machine_mode,
expand_modifier, rtx_def**, bool)
../../gcc/gcc/expr.c:10159
0xa288bc expand_expr
../../gcc/gcc/expr.h:282
0xa288bc expand_operands(tree_node*, tree_node*, rtx_def*, rtx_def**,
rtx_def**, expand_modifier)
../../gcc/gcc/expr.c:8066
0xa2f578 expand_expr_real_2(separate_ops*, rtx_def*, machine_mode,
expand_modifier)
../../gcc/gcc/expr.c:9949
0x905639 expand_gimple_stmt_1
../../gcc/gcc/cfgexpand.c:3786
0x905639 expand_gimple_stmt
../../gcc/gcc/cfgexpand.c:3847
0x90b961 expand_gimple_basic_block
../../gcc/gcc/cfgexpand.c:5888
0x90d58f execute
../../gcc/gcc/cfgexpand.c:6572
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.
make[2]: *** [Makefile:501: _fixunsxfdi.o] Error 1
make[2]: Leaving directory
'/home/jhamby/Projects/Toolchain/gcc-netbsd-m68k-gcc11/m68k--netbsdelf/libgcc'
make[1]: *** [Makefile:12704: all-target-libgcc] Error 2
make[1]: Leaving directory
'/home/jhamby/Projects/Toolchain/gcc-netbsd-m68k-gcc11'
make: *** [Makefile:957: all] Error 2

Because this also doesn't happen with the same compiler and
"m68k-linux", I'm hoping that it, like the other problem I'm seeing,
is a matter of a configuration file that could hopefully be changed to
match what Linux is doing. I'll send another email once I've made
further progress.

Cheers,
Jake

On Sun, Jul 19, 2020 at 10:35 AM Jake Hamby <jake.hamby%gmail.com@localhost> wrote:
>
> 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