Skip to content

Commit 300c41c

Browse files
authored
[X86] Use 32-bit jump table entries on Windows (llvm#95962)
Windows doesn't support relative 64-bit relocations. Fixes llvm#95622
1 parent fad2ad7 commit 300c41c

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

llvm/lib/Target/X86/X86ISelLoweringCall.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,8 @@ unsigned X86TargetLowering::getJumpTableEncoding() const {
417417
if (isPositionIndependent() && Subtarget.isPICStyleGOT())
418418
return MachineJumpTableInfo::EK_Custom32;
419419
if (isPositionIndependent() &&
420-
getTargetMachine().getCodeModel() == CodeModel::Large)
420+
getTargetMachine().getCodeModel() == CodeModel::Large &&
421+
!Subtarget.isTargetCOFF())
421422
return MachineJumpTableInfo::EK_LabelDifference64;
422423

423424
// Otherwise, use the normal jump table encoding heuristics.

llvm/test/CodeGen/X86/win64-jumptable.ll

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
; RUN: llc < %s -relocation-model static | FileCheck %s
1+
; RUN: llc < %s -relocation-model=static | FileCheck %s
2+
; RUN: llc < %s -relocation-model=pic | FileCheck %s --check-prefix=PIC
3+
; RUN: llc < %s -relocation-model=pic -code-model=large | FileCheck %s --check-prefix=PIC
24

3-
; FIXME: Remove '-relocation-model static' when it is no longer necessary to
5+
; FIXME: Remove '-relocation-model=static' when it is no longer necessary to
46
; trigger the separate .rdata section.
57

68
target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
@@ -57,3 +59,9 @@ declare void @g(i32)
5759
; It's important that we switch back to .text here, not .rdata.
5860
; CHECK: .text
5961
; CHECK: .seh_endproc
62+
63+
; Windows PIC code should use 32-bit entries
64+
; PIC: .long .LBB0_2-.LJTI0_0
65+
; PIC: .long .LBB0_3-.LJTI0_0
66+
; PIC: .long .LBB0_4-.LJTI0_0
67+
; PIC: .long .LBB0_5-.LJTI0_0

0 commit comments

Comments
 (0)