Skip to content

Make sanitizer builds respect -c for -g*#614

Merged
keith merged 4 commits into
mainfrom
ks/make-sanitizer-builds-respect-c-for-g
Jul 6, 2026
Merged

Make sanitizer builds respect -c for -g*#614
keith merged 4 commits into
mainfrom
ks/make-sanitizer-builds-respect-c-for-g

Conversation

@keith

@keith keith commented Jul 2, 2026

Copy link
Copy Markdown
Member

Previously for --features=asan you got -gline-tables-only. This
isn't ideal if you actually want to debug the sanitized code. Now it
respects --compilation_mode so with -c dbg you get -g and with
-c fastbuild you get -gline-tables-only.

This is a tiny bit weird because we don't pass any -g for fastbuild
normally.

Fixes #613

Previously for `--features=asan` you got `-gline-tables-only`. This
isn't ideal if you actually want to debug the sanitized code. Now it
respects `--compilation_mode` so with `-c dbg` you get `-g` and with
`-c fastbuild` you get `-gline-tables-only`.

This is a tiny bit weird because we don't pass any `-g` for `fastbuild`
normally.

Fixes #613
@DoDoENT

DoDoENT commented Jul 2, 2026

Copy link
Copy Markdown

A matter of fact was that today I actually wanted to debug fastbuild code - I had some issue that wasn't reproducing without optimizer.

@keith

keith commented Jul 2, 2026

Copy link
Copy Markdown
Member Author

i think at some point there are too many combos and you'll have to do --features=asan --copt=-whatever, so I guess this fix is more about the defaults trying to be as useful as possible

@DoDoENT

DoDoENT commented Jul 2, 2026

Copy link
Copy Markdown

i think at some point there are too many combos and you'll have to do --features=asan --copt=-whatever, so I guess this fix is more about the defaults trying to be as useful as possible

That won't work and was the reason I raised the issue in the first place.

I have common --copt=-g for all my builds, including production (so that symbols can be stripped and binary with symbols retained for future symbolification of crash traces), yet it didn't work.

As described by Gemini, the problem is that Bazel always puts flags that come from features last, thus overriding both --copt and --per_file_copt. The only workaround for clang is using undocumented environment variable CCC_OVERRIDE_OPTIONS which can then override options set by bazel. Without this, the clang invocation line looks something like this:

-g -fsanitize=address -gline-tables-only

which then overrides the former -g option and makes debugging impossible.

@keith

keith commented Jul 2, 2026

Copy link
Copy Markdown
Member Author

ah i don't think the not being able to override the order was explicit in the original report. i think we should probably fix that separately from this: #615

@DoDoENT

DoDoENT commented Jul 2, 2026

Copy link
Copy Markdown

ah i don't think the not being able to override the order was explicit in the original report. i think we should probably fix that separately from this: #615

Heh 😅 , I linked the transcript of my chat with Gemini, who convinced me that flag order is a Bazel thing, not a toolchain thing.

I'm glad it's possible to allow user flags to override toolchain feature flags directly from the toolchain config.

@keith

keith commented Jul 6, 2026

Copy link
Copy Markdown
Member Author

other PR needs to be merged too, but i think with these combined we should be good

@keith keith merged commit b1585a3 into main Jul 6, 2026
26 checks passed
@keith keith deleted the ks/make-sanitizer-builds-respect-c-for-g branch July 6, 2026 17:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Builds with sanitizers are not debuggable

3 participants