[llvm] [SystemZ] Avoid modifying IR in mcount instrumentation. (PR #152298)
Dominik Steenken via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 6 05:08:53 PDT 2025
https://github.com/dominik-steenken created https://github.com/llvm/llvm-project/pull/152298
This PR changes how the call to `mcount` is inserted in `emitPrologue`. It is now emitted as an external symbol rather than a global variable, preventing potentially unexpected IR modification.
>From f1e36f4dbd7b535fd428c120d9ff3e76a15484c5 Mon Sep 17 00:00:00 2001
From: Dominik Steenken <dost at de.ibm.com>
Date: Wed, 6 Aug 2025 13:46:30 +0200
Subject: [PATCH] [SystemZ] Avoid modifying IR in mcount instrumentation.
This commit changes how the call to `mcount` is inserted in `emitPrologue`.
It is now emitted as an external symbol rather than a global variable,
preventing potentially unexpected IR modification.
---
llvm/lib/Target/SystemZ/SystemZFrameLowering.cpp | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/llvm/lib/Target/SystemZ/SystemZFrameLowering.cpp b/llvm/lib/Target/SystemZ/SystemZFrameLowering.cpp
index 6297916310803..ed953fef8c1f1 100644
--- a/llvm/lib/Target/SystemZ/SystemZFrameLowering.cpp
+++ b/llvm/lib/Target/SystemZ/SystemZFrameLowering.cpp
@@ -574,13 +574,11 @@ void SystemZELFFrameLowering::emitPrologue(MachineFunction &MF,
// Call mcount (Regmask from CC AnyReg since mcount preserves all normal
// argument registers).
- FunctionCallee FC = MF.getFunction().getParent()->getOrInsertFunction(
- "mcount", Type::getVoidTy(MF.getFunction().getContext()));
const uint32_t *Mask = MF.getSubtarget<SystemZSubtarget>()
.getSpecialRegisters()
->getCallPreservedMask(MF, CallingConv::AnyReg);
BuildMI(MBB, MBBI, DL, ZII->get(SystemZ::CallBRASL))
- .addGlobalAddress(dyn_cast<Function>(FC.getCallee()))
+ .addExternalSymbol(MF.createExternalSymbolName("mcount"))
.addRegMask(Mask);
// Reload return address from 8 bytes above stack pointer.
More information about the llvm-commits
mailing list