[PATCH, gas] PC-relative fx_offset calculation

Alan Modra amodra@gmail.com
Mon Mar 4 00:05:00 GMT 2013


On Fri, Mar 01, 2013 at 10:02:53PM +0800, Chung-Lin Tang wrote:
> So how does this (one liner) patch look, does the change look sensible?

No, it is not correct.  fx_where is supposed to be location of the
field where the fixup is applied.  "dot" is not necessarily the same
location.  For intstance, given a 4 byte instruction that consists of
a 2 byte opcode followed by a 2 byte offset field, "dot" will point to
the start of the insn but fx_where ought to point at the field.
ie. fx_where = dot + 2.  However if you simply had a .short directive
with the same fixup, then both "dot" and fx_where will point to the
same location.

> 
> 2013-03-01  Chung-Lin Tang  <cltang@codesourcery.com>
> 
> 	gas/
> 	* write.c (fixup_segment): Use fx_where instead of fx_dot_value
> 	in computing fx_offset for the pc-relative case.
> 

> Index: gas/write.c
> ===================================================================
> RCS file: /cvs/src/src/gas/write.c,v
> retrieving revision 1.154
> diff -u -r1.154 write.c
> --- gas/write.c	4 Feb 2013 12:34:17 -0000	1.154
> +++ gas/write.c	1 Mar 2013 13:56:40 -0000
> @@ -976,7 +976,7 @@
>  		   && !TC_FORCE_RELOCATION_SUB_LOCAL (fixP, add_symbol_segment))
>  	    {
>  	      add_number -= S_GET_VALUE (fixP->fx_subsy);
> -	      fixP->fx_offset = (add_number + fixP->fx_dot_value
> +	      fixP->fx_offset = (add_number + fixP->fx_where
>  				 + fixP->fx_frag->fr_address);
>  
>  	      /* Make it pc-relative.  If the back-end code has not

-- 
Alan Modra
Australia Development Lab, IBM



More information about the Binutils mailing list