[llvm] e5afb8e - [X86] Disallow immediate address calls when position independent (#202370)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 12 21:01:40 PDT 2026
Author: agrieve
Date: 2026-06-13T12:01:35+08:00
New Revision: e5afb8e0982c524ee79436a15fb7270d4b9436f3
URL: https://github.com/llvm/llvm-project/commit/e5afb8e0982c524ee79436a15fb7270d4b9436f3
DIFF: https://github.com/llvm/llvm-project/commit/e5afb8e0982c524ee79436a15fb7270d4b9436f3.diff
LOG: [X86] Disallow immediate address calls when position independent (#202370)
Causes problems with mold linker, and was determined to be a compiler
bug. See:
See https://github.com/rui314/mold/pull/1601#issuecomment-4628653209
Added:
Modified:
llvm/lib/Target/X86/X86Subtarget.cpp
llvm/test/CodeGen/X86/call-imm.ll
Removed:
################################################################################
diff --git a/llvm/lib/Target/X86/X86Subtarget.cpp b/llvm/lib/Target/X86/X86Subtarget.cpp
index 7b8437005a031..ed2da3128b44a 100644
--- a/llvm/lib/Target/X86/X86Subtarget.cpp
+++ b/llvm/lib/Target/X86/X86Subtarget.cpp
@@ -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())
return false;
return isTargetELF() || TM.getRelocationModel() == Reloc::Static;
}
diff --git a/llvm/test/CodeGen/X86/call-imm.ll b/llvm/test/CodeGen/X86/call-imm.ll
index b8f5a0cb9b428..39b61c37480a3 100644
--- a/llvm/test/CodeGen/X86/call-imm.ll
+++ b/llvm/test/CodeGen/X86/call-imm.ll
@@ -1,6 +1,7 @@
; RUN: llc < %s -mtriple=i386-apple-darwin -relocation-model=static | FileCheck -check-prefix X86STA %s
; RUN: llc < %s -mtriple=i386-apple-darwin -relocation-model=pic | FileCheck -check-prefix X86PIC %s
; RUN: llc < %s -mtriple=i386-pc-linux -relocation-model=dynamic-no-pic | FileCheck -check-prefix X86DYN %s
+; RUN: llc < %s -mtriple=i386-pc-linux -relocation-model=pic | FileCheck -check-prefix X86ELFPIC %s
; RUN: llc < %s -mtriple=i386-pc-win32 -relocation-model=static | FileCheck -check-prefix X86WINSTA %s
; Call to immediate is not safe on x86-64 unless we *know* that the
@@ -21,5 +22,6 @@ entry:
; X86STA: {{call.*12345678}}
; X86PIC-NOT: {{call.*12345678}}
; X86DYN: {{call.*12345678}}
+; X86ELFPIC: {{call.*[*]%eax}}
; X86WINSTA: {{call.*[*]%eax}}
; X64: {{call.*[*]%rax}}
More information about the llvm-commits
mailing list