Compile OpenWrt on Apple Silicon M1 Pro

Hi, I'm trying to compile OpenWrt on a MacBook with the M1 Pro processor but it fails when compiling gcc. Does anyone have any clues why this could be? I compiled OpenWrt on Macs before, so I'm assuming it has to do with the arm64 switch, however on a regular M1 chip (non Pro/Max) it worked fine in the past.

The error message I'm currently seeing looks like this:

make[5]: Entering directory '/Users/user/src/openwrt/openwrt/build_dir/toolchain-aarch64_cortex-a53_gcc-11.2.0_musl/gcc-11.2.0-initial/gcc'
g++ -std=gnu++11 -no-pie   -O2 -fbracket-depth=512 -pipe -DIN_GCC  -DCROSS_DIRECTORY_STRUCTURE  -fno-strict-aliasing -fno-exceptions -fno-rtti -fasynchronous-unwind-tables -W -Wall -Wno-narrowing -Wwrite-strings -Wcast-qual -Wno-error=format-diag -Wmissing-format-attribute -Woverloaded-virtual -pedantic -Wno-long-long -Wno-variadic-macros -Wno-overlength-strings   -DHAVE_CONFIG_H  -o cc1 c/c-lang.o c-family/stub-objc.o attribs.o c/c-errors.o c/c-decl.o c/c-typeck.o c/c-convert.o c/c-aux-info.o c/c-objc-common.o c/c-parser.o c/c-fold.o c/gimple-parser.o c-family/c-common.o c-family/c-cppbuiltin.o c-family/c-dump.o c-family/c-format.o c-family/c-gimplify.o c-family/c-indentation.o c-family/c-lex.o c-family/c-omp.o c-family/c-opts.o c-family/c-pch.o c-family/c-ppoutput.o c-family/c-pragma.o c-family/c-pretty-print.o c-family/c-semantics.o c-family/c-ada-spec.o c-family/c-ubsan.o c-family/known-headers.o c-family/c-attribs.o c-family/c-warn.o c-family/c-spellcheck.o aarch64-c.o glibc-c.o \
  cc1-checksum.o libbackend.a main.o libcommon-target.a libcommon.a ../libcpp/libcpp.a ../libdecnumber/libdecnumber.a libcommon.a ../libcpp/libcpp.a  -liconv ../libbacktrace/.libs/libbacktrace.a ../libiberty/libiberty.a ../libdecnumber/libdecnumber.a   -L/Users/user/src/openwrt/openwrt/staging_dir/host/lib -L/Users/user/src/openwrt/openwrt/staging_dir/host/lib -L/Users/user/src/openwrt/openwrt/staging_dir/host/lib -lmpc -lmpfr -lgmp   -L./../zlib -lz 
clang: warning: argument unused during compilation: '-no-pie' [-Wunused-command-line-argument]
Undefined symbols for architecture arm64:
  "_host_hooks", referenced from:
      c_common_no_more_pch() in c-pch.o
      toplev::main(int, char**) in libbackend.a(toplev.o)
      gt_pch_save(__sFILE*) in libbackend.a(ggc-common.o)
      gt_pch_restore(__sFILE*) in libbackend.a(ggc-common.o)
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[5]: *** [/Users/user/src/openwrt/openwrt/build_dir/toolchain-aarch64_cortex-a53_gcc-11.2.0_musl/gcc-11.2.0/gcc/c/Make-lang.in:87: cc1] Error 1
make[5]: Leaving directory '/Users/user/src/openwrt/openwrt/build_dir/toolchain-aarch64_cortex-a53_gcc-11.2.0_musl/gcc-11.2.0-initial/gcc'
make[4]: *** [Makefile:4444: all-gcc] Error 2
make[4]: Leaving directory '/Users/user/src/openwrt/openwrt/build_dir/toolchain-aarch64_cortex-a53_gcc-11.2.0_musl/gcc-11.2.0-initial'
make[3]: *** [Makefile:37: /Users/user/src/openwrt/openwrt/build_dir/toolchain-aarch64_cortex-a53_gcc-11.2.0_musl/gcc-11.2.0-initial/.built] Error 2
make[3]: Leaving directory '/Users/user/src/openwrt/openwrt/toolchain/gcc/initial'
time: toolchain/gcc/initial/compile#0.74#0.35#1.39
    ERROR: toolchain/gcc/initial failed to build.
make[2]: *** [toolchain/Makefile:97: toolchain/gcc/initial/compile] Error 1
make[2]: Leaving directory '/Users/user/src/openwrt/openwrt'
make[1]: *** [toolchain/Makefile:93: /Users/user/src/openwrt/openwrt/staging_dir/toolchain-aarch64_cortex-a53_gcc-11.2.0_musl/stamp/.toolchain_compile] Error 2
make[1]: Leaving directory '/Users/user/src/openwrt/openwrt'
make: *** [/Users/user/src/openwrt/openwrt/include/toplevel.mk:230: world] Error 2
1 Like

seems you're not alone Building Packages on Apple M1 CPU

I guess this is rather an issues with Mac OS X or the version of LLVM they ship because build on Linux-based Aarch64 systems works fine (here: Pinebook Pro).

1 Like

The issue is fixed by applying this patch here. We should add it to our tree.

3 Likes

Hi @aparcar . I've sent PR https://github.com/openwrt/openwrt/pull/4808 with this patch, also I added two additional patches for tools/mkimage and tools/fakeroot . OpenWRT(master branch) has been built successfully on my M1 Mac

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.