<html>
<head>
<base href="https://llvm.org/bugs/" />
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW --- - Win64 jump tables should not be executable and should not break SEH unwind info"
href="https://llvm.org/bugs/show_bug.cgi?id=31488">31488</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Win64 jump tables should not be executable and should not break SEH unwind info
</td>
</tr>
<tr>
<th>Product</th>
<td>libraries
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Windows NT
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>Backend: X86
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>rnk@google.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>r290569 switched Win64 from the PIC to static relocation model. This uncovered
some questionable jump table codegen for COFF objects.
The following LLVM IR switch generates a jump table:
target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-pc-windows-msvc19.0.24215"
define void @f(i32 %x) {
entry:
switch i32 %x, label %sw.epilog [
i32 0, label %sw.bb
i32 1, label %sw.bb1
i32 2, label %sw.bb2
i32 3, label %sw.bb3
]
sw.bb: ; preds = %entry
tail call void @g(i32 0) #2
br label %sw.epilog
sw.bb1: ; preds = %entry
tail call void @g(i32 1) #2
br label %sw.epilog
sw.bb2: ; preds = %entry
tail call void @g(i32 2) #2
br label %sw.epilog
sw.bb3: ; preds = %entry
tail call void @g(i32 3) #2
br label %sw.epilog
sw.epilog: ; preds = %entry, %sw.bb3,
%sw.bb2, %sw.bb1, %sw.bb
tail call void @g(i32 10) #2
ret void
}
declare void @g(i32)
Compiling twice with llc -relocation-model pic and -relocation-model static
produces these differing assemblies:
$ diff -u static.s pic.s
--- static.s 2016-12-28 09:44:15.132872900 -0800
+++ pic.s 2016-12-28 09:44:19.827504200 -0800
@@ -18,7 +18,10 @@
ja .LBB0_7
# BB#1: # %entry
movl %ecx, %eax
- jmpq *.LJTI0_0(,%rax,8)
+ leaq .LJTI0_0(%rip), %rcx
+ movslq (%rcx,%rax,4), %rax
+ addq %rcx, %rax
+ jmpq *%rax
.LBB0_2: # %sw.bb
xorl %ecx, %ecx
jmp .LBB0_6
@@ -36,15 +39,14 @@
movl $10, %ecx
addq $40, %rsp
jmp g # TAILCALL
- .section .rdata,"dr"
- .p2align 3
+ .p2align 2, 0x90
.LJTI0_0:
- .quad .LBB0_2
- .quad .LBB0_3
- .quad .LBB0_4
- .quad .LBB0_5
+ .long .LBB0_2-.LJTI0_0
+ .long .LBB0_3-.LJTI0_0
+ .long .LBB0_4-.LJTI0_0
+ .long .LBB0_5-.LJTI0_0
.seh_handlerdata
- .section .rdata,"dr"
+ .text
.Lcfi3:
.seh_endproc
Problem one is that .seh_endproc needs to occur in the same section as
.seh_proc, and the .rdata switch breaks that.
Problem two is that in today's PIC model, this jump table is unnecessarily in
the .text section. MSVC also does this, FWIW, but we can definitely put this
jump table in a separate COMDAT-associative .rdata section.
We definitely *don't* want the .quad codegen, since that will produce runtime
relocations and waste space. This leaves two choices: image relative
relocations, or '.LBBN_M - .Lfunc_beginN', which can be fixed up by the
assembler. MSVC uses image relative relocations, which I suppose are nice if
you have some kind of post-link tool, but the fixups seem nicer from an object
size perspective.</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>