Why -mxgot on MIPS and not -fpic/-fPIC?

Florian Weimer fw@deneb.enyo.de
Mon Oct 3 15:23:00 GMT 2016


* Maciej W. Rozycki:

> On Mon, 3 Oct 2016, Matthew Fortune wrote:
>
>> > It looks like -mxgot has a similar impact on MIPS as using -fPIC
>> > (instead of -fpic) on other architectures.
>> > 
>> > Why wasn't the -fpic/-fPIC distinction carried over to MIPS?
>> 
>> Much of the history here is probably folklore and guesswork but for
>> my understanding is that MIPS has three levels of 'pic'.
>> 
>> MIPS PIC code is really controlled by -mabicalls and -mshared which
>> I assume originate from the MIPS-pro days.
>> 
>> -fpic is simply set to imply -mabicalls and -mshared which is where
>> everything gets far more confusing (but let's not get into that
>> unless we have to)
>> 
>> The reason there is no -fPIC is probably a conscious decision as
>> MIPS has 'multi-got' that allows the small -fpic model to scale to
>> most situations.
>> 
>> -mxgot (aka big-got) is however a good match for -fPIC as it is a
>> model guaranteed to work irrespective of how big the GOT is.
>
>  For MIPS `-fPIC' is an alias to `-fpic' and the actual reason is these 
> options have only been retrofitted to the MIPS target when non-PIC support 
> has been added to shared-library (as opposed to bare-metal) targets.  The 
> original MIPS SVR4 psABI mandated all code to be PIC, even executables, 
> and the model chosen was controlled with the `-mxgot' option, hardly ever 
> used, due to the code bloat implied and link-time incompatibility with the 
> default `-mno-xgot' code.  The latter could be rectified to some extent by 
> a specific GOT entry ordering, but with the advent of multi-GOT there was 
> little incentive to actually implement it.

GHC produces objects which need -mxgot.

The GCC documentation doesn't say anything about incompatibilities
between -mxgot and -mno-xgot.  Will this result in a linker failure at
least?

(On the glibc side, I don't think we compile libc_nonshared.a twice,
once for -mxgot and once for mno-xgot.)



More information about the Gcc-help mailing list