Skip to content

Commit 103811a

Browse files
authored
[RISCV,GISel] Unconditionally use MO_PLT for calls (llvm#72355)
All known linkers handle R_RISCV_CALL and R_RISCV_CALL_PLT in the same way (GNU ld since https://sourceware.org/pipermail/binutils/2020-August/112750.html). MO_CALL is for R_RISCV_CALL, a deprecated relocation type. We don't migrate away from MO_CALL yet. For GISel we don't have the output difference concern and should weigh more on simplicity.
1 parent 322799a commit 103811a

File tree

2 files changed

+4
-20
lines changed

2 files changed

+4
-20
lines changed

llvm/lib/Target/RISCV/GISel/RISCVCallLowering.cpp

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -504,24 +504,8 @@ bool RISCVCallLowering::lowerCall(MachineIRBuilder &MIRBuilder,
504504
// TODO: Support tail calls.
505505
Info.IsTailCall = false;
506506

507-
// If the callee is a GlobalAddress or ExternalSymbol and cannot be assumed as
508-
// DSOLocal, then use MO_PLT. Otherwise use MO_CALL.
509-
if (Info.Callee.isGlobal()) {
510-
const GlobalValue *GV = Info.Callee.getGlobal();
511-
unsigned OpFlags = RISCVII::MO_CALL;
512-
if (!getTLI()->getTargetMachine().shouldAssumeDSOLocal(*GV->getParent(),
513-
GV))
514-
OpFlags = RISCVII::MO_PLT;
515-
516-
Info.Callee.setTargetFlags(OpFlags);
517-
} else if (Info.Callee.isSymbol()) {
518-
unsigned OpFlags = RISCVII::MO_CALL;
519-
if (!getTLI()->getTargetMachine().shouldAssumeDSOLocal(
520-
*MF.getFunction().getParent(), nullptr))
521-
OpFlags = RISCVII::MO_PLT;
522-
523-
Info.Callee.setTargetFlags(OpFlags);
524-
}
507+
// Select the recommended relocation type R_RISCV_CALL_PLT.
508+
Info.Callee.setTargetFlags(RISCVII::MO_PLT);
525509

526510
MachineInstrBuilder Call =
527511
MIRBuilder

llvm/test/CodeGen/RISCV/GlobalISel/irtranslator/calls.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,14 +427,14 @@ define void @test_call_local() {
427427
; RV32I-LABEL: name: test_call_local
428428
; RV32I: bb.1.entry:
429429
; RV32I-NEXT: ADJCALLSTACKDOWN 0, 0, implicit-def $x2, implicit $x2
430-
; RV32I-NEXT: PseudoCALL target-flags(riscv-call) @dso_local_function, csr_ilp32_lp64, implicit-def $x1
430+
; RV32I-NEXT: PseudoCALL target-flags(riscv-plt) @dso_local_function, csr_ilp32_lp64, implicit-def $x1
431431
; RV32I-NEXT: ADJCALLSTACKUP 0, 0, implicit-def $x2, implicit $x2
432432
; RV32I-NEXT: PseudoRET
433433
;
434434
; RV64I-LABEL: name: test_call_local
435435
; RV64I: bb.1.entry:
436436
; RV64I-NEXT: ADJCALLSTACKDOWN 0, 0, implicit-def $x2, implicit $x2
437-
; RV64I-NEXT: PseudoCALL target-flags(riscv-call) @dso_local_function, csr_ilp32_lp64, implicit-def $x1
437+
; RV64I-NEXT: PseudoCALL target-flags(riscv-plt) @dso_local_function, csr_ilp32_lp64, implicit-def $x1
438438
; RV64I-NEXT: ADJCALLSTACKUP 0, 0, implicit-def $x2, implicit $x2
439439
; RV64I-NEXT: PseudoRET
440440
entry:

0 commit comments

Comments
 (0)