arsig: fix macOS (Apple clang) build of xgb_model.c#63
Draft
ProfessionalSeaweedDevourer wants to merge 1 commit into
Draft
arsig: fix macOS (Apple clang) build of xgb_model.c#63ProfessionalSeaweedDevourer wants to merge 1 commit into
ProfessionalSeaweedDevourer wants to merge 1 commit into
Conversation
On macOS the C compiler invoked as 'gcc' is Apple clang, which (1) caps C
bracket nesting at 256 and (2) parses via recursive descent. The generated
src/arsig/xgb_model.c (SVM/XGBoost ambiguity-validation model) exceeds depth
256, so the stock build fails:
xgb_model.c: fatal error: bracket nesting level exceeded maximum of 256
Adding -fbracket-depth raises the limit, but on the default macOS 8 MB stack
clang's parser then overflows the stack and segfaults on this file. The build
only succeeds when the stack is also enlarged.
Fix (arsig/Makefile, no effect on GNU/Linux builds):
- add -fbracket-depth=1024 only when the C compiler is clang (GNU gcc has no
such limit and rejects the flag);
- raise the stack soft limit to the hard limit for the C compile so clang's
recursive parser does not overflow.
Verified on macOS arm64 (Apple clang 17): full install.sh build now completes
under the default 8 MB stack. GNU gcc-16 builds the file unchanged (flag not
added).
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.
Problem
On macOS, the C compiler invoked as
gccis Apple clang. Building from aclean tree fails in
arsigwhile compiling the generatedsrc/arsig/xgb_model.c(the SVM/XGBoost integer-ambiguity-validation model):
Apple clang caps C bracket nesting at 256; that generated file exceeds it.
GNU gcc (Linux) has no such default limit, which is why CI/Linux builds are
unaffected.
Why the obvious one-liner is not enough
Adding
-fbracket-depth=1024lifts the 256 limit, but clang parses viarecursive descent, and on the default macOS stack of 8 MB (
ulimit -s= 8192) the parser then overflows the stack and segfaults on this very
deeply nested file:
So a robust fix must (a) raise the bracket-depth limit and (b) give the
compiler enough stack.
Fix (
src/arsig/Makefile, no effect on GNU/Linux)-fbracket-depth=1024only when the C compiler is clang (GNU gcc hasno such limit and rejects the flag with
unrecognized command-line option);clang's recursive parser does not overflow.
Testing (macOS arm64, Apple clang 17; Homebrew GNU gcc-16)
-fbracket-depth-fbracket-depth-fbracket-depthWith this patch, a full
install.shbuild completes on macOS under the default8 MB stack, and GNU gcc builds the file unchanged (flag not added).
Alternative
The stack bump could instead live once in
install.sh(globalulimit -sbefore the build) rather than in the
arsigrecipe; happy to move it there ifpreferred. Opened as a draft for maintainer feedback on the approach.