[clang] [llvm] [aarch64][x86][win] Add compiler support for MSVC's /funcoverride flag (Windows kernel loader replaceable functions) (PR #125320)
Eli Friedman via cfe-commits
cfe-commits at lists.llvm.org
Tue Feb 4 16:39:26 PST 2025
================
@@ -4661,3 +4661,110 @@ AsmPrinter::getCodeViewJumpTableInfo(int JTI, const MachineInstr *BranchInstr,
return std::make_tuple(Base, 0, BranchLabel,
codeview::JumpTableEntrySize::Int32);
}
+
+void AsmPrinter::emitCOFFReplaceableFunctionData(Module &M) {
+ const Triple &TT = TM.getTargetTriple();
+ assert(TT.isOSBinFormatCOFF());
+
+ bool IsTargetArm64EC = TT.isWindowsArm64EC();
+ SmallVector<char> Buf;
+ SmallVector<MCSymbol *> FuncOverrideDefaultSymbols;
+ bool SwitchedToDirectiveSection = false;
+ for (const auto &F : M.functions()) {
+ if (F.hasFnAttribute("loader-replaceable")) {
+ if (!SwitchedToDirectiveSection) {
+ OutStreamer->switchSection(
+ OutContext.getObjectFileInfo()->getDrectveSection());
+ SwitchedToDirectiveSection = true;
+ }
+
+ auto Name = F.getName();
+
+ // For hybrid-patchable targets, strip the prefix so that we can mark
+ // the real function as replaceable.
+ if (IsTargetArm64EC && Name.ends_with(HybridPatchableTargetSuffix)) {
+ Name = Name.substr(0, Name.size() - HybridPatchableTargetSuffix.size());
+ }
+
+ llvm::Twine FuncOverrideName = Name + "_$fo$";
----------------
efriedma-quic wrote:
Sticking a Twine in a local variable is a bad idea; you end up with references to dead temporaries because a Twine often contains a reference to another Twine, or some other temporary value. (Not sure if that actually happens here, but we discourage the practice in general to avoid issues.)
https://github.com/llvm/llvm-project/pull/125320
More information about the cfe-commits
mailing list