x86-64: Use UD0/UD2 after indirect jump in PLT entries
Optimize indirect jumps in PLT entries by replacing NOPs with UD0/UD2 instructions.
This patch replaces NOP instructions after indirect jumps in PLT entries with UD0 or UD2 on x86-64. This change aligns with Intel’s optimization manual, aiming to improve performance by preventing the processor from decoding unintended fall-through paths. The changes affect the BFD library’s ELF object file handling and include test suite adjustments.
- proposer
Proposes replacing NOPs with UD0 or UD2 after indirect branches in PLT entries to prevent processor decoding down the fall-through path, based on Intel optimization guidelines.
“Replace NOP with UD0 or UD2 after indirect branch in PLT entries to implement optimization guide from Intel optimization manual: Assembly/Compiler Coding Rule 13. (M impact, L generality) When indirect branches are present, try to put the most likely target of an indirect branch immediately following the indirect branch. Alternatively, if indirect branches are common but they cannot be predicte…”
- reviewer
Acknowledges the proposed change and quotes the relevant part of the commit message, indicating review of the patch.
“Replace NOP with UD0 or UD2 after indirect branch in PLT entries to implement optimization guide from Intel optimization manual: Assembly/Compiler Coding Rule 13. (M impact, L generality) When indirect branches are present, try to put the most likely target of an indirect branch immediately following the indirect branch. Alternatively, if indirect branches are common but they cannot be predicte…”
Technical Tradeoffs
- The change introduces a specific instruction (UD0/UD2) that halts decoding, potentially impacting performance if branch prediction was already effective.
In Details
This patch modifies the generation of Procedure Linkage Table (PLT) entries for indirect jumps on x86-64. It replaces the standard NOP instructions with UD0 or UD2, which are intended to halt instruction decoding. This aims to optimize scenarios where branch prediction is unreliable, as per Intel's guidance.
- PLT
- Procedure Linkage Table. A table used in ELF executables to resolve dynamic library function calls at runtime.
- x86-64
- A 64-bit-based assembly language and related computer architecture.
- UD0/UD2
- Undefined instruction opcodes that can be used to halt instruction decoding or signal an error.
- NOP
- No Operation. An instruction that does nothing.