-
Notifications
You must be signed in to change notification settings - Fork 14.7k
[Clang][Basic] Add __has_feature
checks for CFI sanitizers
#151348
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
49149a0
[Clang][Basic] Enable `__has_feature(cfi)`
moorabbit 75b0360
Add more test cases
moorabbit d741f65
add `-fno-sanitize-ignorelist` to fix CI build issue
moorabbit b6a7ce7
Fix driver test failure
moorabbit 7da5378
PiJoules suggestion
moorabbit fded769
PiJoules suggestions
moorabbit cc13c4b
Fix test failure on windows
moorabbit 64556aa
Specify the target platform the test is allowed to run on
moorabbit f0094c0
Merge branch 'main' into has-feature-cfi
moorabbit 6e0c3c7
Merge branch 'main' into has-feature-cfi
moorabbit File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// RUN: %clang_cc1 -E -fsanitize=cfi-cast-strict -o - %s | FileCheck --check-prefix=CHECK-CFISAN %s | ||
// RUN: %clang_cc1 -E -fsanitize=cfi-derived-cast -o - %s | FileCheck --check-prefix=CHECK-CFISAN %s | ||
// RUN: %clang_cc1 -E -fsanitize=cfi-icall -o - %s | FileCheck --check-prefix=CHECK-CFISAN %s | ||
// RUN: %clang_cc1 -E -fsanitize=cfi-mfcall -o - %s | FileCheck --check-prefix=CHECK-CFISAN %s | ||
// RUN: %clang_cc1 -E -fsanitize=cfi-unrelated-cast -o - %s | FileCheck --check-prefix=CHECK-CFISAN %s | ||
// RUN: %clang_cc1 -E -fsanitize=cfi-nvcall -o - %s | FileCheck --check-prefix=CHECK-CFISAN %s | ||
// RUN: %clang_cc1 -E -fsanitize=cfi-vcall -o - %s | FileCheck --check-prefix=CHECK-CFISAN %s | ||
|
||
// RUN: %clang_cc1 -E -fsanitize=kcfi -o - %s | FileCheck --check-prefix=CHECK-CFISAN %s | ||
|
||
// RUN: %clang -E --target=x86_64-linux-gnu -fvisibility=hidden -fno-sanitize-ignorelist -fsanitize=cfi -flto -c %s -o - | FileCheck %s --check-prefix=CHECK-CFISAN | ||
// RUN: %clang -E --target=x86_64-linux-gnu -fvisibility=hidden -fno-sanitize-ignorelist -fsanitize=cfi -fsanitize-cfi-cross-dso -flto -c %s -o - | FileCheck %s --check-prefix=CHECK-CFISAN | ||
|
||
// Disable CFI sanitizers. | ||
// RUN: %clang -E --target=x86_64-linux-gnu -fvisibility=hidden -fno-sanitize=cfi -flto -c %s -o - | FileCheck %s --check-prefix=CHECK-NO-CFISAN | ||
|
||
// Disable some but not all CFI schemes. | ||
// RUN: %clang -E --target=x86_64-linux-gnu -fvisibility=hidden -fno-sanitize-ignorelist -fsanitize=cfi -fno-sanitize-cfi-cross-dso -fno-sanitize=cfi-nvcall,cfi-vcall,cfi-mfcall,cfi-icall -flto -c %s -o - | FileCheck %s --check-prefix=CHECK-CFISAN | ||
|
||
// Disable all CFI schemes. This essentially disables CFI sanitizers. | ||
// RUN: %clang -E --target=x86_64-linux-gnu -fvisibility=hidden -fsanitize=cfi -fno-sanitize-cfi-cross-dso -fno-sanitize=cfi-nvcall,cfi-vcall,cfi-mfcall,cfi-icall,cfi-cast-strict,cfi-derived-cast,cfi-unrelated-cast -flto -c %s -o - | FileCheck %s --check-prefix=CHECK-NO-CFISAN | ||
|
||
#if __has_feature(cfi) | ||
int CFISanitizerEnabled(); | ||
#else | ||
int CFISanitizerDisabled(); | ||
#endif | ||
|
||
// CHECK-CFISAN: CFISanitizerEnabled | ||
// CHECK-NO-CFISAN: CFISanitizerDisabled | ||
|
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you're testing for x86_64-linux-gnu only, you'll probably want
// REQUIRES: x86-registered-target
alsoThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On second thought, since I'm just running the preprocessor (i.e.
clang -E
), I probably don't need to set the target at all. I removed the target specification in the new commit. Let me know if you would like me to keep it and requirex86-registered-target
.