[PATCH] D116511: [clang-cl] Support the /HOTPATCH flag

Alexandre Ganea via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Jan 2 17:52:58 PST 2022


aganea created this revision.
aganea added reviewers: amccarth, craig.topper, hans, rnk, stefan_reinalter.
Herald added subscribers: ormris, dexonsmith, dang, pengfei, hiraditya.
aganea requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

This patch adds support for the /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 `-fhotpatch` cc1 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). Currently `TargetOpcode::PATCHABLE_OP` is only implemented for x86/x64.

Additionally 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 extraneous space before each function, to accommodate for live patching. Please see: https://github.com/llvm/llvm-project/blob/d703b922961e0d02a5effdd4bfbb23ad50a3cc9f/lld/COFF/Writer.cpp#L1298

The end result is that one can finally use Live++ <https://molecular-matters.com/> or Recode <http://www.indefiant.com/> along with clang-cl.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D116511

Files:
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/CodeGen/patchable-function-entry.c
  clang/test/CodeGenCXX/debug-info-hotpatch.cpp
  clang/test/Driver/cl-options.c
  llvm/include/llvm/Target/TargetOptions.h
  llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D116511.396970.patch
Type: text/x-patch
Size: 8287 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220103/1302e325/attachment-0001.bin>


More information about the cfe-commits mailing list