Closed kobykahane closed 1 year ago
This was originally added in #556 at the request of @mcfi - I believe it is being used by the OS where CFG is enabled, so to the best of my knowledge it is working correctly, provided a compatible compiler and target configuration. It is also possible that you're hitting a compiler bug. Hopefully @mcfi can confirm.
Confirmed this is a known bug. The (internal) reference is DevDiv bug 1846207.
Thanks @kennykerr!
By the way, thanks for the clear repro. That helped triage a similar active bug internally.
Version
v2.0.230706.1
Summary
I am unsure whether the following is a cppwinrt bug or a compiler bug.
When compiling a program that targets ARM64EC (i.e., with MSVC 2022 17.6.5, with the ARM64 target compiler, with the
/arm64EC
compiler switch specified) and that has Control Flow Guard enforcement enabled (/guard:cf
) and that program invokesWINRT_IMPL_CoCreateInstance
, the program fastfails with a CFG violation:This does not occur if the program targets normal ARM64 instead of ARM64EC and does not occur if the program is built without CFG.
I've managed to narrow this down to
WINRT_IMPL_LINK
's definition of the alternate name. The following program also crashes in a similar way:(note that there's no significance to the specific COM CLSID and IID being used) However, if instead the alternate name is changed to either:
(i.e., without the leading hash in the first part, but with the hash in prefix for the actual import name) or:
(i.e., no hashes at all, identically to what WINRT_IMPL_LINK would normally do on x64) then the program compiles and links successfully, successfully invokes CoCreateInstance through the pointer and does not trigger a CFG violation on ARM64EC.
Reproducible example
Expected behavior
Programs using
winrt::create_instance
built for ARM64EC with CFG enabled should not crash with a CFG violation.Actual behavior
Programs using
winrt::create_instance
built for ARM64EC with CFG enabled do crash with a CFG violation.Additional comments
Compiler path:
Compiler command line for repros: