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位方式,導致調用時不同而造成此問題。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章