This is an archive of the discontinued LLVM Phabricator instance.

[llvm] Mark CFGuard fn ptr symbol as DSO local and add tests for mingw
ClosedPublic

Authored by alvinhochun on Aug 21 2022, 9:43 AM.

Details

Summary

For mingw target, if a symbol is not marked DSO local, a .refptr is
generated for it. This makes CFG check calls use an extra pointer
dereference, which adds extra overhead compared to the MSVC version,
so mark the CFG guard check funciton pointer DSO local to stop it.
This should have no effect on MSVC target.

Also adapt the existing cfguard tests to run for mingw targets, so that
this change is checked.

Diff Detail

Event Timeline

alvinhochun created this revision.Aug 21 2022, 9:43 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 21 2022, 9:43 AM
alvinhochun requested review of this revision.Aug 21 2022, 9:43 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 21 2022, 9:43 AM

Extract the funclet test (added in D114914) from cfguard-checks so it is not used for mingw, because that test is only supported in MSVC env.

rnk accepted this revision.Aug 22 2022, 2:03 PM

lgtm

llvm/test/CodeGen/WinCFGuard/cfguard-mingw.ll
3

This was generated from some simple sources, right? Please include the C++ sources as a comment here.

This revision is now accepted and ready to land.Aug 22 2022, 2:03 PM

Depends on D132302

Technically it doesn't (a llvm codegen change can't really depend on higher layers), they're quite unrelated - even though it isn't very useful in the end without the other one.

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

Added c++ source to cfguard-mingw.ll and removed "Depends on" line from summary.

shafik added a subscriber: shafik.Aug 23 2022, 4:34 PM
shafik added inline comments.
llvm/lib/Transforms/CFGuard/CFGuard.cpp
250

This generates an implicit conversion of string-literal to bool. Alternatively you can do assert(false && "Invalid CFGuard mechanism");

beanz added a subscriber: beanz.Aug 23 2022, 6:51 PM
beanz added inline comments.
llvm/lib/Transforms/CFGuard/CFGuard.cpp
250
alvinhochun added inline comments.Aug 23 2022, 10:50 PM
llvm/lib/Transforms/CFGuard/CFGuard.cpp
250

Sorry about the error and thanks for fixing it.

mstorsjo added inline comments.Aug 24 2022, 6:44 AM
llvm/lib/Transforms/CFGuard/CFGuard.cpp
250

Thanks for fixing! I guess that instead of assert(false && “message…”); it could also have been llvm_unreachable(“message”);.