[llvm] [SystemZ] Avoid modifying IR in mcount instrumentation. (PR #152298)
Dominik Steenken via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 6 08:02:57 PDT 2025
https://github.com/dominik-steenken updated https://github.com/llvm/llvm-project/pull/152298
>From 153d711c79e1087cee2154a941472fd0e0aee008 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..5ee66e3dfa7a8 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("mcount")
.addRegMask(Mask);
// Reload return address from 8 bytes above stack pointer.
More information about the llvm-commits
mailing list