[all-commits] [llvm/llvm-project] 5af243: [clang-cl] Support the /HOTPATCH flag
Alexandre Ganea via All-commits
all-commits at lists.llvm.org
Thu Jan 20 09:57:32 PST 2022
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 5af2433e1794ebf7e58e848aa612c7912d71dc78
https://github.com/llvm/llvm-project/commit/5af2433e1794ebf7e58e848aa612c7912d71dc78
Author: Alexandre Ganea <alexandre.ganea at legionlabs.com>
Date: 2022-01-20 (Thu, 20 Jan 2022)
Changed paths:
M clang/docs/ReleaseNotes.rst
M clang/include/clang/Basic/CodeGenOptions.def
M clang/include/clang/Driver/Options.td
M clang/lib/CodeGen/BackendUtil.cpp
M clang/lib/CodeGen/CodeGenFunction.cpp
M clang/lib/Driver/ToolChains/Clang.cpp
M clang/lib/Driver/ToolChains/MSVC.cpp
M clang/test/CodeGen/patchable-function-entry.c
A clang/test/CodeGenCXX/debug-info-hotpatch-arm.cpp
A clang/test/CodeGenCXX/debug-info-hotpatch.cpp
M clang/test/Driver/cl-options.c
M llvm/include/llvm/Target/TargetOptions.h
M llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
M llvm/test/DebugInfo/COFF/ARMNT/arm-register-variables.ll
M llvm/test/MC/AArch64/coff-debug.ll
Log Message:
-----------
[clang-cl] Support the /HOTPATCH flag
This patch adds support for the MSVC /HOTPATCH flag: https://docs.microsoft.com/sv-se/cpp/build/reference/hotpatch-create-hotpatchable-image?view=msvc-170&viewFallbackFrom=vs-2019
The flag is translated to a new -fms-hotpatch flag, which in turn adds a 'patchable-function' attribute for each function in the TU. This is then picked up by the PatchableFunction pass which would generate a TargetOpcode::PATCHABLE_OP of minsize = 2 (which means the target instruction must resolve to at least two bytes). TargetOpcode::PATCHABLE_OP is only implemented for x86/x64. When targetting ARM/ARM64, /HOTPATCH isn't required (instructions are always 2/4 bytes and suitable for hotpatching).
Additionally, when using /Z7, we generate a 'hot patchable' flag in the CodeView debug stream, in the S_COMPILE3 record. This flag is then picked up by LLD (or link.exe) and is used in conjunction with the linker /FUNCTIONPADMIN flag to generate extra space before each function, to accommodate for live patching long jumps. Please see: https://github.com/llvm/llvm-project/blob/d703b922961e0d02a5effdd4bfbb23ad50a3cc9f/lld/COFF/Writer.cpp#L1298
The outcome is that we can finally use Live++ or Recode along with clang-cl.
NOTE: It seems that MSVC cl.exe always enables /HOTPATCH on x64 by default, although if we did the same I thought we might generate sub-optimal code (if this flag was active by default). Additionally, MSVC always generates a .debug$S section and a S_COMPILE3 record, which Clang doesn't do without /Z7. Therefore, the following MSVC command-line "cl /c file.cpp" would have to be written with Clang such as "clang-cl /c file.cpp /HOTPATCH /Z7" in order to obtain the same result.
Depends on D43002, D80833 and D81301 for the full feature.
Differential Revision: https://reviews.llvm.org/D116511
More information about the All-commits
mailing list