public inbox for git-commits@fedoraproject.org
help / color / mirror / Atom feed
* [rpms/llvm] rawhide: Backport fix for -mcpu=power10
@ 2026-11-30 14:33 Nikita Popov
0 siblings, 0 replies; only message in thread
From: Nikita Popov @ 2026-11-30 14:33 UTC (permalink / raw)
To: git-commits
A new commit has been pushed.
Repo : rpms/llvm
Branch : rawhide
Commit : e531eab7ec18eac3f16e5cd7ce139c74bb77b581
Author : Nikita Popov <npopov@redhat.com>
Date : 2026-11-30T14:31:56+00:00
Stats : +252/-0 in 2 file(s)
URL : https://src.fedoraproject.org/rpms/llvm/c/e531eab7ec18eac3f16e5cd7ce139c74bb77b581?branch=rawhide
Log:
Backport fix for -mcpu=power10
Backport https://github.com/llvm/llvm-project/pull/246638, which
fixes a miscompile when bootstrapping LLVM with -mcpu=power10,
which is now used by ELN.
---
diff --git a/0001-PowerPC-Fix-stack-protector-indirect-tail-call-on-po.patch b/0001-PowerPC-Fix-stack-protector-indirect-tail-call-on-po.patch
new file mode 100644
index 0000000..65ec52d
--- /dev/null
+++ b/0001-PowerPC-Fix-stack-protector-indirect-tail-call-on-po.patch
@@ -0,0 +1,248 @@
+From 607d19e23be5cfb29192204456984259fd055faf Mon Sep 17 00:00:00 2001
+From: Nikita Popov <npopov@redhat.com>
+Date: Fri, 27 Nov 2026 12:15:45 +0100
+Subject: [PATCH] [PowerPC] Fix stack protector + indirect tail call on power10
+
+The issue here is that findSplitPointForStackProtector() does not
+recognize the mtctr instruction as being part of the terminator
+sequence (as it's not just a physreg COPY). This results in the
+block being split between the physreg copies for the arguments and
+the call. This will fail machine verification, and in release
+builds will end up removing those copies, resulting in a miscompile.
+
+Fix this by using a pseudo that takes a GPR and expands to mtctr
+plus the usual tail-call sequence. This is implemented as a
+custom inserter pseudo so we don't need to deal with register class
+constraints. This is sufficient, as the stack protector split
+happens before finalize-isel, so we don't need this to be an
+emit-time pseudo.
+
+Fixes https://github.com/llvm/llvm-project/issues/195561.
+---
+ llvm/lib/Target/PowerPC/PPCISelLowering.cpp | 44 ++++++++++-----
+ llvm/lib/Target/PowerPC/PPCInstr64Bit.td | 11 +++-
+ llvm/lib/Target/PowerPC/PPCInstrInfo.td | 21 +++++++-
+ ...tack-protector-pcrel-indirect-tail-call.ll | 53 +++++++++++++++++++
+ 4 files changed, 112 insertions(+), 17 deletions(-)
+ create mode 100644 llvm/test/CodeGen/PowerPC/stack-protector-pcrel-indirect-tail-call.ll
+
+diff --git a/llvm/lib/Target/PowerPC/PPCISelLowering.cpp b/llvm/lib/Target/PowerPC/PPCISelLowering.cpp
+index 75e4f266ed67..6b992420b510 100644
+--- a/llvm/lib/Target/PowerPC/PPCISelLowering.cpp
++++ b/llvm/lib/Target/PowerPC/PPCISelLowering.cpp
+@@ -5620,14 +5620,11 @@ static void prepareOutOfLineGlueCall(SelectionDAG &DAG, SDValue &Callee,
+ Glue = MoveToPhysicalReg.getValue(1);
+ }
+
+-static void
+-buildCallOperands(SmallVectorImpl<SDValue> &Ops,
+- PPCTargetLowering::CallFlags CFlags, const SDLoc &dl,
+- SelectionDAG &DAG,
+- SmallVector<std::pair<unsigned, SDValue>, 8> &RegsToPass,
+- SDValue Glue, SDValue Chain, SDValue &Callee, int SPDiff,
+- const PPCSubtarget &Subtarget) {
+- const bool IsPPC64 = Subtarget.isPPC64();
++static void buildCallOperands(
++ SmallVectorImpl<SDValue> &Ops, PPCTargetLowering::CallFlags CFlags,
++ const SDLoc &dl, SelectionDAG &DAG,
++ SmallVector<std::pair<unsigned, SDValue>, 8> &RegsToPass, SDValue Glue,
++ SDValue Chain, SDValue &Callee, int SPDiff, const PPCSubtarget &Subtarget) {
+ // MVT for a general purpose register.
+ const MVT RegVT = Subtarget.getScalarIntVT();
+
+@@ -5669,10 +5666,13 @@ buildCallOperands(SmallVectorImpl<SDValue> &Ops,
+ Ops.push_back(DAG.getRegister(Subtarget.getEnvironmentPointerRegister(),
+ RegVT));
+
+-
+- // Add CTR register as callee so a bctr can be emitted later.
+- if (CFlags.IsTailCall)
+- Ops.push_back(DAG.getRegister(IsPPC64 ? PPC::CTR8 : PPC::CTR, RegVT));
++ // For tail calls, pass the callee address. It is only moved into CTR
++ // after ISel, see TCRETURNri_GPR.
++ if (CFlags.IsTailCall) {
++ assert(!Subtarget.usesFunctionDescriptors() &&
++ "Indirect tail calls through function descriptors unsupported");
++ Ops.push_back(Callee);
++ }
+ }
+
+ // If this is a tail call add stack pointer delta.
+@@ -5735,7 +5735,9 @@ SDValue PPCTargetLowering::FinishCall(
+ prepareDescriptorIndirectCall(DAG, Callee, Glue, Chain, CallSeqStart, CB,
+ dl, CFlags.HasNest, Subtarget);
+ }
+- } else {
++ } else if (!CFlags.IsTailCall) {
++ // Indirect tail calls take the callee address in a GPR. The move into CTR
++ // is only emitted after ISel, see TCRETURNri_GPR.
+ prepareIndirectCall(DAG, Callee, Glue, Chain, dl);
+ }
+
+@@ -5760,6 +5762,8 @@ SDValue PPCTargetLowering::FinishCall(
+ // PC Relative calls also use TC_RETURN as the way to mark tail calls.
+ assert(CallOpc == PPCISD::TC_RETURN &&
+ "Unexpected call opcode for a tail call.");
++ if (CFlags.IsIndirect)
++ CallOpc = PPCISD::TC_RETURN_INDIRECT;
+ DAG.getMachineFunction().getFrameInfo().setHasTailCall();
+ SDValue Ret = DAG.getNode(CallOpc, dl, MVT::Other, Ops);
+ DAG.addNoMergeSiteInfo(Ret.getNode(), CFlags.NoMerge);
+@@ -15020,6 +15024,20 @@ PPCTargetLowering::EmitInstrWithCustomInserter(MachineInstr &MI,
+ .addReg(Ptr);
+ break;
+ }
++ case PPC::TCRETURNri_GPR:
++ case PPC::TCRETURNri8_GPR: {
++ // Now that ISel is done, move the callee address into CTR and switch to
++ // the regular CTR-based tail call pseudo. Importantly, this happens after
++ // stack protector splitting.
++ bool Is64 = MI.getOpcode() == PPC::TCRETURNri8_GPR;
++ BuildMI(*BB, MI, MI.getDebugLoc(),
++ TII->get(Is64 ? PPC::MTCTR8 : PPC::MTCTR))
++ .add(MI.getOperand(0));
++ MI.setDesc(TII->get(Is64 ? PPC::TCRETURNri8 : PPC::TCRETURNri));
++ MI.getOperand(0).ChangeToRegister(Is64 ? PPC::CTR8 : PPC::CTR,
++ /*isDef=*/false);
++ return BB;
++ }
+ default:
+ llvm_unreachable("Unexpected instr type to insert");
+ }
+diff --git a/llvm/lib/Target/PowerPC/PPCInstr64Bit.td b/llvm/lib/Target/PowerPC/PPCInstr64Bit.td
+index 8544f51f1875..1f8781a5062a 100644
+--- a/llvm/lib/Target/PowerPC/PPCInstr64Bit.td
++++ b/llvm/lib/Target/PowerPC/PPCInstr64Bit.td
+@@ -449,6 +449,13 @@ def TCRETURNri8 : PPCEmitTimePseudo<(outs), (ins CTRRC8:$dst, i32imm:$offset),
+ "#TC_RETURNr8 $dst $offset",
+ []>;
+
++// 64-bit version of TCRETURNri_GPR, expanded into MTCTR8 + TCRETURNri8.
++let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1, Uses = [RM] in
++def TCRETURNri8_GPR : PPCCustomInserterPseudo<(outs),
++ (ins g8rc:$dst, i32imm:$offset),
++ "#TC_RETURNri8_GPR $dst $offset",
++ []>;
++
+ let hasSideEffects = 0 in {
+ let isTerminator = 1, isBarrier = 1, PPC970_Unit = 7, isBranch = 1,
+ isIndirectBranch = 1, isCall = 1, isReturn = 1, Uses = [CTR8, RM] in
+@@ -476,8 +483,8 @@ def : Pat<(PPCtc_return (i64 tglobaladdr:$dst), imm:$imm),
+ def : Pat<(PPCtc_return (i64 texternalsym:$dst), imm:$imm),
+ (TCRETURNdi8 texternalsym:$dst, imm:$imm)>;
+
+-def : Pat<(PPCtc_return CTRRC8:$dst, imm:$imm),
+- (TCRETURNri8 CTRRC8:$dst, imm:$imm)>;
++def : Pat<(PPCtc_return_indirect i64:$dst, imm:$imm),
++ (TCRETURNri8_GPR $dst, imm:$imm)>;
+
+
+ // 64-bit CR instructions
+diff --git a/llvm/lib/Target/PowerPC/PPCInstrInfo.td b/llvm/lib/Target/PowerPC/PPCInstrInfo.td
+index 5f254a5470e5..e0ba7955dcfb 100644
+--- a/llvm/lib/Target/PowerPC/PPCInstrInfo.td
++++ b/llvm/lib/Target/PowerPC/PPCInstrInfo.td
+@@ -590,6 +590,12 @@ def PPCretglue : SDNode<"PPCISD::RET_GLUE", SDTNone,
+ def PPCtc_return : SDNode<"PPCISD::TC_RETURN", SDT_PPCTC_ret,
+ [SDNPHasChain, SDNPOptInGlue, SDNPVariadic]>;
+
++// TC_RETURN_INDIRECT - An indirect tail call return with the callee address in
++// a GPR. Same operands as TC_RETURN. Kept separate so that a constant callee
++// address is not mistaken for an absolute branch target.
++def PPCtc_return_indirect : SDNode<"PPCISD::TC_RETURN_INDIRECT", SDT_PPCTC_ret,
++ [SDNPHasChain, SDNPOptInGlue, SDNPVariadic]>;
++
+ // EH_SJLJ_SETJMP - SjLj exception handling setjmp.
+ def PPCeh_sjlj_setjmp : SDNode<"PPCISD::EH_SJLJ_SETJMP",
+ SDTypeProfile<1, 1, [SDTCisInt<0>,
+@@ -1863,6 +1869,17 @@ def TCRETURNri : PPCEmitTimePseudo<(outs), (ins CTRRC:$dst, i32imm:$offset),
+ "#TC_RETURNr $dst $offset",
+ []>;
+
++// Indirect tail call taking the callee address in a GPR. This is what ISel
++// produces, so that the terminator sequence before the tail call only consists
++// of copies into the argument registers (this matters for stack protectors,
++// which split the block in front of that sequence). The custom inserter
++// expands it into MTCTR + TCRETURNri.
++let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1, Uses = [RM] in
++def TCRETURNri_GPR : PPCCustomInserterPseudo<(outs),
++ (ins gprc:$dst, i32imm:$offset),
++ "#TC_RETURNri_GPR $dst $offset",
++ []>;
++
+ let isCall = 1, PPC970_Unit = 7, isCodeGenOnly = 1,
+ Defs = [LR, R2], Uses = [CTR, RM], RST = 2 in {
+ def BCTRL_LWZinto_toc:
+@@ -3437,8 +3454,8 @@ def : Pat<(PPCtc_return (i32 tglobaladdr:$dst), imm:$imm),
+ def : Pat<(PPCtc_return (i32 texternalsym:$dst), imm:$imm),
+ (TCRETURNdi texternalsym:$dst, imm:$imm)>;
+
+-def : Pat<(PPCtc_return CTRRC:$dst, imm:$imm),
+- (TCRETURNri CTRRC:$dst, imm:$imm)>;
++def : Pat<(PPCtc_return_indirect i32:$dst, imm:$imm),
++ (TCRETURNri_GPR $dst, imm:$imm)>;
+
+ def : Pat<(int_ppc_fence), (FENCE)>;
+ def : Pat<(int_ppc_readflm), (MFFS)>;
+diff --git a/llvm/test/CodeGen/PowerPC/stack-protector-pcrel-indirect-tail-call.ll b/llvm/test/CodeGen/PowerPC/stack-protector-pcrel-indirect-tail-call.ll
+new file mode 100644
+index 000000000000..4b66f2fa9bca
+--- /dev/null
++++ b/llvm/test/CodeGen/PowerPC/stack-protector-pcrel-indirect-tail-call.ll
+@@ -0,0 +1,53 @@
++; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 6
++; RUN: llc -mtriple=powerpc64le-unknown-linux-gnu -mcpu=pwr10 -verify-machineinstrs < %s | FileCheck %s
++
++; When using a PC-relative indirect sibcall, make sure that the stack protector
++; split happens before the argument copies, rather than before the mtctr
++; instruction.
++
++declare void @use(ptr)
++
++define void @indirect_tail_call(ptr %fp, i64 %a, i64 %b, i64 %c) nounwind sspreq {
++; CHECK-LABEL: indirect_tail_call:
++; CHECK: # %bb.0:
++; CHECK-NEXT: mflr 0
++; CHECK-NEXT: std 27, -40(1) # 8-byte Folded Spill
++; CHECK-NEXT: std 28, -32(1) # 8-byte Folded Spill
++; CHECK-NEXT: std 29, -24(1) # 8-byte Folded Spill
++; CHECK-NEXT: std 30, -16(1) # 8-byte Folded Spill
++; CHECK-NEXT: std 0, 16(1)
++; CHECK-NEXT: stdu 1, -96(1)
++; CHECK-NEXT: mr 29, 3
++; CHECK-NEXT: ld 3, -28688(13)
++; CHECK-NEXT: mr 30, 6
++; CHECK-NEXT: mr 28, 5
++; CHECK-NEXT: mr 27, 4
++; CHECK-NEXT: std 3, 48(1)
++; CHECK-NEXT: addi 3, 1, 32
++; CHECK-NEXT: bl use@notoc
++; CHECK-NEXT: ld 3, 48(1)
++; CHECK-NEXT: ld 4, -28688(13)
++; CHECK-NEXT: cmpld 4, 3
++; CHECK-NEXT: bne 0, .LBB0_2
++; CHECK-NEXT: # %bb.1:
++; CHECK-NEXT: mtctr 29
++; CHECK-NEXT: mr 3, 27
++; CHECK-NEXT: mr 4, 28
++; CHECK-NEXT: mr 5, 30
++; CHECK-NEXT: mr 12, 29
++; CHECK-NEXT: addi 1, 1, 96
++; CHECK-NEXT: ld 0, 16(1)
++; CHECK-NEXT: ld 30, -16(1) # 8-byte Folded Reload
++; CHECK-NEXT: mtlr 0
++; CHECK-NEXT: ld 29, -24(1) # 8-byte Folded Reload
++; CHECK-NEXT: ld 28, -32(1) # 8-byte Folded Reload
++; CHECK-NEXT: ld 27, -40(1) # 8-byte Folded Reload
++; CHECK-NEXT: bctr
++; CHECK-NEXT: #TC_RETURNr8 ctr 0
++; CHECK-NEXT: .LBB0_2:
++; CHECK-NEXT: bl __stack_chk_fail@notoc
++ %buf = alloca [16 x i8]
++ call void @use(ptr %buf)
++ tail call void %fp(i64 %a, i64 %b, i64 %c)
++ ret void
++}
+--
+2.56.1
+
diff --git a/llvm.spec b/llvm.spec
index 66f4135..bdbe847 100644
--- a/llvm.spec
+++ b/llvm.spec
@@ -640,6 +640,10 @@ Patch2307: 227851.patch
# Fix bolt rpminspect failure.
Patch2308: 80ef20addc82619c07b6deaec5f9995000b5dd16.patch
+# Backport of https://github.com/llvm/llvm-project/pull/246638.
+Patch2309: 0001-PowerPC-Fix-stack-protector-indirect-tail-call-on-po.patch
+Patch2403: 0001-PowerPC-Fix-stack-protector-indirect-tail-call-on-po.patch
+
%if 0%{?rhel} == 8
%global python3_pkgversion 3.12
%global __python3 /usr/bin/python3.12
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-30 14:33 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-30 14:33 [rpms/llvm] rawhide: Backport fix for -mcpu=power10 Nikita Popov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox