Add UBSan flags to Clang builds for enhanced runtime safety - #16
Open
assisted-by-ai wants to merge 3 commits into
Open
Add UBSan flags to Clang builds for enhanced runtime safety#16assisted-by-ai wants to merge 3 commits into
assisted-by-ai wants to merge 3 commits into
Conversation
Contributor
|
Integrated wiki changes. Will add flags where appropriate (including to kloak). |
ArrayBolt3
reviewed
Apr 15, 2026
Comment on lines
-45
to
+55
| #ifeq (,$(findstring clang,$(CC_VERSION))) # if clang | ||
| #WARN_CFLAGS += # | ||
| #endif | ||
|
|
||
| # IMPORTANT: Do NOT remove -ftrapv from the list of flags, it is used to allow | ||
| # signed integer arithmetic without explicit overflow checks. | ||
| FORTIFY_CFLAGS := -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3 \ | ||
| -fstack-clash-protection -fstack-protector-all \ | ||
| -fno-delete-null-pointer-checks -fno-strict-overflow -fno-strict-aliasing \ | ||
| -fstrict-flex-arrays=3 -ftrapv -ftrivial-auto-var-init=pattern | ||
|
|
||
| ifneq (,$(findstring clang,$(CC_VERSION))) # if clang | ||
| FORTIFY_CFLAGS += -fsanitize=undefined -fsanitize-minimal-runtime -fno-sanitize-recover=all | ||
| endif | ||
|
|
Contributor
There was a problem hiding this comment.
This might be a good idea, but is rejected for now. As per the compiler_hardening wiki page:
Note: It is unclear whether this actually provides any meaningful level of hardening. Omitting these flags may be desirable even with Clang.
adrelanos
pushed a commit
that referenced
this pull request
May 11, 2026
Replace secrets: inherit with explicit single-secret map.
Replaces the empty commented-out Clang placeholder with working -fsanitize=undefined -fsanitize-minimal-runtime -fno-sanitize-recover=all flags, guarded by ifneq so they only apply when building with Clang. Also fixes the original placeholder's ifeq/ifneq logic inversion. https://claude.ai/code/session_01E8Jai7NViAgjrdJ6Us48Qd
Add -Wformat-truncation and -fno-strict-overflow to shared section. Add -fzero-call-used-regs=all to both summary command blocks. Add -Wformat-truncation and -fno-strict-overflow to both summary command blocks. https://claude.ai/code/session_01E8Jai7NViAgjrdJ6Us48Qd
assisted-by-ai
force-pushed
the
claude/review-compilation-security-c2DdU
branch
from
May 11, 2026 21:33
d20028f to
bf07dcd
Compare
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 change enhances the security hardening flags used when compiling with Clang by adding undefined behavior sanitizer (UBSan) instrumentation to catch runtime errors at compile time.
Key Changes
-fsanitize=undefined: Enables undefined behavior sanitization-fsanitize-minimal-runtime: Uses minimal UBSan runtime overhead-fno-sanitize-recover=all: Causes the program to halt on first UBSan error instead of continuingFORTIFY_CFLAGSwhen Clang is detectedImplementation Details
The new Clang-specific flags are conditionally added using
ifneqto detect Clang in the compiler version string, ensuring these UBSan options (which may not be supported by GCC in the same way) only apply to Clang builds. This provides additional runtime safety checks for undefined behavior while maintaining compatibility with other compilers.https://claude.ai/code/session_01E8Jai7NViAgjrdJ6Us48Qd