relocation truncated to fit: R_MIPS_CALL16 问题!

转载出处:http://blog.csdn.net/yirui/article/details/1672503

我在broadcom7309上编译链接库生成程序时,出现以下链接问题。链接库时,出现以下很多类似的错误:
relocation truncated to fit: R_MIPS_CALL16 against 'IsHealthy()'
relocation truncated to fit: R_MIPS_GOT16 against `g_dwCommsClock'
relocation truncated to fit: R_MIPS_CALL16 against `SetScreenPixelFormat'

原来这此函数都可正常运行,就是链接上我们的一个库后,出现这个问题。

查询网上的解决方法:
http://www.linux-mips.org/archives/linux-mips/2003-05/msg00243.html

http://sourceware.org/ml/binutils/2003-08/msg00128.html

-mxgot是mips专用的gcc 选项,但mipsel-uclibc-g++没有这个选项

参考:
-Wa,optionlist Asm
The optionlist is a list of one or more comma separated lists of options to be passed to
the assembler. The options are split at the commas and each one is provided to the
assembler as a command line option.
Also see -Wp and -Wl. This option can be written as --for-assembler

-G number
Puts global and static items less than or equal to number bytes in size into the small
data or bss section instead of the normal data or bss section. This allows the assembler
to emit one-word memory reference instructions based on the global pointer (gp or
$28), instead of the normal two words used. By default, number is 8 when the MIPS
assembler is used and 0 when the GNU assembler is used.
This option setting is also passed to the assembler and linker, so all modules should
be compiled with the same number value. 

-mxgot
-mno-xgot
Lift (do not lift) the usual restrictions on the size of the global offset table.
GCC normally uses a single instruction to load values from the GOT. While
this is relatively efficient, it will only work if the GOT is smaller than about
64k. Anything larger will cause the linker to report an error such as:
relocation truncated to fit: R_MIPS_GOT16 foobar
If this happens, you should recompile your code with ‘-mxgot’. It should then
work with very large GOTs, although it will also be less efficient, since it will
take three instructions to fetch the value of a global symbol.
Note that some linkers can create multiple GOTs. If you have such a linker,
you should only need to use ‘-mxgot’ when a single object file accesses more
than 64k’s worth of GOT entries. Very few do

 

最后解决方法:

1.使用-Wa,-xgot重新编译所有的库,包括pthread,libc.

2.使用动态库链接

分析原因:静态库的符号表存储方式不一样,一个库使用32位方式,另一个库使用16位方式,导致调用时不同而造成此问题。

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值