Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does not compile on Apple Silicon #116

Open
jlricon opened this issue Dec 6, 2020 · 9 comments
Open

Does not compile on Apple Silicon #116

jlricon opened this issue Dec 6, 2020 · 9 comments

Comments

@jlricon
Copy link

jlricon commented Dec 6, 2020

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

@jannau
Copy link

jannau commented Dec 6, 2020

See following gcc bug

@richfelker
Copy link
Owner

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.

@jannau
Copy link

jannau commented Dec 6, 2020

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

@jannau
Copy link

jannau commented Apr 20, 2021

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.

richard-vd added a commit to richard-vd/musl-cross-make that referenced this issue Aug 7, 2021
richard-vd added a commit to richard-vd/musl-cross-make that referenced this issue Aug 7, 2021
richard-vd added a commit to richard-vd/musl-cross-make that referenced this issue Aug 7, 2021
richard-vd added a commit to richard-vd/musl-cross-make that referenced this issue Aug 8, 2021
richard-vd added a commit to richard-vd/musl-cross-make that referenced this issue Aug 8, 2021
richard-vd added a commit to richard-vd/musl-cross-make that referenced this issue Aug 8, 2021
richard-vd added a commit to richard-vd/musl-cross-make that referenced this issue Aug 9, 2021
haiku-bot pushed a commit to haiku/buildtools that referenced this issue Aug 23, 2021
This patch fixes a linker error occuring when compiling
the cross-compiler on macOS and ARM64 architecture.

Adapted from:
richfelker/musl-cross-make#116 (comment)

Change-Id: Ia3ee98a163bbb62689f42e2da83a5ef36beb0913
Reviewed-on: https://review.haiku-os.org/c/buildtools/+/4329
Reviewed-by: John Scipione <[email protected]>
Reviewed-by: Adrien Destugues <[email protected]>
jow- pushed a commit to openwrt/openwrt that referenced this issue Dec 2, 2021
Added patch for GCC to fix compilation issues on MacOS arm64

The original commit message from Przemysław Buczkowski:

GCC: Patch for Apple Silicon compatibility

This patch fixes a linker error occuring when compiling
the cross-compiler on macOS and ARM64 architecture.

Adapted from:
richfelker/musl-cross-make#116 (comment)

Signed-off-by: Sergey V. Lobanov <[email protected]>
Vladdrako pushed a commit to Vladdrako/openwrt that referenced this issue Dec 2, 2021
Added patch for GCC to fix compilation issues on MacOS arm64

The original commit message from Przemysław Buczkowski:

GCC: Patch for Apple Silicon compatibility

This patch fixes a linker error occuring when compiling
the cross-compiler on macOS and ARM64 architecture.

Adapted from:
richfelker/musl-cross-make#116 (comment)

Signed-off-by: Sergey V. Lobanov <[email protected]>
Boos4721 pushed a commit to Boos4721/openwrt that referenced this issue Dec 3, 2021
Added patch for GCC to fix compilation issues on MacOS arm64

The original commit message from Przemysław Buczkowski:

GCC: Patch for Apple Silicon compatibility

This patch fixes a linker error occuring when compiling
the cross-compiler on macOS and ARM64 architecture.

Adapted from:
richfelker/musl-cross-make#116 (comment)

Signed-off-by: Sergey V. Lobanov <[email protected]>
Signed-off-by: boos4721 <[email protected]>
aiamadeus pushed a commit to immortalwrt/immortalwrt that referenced this issue Dec 5, 2021
Added patch for GCC to fix compilation issues on MacOS arm64

The original commit message from Przemysław Buczkowski:

GCC: Patch for Apple Silicon compatibility

This patch fixes a linker error occuring when compiling
the cross-compiler on macOS and ARM64 architecture.

Adapted from:
richfelker/musl-cross-make#116 (comment)

Signed-off-by: Sergey V. Lobanov <[email protected]>
richard-vd added a commit to richard-vd/musl-cross-make that referenced this issue Dec 13, 2021
richard-vd added a commit to richard-vd/musl-cross-make that referenced this issue Dec 14, 2021
richard-vd added a commit to richard-vd/musl-cross-make that referenced this issue Dec 19, 2021
@isinyaaa
Copy link

@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".

@richard-vd
Copy link

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

@hoosierEE
Copy link

hoosierEE commented Jun 25, 2022

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. 😅

@richard-vd
Copy link

Thanks @hoosierEE for posting your result!

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

@plafratt
Copy link

plafratt commented Mar 26, 2024

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants