[llvm] [PowerPC] Handle CALL_RM like CALL for 32-bit ELF (PR #72758)
George Koehler via llvm-commits
llvm-commits at lists.llvm.org
Sat Nov 18 12:28:29 PST 2023
https://github.com/kernigh created https://github.com/llvm/llvm-project/pull/72758
If a function call has the strictfp attribute, its opcode changes from CALL to CALL_RM. If the call uses the secure PLT for 32-bit ELF, then it must getGlobalBaseReg() to set r30.
----
This fixes a bug that I described in (OpenBSD) [macppc clang-16 -ftrapping-math crashes Xorg](https://marc.info/?l=openbsd-tech&m=170028494906642&w=2). The short version is that clang -ftrapping-math broke code like `int main(void) { time(NULL); }` by forgetting to set r30 before using the secure PLT.
>From d497ab3af1b438d1a017bd4d9df9b294853ab66c Mon Sep 17 00:00:00 2001
From: George Koehler <kernigh at gmail.com>
Date: Sat, 18 Nov 2023 14:39:36 -0500
Subject: [PATCH] [PowerPC] Handle CALL_RM like CALL for 32-bit ELF
If a function call has the strictfp attribute, its opcode changes from
CALL to CALL_RM. If the call uses the secure PLT for 32-bit ELF, then
it must getGlobalBaseReg() to set r30.
---
llvm/lib/Target/PowerPC/PPCISelDAGToDAG.cpp | 3 ++-
.../CodeGen/PowerPC/ppc32-secure-plt-rm.ll | 21 +++++++++++++++++++
2 files changed, 23 insertions(+), 1 deletion(-)
create mode 100644 llvm/test/CodeGen/PowerPC/ppc32-secure-plt-rm.ll
diff --git a/llvm/lib/Target/PowerPC/PPCISelDAGToDAG.cpp b/llvm/lib/Target/PowerPC/PPCISelDAGToDAG.cpp
index b57d185bb638b8c..6c7b692e368a0ee 100644
--- a/llvm/lib/Target/PowerPC/PPCISelDAGToDAG.cpp
+++ b/llvm/lib/Target/PowerPC/PPCISelDAGToDAG.cpp
@@ -5475,7 +5475,8 @@ void PPCDAGToDAGISel::Select(SDNode *N) {
// generate secure plt code for TLS symbols.
getGlobalBaseReg();
} break;
- case PPCISD::CALL: {
+ case PPCISD::CALL:
+ case PPCISD::CALL_RM: {
if (PPCLowering->getPointerTy(CurDAG->getDataLayout()) != MVT::i32 ||
!TM.isPositionIndependent() || !Subtarget->isSecurePlt() ||
!Subtarget->isTargetELF())
diff --git a/llvm/test/CodeGen/PowerPC/ppc32-secure-plt-rm.ll b/llvm/test/CodeGen/PowerPC/ppc32-secure-plt-rm.ll
new file mode 100644
index 000000000000000..96008b712e0e98d
--- /dev/null
+++ b/llvm/test/CodeGen/PowerPC/ppc32-secure-plt-rm.ll
@@ -0,0 +1,21 @@
+; RUN: llc < %s -mtriple=powerpc-unknown-linux-gnu -mattr=+secure-plt -relocation-model=pic | FileCheck %s
+
+; This variant of ppc32-pic-large.ll checks that a strictfp call sets
+; r30 for the secure PLT.
+
+declare void @call_foo()
+
+define void @foo() {
+entry:
+ call void @call_foo() #0
+ ret void
+}
+
+attributes #0 = { strictfp }
+
+!llvm.module.flags = !{!0}
+!0 = !{i32 1, !"PIC Level", i32 2}
+
+; CHECK: addis 30, 30, .LTOC-.L0$pb at ha
+; CHECK: addi 30, 30, .LTOC-.L0$pb at l
+; CHECK: bl call_foo at PLT+32768
More information about the llvm-commits
mailing list