This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: MIPS patch to avoid lazy binding in la macros


On 21 Feb 2003, Richard Sandiford wrote:

> Suppose foo is a weak function.  For -KPIC, one implementation of:
> 
>         if (foo)
>           foo ()
> 
> might be:
> 
>         la $25,foo
>         beqz $25,1f
>         jal $25
> 1:
> 
> But due to a suspect feature, gas treats
> 
>         la $25,foo
> 
> as a special case and allows foo to be lazily bound.  Not the
> desired effect. ;)
> 
> I hit this on mips-rewrite branch while trying to improve the call
> patterns.  Indirect calls have traditionally had an 'r' constraint,
> even for TARGET_ABICALLS.  So although gcc can sometimes use $25
> as the call destination, it often uses some other register instead.
> The assembler then has to copy that register into $25.
> 
> The mips-rewrite patterns know about $25, giving the code above.
> I guess it's just luck that we haven't been bitten by this before...
> 
> Patch tested in the same way as the last one.  OK to install?
> 
> Richard
> 
> PS. I checked that the new behaviour is consistent with SGI's assembler.

 I object.

 Essentially you kill lazy binding for code as currently emitted by gcc
entirely this way.  And I don't think you have to.  While you have
incorrect CALL relocations in the object file, indeed, they will be
converted to regular GOT references upon the final link as the function
will not get a stub (as this is an undefined weak symbol as I understand;
otherwise it wouldn't be zero or there would be other relocations related
to taking the function's address).  If the function gets a stub
regardless, there is a bug elsewhere, probably in BFD -- try to narrow it
down then.

 One could argue the whole heuristics is fragile, to say at least, and I
would wholeheartedly agree.  It should be replaced with explicit setting
of relocation attributes using "%call_hi", "%call_lo", "%got_hi" and
"%got_lo" (I think there should be two additional operations like "%call" 
and "%got"[*] for the "la" and related macros themselves).  I discussed it
at this list a few years ago and IIRC there was an agreement that is a
good idea with the heuristics being a temporary solution until gcc gets
improved.  It has been on my to-do list since then, but due to the lack of
time I haven't looked into it, yet.  Surprisinly enough no one else,
either. 

 I've seen the ack from Eric, but please revert the patch until we are
really sure you are not trying to mask a bug elsewhere.

  Maciej

[*] Another name should be invented as "%got" is already used for
something that should probably be called "%got16".

-- 
+  Maciej W. Rozycki, Technical University of Gdansk, Poland   +
+--------------------------------------------------------------+
+        e-mail: macro at ds2 dot pg dot gda dot pl, PGP key available        +


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]