← Back to blog

x86-64 Branches

This is a personal study note — I write these to solidify my own understanding. If you spot anything wrong or have thoughts, feel free to reach out. Layout, formatting, and grammar assisted by Claude.


x86-64 has 4 kinds of branch. Conditional jumps and direct jumps and calls are relative to RIP. Indirect jumps, calls and returns take their target from a register, from memory or from the stack. And since Intel APX there is a 4th: a direct jump to an absolute 64-bit address.

x86-64 branch instruction encodings drawn to byte scale bytes 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 reach CONDITIONAL, RELATIVE je rel8 opcode 74 rel8 2B ±127 B jne rel32 opcode 0F 85 rel32 6B ±2 GiB DIRECT, RELATIVE jmp rel8 opcode EB rel8 2B ±127 B jmp rel32 opcode E9 rel32 5B ±2 GiB call rel32 opcode E8 rel32 5B ±2 GiB INDIRECT, ABSOLUTE jmp rax opcode FF ModRM E0 2B any 64-bit address jmp r11 REX 41 opcode FF ModRM E3 3B any 64-bit address jmp [rip+disp32] opcode FF ModRM 25 disp32 6B any; pointer slot ±2 GiB ret opcode C3 1B any (return address) DIRECT, ABSOLUTE 64-BIT jmpabs imm64 REX2 D5 00 opcode A1 imm64 (absolute target) 11B any 64-bit address movabs + jmp rax REX.W 48 opcode B8 imm64 (absolute target) opcode FF ModRM E0 12B any 64-bit address jmp [rip] + .quad opcode FF ModRM 25 disp32 = 0 00 00 00 00 .quad (absolute target, data) 14B any 64-bit address prefix opcode ModRM immediate / displacement data, not an instruction

Conditional branches

A conditional branch reads the status flags that an earlier instruction, usually cmp or test, left behind, and jumps only if its condition holds. Otherwise execution falls through to the next instruction. There are 16 conditions, laid out below in complementary pairs. The target is always relative to the next instruction: the 8-bit form carries a signed displacement and reaches −128 to +127 bytes, and the 32-bit form reaches ±2 GiB. There is no conditional branch through a register or to an absolute address.

The x86-64 conditional branches: 16 condition codes in complementary pairs, and the RCX-based branches overflow 0 JO OF = 1 70 rel8 0F 80 rel32 1 JNO OF = 0 71 rel8 0F 81 rel32 ¬ unsigned below 2 JB / JC / JNAE CF = 1 72 rel8 0F 82 rel32 3 JAE / JNB / JNC CF = 0 73 rel8 0F 83 rel32 ¬ equal 4 JE / JZ ZF = 1 74 rel8 0F 84 rel32 5 JNE / JNZ ZF = 0 75 rel8 0F 85 rel32 ¬ unsigned below or equal 6 JBE / JNA CF = 1 or ZF = 1 76 rel8 0F 86 rel32 7 JA / JNBE CF = 0 and ZF = 0 77 rel8 0F 87 rel32 ¬ sign 8 JS SF = 1 78 rel8 0F 88 rel32 9 JNS SF = 0 79 rel8 0F 89 rel32 ¬ parity A JP / JPE PF = 1 7A rel8 0F 8A rel32 B JNP / JPO PF = 0 7B rel8 0F 8B rel32 ¬ signed less C JL / JNGE SF ≠ OF 7C rel8 0F 8C rel32 D JGE / JNL SF = OF 7D rel8 0F 8D rel32 ¬ signed less or equal E JLE / JNG ZF = 1 or SF ≠ OF 7E rel8 0F 8E rel32 F JG / JNLE ZF = 0 and SF = OF 7F rel8 0F 8F rel32 ¬ Branches on RCX, short form only JRCXZ RCX = 0 E3 rel8 2B JECXZ ECX = 0 67 E3 rel8 3B LOOP RCX -= 1; RCX ≠ 0 E2 rel8 2B LOOPE RCX -= 1; RCX ≠ 0 and ZF = 1 E1 rel8 2B LOOPNE RCX -= 1; RCX ≠ 0 and ZF = 0 E0 rel8 2B

Direct relative JMP and CALL

A direct jump carries a displacement, not an address. The CPU adds it to the address of the next instruction and continues from there. jmp comes in the same two sizes as the conditional branches, an 8-bit and a 32-bit displacement. call has only the 32-bit form, and it does one more thing before jumping: it pushes the address of the instruction after the call, 8 bytes, onto the stack, so that ret can come back to it. With a 32-bit displacement the farthest a direct branch can reach is ±2 GiB from where it sits. Before APX there was no direct form of any kind, relative or absolute, that could name a 64-bit target.

Indirect JMP, CALL and RET

Indirect branches are my favourite, because they touch so much: addressing modes, disassembly, branch prediction and security. An indirect jmp or call takes its target from a register, or from memory through any x86 addressing mode. Three memory forms account for almost all real code: a switch compiles to a jump through a table, jmp [table + rax*8]; a call into a shared library goes through the PLT, jmp [rip + disp32], where the slot holds the address the loader filled in; and a virtual call loads its target from a vtable, call [rax + 0x10]. The reach is any canonical 64-bit address, and before APX this was the only way to branch beyond ±2 GiB, at the cost of a register or a memory load.

Code and stack before and after CALL, RET, and the PUSH plus RET idiom call, then ret BEFORE CALL CODE 0x401000 call 0x402000 RIP 0x401005 (next in caller) 0x402000 (callee) STACK 0x7fffffd0 caller data RSP 0x7fffffc8 0x7fffffc0 call AFTER CALL CODE 0x401000 call 0x402000 0x401005 (next in caller) 0x402000 (callee) RIP STACK 0x7fffffd0 caller data 0x7fffffc8 0x401005 RSP 0x7fffffc0 RSP -= 8; the address of the next instruction is pushed. ret AFTER RET CODE 0x401000 call 0x402000 0x401005 (next in caller) RIP 0x402000 (callee) STACK 0x7fffffd0 caller data RSP 0x7fffffc8 0x401005 0x7fffffc0 RIP = pop(); RSP += 8. The old slot is left behind, below RSP. push, then ret: the same ret, but the slot was written by push BEFORE PUSH CODE 0x401000 push 0x402000 RIP 0x401005 ret 0x402000 (target) STACK 0x7fffffd0 caller data RSP 0x7fffffc8 0x7fffffc0 push AFTER PUSH CODE 0x401000 push 0x402000 0x401005 ret RIP 0x402000 (target) STACK 0x7fffffd0 caller data 0x7fffffc8 0x402000 RSP 0x7fffffc0 RSP -= 8; imm32 is sign-extended to 64 bits and stored. ret AFTER RET CODE 0x401000 push 0x402000 0x401005 ret 0x402000 (target) RIP STACK 0x7fffffd0 caller data RSP 0x7fffffc8 0x402000 0x7fffffc0 Control lands at the pushed value. No call ever happened.
What CALL and RET do to RIP and the stack in 64-bit mode, and the PUSH plus RET idiom that reuses RET as a jump. Addresses are made up; the return address is 8 bytes.

Whatever the operand, a static disassembler faces the same problem: it cannot know where the branch goes without running the program. Decades of work have attacked this, from value-set analysis [1] to the heuristics every production disassembler relies on [2]; they work well on compiler-generated binaries [3], but they remain heuristics, and no one can promise the recovered control-flow graph is complete. The one approach that needs no guess is superset disassembly [4]: decode an instruction at every byte offset, keep them all, and let the real targets fall out at run time.

Indirect branches are also the expensive ones, but not because a miss costs more. The CPU never waits for a branch to resolve; it predicts the outcome and keeps fetching, and if the prediction is wrong it throws the work away. Intel puts that penalty at about 20 cycles, for any kind of branch [5]. The difference is how often each kind misses. A direct jump has one target and nothing to predict. A conditional branch has two outcomes, and history-based prediction gets those right nearly all the time. An indirect branch can go anywhere, and the predictor's main tool is the last target it saw [5], so a switch that keeps landing on different cases, or a virtual call that keeps resolving to different classes, misses again and again.

Indirect branches are also where the security trouble is. Spectre v2, formally Branch Target Injection [6], mistrains the indirect predictor so the CPU speculatively runs code the program never meant to reach, and a hijacked function pointer does the same thing architecturally. Intel's answer to the second is CET Indirect Branch Tracking [7]: with it enabled, the instruction an indirect jmp or call lands on must be endbr64, so every valid target carries a 4-byte marker and landing anywhere else raises a control-protection fault. The marker is a NOP on older processors, so the same binary runs everywhere, and compilers emit it at every function entry under -fcf-protection. Jump tables, which the compiler already bounds-checks, opt out with the notrack prefix.

JMPABS

JMPABS is a new instruction from APX, Intel's Advanced Performance Extensions. APX has been under construction since the spec appeared in 2023, compilers have supported it for two years, and as I write this no processor that runs it has shipped: the first, Nova Lake and Diamond Rapids, are now expected in 2027.

The instruction itself is 11 bytes: a two-byte REX2 prefix D5 00, the opcode A1, and the 8-byte target. There is no ModRM byte and no displacement. REX2 is the prefix APX introduced to reach its new registers. It is D5 followed by a payload byte that carries the old REX bits plus a fifth bit for each register field, and a bit that selects the opcode map, replacing the 0F escape byte that two-byte opcodes such as jne rel32 need.

Before JMPABS, a jump to an arbitrary 64-bit address took two instructions. movabs rax, imm64 followed by jmp rax is 12 bytes and clobbers a register. jmp [rip] followed by an 8-byte literal is 14 bytes, costs a load, and leaves data in the instruction stream. JMPABS is shorter than either, touches no register, loads nothing, and is a direct branch, so the processor predicts it like any other direct jump.

The spec does not include the motivation for JMPABS. From what I can find, people use it to optimise the PLT and JIT-compiled code.

The PLT case comes from an Intel engineer's Linux perf patch [8]: "JMPABS is designed to be used in the procedure linkage table (PLT) to replace indirect jumps, because it has better performance. In that case the jump target will be amended at run time." Today a call into a shared library goes through a stub that jumps through a pointer the dynamic loader fills in:

foo@plt:
    jmp    qword ptr [rip + GOT.foo]   ; FF 25 disp32, 6 bytes, indirect

With JMPABS the loader writes the resolved address into the instruction itself, and the stub becomes a direct branch:

foo@plt:
    jmpabs 0x7f3a1c2e5f10              ; D5 00 A1 imm64, 11 bytes, direct

The JIT case comes from the .NET runtime, which merged JMPABS into its virtual call stubs in 2026 [9]. The stubs used the two-instruction idiom:

    mov    rax, 0x7ff6b2c01230         ; 48 B8 imm64, 10 bytes
    jmp    rax                         ; FF E0, 2 bytes

and now use one instruction, padded to keep the stub its old size:

    jmpabs 0x7ff6b2c01230              ; 11 bytes
    nop                                ; 1 byte

So the gain in the JIT case is one instruction and a free register, not bytes. The PLT use is not hypothetical: glibc has shipped it since 2.39, in January 2024, as an opt-in "PLT rewrite" that turns each entry into a jmp rel32 when the library is within reach and, on an APX processor, into a jmpabs when it is not [10]. None of the three has published a measurement, and Intel has not either.

What I have not fully understood is this. A direct branch is safer than an indirect one: the target lives in read-only code rather than in a writable slot, and it never touches the indirect predictor that Spectre v2 poisons. But JMPABS seems to reopen the thing the GOT was invented to avoid. That may not be a concern for a JIT, but it is for a compiled binary.

glibc made the write happen once and briefly. The rewrite runs only with lazy binding off, so every target is known at startup. The linker records where each PLT jump sits, so the loader need not disassemble. The loader makes the PLT writable with mprotect, patches it, and sets it back to read-and-execute [10]. From then on nothing on the PLT path is writable. But that was already true: the rewrite requires the configuration in which the GOT is read-only, so it removes no writable target. LWN presented the feature as a security measure [11]; on the glibc list nobody did. The worry there was the opposite, that hardened systems would refuse the write, and a bug report proved it within days. The feature is off by default. The commit says why: "SELinux may disallow modifying code pages and ld.so can't detect it in all cases." Hardened systems forbid a process from ever making code writable, even for a moment.

The table below puts the three configurations side by side. The middle column is what the rewrite requires anyway, so it is the one to compare against.

Lazy binding (default)Bind now with full RELROglibc PLT rewrite
Addresses resolvedOn first call to each functionAll at loadAll at load
Written at runtimeGOT slot on first call (data)GOT slots at load (data)GOT slots, then PLT stubs, at load (code)
Page permission changeNoneGOT writable → read-only, onceGOT writable → read-only, once; PLT executable → writable → executable, once
PLT stub per calljmp *GOT[n]jmp *GOT[n]jmp rel32, or jmpabs beyond 2GiB
Per-call costGOT load, indirect branchGOT load, indirect branchOne direct branch
Writable target after startupGOT, for the whole runNoneNone
Allowed under W^X, SELinuxYesYesNo, so off by default
NeedsNothing-z now -z relro-z now -z relro -z mark-plt, glibc.cpu.plt_rewrite=2, APX for jmpabs

Another question is whether there is any gain at all. The rewritten entry saves the load of the pointer from the GOT and turns an indirect branch into a direct one. Whether that is worth the trouble is something we will only learn once a processor is out.

References

[1] Value-set analysis, the classic static analysis for recovering the values a register or memory cell can hold in a binary, including indirect branch targets: Gogul Balakrishnan and Thomas Reps, Analyzing Memory Accesses in x86 Executables, Compiler Construction (CC) 2004, LNCS 2985, pp. 5–23.

[2] A systematisation of nine open-source disassemblers on 3,788 binaries, separating the principled algorithms from the heuristics each tool relies on for coverage: Chengbin Pang, Ruotong Yu, Yaohui Chen, Eric Koskinen, Georgios Portokalidis, Bing Mao and Jun Xu, SoK: All You Ever Wanted to Know About x86/x64 Binary Disassembly But Were Afraid to Ask, IEEE Symposium on Security and Privacy 2021, pp. 833–851.

[3] An evaluation of nine disassemblers on 981 compiler-generated binaries, finding the hard cases rarer in practice than the literature suggested: Dennis Andriesse, Xi Chen, Victor van der Veen, Asia Slowinska and Herbert Bos, An In-Depth Analysis of Disassembly on Full-Scale x86/x64 Binaries, USENIX Security 2016, pp. 583–600.

[4] Superset disassembly, which decodes at every byte offset and so never has to guess where code begins: Erick Bauman, Zhiqiang Lin and Kevin W. Hamlen, Superset Disassembly: Statically Rewriting x86 Binaries Without Heuristics, NDSS 2018.

[5] The misprediction penalty ("about 20 cycles", section 22.5.6.1) and how indirect branches are predicted ("the previously executed branch target", section 3.4.1.5): Intel® 64 and IA-32 Architectures Optimization Reference Manual, Volume 1, document 248966-051, October 2026.

[6] The paper that introduced Spectre; variant 2, branch target injection, is tracked as CVE-2017-5715: Paul Kocher, Jann Horn, Anders Fogh, Daniel Genkin, Daniel Gruss, Werner Haas, Mike Hamburg, Moritz Lipp, Stefan Mangard, Thomas Prescher, Michael Schwarz and Yuval Yarom, Spectre Attacks: Exploiting Speculative Execution, IEEE Symposium on Security and Privacy 2019.

[7] Control-flow Enforcement Technology, including indirect branch tracking, ENDBR64 (F3 0F 1E FA, CPUID flag CET_IBT) and the NOTRACK prefix: Intel® 64 and IA-32 Architectures Software Developer's Manual, Volume 1, the chapter on Control-flow Enforcement Technology, and Volume 2, the ENDBR64 instruction page.

[8] The patch that taught the Linux perf Intel PT decoder about JMPABS, with the only statement of its intended use I could find: Adrian Hunter, perf intel pt: Add new JMPABS instruction to the Intel PT instruction decoder, Linux kernel mailing list, May 2024.

[9] The .NET runtime change that uses JMPABS in virtual call stubs, including the byte-for-byte comparison with the mov plus jmp sequence: dotnet/runtime pull request 131826, "[APX] Add Jmpabs support", merged October 2026.

[10] The glibc commit that added PLT rewrite for x86-64, with the tunable, the lazy-binding condition, the mprotect sequence and the choice between jmp rel32 and JMPABS: H.J. Lu, elf: Add ELF_DYNAMIC_AFTER_RELOC to rewrite PLT, glibc commit 848746e8, January 2024, released in glibc 2.39.

[11] LWN's coverage of the glibc 2.39 release, which presents PLT rewrite as a security feature: Daroc Alden, GNU C Library version 2.39, LWN.net, February 2024.