[RFC] Only NOP in delayed branches in .MIPS.stubs section

Maciej W. Rozycki macro@mips.com
Wed Apr 4 10:47:00 GMT 2018


Hi Maksim,

> I work with mips32 based SoC, which has some restrictions (errata). One of
> them - only the NOP instruction in delay slot is allowed.

 Ouch!

> Mainly, this restriction is resolved easily by passing -fno-delayed-branch
> flag to compiller and by patching .noreorder sections in assembler code.
> But there is a problem with .MIPS.stubs section - ELF backend linker
> generates code like this:

 What about the PLT?

> For now, to resolve this, I use my own patch which is just a dirty hack
> (bellow, at the end of the message). I'm not a GNU tools expert, but, in my
> humble opinion, it would be great to get the same result just by passing
> -fno-delayed-branch flag to compiler.

 That's surely doable.

> I would like to create more proper patch, but my main difficulty is that I
> can not found a right way to detect if -fno-delayed-branch flag is used
> (was used in as). So, I need advice to resolve this. I would be very
> thankfull for that.

 First you need to pass the GCC driver this flag in the link stage as well 
(conventionally among the flags set with the $(LDFLAGS) variable in 
Makefile).  Then you can modify GCC driver specs (see the output from `gcc 
-dumpspecs' and the `link' recipe there) to have the flag set a 
corresponding linker flag in LD invocation, that you need to define.

 We have a few MIPS-specific linker flags already defined in 
ld/emultempl/mipself.em (see PARSE_AND_LIST_* variables), and your new 
option will go there (you'll need both a positive and a negative form, so 
that overriding both ways is possible, and as you can see the convention 
for linker flags is to drop the `f' or `m' prefix and use a double leading 
dash).

> And more general question - does it make sense to develop correct patch for
> that at all? Or this is minor specific problem that everyone should resolve
> himself for his specific situation?

 We do accept properly formed submissions for hardware errata workarounds.  
See: <https://sourceware.org/gdb/wiki/ContributionChecklist> for how a 
proper submission is supposed to be made and if you are unsure about 
anything, then please do not hesitate to ask.

 Hope this helps.

  Maciej



More information about the Binutils mailing list