[llvm] [ARM] support -mlong-calls -fPIC on arm32 #39970 (PR #147313)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 12 05:59:34 PDT 2026
================
@@ -2438,19 +2438,33 @@ ARMTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI,
auto PtrVt = getPointerTy(DAG.getDataLayout());
if (Subtarget->genLongCalls()) {
- assert((!isPositionIndependent() || TT.isOSWindows()) &&
- "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.
+ bool isPIC = isPositionIndependent() && !TT.isOSWindows();
+
if (isa<GlobalAddressSDNode>(Callee)) {
if (Subtarget->genExecuteOnly()) {
+ // Execute-only forbids constant pools in .text, so use movw/movt.
+ // Note: execute-only may not support fPIC on ARM; this path is only
+ // reached for non-PIC targets.
if (Subtarget->useMovt())
++NumMovwMovt;
Callee = DAG.getNode(ARMISD::Wrapper, dl, PtrVt,
DAG.getTargetGlobalAddress(GVal, dl, PtrVt));
+ } else if (isPIC) {
+ // PIC without execute-only: use GOT-based addressing.
+ // DSO-local symbols use a plain PC-relative WrapperPIC;
+ // non-DSO-local symbols additionally load the address from the GOT.
+ 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 {
----------------
jxz-hw wrote:
Thanks for your 解释. Yeah,I 同意你的观点 and 我已经增加assert 的error信息提示用户不要使用 -mlong-calls and -fropi 组合选项,可能会生成错误代码。
https://github.com/llvm/llvm-project/pull/147313
More information about the llvm-commits
mailing list