This is an archive of the discontinued LLVM Phabricator instance.

[Clang] Introduce -fexperimental-sanitize-metadata=
ClosedPublic

Authored by melver on Aug 1 2022, 2:00 AM.

Details

Summary

Introduces the frontend flag -fexperimental-sanitize-metadata=, which
enables SanitizerBinaryMetadata instrumentation.

The first intended user of the binary metadata emitted will be a variant
of GWP-TSan [1]. The plan is to open source a stable and production
quality version of GWP-TSan. The development of which, however, requires
upstream compiler support.

[1] https://llvm.org/devmtg/2020-09/slides/Morehouse-GWP-Tsan.pdf

Until the tool has been open sourced, we mark this kind of
instrumentation as "experimental", and reserve the option to change
binary format, remove features, and similar.

Depends on D130887

Diff Detail

Event Timeline

melver created this revision.Aug 1 2022, 2:00 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 1 2022, 2:01 AM
Herald added a subscriber: ormris. · View Herald Transcript
melver requested review of this revision.Aug 1 2022, 2:01 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 1 2022, 2:01 AM
MaskRay added inline comments.Aug 2 2022, 8:18 PM
clang/include/clang/Driver/Options.td
5505

Let CC1 options use the same spelling as the driver options.

clang/lib/Driver/SanitizerArgs.cpp
848

Use Args.getLastArg(...)

clang/test/Driver/fsanitize-metadata.c
2

This RUN line is redundant. For other opt-in features, we don't check that the cc1 command line doesn't have an option.

5

-target is legacy. Use --target=. If a feature isn't Linux specific, use --target=x86_64.

melver updated this revision to Diff 449671.Aug 3 2022, 8:21 AM
melver marked 4 inline comments as done.

Address comments.

clang/lib/Driver/SanitizerArgs.cpp
848

This won't work if someone does:

-fsanitize-metadata=feature1 -fsanitize-metadata=feature2

(instead of '-fsanitize-metadata=feature1,feature2')

Added a test case.

clang/test/Driver/fsanitize-metadata.c
2

I've made the negative-presence test more useful by checking -fno- option works.

Another test under llvm-project/clang/test/CodeGen/ is needed which tests IR generated from C/C++ contains expected info.
Random example clang/test/CodeGen/attr-noundef.cpp

melver updated this revision to Diff 457543.Sep 2 2022, 2:49 AM

Add CodeGen test.

PTAL.

vitalybuka accepted this revision.Sep 2 2022, 9:58 AM
vitalybuka added inline comments.
clang/test/Driver/fsanitize-metadata.c
25

If possible, don't split long RUN: line
it's much easier to see a difference between different invocations

clang format is configured to ignore line length in tests nowadays anyway

This revision is now accepted and ready to land.Sep 2 2022, 9:58 AM
melver updated this revision to Diff 457637.Sep 2 2022, 10:52 AM

Don't split RUN lines.

MaskRay accepted this revision.Sep 2 2022, 1:27 PM
MaskRay added inline comments.
clang/include/clang/Driver/Options.td
1687

You can use f_Group instead of f_clang_Group. There are so many clang-specific (not in gcc) options, so the group is not useful.

Remove NoXarchOption.

clang/test/Driver/fsanitize-metadata.c
1

-fno-experimental-sanitize-metadata= works on bitmasks. You can change this run line to remove one bit instead of all.

melver updated this revision to Diff 457779.Sep 3 2022, 3:41 AM
melver marked 3 inline comments as done.
  • Options.td: s/f_clang_Group/f_Group/, remove NoXarchOption
  • Driver test: also test -fexperimental-sanitize-metadata=all -fno-experimental-metadata=<some option>
clang/test/Driver/fsanitize-metadata.c
1

Added more tests to check removing one bit after =all, but left this in place for the extra coverage.

This revision was landed with ongoing or failed builds.Sep 7 2022, 12:26 PM
This revision was automatically updated to reflect the committed changes.