MSVC defines _KERNEL_MODE when /kernel is passed.
Also, /kernel disables RTTI and C++ exception handling.
https://docs.microsoft.com/en-us/cpp/build/reference/kernel-create-kernel-mode-binary?view=msvc-170
Paths
| Differential D126719
[clang-cl] Add support for /kernel ClosedPublic Authored by steplong on May 31 2022, 1:50 PM.
Details Summary MSVC defines _KERNEL_MODE when /kernel is passed. https://docs.microsoft.com/en-us/cpp/build/reference/kernel-create-kernel-mode-binary?view=msvc-170
Diff Detail
Event TimelineComment Actions https://docs.microsoft.com/en-us/cpp/build/reference/kernel-create-kernel-mode-binary?view=msvc-170 says we should err when /kernel is used with various flags (e.g. most /arch:) flags. Want to add that too? It also says /kernel is passed on to the linker. What does cl do if both /kernel and (eg) /EHsc is passed (try both orders)? Same question for /kernel /GR.
Comment Actions
From my experiments, cl doesn't complain and happily compiles the code if /kernel /EHsc is passed (both orders), unless the code uses exceptions. Then, it complains error C2980: C++ exception handling is not supported with /kernel (both orders) Comment Actions
Do you know how the linker distinguishes objects created by /kernel vs non-/kernel? At the moment, we are just using MSVC's linker to link separately instead of being invoked by the compiler
This revision is now accepted and ready to land.Jun 3 2022, 8:31 AM Comment Actions
Closed by commit rGe3a6784ac967: [clang-cl] Add support for /kernel (authored by pzheng, committed by steplong). · Explain WhyJun 7 2022, 6:43 AM This revision was automatically updated to reflect the committed changes.
Revision Contents
Diff 433502 clang/include/clang/Basic/LangOptions.def
clang/include/clang/Driver/Options.td
clang/lib/Basic/Targets/OSTargets.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/cl-zc.cpp
|
clang-format suggested style edits found: