richfelker / musl-cross-make

Simple makefile-based build for musl cross compiler

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Does not compile on Apple Silicon

jlricon opened this issue · comments

It returns the following after running TARGET=x86_64-linux-musl make

g++ -no-pie   -g -O2 -DIN_GCC  -DCROSS_DIRECTORY_STRUCTURE  -fno-strict-aliasing -fno-exceptions -fno-rtti -fasynchronous-unwind-tables -W -Wall -Wno-narrowing -Wwrite-strings -Wcast-qual -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 i386-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 ./../intl/libintl.a -liconv  ../libbacktrace/.libs/libbacktrace.a ../libiberty/libiberty.a ../libdecnumber/libdecnumber.a   -L/Users/jlricon/gits/musl-cross-make/build/local/x86_64-linux-musl/obj_gcc/./gmp/.libs -L/Users/jlricon/gits/musl-cross-make/build/local/x86_64-linux-musl/obj_gcc/./mpfr/src/.libs -L/Users/jlricon/gits/musl-cross-make/build/local/x86_64-linux-musl/obj_gcc/./mpc/src/.libs -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[3]: *** [cc1] Error 1
make[2]: *** [all-gcc] Error 2
make[1]: *** [obj_gcc/gcc/.lc_built] Error 2
make: *** [all] Error 2

See following gcc bug

So it looks like we need a backport of the GCC fix to all supported GCC versions. How hard is that going to be? IMO it should strip out useless hunks like the line number changes so that the diff is minimal and ideally a single patch applies to all affected versions.

Still the same error with
0019-backport-MacOS-11.0-support-to-gcc-9.2.0.patch.txt which is expected as the error occurs in gcc for which the patch doesn't add -Wl,-undefined,dynamic_lookup

gcc-10.3.0 builds TARGET=aarch64-linux-musl and seems to work with minimal patching. I just noticed that the error reported by @jlricon is not related to the gcc bug. Following patch fixes that link error.

diff -ru a/gcc/config/host-darwin.c b/gcc/config/host-darwin.c
--- a/gcc/config/host-darwin.c	2021-04-08 13:56:28.000000000 +0200
+++ b/gcc/config/host-darwin.c	2021-04-20 23:05:04.000000000 +0200
@@ -22,6 +22,8 @@
 #include "coretypes.h"
 #include "diagnostic-core.h"
 #include "config/host-darwin.h"
+#include "hosthooks.h"
+#include "hosthooks-def.h"
 
 /* Yes, this is really supposed to work.  */
 /* This allows for a pagesize of 16384, which we have on Darwin20, but should
@@ -78,3 +80,5 @@
 
   return ret;
 }
+
+const struct host_hooks host_hooks = HOST_HOOKS_INITIALIZER;

Blindly copied from other host-*.c files.

For TARGET=aarch64-linux-musl support for {march,cpu,tune}=native has to be disabled:

diff -ru a/gcc/config/aarch64/aarch64.h b/gcc/config/aarch64/aarch64.h
--- a/gcc/config/aarch64/aarch64.h	2021-04-08 13:56:28.000000000 +0200
+++ b/gcc/config/aarch64/aarch64.h	2021-04-20 22:41:03.000000000 +0200
@@ -1200,7 +1200,7 @@
 #define MCPU_TO_MARCH_SPEC_FUNCTIONS \
   { "rewrite_mcpu", aarch64_rewrite_mcpu },
 
-#if defined(__aarch64__)
+#if defined(__aarch64__) && ! defined(__APPLE__)
 extern const char *host_detect_local_cpu (int argc, const char **argv);
 #define HAVE_LOCAL_CPU_DETECT
 # define EXTRA_SPEC_FUNCTION

I've have only build TARGET=aarch64-linux-musl and did minimal testing.

@jlricon if I may ask, what sort of config were you using to build this? I'm getting many errors with the clang compiler on the M1, especially in the GCC configure script, which checks if the compiler is "working".

Can you try using richard-vd@b298706? That is like fe91582 with PRs #148, #140 and #129 merged.

Can you try using richard-vd@b298706? That is like fe91582 with PRs #148, #140 and #129 merged.

I'm not the original commenter, but I just built this patch/commit and it finished without error (MacOS 12.4, M1 chip). I used TARGET=aarch64-linux-musl make -j so now I'm waiting for the laptop to cool back down. 😅

Thanks @hoosierEE for posting your result!

@richfelker could you please merge PRs #148, #140 and #129?

I'm getting this same error (Undefined symbols for architecture arm64: "_host_hooks") when building riscv64-linux-musl. Does anyone happen to know how to adjust the above patches to fix the error when building the riscv64-linux-musl target?