[llvm] [ARM] support -mlong-calls -fPIC on arm32 #39970 (PR #147313)

via llvm-commits llvm-commits at lists.llvm.org
Sun Jul 13 02:10:34 PDT 2025


================
@@ -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()) {
----------------
jiangxuezhi wrote:

Thank you for the reminder. Considering that XOM is a security feature which prevents the creation of constant pools in executable memory, and referring to this commit: https://github.com/llvm/llvm-project/commit/52a7dd7d7825b269ae569db0e2bcb193c7698666, it makes sense to first check Subtarget->genExecuteOnly() before evaluating isPositionIndependent().
I have updated the code accordingly. Thanks again for your feedback.

https://github.com/llvm/llvm-project/pull/147313


More information about the llvm-commits mailing list