aarch64: mingw: Prevent relocation types from being overwritten
Binutils patch changes how relocation types are handled for aarch64 targets to avoid overwriting and breaking other relocation logic.
This patch series for binutils addresses an issue with relocation types on aarch64 targets using the mingw toolchain. The original approach of setting relocation types to IMAGE_REL_ARM64_ABSOLUTE to bypass certain processing has been found to interfere with other relocation logic. The proposed solution replaces this with a less invasive method of marking the relocation for skipping, aiming to preserve the initial relocation type.
- proposer
Proposes to replace the use of rel->r_type = IMAGE_REL_ARM64_ABSOLUTE with rel->r_vaddr = -1 to avoid impacting other relocation logic.
“However, it impacts another relocation logic, as the initial relocation type is no longer known. To avoid extra processing, rel->r_type = IMAGE_REL_ARM64_ABSOLUTE has been replaced with rel->r_vaddr = -1, and a condition to skip relocation processing has been added to _bfd_coff_generic_relocate_section.”
- reviewer
Expresses reservations about using a specific value like -1 as a flag, questioning if it's strictly excluded by the specification.
“I have to admit that I have reservations against such a(n) (ab)use of a particular value. Yes, -1 may be very unlikely to occur in this field, but is it excluded by the spec?”
- reviewer
Questions the necessity of the change and asks for clarification on what exactly goes wrong with the current code before committing.
“Firstly, is it really necessary? What exactly goes wrong with the current code?”
Technical Tradeoffs
- Using a magic value (-1) for r_vaddr may be fragile if that value becomes valid.
- The change aims to provide a cleaner solution than overwriting relocation types, but requires discussion on its robustness.
In Details
This patch touches coff-aarch64.c and cofflink.c within GNU Binutils. It addresses how linker relocations are processed for the aarch64 Windows (mingw) target. Specifically, it modifies the handling of IMAGE_REL_ARM64_PAGEBASE_REL21 and related logic by using a magic value (-1) in r_vaddr to signal that a relocation should be skipped, avoiding issues caused by the previous method of overwriting r_type.
- Relocation
- A modification applied to code or data by the linker to resolve symbol references. It ensures that addresses and references are correct in the final executable or shared library.
- aarch64
- The 64-bit ARM architecture, commonly used in mobile devices and increasingly in servers and desktops.
- mingw
- Minimalist GNU for Windows, a development environment that provides a Windows port of the GNU Compiler Collection (GCC) and related tools, enabling compilation of native Windows applications.
- IMAGE_REL_ARM64_ABSOLUTE
- A specific relocation type used for the ARM64 architecture in the PE/COFF object file format, indicating an absolute address.
- r_vaddr
- In COFF relocation entries, this field typically stores a virtual address related to the relocation.
- cofflink.c
- A source file within binutils that handles the linking process for COFF (Common Object File Format) binaries.