Dean Michael Berris via llvm-dev
2016-Jun-22 07:10 UTC
[llvm-dev] x86: How to Force 2-byte `jmp` instruction in lowering
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>
Nirav Davé via llvm-dev
2016-Jun-22 13:04 UTC
[llvm-dev] x86: How to Force 2-byte `jmp` instruction in lowering
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>
Dean Michael Berris via llvm-dev
2016-Jun-22 16:14 UTC
[llvm-dev] x86: How to Force 2-byte `jmp` instruction in lowering
On Wed, Jun 22, 2016 at 6:05 AM Nirav Davé <niravd at google.com> wrote:> This appears to work: > > auto Target = OutContext.createLinkerPrivateTempSymbol(); > > with > > auto Target = OutContext.createTempSymbol(); > > -Nirav > >Thanks Nirav -- I tried this but I'm still getting a "jmpq <address>" with this incantation when I load and disassemble from gdb. I'm seeing a 5-instruction jump, followed by the nops. If I disassemble with llvm-objdump though I see the following: _Z3foov: 400c10: e9 09 00 00 00 jmp 9 <_Z3foov+0xE> 400c15: 66 0f 1f 84 00 00 02 00 00 nopw 512(%rax,%rax) I'm not sure whether the extra 0's after '0xe9 0x09' are alignment padding (though I was expecing 0x90 to show up if this was an alignment issue). Is there anything else I can try here? Thanks in advance! -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160622/8aa6fd99/attachment.html>
Maybe Matching Threads
- x86: How to Force 2-byte `jmp` instruction in lowering
- x86: How to Force 2-byte `jmp` instruction in lowering
- x86: How to Force 2-byte `jmp` instruction in lowering
- x86: How to Force 2-byte `jmp` instruction in lowering
- XRay: Demo on x86_64/Linux almost done; some questions.