build: work around zig linker bug in macos-aarch64 openssl assembly#815
Merged
pkova merged 5 commits intomsl/zig-v0.14.0from May 16, 2025
Merged
build: work around zig linker bug in macos-aarch64 openssl assembly#815pkova merged 5 commits intomsl/zig-v0.14.0from
pkova merged 5 commits intomsl/zig-v0.14.0from
Conversation
This is just wrong, the macro means "INT" "LONG" "POINTER" == 32 bits. It was muna here since the beginning to work around a very peculiar issue, see next commit for details.
All vere versions since the introduction of the zig build system in vere-v3.2 have had a misconfigured openssl build. This was eventually caught by simply doing +https://facebook.com in the dojo on mac or linux aarch64, segfaulting the binary instantly. Facebook uses TLS 1.3 with the TLS_CHACHA20_POLY1305_SHA256 cryptosuite, exercising the vendored assembly file poly1305-armv8.S. We had mistakenly defined the macro __ILP32__ for this translation unit which means integers, longs and pointers are 32 bits which is obviously wrong. Fixing this bug lead to a more insidious problem, however. The obvious fix of removing the __ILP32__ macro fixed the facebook problem on linux-aarch64. On macos-aarch64 the fix caused an immediate segfault in the macos loader (dyld) when starting the vere binary. The zig build system shells out to the LLVM linker LLD in all cases except Mach-O. When inspecting the vere binary and the operation of the zig Mach-O linker it became clear that the segfault in the loader happens because the zig Mach-O linker emits a rebase into the read-only __TEXT section of the vere binary. When running the build with --verbose-link and grabbing the final zig link command and switching out the linker to the macos native ld the vere binary was completely fine. This is in other words a bug in the zig Mach-O linker. Further examination revealed that the incorrectly rebased symbol was _OPENSSL_armcap_P. This is a constant ARMV7_NEON on macos-aarch64 so we work around the zig linker bug by not using the symbol at all.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
All vere versions since the introduction of the zig build system in vere-v3.2 have had a misconfigured openssl build. This was eventually caught by simply doing
+https://facebook.comin the dojo on mac or linux aarch64, segfaulting the binary instantly. Facebook uses TLS 1.3 with the TLS_CHACHA20_POLY1305_SHA256 cryptosuite, exercising the vendored assembly filepoly1305-armv8.S. We had mistakenly defined the macro__ILP32__for this translation unit which means integers, longs and pointers are 32 bits which is obviously wrong. Fixing this bug lead to a more insidious problem, however.The obvious fix of removing the
__ILP32__macro fixed the facebook problem on linux-aarch64. On macos-aarch64 the fix caused an immediate segfault in the macos loader (dyld) when starting the vere binary.The zig build system shells out to the LLVM linker LLD in all cases except Mach-O. When inspecting the vere binary and the operation of the zig Mach-O linker it became clear that the segfault in the loader happens because the zig Mach-O linker emits a rebase into the read-only
__TEXTsection of the vere binary. When running the build with--verbose-linkand grabbing the finalzig linkcommand and switching out the linker to the macos nativeldthe vere binary wascompletely fine. This is in other words a bug in the zig Mach-O linker.
Further examination revealed that the incorrectly rebased symbol was
_OPENSSL_armcap_P. This is a constantARMV7_NEONon macos-aarch64 so we work around the zig linker bug by not using the symbol at all.