This is an archive of the discontinued LLVM Phabricator instance.

[clang] Add support for __attribute__((guard(nocf)))
ClosedPublic

Authored by alvinhochun on Aug 20 2022, 8:54 AM.

Details

Summary

To support using Control Flow Guard with mingw-w64, Clang needs to
accept __declspec(guard(nocf)) also for the GNU target. Since mingw
has #define __declspec(a) __attribute__((a)) as built-in, the simplest
solution is to accept __attribute((guard(nocf))) to be compatible with
MSVC and Clang's msvc target.

As a side effect, this also adds [[clang::guard(nocf)]] for C++.

Diff Detail

Event Timeline

alvinhochun created this revision.Aug 20 2022, 8:54 AM
Herald added a project: Restricted Project. · View Herald Transcript
alvinhochun edited the summary of this revision. (Show Details)

Update patch

Revert llvm test changes

alvinhochun published this revision for review.Aug 21 2022, 12:38 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 21 2022, 12:38 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript

Specify x86_64-w64-windows-gnu in tests instead of using %itanium_abi_triple because it doesn't work on Linux.

There should be some explicit test coverage that show the new attribute spelling(s) work when spelled directly rather than when relying on predefined macros.

clang/include/clang/Basic/Attr.td
3497

I don't see any evidence that this is supported by GCC: https://godbolt.org/z/bEPv4E7ab

I think this should be using Clang instead of GCC so that it works as both [[clang::guard(nocf)]] and __attribute__((guard(nocf))).

alvinhochun edited the summary of this revision. (Show Details)

Applied suggestions from Aaron. Thanks for the comment.

aaron.ballman accepted this revision.Aug 22 2022, 11:20 AM

LGTM! Please be sure to add a release note when you land (we have a section about changes to attributes).

This revision is now accepted and ready to land.Aug 22 2022, 11:20 AM
alvinhochun marked an inline comment as done.

Rebased and added a release note entry. @mstorsjo would you mind landing this for me? Thanks.

This revision was automatically updated to reflect the committed changes.