[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Help: build failure due to relocation truncated to fit: R_MIPS_GOT16 and others

On 20/11/16 16:47, Steve M. Robbins wrote:
> Hi,
> I'd appreciate some help solving a MIPS-only build failure in googletest.  It 
> fails for arch mips [1], mipsel, and mips64el.  A sample of the error output:
>     relocation truncated to fit: R_MIPS_GOT16 against 
> `__stack_chk_guard@@GLIBC_2.4'
>     relocation truncated to fit: R_MIPS_CALL16 against `operator new(unsigned 
> int)@@GLIBCXX_3.4'
> [ and many similar]
> I'm kind of googling blind here .   I've found a smattering of similar 
> questions with answers that point to using '-Gn' or '-mxgot'.  But I haven't a 
> solid grounding to understand what the implications are.  

These relocation errors mean you have too many symbols in the GOT in
your executable. MIPS usually uses a single instruction to access the
GOT, but that only works for small GOTs. If your GOT is too large, it's
still possible to make it work using -mxgot, but it takes 3 instructions
to load a 32-bit address, add to the gp register, and do the final load.
Since you don't know how the linker will allocate the GOT, you have to
use -mxgot on all C/C++ files. The penalty occurs when you access any
non-static global functions/variables.

Your options are: reduce the number of symbols which span across
translation unit boundaries (thus reducing the size of the GOT), or
compile with -mxgot on MIPS with a slight speed penalty.


Attachment: signature.asc
Description: OpenPGP digital signature

Reply to: