llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[clang][Driver] AllAddedKinds leaks disabled sanitizer settings into cc1 invocation

Open dgg5503 opened this issue 2 months ago • 1 comments

SanitizerArgs uses AllAddedKinds, a collection of all sanitizers ever mentioned in a Clang driver invocation, is used to parse many sanitizer-specific options. This is appropriate for claiming and validating arguments, but the resulting properties are frequently not cross-checked against final Kinds. Consequently, disabled sanitizers can still affect cc1 or linker arguments when another sanitizer remains enabled.

This pattern affects multiple sanitizers; CFI is one example:

clang -fsanitize=undefined,cfi -fno-sanitize=cfi -### -x c++ -o- - < /dev/null

The final cc1 -fsanitize= contains only UBSan checks, but the invocation still contains:

"-fsanitize-cfi-canonical-jump-tables"

See https://godbolt.org/z/fszoj9beW

The same underlying pattern occurs in several other sanitizer related settings.

AllAddedKinds should continue controlling parsing & claiming, but properties affecting compilation or linking should additionally be gated by final resolved Kinds.

dgg5503 avatar Oct 02 '26 17:10 dgg5503

@llvm/issue-subscribers-clang-driver

Author: Douglas (dgg5503)

`SanitizerArgs` uses `AllAddedKinds`, a collection of all sanitizers ever mentioned in a Clang driver invocation, is used to parse many sanitizer-specific options. This is appropriate for claiming and validating arguments, but the resulting properties are frequently not cross-checked against final `Kinds`. Consequently, disabled sanitizers can still affect cc1 or linker arguments when another sanitizer remains enabled.

This pattern affects multiple sanitizers; CFI is one example:

clang -fsanitize=undefined,cfi -fno-sanitize=cfi -### -x c++ -o- - &lt; /dev/null

The final cc1 -fsanitize= contains only UBSan checks, but the invocation still contains:

"-fsanitize-cfi-canonical-jump-tables"

See https://godbolt.org/z/fszoj9beW

The same underlying pattern occurs in several other sanitizer related settings.

AllAddedKinds should continue controlling parsing & claiming, but properties affecting compilation or linking should additionally be gated by final resolved Kinds.