[PATCH v2] microblaze: add BFD_RELOC_8 and BFD_RELOC_16 cases

Michael Eager eager@eagerm.com
Tue Sep 22 16:59:09 GMT 2026


On 9/21/26 6:29 PM, Sam Price wrote:
> From: Samuel Price <thesamprice@gmail.com>
> 
> md_apply_fix has cases for BFD_RELOC_32, BFD_RELOC_64 and for the
> MicroBlaze-specific relocations, but none for BFD_RELOC_8 or BFD_RELOC_16.
> Those fall through to the default and nothing is written, so a byte or
> halfword datum whose value is only known at fixup time assembles to zero.
> The fixup is then resolved and turned into BFD_RELOC_NONE, so no relocation
> survives for the linker to correct it either, and the zero is permanent.
> 
> The two new cases replicate the BFD_RELOC_32 case immediately below them in
> the same switch -- the same S_IS_DEFINED guard and the same target_big_endian
> byte order -- narrowed to one and two bytes.
> 
> Fixes gas/all/simple-forward.  It also fixes gas/all/forward, which was
> xfailed for microblaze-*-*, so drop it from that xfail list.  The gas
> testsuite on microblaze-elf goes from 327 passes and 1 unexpected failure to
> 329 passes and 0 failures.
> 
> gas/
> 	* config/tc-microblaze.c (md_apply_fix): Handle BFD_RELOC_8 and
> 	BFD_RELOC_16.
> 	* testsuite/gas/all/forward.d: Remove the microblaze-*-* xfail.
> 
> Signed-off-by: Sam Price <thesamprice@gmail.com>
> Reviewed-by: Neal Frager <neal.frager@amd.com>
> Assisted-by: Claude (Anthropic)
> ---
> 
> Changes since v1:
> 
>    - forward.d: also update the comment above the #xfail line, which still
>      read "mep and microblaze use complex relocs and don't resolve the
>      relocs" after microblaze was dropped from the xfail list.  Caught by
>      Neal Frager.  Reworded for the now-single target: "mep uses ...
>      doesn't".
> 
> No change to gas/config/tc-microblaze.c.  The testsuite result is unchanged
> and was re-measured on f621e384d9c with the new comment in place: 327 passes
> and 1 unexpected failure -> 329 passes and 0, no unexpected successes.  The
> comment is inert to DejaGnu.
> 
> v1: https://inbox.sourceware.org/binutils/20260920235724.37190-1-thesamprice@gmail.com/
> 
> I considered writing the two new cases the way aarch64 and mips do instead --
> 
>    case BFD_RELOC_16:
>    case BFD_RELOC_8:
>      if (fixP->fx_done)
>        md_number_to_chars (buf, *valP, fixP->fx_size);
>      break;
> 
> -- which is shorter, drops the endianness branch, and guards on fx_done
> rather than S_IS_DEFINED, which is arguably what is really meant here.  The
> comment on that case in tc-mips.c describes this exact failure mode: "If we
> are deleting this reloc entry, we must fill in the value now."
> 
> I kept the local form so the patch stays minimal and consistent with its
> neighbour, but I am happy to send the md_number_to_chars version instead if
> you would rather have it.  Or if you want the neighbors converted to
> aarch64 / mips and tested I can do that also.

I think that using md_number_to_chars() like aarch64, mips, sparc, 
others is better.

Cleaning up the similar code for BFD_RELOC_MICROBLAZE_... would also be 
a good thing.

> 
>   gas/config/tc-microblaze.c      | 23 +++++++++++++++++++++++
>   gas/testsuite/gas/all/forward.d |  4 ++--
>   2 files changed, 25 insertions(+), 2 deletions(-)
> 
> diff --git a/gas/config/tc-microblaze.c b/gas/config/tc-microblaze.c
> index 3e3dca81921..36b98bbd8fc 100644
> --- a/gas/config/tc-microblaze.c
> +++ b/gas/config/tc-microblaze.c
> @@ -2145,6 +2145,29 @@ md_apply_fix (fixS *   fixP,
>   	    }
>   	}
>         break;
> +    case BFD_RELOC_8:
> +      /* Don't do anything if the symbol is not defined.  */
> +      if (fixP->fx_addsy == NULL || S_IS_DEFINED (fixP->fx_addsy))
> +	buf[0] |= (val & 0xff);
> +      break;
> +
> +    case BFD_RELOC_16:
> +      /* Don't do anything if the symbol is not defined.  */
> +      if (fixP->fx_addsy == NULL || S_IS_DEFINED (fixP->fx_addsy))
> +	{
> +	  if (target_big_endian)
> +	    {
> +	      buf[0] |= ((val >> 8) & 0xff);
> +	      buf[1] |= (val & 0xff);
> +	    }
> +	  else
> +	    {
> +	      buf[1] |= ((val >> 8) & 0xff);
> +	      buf[0] |= (val & 0xff);
> +	    }
> +	}
> +      break;
> +
>       case BFD_RELOC_32:
>       case BFD_RELOC_RVA:
>       case BFD_RELOC_32_PCREL:
> diff --git a/gas/testsuite/gas/all/forward.d b/gas/testsuite/gas/all/forward.d
> index d921ec517be..39f7b2941e8 100644
> --- a/gas/testsuite/gas/all/forward.d
> +++ b/gas/testsuite/gas/all/forward.d
> @@ -8,10 +8,10 @@
>   # choose to emit them even though the relocs are in .data, leading to
>   # "redefined symbol cannot be used on reloc".
>   #xfail: am33*-*-* crx*-*-* h8300*-*-* mn10200*-*-* mn10300*-*-*
> -# mep and microblaze use complex relocs and don't resolve the relocs.
> +# mep uses complex relocs and doesn't resolve the relocs.
>   # one of the relocs references minus_one, which is a bug, but no one
>   # seems bothered enough to fix this.
> -#xfail: mep-*-* microblaze-*-*
> +#xfail: mep-*-*
>   
>   .*: .*
>   



More information about the Binutils mailing list