binutils Newspaper
OCTOBER 6, 2026
microblaze — Proposed

microblaze: use md_number_to_chars in md_apply_fix

Refactors MicroBlaze's `md_apply_fix` to use `md_number_to_chars` for more consistent and cleaner relocation handling.

This patch refactors the md_apply_fix function in the MicroBlaze backend to utilize the generic md_number_to_chars function for writing relocation data. This approach is consistent with how other backends like AArch64, MIPS, and SPARC handle relocations. For data relocations, this simplifies the code by removing endianness-specific branches. For instruction relocations, a new macro INST_IMM_OFFSET is introduced to handle the immediate field’s offset within the instruction word, as md_number_to_chars only addresses byte ordering. The change aims to have no functional impact and has been validated by the test suite, showing no unexpected failures on either MicroBlaze endianness.

In Details

This patch replaces manual, open-coded byte writes within MicroBlaze's md_apply_fix (in gas/config/tc-microblaze.c) with calls to md_number_to_chars. This function is the standard BFD way to write numerical values as bytes according to the target's endianness. For data relocations (BFD_RELOC_32, etc.), this removes endianness checks. For instruction relocations, the immediate field's offset within the 32-bit word requires special handling, hence the introduction of INST_IMM_OFFSET. The 64-bit instruction cases are adjusted accordingly. The series' test results show identical outcome…

For Context
md_apply_fix
A BFD function responsible for applying relocation fixups to data or code during the assembly process for a specific target architecture.
md_number_to_chars
A generic BFD utility function that converts a number into a sequence of bytes respecting the target's endianness.
BFD_RELOC_32
A relocation type indicating a 32-bit value needs to be adjusted.
INST_IMM_OFFSET
A MicroBlaze-specific macro defining the byte offset of the immediate field within a 32-bit instruction word.
Relocation
The process of updating symbolic references in object code to their final memory addresses. Relocations are instructions for the linker or dynamic loader on how to modify addresses.
Filed Under: microblazegasrefactoringrelocation