[llvm-dev] x86: How to Force 2-byte `jmp` instruction in lowering

Nirav Davé via llvm-dev llvm-dev at lists.llvm.org
Wed Jun 22 06:04:57 PDT 2016


This appears to work:

auto Target = OutContext.createLinkerPrivateTempSymbol();

with

auto Target = OutContext.createTempSymbol();

-Nirav


On Wed, Jun 22, 2016 at 3:10 AM, Dean Michael Berris via llvm-dev <
llvm-dev at lists.llvm.org> wrote:

> I have a bit of a riddle:
>
> In http://reviews.llvm.org/D19904 I'm trying to spell the following
> assembly:
>
>   .palign 2, 0x90
>   jmp +0x9
>   nopw 512(%rax,%rax,1)
>   // rest of the code
>
> I try the following snippet to accomplish this:
>
>   OutStreamer->EmitLabel(CurSled);
>   OutStreamer->EmitCodeAlignment(4);
>   auto Target = OutContext.createLinkerPrivateTempSymbol();
>
>   // Use a two-byte `jmp`. This version of JMP takes an 8-bit relative
> offset as
>   // an operand (computed as an offset from the jmp instruction).
>   OutStreamer->EmitInstruction(
>       MCInstBuilder(X86::JMP_1)
>           .addExpr(MCSymbolRefExpr::create(Target, OutContext)),
>       getSubtargetInfo());
>   EmitNops(*OutStreamer, 9, Subtarget->is64Bit(), getSubtargetInfo());
>   OutStreamer->EmitLabel(Target);
>
> Which turns into:
>
> .Lxray_sled_0:
>   .palign 2, 0x90
>   jmp .Ltmp0
>   nopw 512(%rax,%rax,1)
> .Ltmp0:
>   // rest of the code
>
> Is there a way of forcing the lowered JMP instruction to turn into a
> two-byte jump that does a short relative jump (one that fits within 8
> bits)? When I run the binary and disassemble the function I'm seeing it
> turn into a 5-byte jump (jmpq <32-bit offset>) instead of a 2-byte jump
> (jmp <8-bit offset>).
>
> Thanks in advance!
>
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160622/b12ad6e7/attachment.html>


More information about the llvm-dev mailing list