<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Thu, Mar 20, 2014 at 2:37 PM, Tom Roeder <span dir="ltr"><<a href="mailto:tmroeder@google.com" target="_blank">tmroeder@google.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi,<div><br></div><div><div>This patch adds an intrinsic for creating jump-instruction table entries of the form:</div>

<div><br></div><div>  .type f_JT,@function</div><div>  f_JT:</div><div>    jmp f@PLT</div>
<div><br></div><div>It adds an intrinsic void @llvm.jump.instr.table.entry(i8*) and X86 backend support for this intrinsic. The intrinsic takes a bitcast function pointer as input and generates the jump-instruction table entry. Note that while jump tables are supported in CodeGen, they are a different kind of jump table, AFAICT: one that uses indices rather than one that contains jump instructions.</div>


<div><br></div><div>This intrinsic would allow me to remove the inline assembly that I currently use for control-flow integrity (CFI), as discussed on llvmdev; these intrinsics would be generated by the CFI pass along with declarations of the jump-table functions (required because the CFI pass replaces address-taken functions with the address of the _JT function).</div>


<div><br></div><div>I couldn't find any way to do this above the arch-specific Targets, given that it violates the IR branch semantics of jumping to a block; and even so, I had to add a check to one of the X86 optimizations that was assuming that all JMP_4 instructions had a MachineBasicBlock as an operand.</div>


<div><br></div><div>The patch also adds another kind of label, JUMP_FUNCTION_LABEL, which produces a label that looks like the start of a function (with MCSA_Global and sometimes MCSA_ELF_TypeFunction). So, the intrinsic lowers to a JUMP_FUNCTION_LABEL and a JMP_4.</div>


<div><br></div><div>I was able to do much of the work in the target-independent portions of the code, so I don't think it will take much effort to add support to some other architectures (like ARM), and I intend to do that if this patch is acceptable.</div>


<div><br></div><div>One question: what's the right way to do the mangling (the "_JT") for the jump-table functions? For my purposes in CFI, I'd like to have a way of naming these jump entries that a pass at the IR level could also discover or reproduce. Is there a standard mangling facility for specialized suffixes?<br>


</div><div><br></div><div>Please let me know what you think.</div></div><div><br></div><div>Thanks,</div><div><br></div><div>Tom</div></div></blockquote><div><br></div><div>Just realized that there were a few line-length violations that I hadn't cleaned up in the code. Here's a slightly tweaked patch.</div>

<div><br></div><div>Tom </div></div><br></div></div>