RFC: Patch to fix MIPS -mno-shared with multi-got...

David Daney ddaney@avtrex.com
Thu Mar 3 22:34:00 GMT 2005


Richard Sandiford wrote:
> David Daney <ddaney@avtrex.com> writes:
> 
>>Possible problems are code that use relocations other than R_MIPS_HI16,
>>R_MIPS_LO16, R_MIPS16_HI16 and R_MIPS16_LO16 against "_gp" as they would
>>now be illegal.
> 
> 
> Couldn't you get around that by:
> 
> 
>>@@ -3135,6 +3137,20 @@ mips_elf_calculate_relocation (bfd *abfd
>> 
>> 	  gp_disp_p = TRUE;
>> 	}
>>+      /* See if this is the special _gp symbol.  Note that such a
>>+	 symbol must always be a global symbol.  */
>>+      else if (strcmp (*namep, "_gp") == 0
>>+	  && ! NEWABI_P (input_bfd))
>>+	{
>>+	  /* Relocations against _gp are permitted only with
>>+	     R_MIPS_HI16 and R_MIPS_LO16 relocations.  */
>>+	  if (r_type != R_MIPS_HI16 && r_type != R_MIPS_LO16
>>+	      && r_type != R_MIPS16_HI16 && r_type != R_MIPS16_LO16)
>>+	    return bfd_reloc_notsupported;
>>+
>>+	  gp_p = TRUE;
>>+	}
> 
> 
> setting "symbol" to the local _gp value here?  There would then be
> no need for the gp_p variable.
> 

That is a good idea in theory.  But the _gp value is calculated later, 
so in practice I would remove the checks against r_type and set the gp_p 
flag here.  Then right before the big switch on r_type where the 
relocations are calculated I would set "symbol = gp".


One thing I was wondering about is if a R_MIPS_HI16 or R_MIPS_LO16 
relocation overflows for '_gp_disp' and error is emmited, but for other 
symbols overflow is not checked and the value is just masked off to the 
appropiate number of bits (16).  Why different treatment for the 
_gp_disp case?


> 
> WRT possible breakge to things expecting the real "_gp": I agree that
> might be a problem.  One possibility would be to define a new symbol,
> something like __gnu_local_gp, and make -mno-shared use that instead
> of plain _gp.  -mno-shared is a new option, so there's no backwards
> compatiblity problem.

OK, I kind of like this idea.  But I am not an ABI authority.  I am 
assuming the the meaning of "_gp_disp" is defined somewhere in the ABI 
specs.  I know _gp is specified.  Does anybody have objections to adding 
the new magic __gnu_local_gp symbol?

I am working on a new patch...

David Daney.



More information about the Binutils mailing list