Fix stacktrace compilation on musl libc (Alpine Linux)#28249
Open
tekintian wants to merge 2 commits intomicrosoft:mainfrom
Open
Fix stacktrace compilation on musl libc (Alpine Linux)#28249tekintian wants to merge 2 commits intomicrosoft:mainfrom
tekintian wants to merge 2 commits intomicrosoft:mainfrom
Conversation
- Add __GLIBC__ check to conditionally include execinfo.h - execinfo.h is glibc-specific and not available in musl libc - This fix enables ONNX Runtime to compile on Alpine Linux and other musl-based distributions - The stacktrace functionality will be gracefully disabled on non-glibc systems Fixes compilation error: fatal error: execinfo.h: No such file or directory Tested on: - Alpine Linux 3.23 with GCC 15.2.0 - Successfully builds ONNX Runtime 1.26.0 Signed-off-by: Tekin <tekintian@gmail.com>
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
This PR fixes a compilation error when building ONNX Runtime on Alpine Linux and other musl libc-based distributions. The issue occurs because
execinfo.his a glibc-specific header that is not available in musl libc.🔧 Changes
File Modified:
onnxruntime/core/platform/posix/stacktrace.ccChange: Added
&& defined(__GLIBC__)condition to the preprocessor check before including<execinfo.h>❓ Problem
When building ONNX Runtime on Alpine Linux (which uses musl libc instead of glibc), the build fails with:
This happens because:
execinfo.his a glibc-specific header for backtrace functionality✅ Solution
By adding
&& defined(__GLIBC__)to the condition, we ensure that:execinfo.his only included on glibc-based systems (Linux with glibc)This is consistent with how other platform-specific features are handled in the codebase (e.g.,
__ANDROID__,__wasm__,_AIX).🧪 Testing
Build Environment
Build Command
docker build -f Dockerfile.onnx-alpine \ -t onnx-alpine .Results
✅ Successfully compiled ONNX Runtime 1.26.0
✅ Generated
libonnxruntime.so.1.26.0(24 MB)✅ All core functionality working
✅ No runtime errors
Build Statistics
📊 Impact
Positive Impact
Potential Concerns
🔄 Compatibility
This change is fully backward compatible:
📝 Related Issues
This fix addresses the common issue reported by users trying to build ONNX Runtime on:
🚀 Usage Example
After this fix, users can build ONNX Runtime on Alpine Linux:
✍️ Author
TekinTian tekintian@gmail.com
📅 Date
April 28, 2026
Checklist
Note: This is a critical fix for Alpine Linux users and should be considered for inclusion in the next release.