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

Dean Michael Berris via llvm-dev llvm-dev at lists.llvm.org
Wed Jun 22 00:10:16 PDT 2016


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!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160622/e14aea1d/attachment.html>


More information about the llvm-dev mailing list