[clang] [llvm] Add support for Windows hot-patching (PR #138972)
Alexandre Ganea via cfe-commits
cfe-commits at lists.llvm.org
Tue May 13 09:46:32 PDT 2025
================
@@ -453,6 +453,37 @@ CodeGenModule::CodeGenModule(ASTContext &C,
if (Context.getTargetInfo().getTriple().getArch() == llvm::Triple::x86)
getModule().addModuleFlag(llvm::Module::Error, "NumRegisterParameters",
CodeGenOpts.NumRegisterParameters);
+
+ // If there are any functions that are marked for Windows hot-patching,
+ // then build the list of functions now.
+ if (!CGO.MSHotPatchFunctionsFile.empty() ||
+ !CGO.MSHotPatchFunctionsList.empty()) {
+ if (!CGO.MSHotPatchFunctionsFile.empty()) {
+ auto BufOrErr = llvm::MemoryBuffer::getFile(CGO.MSHotPatchFunctionsFile);
+ if (BufOrErr) {
+ const llvm::MemoryBuffer &FileBuffer = **BufOrErr;
+ for (llvm::line_iterator I(FileBuffer.getMemBufferRef(), true), E;
+ I != E; ++I) {
+ this->MSHotPatchFunctions.push_back(std::string{*I});
+ }
+ } else {
+ auto &DE = Context.getDiagnostics();
+ unsigned DiagID =
+ DE.getCustomDiagID(DiagnosticsEngine::Error,
+ "failed to open hotpatch functions file "
+ "(-fms-hotpatch-functions-file): %0 : %1");
+ DE.Report(DiagID) << CGO.MSHotPatchFunctionsFile
+ << BufOrErr.getError().message();
+ }
+ }
+
+ for (const auto &FuncName : CGO.MSHotPatchFunctionsList) {
----------------
aganea wrote:
LLVM coding standards [instructs](https://llvm.org/docs/CodingStandards.html#don-t-use-braces-on-simple-single-statement-bodies-of-if-else-loop-statements) to omit braces for one liners, but TBH I prefer the Rust rule where the brace should always be mandatory. What do other reviewers think?
https://github.com/llvm/llvm-project/pull/138972
More information about the cfe-commits
mailing list