Skip to content

Commit 5e0be96

Browse files
authored
[PowerPC] Support PIC Secure PLT for CALL_RM
https://reviews.llvm.org/D111433 introduced PPCISD::CALL_RM for -frounding-math. -msecure-plt -frounding-math {-fpic,-fPIC} codegen for PPC32 became incorrect when a function contains function calls but no global variable references (GlobalBaseReg). As reported by @q66 , musl/src/dirent/closedir.c implements such a function, which is miscompiled. PPCISD::CALL has custom logic to set up the base register (https://reviews.llvm.org/D42112). Add an extra case for CALL_RM. While here, improve the test to * actually test `case PPCISD::CALL`: we need a non-leaf function that doesn't access global variables (global variables lead to GlobalBaseReg, which call `getGlobalBaseReg()` as well). * test `ExternalSymbolSDNode` with a memset. Supersedes: #72758 Pull Request: #121281
1 parent d00f65c commit 5e0be96

File tree

2 files changed

+49
-6
lines changed

2 files changed

+49
-6
lines changed

llvm/lib/Target/PowerPC/PPCISelDAGToDAG.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5473,10 +5473,10 @@ void PPCDAGToDAGISel::Select(SDNode *N) {
54735473
// generate secure plt code for TLS symbols.
54745474
getGlobalBaseReg();
54755475
} break;
5476-
case PPCISD::CALL: {
5477-
if (PPCLowering->getPointerTy(CurDAG->getDataLayout()) != MVT::i32 ||
5478-
!TM.isPositionIndependent() || !Subtarget->isSecurePlt() ||
5479-
!Subtarget->isTargetELF())
5476+
case PPCISD::CALL:
5477+
case PPCISD::CALL_RM: {
5478+
if (Subtarget->isPPC64() || !TM.isPositionIndependent() ||
5479+
!Subtarget->isSecurePlt() || !Subtarget->isTargetELF())
54805480
break;
54815481

54825482
SDValue Op = N->getOperand(1);
@@ -5489,8 +5489,7 @@ void PPCDAGToDAGISel::Select(SDNode *N) {
54895489
if (ES->getTargetFlags() == PPCII::MO_PLT)
54905490
getGlobalBaseReg();
54915491
}
5492-
}
5493-
break;
5492+
} break;
54945493

54955494
case PPCISD::GlobalBaseReg:
54965495
ReplaceNode(N, getGlobalBaseReg());

llvm/test/CodeGen/PowerPC/ppc32-pic-large.ll

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ $bar1 = comdat any
1313
@bar2 = global i32 0, align 4, comdat($bar1)
1414

1515
declare i32 @call_foo(i32, ...)
16+
declare i32 @call_strictfp() strictfp
17+
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg)
1618

1719
define i32 @foo() {
1820
entry:
@@ -21,6 +23,23 @@ entry:
2123
ret i32 %0
2224
}
2325

26+
define i32 @foo1() strictfp {
27+
entry:
28+
%call = call i32 (i32, ...) @call_foo(i32 0)
29+
ret i32 %call
30+
}
31+
32+
define i32 @foo1_strictfp() strictfp {
33+
entry:
34+
%call = call i32 () @call_strictfp()
35+
ret i32 %call
36+
}
37+
38+
define void @foo2(ptr %a) {
39+
call void @llvm.memset.p0.i64(ptr align 1 %a, i8 1, i64 1000, i1 false)
40+
ret void
41+
}
42+
2443
define i32 @load() {
2544
entry:
2645
%0 = load i32, ptr @bar1
@@ -49,6 +68,31 @@ entry:
4968
; LARGE-SECUREPLT: addi 30, 30, .LTOC-.L0$pb@l
5069
; LARGE-SECUREPLT: bl call_foo@PLT+32768
5170

71+
; LARGE-SECUREPLT-LABEL: foo1:
72+
; LARGE-SECUREPLT: .L1$pb:
73+
; LARGE-SECUREPLT-NEXT: crxor 6, 6, 6
74+
; LARGE-SECUREPLT-NEXT: mflr 30
75+
; LARGE-SECUREPLT-NEXT: addis 30, 30, .LTOC-.L1$pb@ha
76+
; LARGE-SECUREPLT-NEXT: addi 30, 30, .LTOC-.L1$pb@l
77+
; LARGE-SECUREPLT-NEXT: li 3, 0
78+
; LARGE-SECUREPLT-NEXT: bl call_foo@PLT+32768
79+
80+
; LARGE-SECUREPLT-LABEL: foo1_strictfp:
81+
; LARGE-SECUREPLT: .L2$pb:
82+
; LARGE-SECUREPLT-NEXT: mflr 30
83+
; LARGE-SECUREPLT-NEXT: addis 30, 30, .LTOC-.L2$pb@ha
84+
; LARGE-SECUREPLT-NEXT: addi 30, 30, .LTOC-.L2$pb@l
85+
; LARGE-SECUREPLT-NEXT: bl call_strictfp@PLT+32768
86+
87+
; LARGE-SECUREPLT-LABEL: foo2:
88+
; LARGE-SECUREPLT: .L3$pb:
89+
; LARGE-SECUREPLT: mflr 30
90+
; LARGE-SECUREPLT-NEXT: addis 30, 30, .LTOC-.L3$pb@ha
91+
; LARGE-SECUREPLT-NEXT: addi 30, 30, .LTOC-.L3$pb@l
92+
; LARGE-SECUREPLT: bl memset@PLT+32768
93+
94+
; LARGE-SECUREPLT-LABEEL: load:
95+
5296
; LARGE: .section .bss.bar1,"awG",@nobits,bar1,comdat
5397
; LARGE: bar1:
5498
; LARGE: .section .bss.bar2,"awG",@nobits,bar1,comdat

0 commit comments

Comments
 (0)