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

Can't build toolchain on mac os arm M1 apple silicon aarch64 #461

Closed
alexvnesta opened this issue Oct 31, 2023 · 5 comments
Closed

Can't build toolchain on mac os arm M1 apple silicon aarch64 #461

alexvnesta opened this issue Oct 31, 2023 · 5 comments

Comments

@alexvnesta
Copy link
Contributor

Hey - I tried to follow the install guide here, but unfortunately have an error - looks like an issue with the mac os libz? I tried removing --with-system-zlib from the gcc configure, but got a whole bunch of errors for stddef.h

Here is what I did so far:

https://github.com/DragonMinded/libdragon/wiki/Installing-libdragon

Computer model and OS: 2022 macbook air - Apple M2, 16gb ram, macOS Ventura 13.1

Homebrew version

(base) MacBook-Air-2:tools alex$ brew --version
Homebrew 4.1.18-33-g83b4b2f

Homebrew installed packages

(base) MacBook-Air-2:tools alex$ brew list
==> Formulae
armv7-unknown-linux-gnueabihf	glib				libxcb				[email protected]
autoconf			gmp				libxdmcp			[email protected]
automake			gnu-sed				libxext				[email protected]
bash				gnutls				libxrender			qemu
bdw-gc				graphite2			little-cms2			readline
binutils			grep				lz4				rhash
binwalk				guile				lzip				sevenzip
bison				harfbuzz			lzo				six
ca-certificates			icu4c				m4				snappy
cairo				isl				make				sqlite
capstone			jpeg-turbo			meson				squashfs
cargo-zigbuild			libevent			mips64-elf-binutils		ssdeep
cloudprober			libidn2				mpdecimal			tcl-tk
coreutils			libimagequant			mpfr				texinfo
crosstool-ng			libmpc				ncurses				tree
ddcctl				libnghttp2			nettle				unbound
dtc				libpng				ninja				vde
e2fsprogs			libraqm				numpy				webp
flex				libslirp			openblas			wget
fontconfig			libssh				openjpeg			xorgproto
freetype			libtasn1			openssl@3			xz
fribidi				libtiff				p11-kit				z3
gawk				libtool				p7zip				zig
gcc				libunistring			pcre2				zstd
gdbm				libusb				pillow
gettext				libx11				pixman
giflib				libxau				pkg-config

==> Casks
android-platform-tools	microsoft-auto-update	microsoft-office	paragon-vmdk-mounter	stats
(base) MacBook-Air-2:tools alex$ 

I attached the full build log, but here is the bit where I think the error occurred:

g++ -std=gnu++11 -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 -Wconditionally-supported -Woverloaded-virtual -pedantic -Wno-long-long -Wno-variadic-macros -Wno-overlength-strings   -DHAVE_CONFIG_H  gcc-ar.o -o gcc-ar \
		file-find.o libcommon.a ../libcpp/libcpp.a  -liconv ../libbacktrace/.libs/libbacktrace.a ../libiberty/libiberty.a ../libdecnumber/libdecnumber.a  
clangclang: warning: argument unused during compilation: '-no-pie' [-Wunused-command-line-argument]
: warning: argument unused during compilation: '-no-pie' [-Wunused-command-line-argument]
clang: warning: argument unused during compilation: '-no-pie' [-Wunused-command-line-argument]
warning: unknown warning option '-Wconditionally-supported' [-Wunknown-warning-option]
clang: warning: argument unused during compilation: '-no-pie' [-Wunused-command-line-argument]
clang: warning: argument unused during compilation: '-no-pie' [-Wunused-command-line-argument]
ld: warning: ignoring file /usr/local/lib/libz.so, building for macOS-arm64 but attempting to link with file built for unknown-unsupported file format ( 0x7F 0x45 0x4C 0x46 0x01 0x01 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 )
clang: warning: argument unused during compilation: '-no-pie' [-Wunused-command-line-argument]
warning: unknown warning option '-Wconditionally-supported' [-Wunknown-warning-option]
Undefined symbols for architecture arm64:
  "_gzclose", referenced from:
      _main in gcov.o
  "_gzopen", referenced from:
      _main in gcov.o
  "_gzputs", referenced from:
      _main in gcov.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[1]: *** [gcov] Error 1
make[1]: *** Waiting for unfinished jobs....

all_build_log.txt

@alexvnesta
Copy link
Contributor Author

I got it to build. Here is what I did:

  1. install zlib using homebrew

  2. modified the build toolchain script - I tried a few things to manually specify zlib from homebrew instead of mac os clang. You can make a diff if you want to see the details.

  3. explicitly defined my library path for homebrew packages (specifically including zlib) :
    export LIBRARY_PATH="/opt/homebrew/lib"

build-toolchain.txt

@alexvnesta alexvnesta reopened this Nov 1, 2023
@alexvnesta
Copy link
Contributor Author

I'd like to request that someone review my changes and test them on their own system to confirm. Then maybe we can do a pull request?

@rasky
Copy link
Collaborator

rasky commented Nov 1, 2023

On my Mac OS M1 with Ventura, I do have zlib installed on Homebrew, but I don't think it's using that one (as the build script, as you noted, doesn't make an effort to use it). I think it's using a "system" one. I think the system one that I have is installed with XCode command line tools.

What happens if you run xcode-select -p on your system? It should either show a path or print an error. Can you check if the process returns a non-zero exit code when the tools are not installed? In that case, xcode-select --install should install them.

Alternatively we can try to use zlib from homebrew, but we need a solution that doesn't involve changing LIBRARY_PATH as that can bring too much stuff into the build, and I can see it causing hard to diagnose problems.

@alexvnesta
Copy link
Contributor Author

Thanks for looking into this.

(base) MacBook-Air-2:~ alex$ xcode-select -p 
/Applications/Xcode.app/Contents/Developer
(base) MacBook-Air-2:~ alex$ /usr/bin/xcodebuild -version
Xcode 14.3.1
Build version 14E300c

I think the main change that fixed the compilation issues was to remove the --with-system-zlib argument from the mips gcc compilation, but I haven't tried messing with multiple changes to figure out the one true thing that fixed the issue. Just removing --with-system-zlib and not anything else lead to a bunch of missing c standard library errors:

#../"gcc-$GCC_V"/configure "${GCC_CONFIGURE_ARGS[@]}" \
LDFLAGS="-L/opt/homebrew/lib" CPPFLAGS="-I/opt/homebrew/include" ../"gcc-$GCC_V"/configure "${GCC_CONFIGURE_ARGS[@]}" \
    --prefix="$CROSS_PREFIX" \
    --target="$N64_TARGET" \
    --with-arch=vr4300 \
    --with-tune=vr4300 \
    --enable-languages=c,c++ \
    --without-headers \
    --disable-libssp \
    --enable-multilib \
    --disable-shared \
    --with-gcc \
    --with-newlib \
    --disable-threads \
    --disable-win32-registry \
    --disable-nls \
    --disable-werror
    #--with-system-zlib 

@rasky
Copy link
Collaborator

rasky commented Jan 12, 2024

Fixed on both stable and unstable by #483

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

2 participants