-
Notifications
You must be signed in to change notification settings - Fork 14.4k
[ARM] mlong-calls generate PIC code using GOT #39970 #147313
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2815,13 +2815,20 @@ ARMTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI, | |
auto PtrVt = getPointerTy(DAG.getDataLayout()); | ||
|
||
if (Subtarget->genLongCalls()) { | ||
assert((!isPositionIndependent() || Subtarget->isTargetWindows()) && | ||
"long-calls codegen is not position independent!"); | ||
// Handle a global address or an external symbol. If it's not one of | ||
// those, the target's already in a register, so we don't need to do | ||
// anything extra. | ||
if (isa<GlobalAddressSDNode>(Callee)) { | ||
if (Subtarget->genExecuteOnly()) { | ||
if (isPositionIndependent() && !Subtarget->isTargetWindows() && | ||
!Subtarget->genExecuteOnly()) { | ||
SDValue G = DAG.getTargetGlobalAddress( | ||
GVal, dl, PtrVt, 0, GVal->isDSOLocal() ? 0 : ARMII::MO_GOT); | ||
Callee = DAG.getNode(ARMISD::WrapperPIC, dl, PtrVt, G); | ||
if (!GVal->isDSOLocal()) | ||
Callee = | ||
DAG.getLoad(PtrVt, dl, DAG.getEntryNode(), Callee, | ||
MachinePointerInfo::getGOT(DAG.getMachineFunction())); | ||
} else if (Subtarget->genExecuteOnly()) { | ||
if (Subtarget->useMovt()) | ||
++NumMovwMovt; | ||
Callee = DAG.getNode(ARMISD::Wrapper, dl, PtrVt, | ||
|
@@ -2839,7 +2846,8 @@ ARMTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI, | |
PtrVt, dl, DAG.getEntryNode(), Addr, | ||
MachinePointerInfo::getConstantPool(DAG.getMachineFunction())); | ||
} | ||
} else if (ExternalSymbolSDNode *S=dyn_cast<ExternalSymbolSDNode>(Callee)) { | ||
} else if (ExternalSymbolSDNode *S = | ||
dyn_cast<ExternalSymbolSDNode>(Callee)) { | ||
const char *Sym = S->getSymbol(); | ||
|
||
if (Subtarget->genExecuteOnly()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does the external-symbol codepath work correctly with PIC? (I think you can trigger this with llvm.memset or something like that.) |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5 | ||
; RUN: llc -mtriple=armv7-unknown-linux-gnueabi -relocation-model pic -mattr=+long-calls -o - %s \ | ||
; RUN: | FileCheck %s | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can this be integrated into llvm/test/CodeGen/ARM/subtarget-features-long-calls.ll? |
||
|
||
@msg = private unnamed_addr constant [12 x i8] c"hello world\00", align 1 | ||
|
||
declare i32 @puts(ptr) | ||
|
||
define void @test() { | ||
; CHECK-LABEL: test: | ||
; CHECK: @ %bb.0: @ %entry | ||
; CHECK-NEXT: .save {r11, lr} | ||
; CHECK-NEXT: push {r11, lr} | ||
; CHECK-NEXT: ldr r0, .LCPI0_0 | ||
; CHECK-NEXT: ldr r1, .LCPI0_1 | ||
; CHECK-NEXT: .LPC0_0: | ||
; CHECK-NEXT: add r0, pc, r0 | ||
; CHECK-NEXT: .LPC0_1: | ||
; CHECK-NEXT: ldr r1, [pc, r1] | ||
; CHECK-NEXT: blx r1 | ||
; CHECK-NEXT: pop {r11, pc} | ||
; CHECK-NEXT: .p2align 2 | ||
; CHECK-NEXT: @ %bb.1: | ||
; CHECK-NEXT: .LCPI0_0: | ||
; CHECK-NEXT: .long .Lmsg-(.LPC0_0+8) | ||
; CHECK-NEXT: .LCPI0_1: | ||
; CHECK-NEXT: .Ltmp0: | ||
; CHECK-NEXT: .long puts(GOT_PREL)-(.LPC0_1+8-.Ltmp0) | ||
entry: | ||
%call = call i32 @puts(ptr @msg) | ||
ret void | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the execute-only codepath work correctly with PIC?