GCC cross-compiler for Apple silicon

C and PASCAL (or any other high-level languages) in here please
Post Reply
ThorstenOtto
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 3412
Joined: Sun Aug 03, 2014 5:54 pm

GCC cross-compiler for Apple silicon

Post by ThorstenOtto »

GCC & binutils, as universal binaries for x86_64 & arm64, are now available. Since i cannot compile them myself, they are compiled using github runners. You will find the resulting binaries at https://tho-otto.de/snapshots/crossmint/macos/.

The repo with the scripts can be found here: https://github.com/th-otto/crossmint

Note that, unlike my other compilers for macOS, you will need atleast macOS Big Sur for these, they won't work on anything older, not even on x86_64 hardware.

Please let me know if they work, or if you encounter any problems.
cdpjenkins
Atari maniac
Atari maniac
Posts: 79
Joined: Wed Dec 22, 2021 8:37 pm

Re: GCC cross-compiler for Apple silicon

Post by cdpjenkins »

Many thanks for compiling these.

I tried using gcc-4.6.4-mint-20230206-bin-macos.tar.xz to build a small C++ program on my M1 Macbook Pro running Monterey. It blew up with a couple of errors [0]:

1.

Code: Select all

internal compiler error: in darwin_gt_pch_use_address, at config/host-darwin.c:51
I need to look into the GCC code to figure out what it thinks it's doing there but something is wrong...

2.

Code: Select all

stdio.h: No such file or directory
Do I need to do anything special in order to have the C standard library available when compiling? I'm pretty certain I haven't done anything when using cross-mint toolchains that you have previously built.

I'm not very familiar with the internals of GCC so I am interested if you have any ideas for things I can further investigate.

FYI the code that I'm trying to build can be found here: https://github.com/cdpjenkins/hello_gem ... /cppconway (Please don't judge me: this is pretty much the first C++ code that I wrote after 15 years away from the language!)

[0]

Code: Select all

m68k-atari-mint-g++ -O3 -m68000 src/Dots.cpp src/ConwayGui.cpp src/ConwayGrid.cpp -o dist/conway.prg  -lgem -lgcc
In file included from src/dots.hpp:5:0,
                 from src/Dots.cpp:1:
src/types.hpp:4:1: internal compiler error: in darwin_gt_pch_use_address, at config/host-darwin.c:51
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.
src/ConwayGui.cpp:1:19: fatal error: stdio.h: No such file or directory
compilation terminated.
src/ConwayGrid.cpp:1:19: fatal error: stdio.h: No such file or directory
compilation terminated.
make: *** [dist/conway.prg] Error 1
cdpjenkins
Atari maniac
Atari maniac
Posts: 79
Joined: Wed Dec 22, 2021 8:37 pm

Re: GCC cross-compiler for Apple silicon

Post by cdpjenkins »

I then tried using gcc-7.5.0-mint-20230206-bin-macos.tar.xz to build the same codebase. I get the same two errors (or two very similar errors...), which is interesting. Maybe I'm just doing something wrong:

Code: Select all

$ make
mkdir -p dist
cp grids/*.cwy dist/
m68k-atari-mint-g++ -O3 -m68000 src/Dots.cpp src/ConwayGui.cpp src/ConwayGrid.cpp -o dist/conway.prg  -lgem -lgcc
In file included from src/dots.hpp:5:0,
                 from src/Dots.cpp:1:
src/types.hpp:4:1: internal compiler error: in darwin_gt_pch_use_address, at config/host-darwin.c:51
 typedef unsigned int   uint32;
 ^~~~~~~
libbacktrace could not find executable to open
Please submit a full bug report,
with preprocessed source if appropriate.
See <https://gcc.gnu.org/bugs/> for instructions.
src/ConwayGui.cpp:1:10: fatal error: stdio.h: No such file or directory
 #include <stdio.h>
          ^~~~~~~~~
compilation terminated.
src/ConwayGrid.cpp:1:10: fatal error: stdio.h: No such file or directory
 #include <stdio.h>
          ^~~~~~~~~
compilation terminated.
make: *** [dist/conway.prg] Error 1
cdpjenkins
Atari maniac
Atari maniac
Posts: 79
Joined: Wed Dec 22, 2021 8:37 pm

Re: GCC cross-compiler for Apple silicon

Post by cdpjenkins »

I tried gcc-12.2.0-mint-20230112-bin-macos.tar.xz and get a different error [0] that says clang: error: the clang compiler does not support '-mcpu=68000'. I'm not sure why clang is getting invoked here :-/

I also get the same error telling me that stdio.h is not found, which makes me think that I might be doing something wrong.

Code: Select all

$ m68k-atari-mint-g++ -O3 -m68000 src/Dots.cpp src/ConwayGui.cpp src/ConwayGrid.cpp -o dist/conway.prg  -lgem -lgcc
clang: error: the clang compiler does not support '-mcpu=68000'
src/ConwayGui.cpp:1:10: fatal error: stdio.h: No such file or directory
    1 | #include <stdio.h>
      |          ^~~~~~~~~
compilation terminated.
src/ConwayGrid.cpp:1:10: fatal error: stdio.h: No such file or directory
    1 | #include <stdio.h>
cdpjenkins
Atari maniac
Atari maniac
Posts: 79
Joined: Wed Dec 22, 2021 8:37 pm

Re: GCC cross-compiler for Apple silicon

Post by cdpjenkins »

A quick Google search shows that at least one person hit the internal error in darwin_gt_pch_use_address:

https://github.com/iains/gcc-darwin-arm ... -749031593

The suggested fix was to pull in this patch https://github.com/iains/gcc-darwin-arm ... 18978f1efa which apparently takes into account a different page size. Looking at your set of patches, I don't see a change that affects pch_address_space but I might have missed something.
ThorstenOtto
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 3412
Joined: Sun Aug 03, 2014 5:54 pm

Re: GCC cross-compiler for Apple silicon

Post by ThorstenOtto »

Thanks for testing.

Looks like for gcc-12, the fix you mentioned is already in the upstream code (or has been replaced by something else, that pch_address_space variable does not exist anymore). For gcc-7 and gcc-4 i'll try to backport that patch. May take a few hours.

As for the missing stdio.h: did you install mintlib (and any other libraries you need, like fdlibm & gemlib)? That error is a typical symptom of not installing it (or in the wrong path). By default, the compiler for macOS is installed in /opt/cross-mint, and other libraries should be installed there, too. So the directory layout should look like

Code: Select all

/opt/cross-mint/
/opt/cross-mint/bin
/opt/cross-mint/lib
/opt/cross-mint/lib/gcc
/opt/cross-mint/lib/gcc/m68k-atari-mint
/opt/cross-mint/lib/gcc/m68k-atari-mint/4.6.4
/opt/cross-mint/lib/gcc/m68k-atari-mint/7
/opt/cross-mint/lib/gcc/m68k-atari-mint/12
/opt/cross-mint/m68k-atari-mint
/opt/cross-mint/m68k-atari-mint/bin
/opt/cross-mint/m68k-atari-mint/lib
/opt/cross-mint/m68k-atari-mint/lib/ldscripts
/opt/cross-mint/m68k-atari-mint/sys-root
/opt/cross-mint/m68k-atari-mint/sys-root/bin
/opt/cross-mint/m68k-atari-mint/sys-root/mint
/opt/cross-mint/m68k-atari-mint/sys-root/mint/slb
/opt/cross-mint/m68k-atari-mint/sys-root/sbin
/opt/cross-mint/m68k-atari-mint/sys-root/usr
/opt/cross-mint/m68k-atari-mint/sys-root/usr/bin
/opt/cross-mint/m68k-atari-mint/sys-root/usr/etc
/opt/cross-mint/m68k-atari-mint/sys-root/usr/include
/opt/cross-mint/m68k-atari-mint/sys-root/usr/include/c++
/opt/cross-mint/m68k-atari-mint/sys-root/usr/include/c++/4.6.4
/opt/cross-mint/m68k-atari-mint/sys-root/usr/include/c++/7
/opt/cross-mint/m68k-atari-mint/sys-root/usr/include/c++/12
/opt/cross-mint/m68k-atari-mint/sys-root/usr/lib
/opt/cross-mint/m68k-atari-mint/sys-root/usr/lib/m5475
/opt/cross-mint/m68k-atari-mint/sys-root/usr/lib/m5475/mfastcall
/opt/cross-mint/m68k-atari-mint/sys-root/usr/lib/m5475/mshort
/opt/cross-mint/m68k-atari-mint/sys-root/usr/lib/m68020-60
/opt/cross-mint/m68k-atari-mint/sys-root/usr/lib/m68020-60/mshort
/opt/cross-mint/m68k-atari-mint/sys-root/usr/lib/mshort
/opt/cross-mint/m68k-atari-mint/sys-root/usr/lib/pkgconfig
/opt/cross-mint/m68k-atari-mint/sys-root/usr/sbin
/opt/cross-mint/m68k-atari-mint/sys-root/usr/share
/opt/cross-mint/m68k-atari-mint/sys-root/usr/stguide
Actually, all atari related code should be below /opt/cross-mint/m68k-atari-mint/sys-root/, and that directory will look like it would on a native installation, with headers in <sys-root>/usr/include, libraries in <sys-root>/usr/lib etc.

Why clang is invoked: i have no idea. That certainly should not happen. Can you try to add -v to your commandline, and see what steps are executed?
ThorstenOtto
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 3412
Joined: Sun Aug 03, 2014 5:54 pm

Re: GCC cross-compiler for Apple silicon

Post by ThorstenOtto »

New binaries are now available. Currently, the gcc-12 archive is a bit misnamed (it still has the date 20230112 in the archive name), but was just compiled. I'll start another run to fix that.

BTW, in the github repo you linked above are also some more changes, most of them seem also to be darwin/aarch64 related. Since the author marks them as work-in-progress, i did not integrate them. If you think some of them are needed, pls. let me know. I've attached an archive with the patches that are not in the master branch.
You do not have the required permissions to view the files attached to this post.
Perdrix24
Captain Atari
Captain Atari
Posts: 204
Joined: Mon Feb 26, 2018 1:47 pm
Location: Québec, Canada
Contact:

Re: GCC cross-compiler for Apple silicon

Post by Perdrix24 »

Is this supposed to work with non-silicon Macs too? I have Ventura 13.0.1. When I try to compile the USB mouse driver with 7.5.0 or 12.2.0, for the PRG target, I get:

MacBook-Air-de-Claude:mouse claudelabelle$ make prg
/Applications/Xcode.app/Contents/Developer/usr/bin/make buildmouse mouse=prg
mkdir -p .compile_prg
cp Makefile.objs .compile_prg/Makefile
cd .compile_prg; /Applications/Xcode.app/Contents/Developer/usr/bin/make all
cp ../../../../../../usb/src.km/tos-common/stripex.c .
gcc stripex.c -o stripex
m68k-atari-mint-gcc -I../../../../../.. -I../../../../../../../../sys -D__KERNEL_MODULE__ -DMODULE_NAME=mouse -DTOSONLY -fno-builtin -DSTACKSIZE=8192 -m68000 -fgnu89-inline -Werror -mshort -g -O2 -fomit-frame-pointer -Wall -Wmissing-prototypes -Wshadow -Wpointer-arith -Wcast-qual -c ../entry.S -o entry.o
clang: error: unsupported option '--gstabs'
make[2]: *** [entry.o] Error 1
make[1]: *** [_stmp_prg] Error 2
make: *** [prg] Error 2
MacBook-Air-de-Claude:mouse claudelabelle$

And for the 02060 target, I get:
MacBook-Air-de-Claude:mouse claudelabelle$ make 02060
/Applications/Xcode.app/Contents/Developer/usr/bin/make buildmouse mouse=02060
mkdir -p .compile_02060
cp Makefile.objs .compile_02060/Makefile
cd .compile_02060; /Applications/Xcode.app/Contents/Developer/usr/bin/make all
m68k-atari-mint-gcc -I../../../../../.. -I../../../../../../../../sys -D__KERNEL_MODULE__ -DMODULE_NAME=mouse -m68020-60 -fgnu89-inline -Werror -mshort -g -O2 -fomit-frame-pointer -Wall -Wmissing-prototypes -Wshadow -Wpointer-arith -Wcast-qual -c ../hid.c -o hid.o
In file included from ../../../../../../mint/mint.h:18:0,
from ../../../../../../cookie.h:13,
from ../../../../global.h:26,
from ../hid.c:10:
../../../../../../mint/kcompiler.h:39:11: fatal error: compiler.h: No such file or directory
# include <compiler.h>
^~~~~~~~~~~~
compilation terminated.
make[2]: *** [hid.o] Error 1
make[1]: *** [_stmp_02060] Error 2
make: *** [02060] Error 2
MacBook-Air-de-Claude:mouse claudelabelle$
ThorstenOtto
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 3412
Joined: Sun Aug 03, 2014 5:54 pm

Re: GCC cross-compiler for Apple silicon

Post by ThorstenOtto »

Perdrix24 wrote: Fri Feb 10, 2023 2:05 pm Is this supposed to work with non-silicon Macs too? I have Ventura 13.0.1.
Yes, that should work. That's why it is a universal binary. The runner on github is a x86_64 machine, too. But on x86_64 hosts, the previous macOS ports should work, too.
clang: error: unsupported option '--gstabs'
Hm, strange. Maybe same problem as above. Can you add -v to the link step to see what happens? clang should not be involved at all. Must be something going wrong with the configuration.
../../../../../../mint/kcompiler.h:39:11: fatal error: compiler.h: No such file or directory
<compiler.h> is from mintlib. Is that installed?
cdpjenkins
Atari maniac
Atari maniac
Posts: 79
Joined: Wed Dec 22, 2021 8:37 pm

Re: GCC cross-compiler for Apple silicon

Post by cdpjenkins »

ThorstenOtto wrote: Fri Feb 10, 2023 6:41 am As for the missing stdio.h: did you install mintlib (and any other libraries you need, like fdlibm & gemlib)? That error is a typical symptom of not installing it (or in the wrong path). By default, the compiler for macOS is installed in /opt/cross-mint, and other libraries should be installed there, too.
It turned out I had not untarred mintlib into the same directory. Doing that fixed the problem.
Why clang is invoked: i have no idea. That certainly should not happen. Can you try to add -v to your commandline, and see what steps are executed?
It turned out I had also messed up by not untarring binutils into the same directory, so the compiler was trying to invoke Apple's as command from /usr/bin/as. Untarring binutils into the correct directory fixed that.

So the gcc 12 that you built now works well for me so far. I can compile my own little programs with it, anyway, and they run ok under FreeMiNT in ARAnyM so I'm happy so far. Many thanks!
cdpjenkins
Atari maniac
Atari maniac
Posts: 79
Joined: Wed Dec 22, 2021 8:37 pm

Re: GCC cross-compiler for Apple silicon

Post by cdpjenkins »

ThorstenOtto wrote: Fri Feb 10, 2023 11:49 am New binaries are now available. Currently, the gcc-12 archive is a bit misnamed (it still has the date 20230112 in the archive name), but was just compiled. I'll start another run to fix that.
Next, I tried the gcc 4.6.4 compiler in gcc-4.6.4-mint-20230210-bin-macos.tar.xz. This fails with a segmentation fault:

Code: Select all

$ m68k-atari-mint-g++ -O3 -m68000 src/ConwayGui.cpp src/ConwayGrid.cpp -o dist/conway.prg  -lgem -lgcc
src/ConwayGui.cpp: In function 'void _Z16draw_conway_gridtP9RectangleP10ConwayGrid.constprop.0(uint16, Rectangle*)':
src/ConwayGui.cpp:280:6: internal compiler error: Segmentation fault: 11
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.
src/ConwayGrid.cpp: In constructor 'ConwayGrid::ConwayGrid(int16, int16)':
src/ConwayGrid.cpp:12:1: internal compiler error: Segmentation fault: 11
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.
I ran lldb on the underlying cc1plus command [0]. It fails with a bad access to address 0x140f which doesn't look like a valid MacOS address to me. I confess I'm not familiar with how a MacOS process is laid out but I believe that an address that low does not point to valid memory.

Any ideas for what I could look at next to debug this?

Code: Select all

$ lldb /Users/cdpj/opt/cross-mint/bin/../lib/gcc/m68k-atari-mint/4.6.4/cc1plus --  -v -iprefix /Users/cdpj/opt/cross-mint/bin/../lib/gcc/m68k-atari-mint/4.6.4/ -isysroot /Users/cdpj/opt/cross-mint/bin/../m68k-atari-mint/sys-root -D__M68000__ src/ConwayGui.cpp -dumpbase ConwayGui.cpp -da -m68000 -auxbase ConwayGui -O3 -version -o /var/folders/y5/lz8_p3m15cbfg3gg0y268pk00000gn/T//ccUXjUnB.s
(lldb) target create "/Users/cdpj/opt/cross-mint/bin/../lib/gcc/m68k-atari-mint/4.6.4/cc1plus"
Current executable set to '/Users/cdpj/opt/cross-mint/lib/gcc/m68k-atari-mint/4.6.4/cc1plus' (arm64).
(lldb) settings set -- target.run-args  "-v" "-iprefix" "/Users/cdpj/opt/cross-mint/bin/../lib/gcc/m68k-atari-mint/4.6.4/" "-isysroot" "/Users/cdpj/opt/cross-mint/bin/../m68k-atari-mint/sys-root" "-D__M68000__" "src/ConwayGui.cpp" "-dumpbase" "ConwayGui.cpp" "-da" "-m68000" "-auxbase" "ConwayGui" "-O3" "-version" "-o" "/var/folders/y5/lz8_p3m15cbfg3gg0y268pk00000gn/T//ccUXjUnB.s"
(lldb) run
Process 88895 launched: '/Users/cdpj/opt/cross-mint/lib/gcc/m68k-atari-mint/4.6.4/cc1plus' (arm64)
GNU C++ (MiNT 20230210) version 4.6.4 (m68k-atari-mint)
	compiled by GNU C version Apple LLVM 14.0.0 (clang-1400.0.29.202), GMP version 6.2.1, MPFR version 3.1.4, MPC version 1.0.3
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "/Users/cdpj/opt/cross-mint/bin/../lib/gcc/m68k-atari-mint/4.6.4/../../../../m68k-atari-mint/include"
ignoring nonexistent directory "/opt/cross-mint/m68k-atari-mint/sys-root/usr/include/c++/4.6.4"
ignoring nonexistent directory "/opt/cross-mint/m68k-atari-mint/sys-root/usr/include/c++/4.6.4/m68k-atari-mint"
ignoring nonexistent directory "/opt/cross-mint/m68k-atari-mint/sys-root/usr/include/c++/4.6.4/backward"
ignoring nonexistent directory "/opt/cross-mint/lib/gcc/m68k-atari-mint/4.6.4/include"
ignoring nonexistent directory "/Users/cdpj/opt/cross-mint/bin/../m68k-atari-mint/sys-root/usr/local/include"
ignoring nonexistent directory "/opt/cross-mint/lib/gcc/m68k-atari-mint/4.6.4/include-fixed"
ignoring nonexistent directory "/opt/cross-mint/m68k-atari-mint/include"
#include "..." search starts here:
#include <...> search starts here:
 /Users/cdpj/opt/cross-mint/bin/../lib/gcc/m68k-atari-mint/4.6.4/include
 /Users/cdpj/opt/cross-mint/bin/../lib/gcc/m68k-atari-mint/4.6.4/include-fixed
 /Users/cdpj/opt/cross-mint/bin/../m68k-atari-mint/sys-root/usr/include
End of search list.
GNU C++ (MiNT 20230210) version 4.6.4 (m68k-atari-mint)
	compiled by GNU C version Apple LLVM 14.0.0 (clang-1400.0.29.202), GMP version 6.2.1, MPFR version 3.1.4, MPC version 1.0.3
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
options passed:  -v
 -iprefix /Users/cdpj/opt/cross-mint/bin/../lib/gcc/m68k-atari-mint/4.6.4/
 -isysroot /Users/cdpj/opt/cross-mint/bin/../m68k-atari-mint/sys-root
 -D__M68000__ src/ConwayGui.cpp -m68000 -O3
options enabled:  -falign-functions -falign-jumps -falign-labels
 -falign-loops -fauto-inc-dec -fbranch-count-reg -fcaller-saves
 -fcombine-stack-adjustments -fcommon -fcompare-elim -fcprop-registers
 -fcrossjumping -fcse-follow-jumps -fdefer-pop -fdelete-null-pointer-checks
 -fdevirtualize -fearly-inlining -feliminate-unused-debug-types
 -fexceptions -fexpensive-optimizations -fforward-propagate -ffunction-cse
 -fgcse -fgcse-after-reload -fgcse-lm -fguess-branch-probability -fident
 -fif-conversion -fif-conversion2 -findirect-inlining -finline
 -finline-functions -finline-functions-called-once -finline-small-functions
 -fipa-cp -fipa-cp-clone -fipa-profile -fipa-pure-const -fipa-reference
 -fipa-sra -fira-share-save-slots -fira-share-spill-slots -fivopts
 -fkeep-static-consts -fleading-underscore -fmath-errno -fmerge-constants
 -fmerge-debug-strings -fmove-loop-invariants -foptimize-register-move
 -foptimize-sibling-calls -fpartial-inlining -fpeephole -fpeephole2
 -fpredictive-commoning -fprefetch-loop-arrays -freg-struct-return
 -fregmove -freorder-blocks -freorder-functions -frerun-cse-after-loop
 -fsched-critical-path-heuristic -fsched-dep-count-heuristic
 -fsched-group-heuristic -fsched-interblock -fsched-last-insn-heuristic
 -fsched-rank-heuristic -fsched-spec -fsched-spec-insn-heuristic
 -fsched-stalled-insns-dep -fshow-column -fsigned-zeros
 -fsplit-ivs-in-unroller -fsplit-wide-types -fstrict-aliasing
 -fstrict-overflow -fstrict-volatile-bitfields -fthread-jumps
 -ftoplevel-reorder -ftrapping-math -ftree-bit-ccp -ftree-builtin-call-dce
 -ftree-ccp -ftree-ch -ftree-copy-prop -ftree-copyrename -ftree-cselim
 -ftree-dce -ftree-dominator-opts -ftree-dse -ftree-forwprop -ftree-fre
 -ftree-loop-distribute-patterns -ftree-loop-if-convert -ftree-loop-im
 -ftree-loop-ivcanon -ftree-loop-optimize -ftree-parallelize-loops=
 -ftree-phiprop -ftree-pre -ftree-pta -ftree-reassoc -ftree-scev-cprop
 -ftree-sink -ftree-slp-vectorize -ftree-sra -ftree-switch-conversion
 -ftree-ter -ftree-vect-loop-version -ftree-vectorize -ftree-vrp
 -funit-at-a-time -funswitch-loops -fvar-tracking
 -fvar-tracking-assignments -fzero-initialized-in-bss -mstrict-align
Compiler executable checksum: 03cde72dbd6951a172d7d74960589187
 int vprintf(const char*, __gnuc_va_list) int vfscanf(FILE*, const char*, __gnuc_va_list) int vscanf(const char*, __gnuc_va_list) int vsscanf(const char*, const char*, __gnuc_va_list) int getchar() int getc_unlocked(FILE*) int getchar_unlocked() int putchar(int) int fputc_unlocked(int, FILE*) int putc_unlocked(int, FILE*) int putchar_unlocked(int) __uint16_t __bswap_16(__uint16_t) __uint32_t __bswap_32(__uint32_t) __uint64_t __bswap_64(__uint64_t) __uint16_t __uint16_identity(__uint16_t) __uint32_t __uint32_identity(__uint32_t) __uint64_t __uint64_identity(__uint64_t) short int appl_init() bool ConwayGrid::cell_alive_at(int16, int16) void ConwayGrid::set_cell(bool*, int16, int16, bool) int16 ConwayGrid::grid_index(int16, int16) int main(int, char**) void open_vwork() void start_program() void event_loop(win_data*) void do_redraw(win_data*, GRECT*) void draw_within_clip(win_data*, GRECT) void draw_conway_grid(uint16, Rectangle*, ConwayGrid*) void draw_rectangle(int16, int16, int16, int16, int16) void set_clip(bool, GRECT) bool is_full_window(uint16) void do_fulled(uint16) void do_sized(uint16, int16, int16, int16, int16) void do_menu(win_data*, int, bool*) void pause() void run() void __static_initialization_and_destruction_0(int, int) void _GLOBAL__sub_I_grid()
Analyzing compilation unit
Performing interprocedural optimizations
 <*free_lang_data> <visibility> <early_local_cleanups> <emutls> <whole-program> <ipa-profile> <cp> <inline> <pure-const> <static-var>Assembling functions:
 void _Z16draw_conway_gridtP9RectangleP10ConwayGrid.constprop.0(uint16, Rectangle*)Process 88895 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x140f)
    frame #0: 0x000000010058cf2c cc1plus`___lldb_unnamed_symbol10578 + 316
cc1plus`___lldb_unnamed_symbol10578:
->  0x10058cf2c <+316>: ldrh   w8, [x8]
    0x10058cf30 <+320>: cmp    w8, #0x25
    0x10058cf34 <+324>: b.ne   0x10058d194               ; <+932>
    0x10058cf38 <+328>: ldr    x8, [x0, #0x8]
Target 0: (cc1plus) stopped.
ThorstenOtto
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 3412
Joined: Sun Aug 03, 2014 5:54 pm

Re: GCC cross-compiler for Apple silicon

Post by ThorstenOtto »

Just as reminder (because that bug of the hosts assembler being used already hit me several times): you can always check whether the intended assembler/linker is invoked by using

Code: Select all

$ m68k-atari-mint-gcc -print-prog-name=as
If that just prints "as" instead of the full path to the assembler, something is going wrong.

On cygwin, and an newer distros where /bin and /usr/bin are the same directory, there is another pitfall. For example here on linux, i get

Code: Select all

$ /usr/bin/m68k-atari-mint-gcc -print-prog-name=as
/usr/lib64/gcc/m68k-atari-mint/4.6.4/../../../../m68k-atari-mint/bin/as
As you can see, gcc tries to locate its tools using a relative path, assuming a certain directory layout. If you count the "..", that will end up in being

Code: Select all

/usr/m68k-atari-mint/bin/as
which is fine, since in the archive symlinks are installed to this directory. However, if /bin and /usr/bin are the same directory, and /bin is first on the path, that will go up one level too much, resulting in /m68k-atari-mint/bin/as, which does not exist. Simple solution: make sure /usr/bin is first on your $PATH
cdpjenkins
Atari maniac
Atari maniac
Posts: 79
Joined: Wed Dec 22, 2021 8:37 pm

Re: GCC cross-compiler for Apple silicon

Post by cdpjenkins »

ThorstenOtto wrote: Fri Feb 10, 2023 6:04 pm Just as reminder (because that bug of the hosts assembler being used already hit me several times): you can always check whether the intended assembler/linker is invoked by using

Code: Select all

$ m68k-atari-mint-gcc -print-prog-name=as
Many thanks. I was not aware of that and will remember it for next time!
cdpjenkins
Atari maniac
Atari maniac
Posts: 79
Joined: Wed Dec 22, 2021 8:37 pm

Re: GCC cross-compiler for Apple silicon

Post by cdpjenkins »

I also tried GCC 7.5.0 from gcc-7.5.0-mint-20230210-bin-macos.tar.xz. That also works fine on my Mac now (compiling my toy app). Many thanks for the hard work building this and getting it working :-)
ThorstenOtto
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 3412
Joined: Sun Aug 03, 2014 5:54 pm

Re: GCC cross-compiler for Apple silicon

Post by ThorstenOtto »

cdpjenkins wrote: Fri Feb 10, 2023 6:00 pm I ran lldb on the underlying cc1plus command [0]. It fails with a bad access to address 0x140f which doesn't look like a valid MacOS address to me. I confess I'm not familiar with how a MacOS process is laid out but I believe that an address that low does not point to valid memory.
Yes, that is certainly not a valid address.
Any ideas for what I could look at next to debug this?
That line(s) looks suspicious to me:

Code: Select all

ignoring nonexistent directory "/opt/cross-mint/m68k-atari-mint/sys-root/usr/include/c++/4.6.4"
ignoring nonexistent directory "/opt/cross-mint/m68k-atari-mint/sys-root/usr/include/c++/4.6.4/m68k-atari-mint"
ignoring nonexistent directory "/opt/cross-mint/m68k-atari-mint/sys-root/usr/include/c++/4.6.4/backward"
because that's exactly the location where the c++ headers should be. Those are from the compiler archive, not from mintlib. Maybe some installation problem again?

(that doesn't exactly explain the crash, it should rather complain about the missing header files, but maybe that is the initial cause of the problem)
cdpjenkins
Atari maniac
Atari maniac
Posts: 79
Joined: Wed Dec 22, 2021 8:37 pm

Re: GCC cross-compiler for Apple silicon

Post by cdpjenkins »

ThorstenOtto wrote: Fri Feb 10, 2023 11:49 am BTW, in the github repo you linked above are also some more changes, most of them seem also to be darwin/aarch64 related. Since the author marks them as work-in-progress, i did not integrate them. If you think some of them are needed, pls. let me know. I've attached an archive with the patches that are not in the master branch.
I'm afraid my GCC skills are not very strong so I don't know how to understand whether most of those are needed. I suggest we keep that repo in mind while we try using the compilers that you have built and look at the patches again if we hit any other problems.
ThorstenOtto
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 3412
Joined: Sun Aug 03, 2014 5:54 pm

Re: GCC cross-compiler for Apple silicon

Post by ThorstenOtto »

Oh, and another note: it is possible to install all three toolchains concurrently like you did, however there is no common way for all systems to specify which compiler is the default one when you just say "m68k-atari-mint-gcc". Most likely, this will be just the version you installed last. If in doubt, check the symlinks in /opt/cross-mint/bin
cdpjenkins
Atari maniac
Atari maniac
Posts: 79
Joined: Wed Dec 22, 2021 8:37 pm

Re: GCC cross-compiler for Apple silicon

Post by cdpjenkins »

ThorstenOtto wrote: Fri Feb 10, 2023 6:14 pm
That line(s) looks suspicious to me:

Code: Select all

ignoring nonexistent directory "/opt/cross-mint/m68k-atari-mint/sys-root/usr/include/c++/4.6.4"
ignoring nonexistent directory "/opt/cross-mint/m68k-atari-mint/sys-root/usr/include/c++/4.6.4/m68k-atari-mint"
ignoring nonexistent directory "/opt/cross-mint/m68k-atari-mint/sys-root/usr/include/c++/4.6.4/backward"
That's weird, because the directories do exist:
- /opt/cross-mint/m68k-atari-mint/sys-root/usr/include/c++/4.6.4 (appears to contain all the C++ headers...)
- /opt/cross-mint/m68k-atari-mint/sys-root/usr/include/c++/4.6.4/m68k-atari-mint (contains bits, m5475 and m68020-60)
- /opt/cross-mint/m68k-atari-mint/sys-root/usr/include/c++/4.6.4/backward (contains some presumably deprecated C++ headers like auto_ptr.h)

So I'm not sure what's going on there. I suspected a permissions problem but the directories are all readable.
Perdrix24
Captain Atari
Captain Atari
Posts: 204
Joined: Mon Feb 26, 2018 1:47 pm
Location: Québec, Canada
Contact:

Re: GCC cross-compiler for Apple silicon

Post by Perdrix24 »

ThorstenOtto wrote: Fri Feb 10, 2023 2:51 pm
Perdrix24 wrote: Fri Feb 10, 2023 2:05 pm Is this supposed to work with non-silicon Macs too? I have Ventura 13.0.1.
Yes, that should work. That's why it is a universal binary. The runner on github is a x86_64 machine, too. But on x86_64 hosts, the previous macOS ports should work, too.
clang: error: unsupported option '--gstabs'
Hm, strange. Maybe same problem as above. Can you add -v to the link step to see what happens? clang should not be involved at all. Must be something going wrong with the configuration.
../../../../../../mint/kcompiler.h:39:11: fatal error: compiler.h: No such file or directory
<compiler.h> is from mintlib. Is that installed?
Great! Thanks for your work. I hope to make it work.

I need help setting up. I have the package at https://donzé.ch/atari/articles/cross-compiler/ installed, it's 4.6.4 and it's an "all included" package. How do I bring it up to date with 7.5.0?

Claude
ThorstenOtto
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 3412
Joined: Sun Aug 03, 2014 5:54 pm

Re: GCC cross-compiler for Apple silicon

Post by ThorstenOtto »

To install the compiler, binutils & mintbin:

Code: Select all

tar xvf gcc-7.5.0-mint-20230210-bin-macos.tar.xz -C /
tar xvf binutils-2.39-mint-20220911-bin-macos.tar.xz -C /
tar xvf mintbin-0.3-mint-20230206-bin-macos.tar.xz -C /
But note that this will overwrite most files from Philipp's archive.

Library packages have a different directory layout because they are not system dependent, and the default prefix for other hosts is /usr instead of /opt/cross-mint. You should be able to install them with:

Code: Select all

tar xvf mintlib-0.60.1-mint-20200102-dev.tar.xz --strip-components=1 -C /opt/cross-mint
tar xvf fdlibm-20230210-mint-dev.tar.xz --strip-components=1 -C /opt/cross-mint
...
if you are using the archives from my site. The snapshot archives built from the freemint repo are meant for native installation, and don't have the /usr/m68k-atari-mint/sys-root/ prefix.
Perdrix24
Captain Atari
Captain Atari
Posts: 204
Joined: Mon Feb 26, 2018 1:47 pm
Location: Québec, Canada
Contact:

Re: GCC cross-compiler for Apple silicon

Post by Perdrix24 »

ThorstenOtto wrote: Sat Feb 11, 2023 6:12 am To install the compiler, binutils & mintbin:

Code: Select all

tar xvf gcc-7.5.0-mint-20230210-bin-macos.tar.xz -C /
tar xvf binutils-2.39-mint-20220911-bin-macos.tar.xz -C /
tar xvf mintbin-0.3-mint-20230206-bin-macos.tar.xz -C /
But note that this will overwrite most files from Philipp's archive.

Library packages have a different directory layout because they are not system dependent, and the default prefix for other hosts is /usr instead of /opt/cross-mint. You should be able to install them with:

Code: Select all

tar xvf mintlib-0.60.1-mint-20200102-dev.tar.xz --strip-components=1 -C /opt/cross-mint
tar xvf fdlibm-20230210-mint-dev.tar.xz --strip-components=1 -C /opt/cross-mint
...
if you are using the archives from my site. The snapshot archives built from the freemint repo are meant for native installation, and don't have the /usr/m68k-atari-mint/sys-root/ prefix.
Success! Thank you. I followed your instructions and I can now compile flawlessly with 7.5.0 (verified version with

Code: Select all

m68k-atari-mint-gcc --version
). The libraries files and folders extracted to the root of crossmint. I moved them manually into m68k-atari-mint/ include or lib accordingly.

So now I am able to compile usb4tos with 7.5.0, is that the same version as for the usb4tos snapshots on your site? Another question, would GCC 12 make a difference?


Claude
ThorstenOtto
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 3412
Joined: Sun Aug 03, 2014 5:54 pm

Re: GCC cross-compiler for Apple silicon

Post by ThorstenOtto »

Perdrix24 wrote: Mon Feb 13, 2023 3:06 pm [The libraries files and folders extracted to the root of crossmint.
The ones from freemint, ie. the ones from the snapshots directory? Yes, they have a different layout. But glad to here that you got it working.
is that the same version as for the usb4tos snapshots on your site
IIRC binutils and gcc that are used for the snaphots are the ones build by mikro, but they should produce the same code.
Another question, would GCC 12 make a difference?
Maybe a bit. @czietz did some benchmarking here: Re: C compiler benchmarking I did the same with 7.5.0, and it was close to what 10.4 produced. You just have to try. From what i've seen in some disassemblies, it sometimes seem to produce quite inefficient code for short functions (like calling memset for clearing 4 bytes of memory),
ThorstenOtto
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 3412
Joined: Sun Aug 03, 2014 5:54 pm

Re: GCC cross-compiler for Apple silicon

Post by ThorstenOtto »

GCC version 13 is now also available: http://tho-otto.de/snapshots/crossmint/macos/gcc-13/
zrhbert
Atarian
Atarian
Posts: 1
Joined: Fri Dec 06, 2024 10:39 am

Re: GCC cross-compiler for Apple silicon

Post by zrhbert »

I got the compiler and linker to work on a Mac today, that’s great. But I’m struggling to integrate GCC into Xcode 16.2. It seems like the handling of plug-ins has changed in version 16. So, getting the GCC plugin to work is what I need help with. The dvtplugincompatibilityUUID is not featured in Xcode 16 defaults anymore. Has anybody gotten that to work yet?
Last edited by zrhbert on Fri Jan 03, 2025 9:48 pm, edited 1 time in total.
Post Reply

Return to “C / PASCAL etc.”