Skip to content

Commit 502c655

Browse files
committed
Merging r352465:
------------------------------------------------------------------------ r352465 | mstorsjo | 2019-01-29 10:36:48 +0100 (Tue, 29 Jan 2019) | 17 lines [COFF, ARM64] Don't put jump table into a separate COFF section for EK_LabelDifference32 Windows ARM64 has PIC relocation model and uses jump table kind EK_LabelDifference32. This produces jump table entry as ".word LBB123 - LJTI1_2" which represents the distance between the block and jump table. A new relocation type (IMAGE_REL_ARM64_REL32) is needed to do the fixup correctly if they are in different COFF section. This change saves the jump table to the same COFF section as the associated code. An ideal fix could be utilizing IMAGE_REL_ARM64_REL32 relocation type. Patch by Tom Tan! Differential Revision: https://reviews.llvm.org/D57277 ------------------------------------------------------------------------ llvm-svn: 355311
1 parent e65cd4e commit 502c655

File tree

3 files changed

+61
-4
lines changed

3 files changed

+61
-4
lines changed

llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -471,9 +471,18 @@ void AArch64AsmPrinter::EmitJumpTableInfo() {
471471
const std::vector<MachineJumpTableEntry> &JT = MJTI->getJumpTables();
472472
if (JT.empty()) return;
473473

474+
const Function &F = MF->getFunction();
474475
const TargetLoweringObjectFile &TLOF = getObjFileLowering();
475-
MCSection *ReadOnlySec = TLOF.getSectionForJumpTable(MF->getFunction(), TM);
476-
OutStreamer->SwitchSection(ReadOnlySec);
476+
bool JTInDiffSection =
477+
!STI->isTargetCOFF() ||
478+
!TLOF.shouldPutJumpTableInFunctionSection(
479+
MJTI->getEntryKind() == MachineJumpTableInfo::EK_LabelDifference32,
480+
F);
481+
if (JTInDiffSection) {
482+
// Drop it in the readonly section.
483+
MCSection *ReadOnlySec = TLOF.getSectionForJumpTable(F, TM);
484+
OutStreamer->SwitchSection(ReadOnlySec);
485+
}
477486

478487
auto AFI = MF->getInfo<AArch64FunctionInfo>();
479488
for (unsigned JTI = 0, e = JT.size(); JTI != e; ++JTI) {

llvm/lib/Target/AArch64/AArch64TargetMachine.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,8 @@ static std::string computeDataLayout(const Triple &TT,
209209

210210
static Reloc::Model getEffectiveRelocModel(const Triple &TT,
211211
Optional<Reloc::Model> RM) {
212-
// AArch64 Darwin is always PIC.
213-
if (TT.isOSDarwin())
212+
// AArch64 Darwin and Windows are always PIC.
213+
if (TT.isOSDarwin() || TT.isOSWindows())
214214
return Reloc::PIC_;
215215
// On ELF platforms the default static relocation model has a smart enough
216216
// linker to cope with referencing external symbols defined in a shared
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
; RUN: llc -o - %s -mtriple=aarch64-windows -aarch64-enable-compress-jump-tables=0 | FileCheck %s
2+
3+
define void @f(i32 %x) {
4+
entry:
5+
switch i32 %x, label %sw.epilog [
6+
i32 0, label %sw.bb
7+
i32 1, label %sw.bb1
8+
i32 2, label %sw.bb2
9+
i32 3, label %sw.bb3
10+
]
11+
12+
sw.bb: ; preds = %entry
13+
tail call void @g(i32 0) #2
14+
br label %sw.epilog
15+
16+
sw.bb1: ; preds = %entry
17+
tail call void @g(i32 1) #2
18+
br label %sw.epilog
19+
20+
sw.bb2: ; preds = %entry
21+
tail call void @g(i32 2) #2
22+
br label %sw.epilog
23+
24+
sw.bb3: ; preds = %entry
25+
tail call void @g(i32 3) #2
26+
br label %sw.epilog
27+
28+
sw.epilog: ; preds = %entry, %sw.bb3, %sw.bb2, %sw.bb1, %sw.bb
29+
tail call void @g(i32 10) #2
30+
ret void
31+
}
32+
33+
declare void @g(i32)
34+
35+
; CHECK: .text
36+
; CHECK: f:
37+
; CHECK: .seh_proc f
38+
; CHECK: b g
39+
; CHECK-NEXT: .p2align 2
40+
; CHECK-NEXT: .LJTI0_0:
41+
; CHECK: .word .LBB0_2-.LJTI0_0
42+
; CHECK: .word .LBB0_3-.LJTI0_0
43+
; CHECK: .word .LBB0_4-.LJTI0_0
44+
; CHECK: .word .LBB0_5-.LJTI0_0
45+
; CHECK: .section .xdata,"dr"
46+
; CHECK: .seh_handlerdata
47+
; CHECK: .text
48+
; CHECK: .seh_endproc

0 commit comments

Comments
 (0)