Repository navigation
Fix Asherah on musl (Alpine): install-native asset selection and thread stack overflow - #405
Open
awankhede-godaddy wants to merge 2 commits into
Open
awankhede-godaddy wants to merge 2 commits into
awankhede-godaddy wants to merge 2 commits into
Conversation
assetNameForPlatform always returned the glibc asset (libasherah-<arch>.so), so on Alpine install-native downloaded a library that fails to load with "Error loading shared library ld-linux-x86-64.so.2". The troubleshooting doc claimed musl was selected automatically, but nothing detected it. Detect musl by the presence of /lib/ld-musl-*.so.1 and install libasherah-<arch>-musl.so, which every release already publishes. Add --libc=auto|gnu|musl for builds whose build and runtime images differ. [ai assisted] Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
On musl every thread except the main one gets a 128 KiB stack. Go callers using purego run FFI calls on arbitrary runtime threads, and building a factory with AWS KMS + DynamoDB (and the AWS calls behind encrypt/decrypt) needs more than that, so asherah-go segfaulted on Alpine (SIGSEGV, sigcode=2, "signal arrived during cgo execution") in Setup and Decrypt. Wrap the factory, session, encrypt and decrypt entry points in stacker::maybe_grow: when less than 1 MiB of stack is left the call runs on a separately allocated 8 MiB stack, otherwise in place, so glibc threads and the musl main thread only pay a stack-pointer check. asherah-go/cmd/musl-stack-repro reproduces it: on Alpine with the v1.0.0 musl library, `musl-stack-repro aws` crashes in Setup on a non-main thread; with this change it returns the expected AWS error. [ai assisted] Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
awankhede-godaddy
force-pushed
the
fix/musl-support
branch
2 times, most recently
from
November 23, 2026 11:21
0feeaf9 to
051d695
Compare
awankhede-godaddy
marked this pull request as ready for review
November 23, 2026 11:41
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.
Summary
asherah-go v1.0.0 doesn't work on musl-based images such as Alpine. This PR fixes two separate problems:
install-nativealways installs the glibc library, which fails to load on Alpine.Decrypt, and sometimes inSetup.Problem 1:
install-nativeinstalls the glibc build on muslassetNameForPlatformalways returnslibasherah-<arch>.so, even though every release also publisheslibasherah-<arch>-musl.so. On Alpine the library then fails to load:docs/troubleshooting.md("Alpine/musl LoadError") says musl is selected automatically, but nothing in the tool detects it.Fix (
e561b53):install-nativedetects musl by checking for/lib/ld-musl-*.so.1, and installslibasherah-<arch>-musl.sowhen it's found.--libc=auto|gnu|musl, covers builds where the build and runtime images differ.Problem 2: SIGSEGV on musl threads
musl gives every thread except the main one a 128 KiB stack. Go callers using purego run FFI calls on whichever runtime thread the goroutine is on. Building a factory with AWS KMS and DynamoDB, and the AWS calls behind encrypt and decrypt, need more stack than that:
Request goroutines don't run on the main thread, so
Decryptcrashes every time.Setuponly crashes on starts where it doesn't happen to run on the main thread. glibc threads get 8 MiB by default, so glibc isn't affected.Fix (
051d695):stacker::maybe_grow. When less than 1 MiB of stack is left, the call runs on a separately allocated 8 MiB stack. Otherwise it runs in place, so glibc threads and the musl main thread only pay a stack-pointer check.asherah-go/cmd/musl-stack-reprois new: a small repro that runsSetup, encrypt and decrypt on threads other than the main one.Most of the
asherah-ffi/src/lib.rsdiff isrustfmtre-indenting the wrapped bodies. The actual change is thewith_stackhelper and a wrapper around each of the 7 entry points.The
*_asyncentry points aren't wrapped: they hand the work to tokio, whose worker threads get a 2 MiB stack on every libc.Testing
All tests ran on Alpine (x86_64), with the library built from this branch using
cargo build --release -p asherah-ffiand-crt-staticdisabled.musl-stack-repro aws(KMS + DynamoDB clients, thread other than the main one), 3 runsmusl-stack-repro(memory metastore, static KMS)Setupand 32 encrypt/decrypt round trips OKinstall-native:golang:1.26-alpine: installslibasherah-x64-musl.so, checksum verified.golang:1.26(Debian): installslibasherah-x64.so, checksum verified.platform_test.gotests pass.Downstream: rdproxy (Go, Alpine), with the library built from this branch and its own
PT_GNU_STACKstack workaround removed, starts, passes its Asherah encrypt/decrypt startup check, and decrypts stored values without crashing.Not tested:
Notes
stackerinasherah-ffi, plus its dependencypsmand the build-time cratesobjectandar_archive_writer.Cargo.lockonly adds these four..sobuilt from this branch linkslibgcc_s.so.1, so Alpine runtime images needapk add libgcc. The v1.0.0 release didn't need this. Worth checking whether the release workflow'scargo-zigbuildbuild has the same dependency.🤖 Generated with Claude Code