Zig fails to compile on arm64, in two different ways depending on whether the llvm USE flag is enabled. With LLVM: the ebuild fails, panicking during stage 3 by reaching unreachable code. While I have LTO enabled on my system, this is reproducible with LTO disabled (which makes sense, as the bootstrapper appears to set its own CFLAGS). Without LLVM: the ebuild fails, with the stage2 zig compiler segfaulting while building stage3. Reproducible: Always Steps to Reproduce: 1. Attempt to install dev-lang/zig on arm64 Actual Results: The ebuild fails. Expected Results: The ebuild doesn't fail. emerge --info output: Portage 3.0.66.1 (python 3.12.7-final-0, default/linux/arm64/23.0/desktop/systemd, gcc-14, glibc-2.40-r5, 6.12.4-p1-asahi-dist aarch64) ================================================================= System Settings ================================================================= System uname: Linux-6.12.4-p1-asahi-dist-aarch64-with-glibc2.40 KiB Mem: 32648864 total, 17123376 free KiB Swap: 0 total, 0 free Timestamp of repository gentoo: Fri, 27 Dec 2024 13:00:00 +0000 Head commit of repository gentoo: 3f7fab4cc3b823bd4ebd33a0e0502205004842c6 Head commit of repository asahi: fdf32c6589d8ef861c0023649d8974560d2481cc Timestamp of repository guru: Thu, 26 Dec 2024 15:50:23 +0000 Head commit of repository guru: ef845b7b1ed24a523da54b44698fa9ed5620a189 sh bash 5.2_p37 ld GNU ld (Gentoo 2.43 p3) 2.43.1 app-misc/pax-utils: 1.3.8::gentoo app-shells/bash: 5.2_p37::gentoo dev-build/autoconf: 2.71-r7::gentoo, 2.72-r1::gentoo dev-build/automake: 1.16.5-r2::gentoo dev-build/cmake: 3.30.6::gentoo dev-build/libtool: 2.4.7-r4::gentoo dev-build/make: 4.4.1-r100::gentoo dev-build/meson: 1.6.1::gentoo dev-lang/perl: 5.40.0::gentoo dev-lang/python: 3.11.11_p1::gentoo, 3.12.7_p1::gentoo, 3.13.0::gentoo dev-lang/rust: 1.83.0-r1::gentoo llvm-core/clang: 18.1.8-r6::gentoo, 19.1.6::gentoo llvm-core/lld: 18.1.8::gentoo, 19.1.6::gentoo llvm-core/llvm: 18.1.8-r6::gentoo, 19.1.6::gentoo sys-apps/baselayout: 2.17::gentoo sys-apps/sandbox: 2.39::gentoo sys-apps/systemd: 256.7::gentoo sys-devel/binutils: 2.43-r2::gentoo sys-devel/binutils-config: 5.5.2::gentoo sys-devel/gcc: 14.2.1_p20241116::gentoo sys-devel/gcc-config: 2.11::gentoo sys-kernel/linux-headers: 6.6-r1::gentoo (virtual/os-headers) sys-libs/glibc: 2.40-r5::gentoo Repositories: gentoo location: /var/db/repos/gentoo sync-type: rsync sync-uri: rsync://rsync.gentoo.org/gentoo-portage/ priority: -1000 volatile: False sync-rsync-extra-opts: sync-rsync-verify-max-age: 3 sync-rsync-verify-jobs: 1 sync-rsync-verify-metamanifest: yes asahi location: /var/db/repos/asahi sync-type: git sync-uri: https://github.com/chadmed/asahi-overlay masters: gentoo volatile: False guru location: /var/db/repos/guru sync-type: git sync-uri: https://github.com/gentoo-mirror/guru.git masters: gentoo volatile: False Binary Repositories: gentoobinhost priority: 1 sync-uri: https://distfiles.gentoo.org/releases/arm64/binpackages/23.0/arm64 ACCEPT_KEYWORDS="arm64" ACCEPT_LICENSE="*" CBUILD="aarch64-unknown-linux-gnu" CFLAGS="-march=armv8.4-a+simd+crypto+i8mm+bf16 -mtune=native -O2 -pipe -flto=4 -Werror=odr -Werror=strict-aliasing" CHOST="aarch64-unknown-linux-gnu" CONFIG_PROTECT="/etc /usr/share/config /usr/share/gnupg/qualified.txt /var/bind" CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/dconf /etc/env.d /etc/fonts/fonts.conf /etc/gconf /etc/gentoo-release /etc/sandbox.d" CXXFLAGS="-march=armv8.4-a+simd+crypto+i8mm+bf16 -mtune=native -O2 -pipe -flto=4 -Werror=odr -Werror=strict-aliasing" DISTDIR="/var/cache/distfiles" EMERGE_DEFAULT_OPTS="-j3 -l4" ENV_UNSET="CARGO_HOME DBUS_SESSION_BUS_ADDRESS DISPLAY GDK_PIXBUF_MODULE_FILE GOBIN GOPATH PERL5LIB PERL5OPT PERLPREFIX PERL_CORE PERL_MB_OPT PERL_MM_OPT XAUTHORITY XDG_CACHE_HOME XDG_CONFIG_HOME XDG_DATA_HOME XDG_RUNTIME_DIR XDG_STATE_HOME" FCFLAGS="-march=armv8.4-a+simd+crypto+i8mm+bf16 -mtune=native -O2 -pipe -flto=4 -Werror=odr -Werror=strict-aliasing" FEATURES="assume-digests binpkg-docompress binpkg-dostrip binpkg-logs binpkg-multi-instance buildpkg-live config-protect-if-modified distlocks ebuild-locks fixlafiles ipc-sandbox merge-sync merge-wait multilib-strict network-sandbox news parallel-fetch pid-sandbox pkgdir-index-trusted preserve-libs protect-owned qa-unresolved-soname-deps sandbox sfperms strict unknown-features-warn unmerge-logs unmerge-orphans userfetch userpriv usersandbox usersync xattr" FFLAGS="-march=armv8.4-a+simd+crypto+i8mm+bf16 -mtune=native -O2 -pipe -flto=4 -Werror=odr -Werror=strict-aliasing" GENTOO_MIRRORS="http://gentoo.mirrors.ovh.net/gentoo-distfiles/" LANG="en_US.utf8" LDFLAGS="-Wl,-O1 -Wl,--as-needed" LEX="flex" MAKEOPTS="-j4 -l4" PKGDIR="/var/cache/binpkgs" PORTAGE_CONFIGROOT="/" PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --omit-dir-times --compress --force --whole-file --delete --stats --human-readable --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages --exclude=/.git" PORTAGE_TMPDIR="/var/tmp" SHELL="/bin/fish" USE="X a52 aac acl acpi alsa arm64 bluetooth branding bzip2 cairo cdda cdr crypt cryptsetup cups dbus dri dts dvdr encode exif ffmpeg flac gdbm gif gpm grub gtk gui iconv icu ipv6 jpeg kde kf6compat lcms libnotify libtirpc lto mad mng mp3 mp4 mpeg ncurses networkmanager nls ogg opengl openmp opus pam pango pcre pdf pipewire png policykit ppds pulseaudio qml qt5 qt6 readline sdl seccomp semantic-desktop sound spell ssl startup-notification svg systemd test-rust tiff truetype udev udisks unicode upower usb v4l vorbis vulkan wayland wifi wxwidgets x264 xattr xcb xft xml xv xvid zlib" ADA_TARGET="gcc_12" APACHE2_MODULES="authn_core authz_core socache_shmcb unixd actions alias auth_basic authn_anon authn_dbm authn_file authz_dbm authz_groupfile authz_host authz_owner authz_user autoindex cache cgi cgid dav dav_fs dav_lock deflate dir env expires ext_filter file_cache filter headers include info log_config logio mime mime_magic negotiation rewrite setenvif speling status unique_id userdir usertrack vhost_alias" CALLIGRA_FEATURES="karbon sheets words" COLLECTD_PLUGINS="df interface irq load memory rrdtool swap syslog" CPU_FLAGS_ARM="edsp v8 vfp vfp-d32 vfpv3 vfpv4" ELIBC="glibc" GPSD_PROTOCOLS="ashtech aivdm earthmate evermore fv18 garmin garmintxt gpsclock greis isync itrax navcom oceanserver oncore rtcm104v2 rtcm104v3 sirf skytraq superstar2 tsip tripmate tnt ublox" GRUB_PLATFORMS="efi-64" GUILE_SINGLE_TARGET="3-0" GUILE_TARGETS="3-0" INPUT_DEVICES="libinput" KERNEL="linux" L10N="en en-CA en-US ja" LCD_DEVICES="bayrad cfontz glk hd44780 lb216 lcdm001 mtxorb text" LUA_SINGLE_TARGET="lua5-1" LUA_TARGETS="lua5-1" OFFICE_IMPLEMENTATION="libreoffice" PHP_TARGETS="php8-2" POSTGRES_TARGETS="postgres16" PYTHON_SINGLE_TARGET="python3_12" PYTHON_TARGETS="python3_12 python3_11" RUBY_TARGETS="ruby32" VIDEO_CARDS="asahi" XTABLES_ADDONS="quota2 psd pknock lscan length2 ipv4options ipp2p iface geoip fuzzy condition tarpit sysrq proto logmark ipmark dhcpmac delude chaos account" Unset: ADDR2LINE, AR, ARFLAGS, AS, ASFLAGS, CC, CCLD, CONFIG_SHELL, CPP, CPPFLAGS, CTARGET, CXX, CXXFILT, ELFEDIT, EXTRA_ECONF, F77FLAGS, FC, GCOV, GPROF, INSTALL_MASK, LC_ALL, LD, LFLAGS, LIBTOOL, LINGUAS, MAKE, MAKEFLAGS, NM, OBJCOPY, OBJDUMP, PORTAGE_BINHOST, PORTAGE_BUNZIP2_COMMAND, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS, PYTHONPATH, RANLIB, READELF, RUSTFLAGS, SIZE, STRINGS, STRIP, YACC, YFLAGS
Created attachment 915288 [details] build.log (with llvm USE)
Created attachment 915289 [details] build.log (without LLVM USE)
Created attachment 915290 [details] environment (with llvm USE)
Created attachment 915291 [details] environment (with no llvm USE)
This is probably an upstream issue, actually; looks like zig doesn't work with nonstandard page sizes: https://github.com/ziglang/zig/issues/11308
Yes, this is most likely that upstream issue, that PR closes alone 5 similar issues. Unfortunately it is a vast and incompatible (although I can fix it in dependants, I can't fix 9999 or zig-bin) change and still not merged yet, so I'm not sure if I should try to backport it or wait until next release is out (should be somewhere in January/February)... But just to verify, can you try to build :9999 with this rebased patch and see if it works? https://paste.sr.ht/blob/fb554e6d276585afbf3c51b6ef9c0752d94fb8ad
Created attachment 915301 [details, diff] Upstream PR rebased against 42dac40b3feeabe39b5f191d1e72d247327133ba
Sorry, previous one was wrong patch, see latest in attachment
Using the patch from the attachment, it fails much earlier, and consistently between both USE=llvm and USE=-llvm. I think this is because the PR isn't actually up-to-date with master: FAILED: zig2.c /var/tmp/portage/dev-lang/zig-9999/work/zig-9999_build/zig2.c cd /var/tmp/portage/dev-lang/zig-9999/work/zig-9999 && /var/tmp/portage/dev-lang/zig-9999/work/zig-9999_build/zig1 /var/tmp/portage/dev-lang/zig-9999/work/zig-9999/lib build-exe -ofmt=c -lc -OReleaseSmall --name zig2 -femit-bin="/var/tmp/portage/dev-lang/zig-9999/work/zig-9999_build/zig2.c" -target aarch64-linux-gnu --dep build_options --dep aro -Mroot=src/main.zig -Mbuild_options=/var/tmp/portage/dev-lang/zig-9999/work/zig-9999_build/config.zig -Maro=lib/compiler/aro/aro.zig /lib/std/c.zig:2214:6: error: no field named 'bridgeos' in enum 'Target.Os.Tag' /lib/std/Target.zig:18:21: note: enum declared here If I remove .bridgeos, it gets further, but leads down what may be a totally separate rabbit hole: * ZBS: compiling with: -j4 -Dtarget=native -Dcpu=generic+v8_4a+simd+crypto+i8mm+bf16 --release=safe --prefix-exe-dir bin/ --prefix-lib-dir lib64/ --prefix-include-dir include/ --prefix usr/ --libc /var/tmp/portage/dev-lang/zig-9999/temp/zig_libc.txt --summary all --verbose --build-file /var/tmp/portage/dev-lang/zig-9999/work/zig-9999/build.zig --zig-lib-dir /var/tmp/portage/dev-lang/zig-9999/work/zig-9999/lib/ --prefix-lib-dir lib/ -Dno-langref -Dstd-docs=false --release=fast -Denable-llvm=true -Dstatic-llvm=false -Dconfig_h=/var/tmp/portage/dev-lang/zig-9999/work/zig-9999_build/config.h --prefix /var/tmp/portage/dev-lang/zig-9999/work/zig-9999_build/stage3/ unknown CPU feature: 'simd' If you'd like, I can give you the massive list of CPU features zig prints following that (it's too big to paste here, I'd need to upload as an attachment). It does not contain simd, but neon might work instead, though I certainly do not know how to change what the stage3 does to test my theory myself.
> unknown CPU feature: 'simd' This is because zig-utils.eclass does not translate CPU definitions like in your CFLAGS yet, as a workaround you can try setting ZIG_CPU="generic+v8_4a+neon+crypto+i8mm+bf16" in your make.conf or package.env, it should parse fine then. > If you'd like, I can give you the massive list of CPU features zig prints > following that No need to, I can see it locally with `zig build-exe -target aarch64-linux-gnu -mcpu generic+simd --show-builtin` :)
Alright, looks like that works! zig successfully bootstraps and installs, with the modification I mentioned to the patch.
The upstream PR was merged as of 0.14, and I've been building this successfully on Asahi Gentoo for some time now. With 0.14 out today, this should be good to close now, from my end :)
Thanks!