[llvm] [X86] Disallow immediate address calls when position independent (PR #202370)
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 8 22:58:42 PDT 2026
================
@@ -241,7 +241,7 @@ bool X86Subtarget::isLegalToCallImmediateAddr() const {
// FIXME: I386 PE/COFF supports PC relative calls using IMAGE_REL_I386_REL32
// but WinCOFFObjectWriter::RecordRelocation cannot emit them. Once it does,
// the following check for Win32 should be removed.
- if (Is64Bit || isTargetWin32())
+ if (Is64Bit || isTargetWin32() || isPositionIndependent())
----------------
rui314 wrote:
Not sure I fully understand the question, but my understanding is that this change makes the backend emit something like `mov imm32, %reg; call *%reg` instead of `call imm32` when the callee is an immediate address and the output is position-independent.
My understanding is that is exactly what we want here: on i386, the immediate operand of `call imm32` is a PC-relative displacement from the next instruction, not an absolute address. In PIC/PIE, that's not representable, so we always have to use a register-indirect call instruction.
https://github.com/llvm/llvm-project/pull/202370
More information about the llvm-commits
mailing list