Hi,

On Mon, 20 Nov 2017, Sandra Loosemore wrote:

> > I have a hard time imaging that, so can you give details?  FWIW I've 
> > personally always considered using common symbols nicer.
> 
> The optimization case I'm familiar with is for targets that support -G 
> and GP-relative addressing modes to address small data.  Generally you 
> can only do that if the variable is allocated in the same compilation 
> unit as the reference, so the compiler knows definitely where it's 
> placed

For this to work it doesn't have to be from the same compilation unit, but 
rather needs to be put into something like .sdata or .sbss.  That in turn 
can be placed near whereever GP points to (GOT-like usually) by the link 
editor and then benefit from gp-relative addressing because the working 
theory is that by putting small stuff into .sdata it doesn't become larger 
than whatever the allowed offset for this addressing mode can be.  What 
I'm getting at is that this needs help from the link editor.

Same compilation unit doesn't really enter the picture, except if you 
indeed have different GPs per compilation unit.  But sure, making 
those symbols SHN_COMMON (let's speak ELF :) ) indeed defeats this (well, 
except if the linker puts small SHN_COMMONs into the equivalent of .sbss).  
Could also be done by the symtab placing routines, remove DECL_COMMON and 
give it .sbss section or equivalent.  I can see how just not enabling 
-fcommon is the easier path of course.


Ciao,
Michael.

Reply via email to