Skip to content

Various errors building on ARM MacOS or cross-compiling for ARM MacOS #1780

@jimfangx

Description

@jimfangx

I am trying to build the toolchain for ARM MacOS by building on MacOS and cross-compiling from a x86 Linux machine, and I am running into issues on both flows.

Canadian cross for aarch64-apple-darwin24-clang from x86_64 linux machine

I have setup OSXCross macOS cross compilation toolchain and following the autotools project build instructions here (https://github.com/tpoechtrager/osxcross?tab=readme-ov-file#build-autotools-project), run the following ./configure command in the riscv-gnu-toolchain directory:

CC=aarch64-apple-darwin24-clang CCX=aarch64-apple-darwin24-clang++ ./configure --prefix=/opt/riscv --with-arch=rv64gc --with-abi=lp64d --enable-llvm --build=x86_64-pc-linux-gnu --host=aarch64-apple-darwin24 --with-host=aarch64-apple-darwin24 --disable-gdb

While making, it results in a ton of undefined reference messages and then eventually errors with the following:

/scratch/jimfang/riscv-gnu-toolchain/binutils/gas/config/atof-ieee.c:377:(.text+0x159): undefined reference to `_sch_toupper'
/usr/bin/ld: /scratch/jimfang/riscv-gnu-toolchain/binutils/gas/config/atof-ieee.c:384:(.text+0x184): undefined reference to `_sch_istable'
/usr/bin/ld: /scratch/jimfang/riscv-gnu-toolchain/binutils/gas/config/atof-ieee.c:339:(.text+0x2cb): undefined reference to `_sch_toupper'
/usr/bin/ld: /scratch/jimfang/riscv-gnu-toolchain/binutils/gas/config/atof-ieee.c:346:(.text+0x5c3): undefined reference to `_sch_toupper'
/usr/bin/ld: warning: creating DT_TEXTREL in a PIE
collect2: error: ld returned 1 exit status
make[5]: *** [Makefile:1298: as-new] Error 1
make[5]: *** Waiting for unfinished jobs....
make[5]: Leaving directory '/scratch/jimfang/riscv-gnu-toolchain/build-binutils-newlib/gas'
make[4]: *** [Makefile:1676: all-recursive] Error 1
make[4]: Leaving directory '/scratch/jimfang/riscv-gnu-toolchain/build-binutils-newlib/gas'
make[3]: *** [Makefile:1025: all] Error 2
make[3]: Leaving directory '/scratch/jimfang/riscv-gnu-toolchain/build-binutils-newlib/gas'
make[2]: *** [Makefile:5510: all-gas] Error 2
make[2]: Leaving directory '/scratch/jimfang/riscv-gnu-toolchain/build-binutils-newlib'
make[1]: *** [Makefile:1027: all] Error 2
make[1]: Leaving directory '/scratch/jimfang/riscv-gnu-toolchain/build-binutils-newlib'
make: *** [Makefile:609: stamps/build-binutils-newlib] Error 2

Config.log: https://pastebin.com/ur0iFQvF
make run log: run.log

uname -a: Linux hummingbird 6.14.0-33-generic #33~24.04.1-Ubuntu SMP PREEMPT_DYNAMIC Fri Sep 19 17:02:30 UTC 2 x86_64 x86_64 x86_64 GNU/Linux

Building natively on ARM mac

All of the following was done in a case-sensitive volume.

./configure --prefix=/Volumes/case-sensitive/opt/riscv --with-arch=rv64gc --with-abi=lp64d --disable-gdb --enable-llvm

results in:

if test -f /Volumes/case-sensitive/riscv-gnu-toolchain/gcc/contrib/download_prerequisites && test "false" = "true"; then cd /Volumes/case-sensitive/riscv-gnu-toolchain/gcc && ./contrib/download_prerequisites; fi
rm -rf stamps/build-gcc-newlib-stage1 build-gcc-newlib-stage1
mkdir build-gcc-newlib-stage1
cd build-gcc-newlib-stage1 && /Volumes/case-sensitive/riscv-gnu-toolchain/gcc/configure \
        --target=riscv64-unknown-elf \
         \
        --prefix=/Volumes/case-sensitive/opt/riscv \
        --disable-shared \
        --disable-threads \
        --disable-tls \
        --enable-languages=c,c++ \
        --with-system-zlib \
        --with-newlib \
        --with-sysroot=/Volumes/case-sensitive/opt/riscv/riscv64-unknown-elf \
        --disable-libmudflap \
        --disable-libssp \
        --disable-libquadmath \
        --disable-libgomp \
        --disable-nls \
        --disable-tm-clone-registry \
        --src=.././gcc \
         \
        --disable-multilib \
        --with-abi=lp64d \
        --with-arch=rv64gc \
         \
        --with-isa-spec=20191213 \
         \
        CFLAGS_FOR_TARGET="-Os    -mcmodel=medlow" \
        CXXFLAGS_FOR_TARGET="-Os    -mcmodel=medlow"
checking build system type... aarch64-apple-darwin24.6.0
checking host system type... aarch64-apple-darwin24.6.0
checking target system type... riscv64-unknown-elf
checking for a BSD-compatible install... /opt/homebrew/bin/ginstall -c
checking whether ln works... yes
checking whether ln -s works... yes
checking for a sed that does not truncate output... /opt/homebrew/bin/gsed
checking for gawk... /opt/homebrew/bin/gawk
checking for libatomic support... no
checking for libitm support... no
checking for libsanitizer support... no
checking for libvtv support... no
checking for libphobos support... no
checking for libgcobol support... no
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking for gcc option to accept ISO C99... none needed
checking for g++... g++
checking whether we are using the GNU C++ compiler... yes
checking whether g++ accepts -g... yes
checking whether g++ accepts -static-libstdc++ -static-libgcc... no
checking for gnatbind... no
checking for gnatmake... no
checking whether compiler driver understands Ada and is recent enough... no
checking for gdc... no
checking whether the D compiler works... no
checking for cargo... cargo
checking how to compare bootstrapped objects... cmp --ignore-initial=16 $$f1 $$f2
checking whether g++ supports C++14 features by default... no
checking whether g++ supports C++14 features with -std=gnu++14... yes
checking for objdir... .libs
checking for the correct version of gmp.h... no
configure: error: Building GCC requires GMP 4.2+, MPFR 3.1.0+ and MPC 0.8.0+.
Try the --with-gmp, --with-mpfr and/or --with-mpc options to specify
their locations.  Source code for these libraries can be found at
their respective hosting sites as well as at
https://gcc.gnu.org/pub/gcc/infrastructure/.  See also
http://gcc.gnu.org/install/prerequisites.html for additional info.  If
you obtained GMP, MPFR and/or MPC from a vendor distribution package,
make sure that you have installed both the libraries and the header
files.  They may be located in separate packages.
gmake: *** [Makefile:653: stamps/build-gcc-newlib-stage1] Error 1

I had GMP, MPFR and MPC installed via brew already, seems like they cannot be found... so I set the following environment variables:

export CPPFLAGS="-I$(brew --prefix gmp)/include -I$(brew --prefix mpfr)/include -I$(brew --prefix libmpc)/include -I$(brew --prefix isl)/include
export LDFLAGS="-L$(brew --prefix gmp)/lib -L$(brew --prefix mpfr)/lib -L$(brew --prefix libmpc)/lib -L$(brew --prefix isl)/lib"

Along with the hint given by the error message, this was the new ./configure I used:

./configure --prefix=/Volumes/case-sensitive/opt/riscv --with-arch=rv64gc --with-abi=lp64d --disable-gdb --with-gmp=$(brew --prefix gmp) --with-mpfr=$(brew --prefix mpfr) --with-mpc=$(brew --prefix libmpc) --with-isl=$(brew --prefix isl) --enable-llvm

this resulted in the following error:

checking for ANSI C header files... (cached) yes
checking for nl_langinfo and CODESET... yes
checking whether NLS is requested... no
checking for msgfmt... /opt/homebrew/bin/msgfmt
checking for gmsgfmt... /opt/homebrew/bin/msgfmt
checking for xgettext... /opt/homebrew/bin/xgettext
checking for msgmerge... /opt/homebrew/bin/msgmerge
checking for ld used by GCC... /Library/Developer/CommandLineTools/usr/bin/ld
checking if the linker (/Library/Developer/CommandLineTools/usr/bin/ld) is GNU ld... no
checking for shared library run path origin... done
checking for CFPreferencesCopyAppValue... yes
checking for CFLocaleCopyPreferredLanguages... yes
checking whether to use NLS... no
checking whether NLS is requested... no
checking for uchar...
checking size of ino_t... 8
checking size of dev_t... 4
checking for iconv... yes
checking for working iconv... yes
checking how to link with libiconv... -liconv
checking whether iconv is compatible with its POSIX signature... yes
checking for CET support... no
configure: updating cache ./config.cache
configure: creating ./config.status
config.status: creating Makefile
config.status: creating config.h
config.status: executing depdir commands
mkdir -p -- .deps
config.status: executing default-1 commands
gmake[1]: Leaving directory '/Volumes/case-sensitive/riscv-gnu-toolchain/build-gcc-newlib-stage1'
gmake: *** [Makefile:654: stamps/build-gcc-newlib-stage1] Error 2

config.log: https://pastebin.com/4Z8FexR8
full run log: output.log

uname -a: Darwin Mac.localdomain 24.6.0 Darwin Kernel Version 24.6.0: Tue Jun 17 22:13:09 PDT 2025; root:xnu-11417.140.64.0.1~35/RELEASE_ARM64_T6020 arm64 arm Darwin

  • MacOS Sequia 15.06, M2 Max Chip

I am trying to build the toolchain from source -- I am aware of prebuilt versions such as the one from homebrew or xPack, however those are not preferred unless there is absolutely no way to build from source for ARM macs.

Any pointers would be appreciated - and I am happy to try out things as needed; I know from reading previous issues that maintainers may not have access to a Mac -- I am happy to help run things or supply a XCode SDK for people to setup the cross compilation toolchain on their Linux machine.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions