[PATCH] RISC-V: Adjust __global_pointer$ value to reduce code size.

Jim Wilson jimw@sifive.com
Tue Oct 16 00:39:00 GMT 2018


On Mon, Oct 15, 2018 at 4:43 PM Palmer Dabbelt <palmer@sifive.com> wrote:
> This smells like a bug lurking somewhere.  IIRC we avoided relaxing anything
> that points to a mergeable segment due to these sorts of constraints, are we
> just missing something?  I would consider it a bug if users can end up with
> incorrect relaxations, regardless of where they're targeting the GP.

We avoid relaxation in mergeable and code sections.  In this case the
problem is rodata which is neither, but immediately follows .text and
hence variables in rodata can change address when .text shrinks.  We
probably never tried to relax references to rodata before.  I didn't
look at trying to handle this in relaxation itself, it was easier to
just fix gp to avoid overlapping rodata.  We should probably look at
the rodata problem later though.

> FWIW, when drag racing linker relaxation I always ended up using an offset of
> 0x7C0 instead of 0x800 because of that extra bit of pessimism in the linker
> relaxations that eats a few bytes of offset.  IIRC that saves you something
> like 3 instructions in Dhrystone's inner loop because it allows relaxing
> against the first few bytes of .sdata.

The current definition is .sdata+0x800 which makes everything .sdata
and later relaxable.  If you used .sdata+0x7c0, then you would get the
last 64 bytes of the .data section as relaxable.  My patch should do
this automatically for you if .sdata+.sbss is smaller than 0x1000.
Though if you have your own linker script you don't get any benefit
from this unless you update your linker script.;

> I don't know if it matters any more here, as if I understand how this is all
> working we'll end up with GP pointing quite a way before ".sdata+0x800" for
> small programs and for big programs the extra few symbols will just be noise.

For big programs there will be no extra symbols, because if
.sdata+.bss is 0x1000 or larger we get the exact same gp value as
before.  The smaller the program the more the benefit.  The larger the
program the less the benefit, with the benefit dropping to zero once
the program gets big enough.

Jim



More information about the Binutils mailing list