AArch64 ADD relocation optimization invalid with pending relocations
Reviewer flags that optimizing ADD instructions to MOV/NOP when relocations resolve to zero is invalid if the linker still emits relocations, as it breaks idem…
A reviewer has raised a concern regarding a proposed optimization for AArch64 ADD instructions. The optimization replaces ADD instructions whose immediate value becomes zero after relocation with MOV or NOP instructions. The reviewer argues this is invalid if the linker continues to emit relocations for these instructions, as it breaks idempotency. Further clarification from maintainers is requested on how to check for this condition.
- reviewer
Raises a concern that the proposed optimization for AArch64 `ADD` instructions to `MOV`/`NOP` is invalid if the linker still emits relocations, as it breaks idempotency.
“I think this optimization is invalid if we're still emitting relocations, because it breaks idempotency, so we probably need to add a check for that.”
In Details
A proposed optimization in the AArch64 backend of GNU ld aims to replace ADD instructions where the immediate operand becomes zero after relocation with equivalent MOV or NOP instructions, following an ELF specification recommendation. However, a reviewer points out that this optimization is problematic if the linker still emits relocations for these instructions, as it violates idempotency. The reviewer requests guidance on how to correctly detect and handle this situation, particularly concerning the state of pending relocations.
- AArch64
- The 64-bit instruction set architecture for ARM processors.
- relocation
- A process performed by the linker to adjust symbolic references in object files to their final memory addresses in the executable or shared library.
- ADD instruction
- A processor instruction that performs addition.
- idempotency
- In this context, it refers to the property that applying an operation multiple times has the same effect as applying it once. If an optimization breaks idempotency, repeated linking or processing could lead to incorrect results.
- linker
- A program that combines object files and libraries into an executable or shared library, resolving symbol references and performing relocations.
- ELF
- Executable and Linkable Format, a standard file format for object files, executables, and shared libraries on Unix-like systems.
- MOV instruction
- A processor instruction that moves data from one location to another.
- NOP
- No Operation. A processor instruction that does nothing but consume CPU cycles.