[patch] MIPS: Use the right offset for LO16 in add_got_offset_hilo() (ping)

Richard Sandiford rsandifo@redhat.com
Mon Feb 28 10:27:00 GMT 2005


"Maciej W. Rozycki" <macro@linux-mips.org> writes:
> @@ -4104,7 +4104,9 @@ add_got_offset_hilo (int dest, expressio
>    mips_optimize = 2;
>    macro_build_lui (&global, tmp);
>    mips_optimize = hold_mips_optimize;
> +  local->X_add_number = ((local->X_add_number + 0x8000) & 0xffff) - 0x8000;
>    macro_build (local, ADDRESS_ADDI_INSN, "t,r,j", tmp, tmp, BFD_RELOC_LO16);
> +  local->X_add_number = global.X_add_number;
>    relax_end ();
>  
>    macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", dest, dest, tmp);

You asked about this patch in the other thread, so FWIW, I agree that
it does the right thing.  Obviously I can't approve it though.

My main concern is that it seems to leave things in a slightly
inconsistent state.  In the case of load_got_offset, it's the caller
that adjusts the GOT16 offset:

	      expr1.X_add_number = offset_expr.X_add_number;
	      offset_expr.X_add_number =
		((offset_expr.X_add_number + 0x8000) & 0xffff) - 0x8000;
	      load_got_offset (tempreg, &offset_expr);
	      offset_expr.X_add_number = expr1.X_add_number;

whereas the patch makes the callee adjust the LO16 offset.  I had to
stare at the patch for a while before realising that the new code is
compensating for an adjustment made by the _caller_ of load_got_offset,
not load_got_offset itself.

I agree that hiding this adjustment in add_got_offset_hilo is the right
way to go.  However, it might be better to move the offset_expr adjustment
into load_got_offset at the same time.

Richard



More information about the Binutils mailing list