[LLVMdev] building a jump table in LLVM IR

Zonr Chang zonr.xchg at gmail.com
Sun Jan 6 20:06:05 PST 2013


On Fri, Jan 4, 2013 at 2:49 PM, Tom Roeder <tmroeder at google.com> wrote:

> Thanks for the followup.
>
> If I understand the suggestion correctly, this doesn't solve the
> problem of building a jump table to call into other functions, since,
> as you note, indirectbr can only call into blocks in the same
> function. Is the conclusion then that there is no way to do this in
> LLVM IR?


How about creating a new basic block in the current function and placing a
"call" instruction to the desired function call inside it?


> It looks like these kind of restrictions (no branching
> between functions and no instructions outside of functions) are
> designed into the structure of LLVM IR. Is this correct?
>
> Thanks,
>
> Tom
>
> On Thu, Jan 3, 2013 at 6:50 AM, Joshua Cranmer <pidgeot18 at gmail.com>
> wrote:
> > On 1/2/2013 11:05 AM, Tom Roeder wrote:
> >>
> >> Hi,
> >>
> >> I'm currently writing an opt module for fast indirect call checks
> >> using a table of allowed indirect call targets. The code replaces
> >> function pointers with offsets into the table then masks the offset
> >> for the table size and restores the function pointer before the call.
> >> I have some ways of dealing with some kinds of external code that are
> >> sufficient for my use case but not for more general use.
> >>
> >> I'd like to generalize the table to be a table of jump instructions (a
> >> classic jump table) rather than just a table of function pointers,
> >> since this would solve some of my problems for the more general cases.
> >> I know how to do this using inline assembly in LLVM, but this ties the
> >> module to a particular architecture or set of architectures.
> >>
> >> Is there a way to build a table of jump instructions like this in pure
> >> LLVM IR? My limited understanding of LLVM says no, and I haven't been
> >> able to find a way to do this, but I would appreciate any pointers you
> >> can give me.
> >
> >
> > You can use a jump table using indirectbr, although note that this
> > instruction requires you to label all the possible target blocks and that
> > the targets can only be blocks in the same function.
> >
> > --
> > Joshua Cranmer
> > News submodule owner
> > DXR coauthor
> >
> > _______________________________________________
> > LLVM Developers mailing list
> > LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130107/1d097f5b/attachment.html>


More information about the llvm-dev mailing list