交叉编译出错之:reloaction truncated to fit : R_MIPS_CALL16

本文介绍了解决在MIPS平台上使用cross-gcc-4.9.3-n64-loongson-rc6.1工具链进行交叉编译时出现的relocation truncated to fit错误的方法。通过使用-mxgot参数,可以成功编译并避免链接器错误。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

交叉编译工具链:cross-gcc-4.9.3-n64-loongson-rc6.1
交叉编译出错的日志:

/home/loongson/work/common/3rd/lib//3gpp.o: In function `asn1Init_ngap_GUAMI':
/home/loongson/work/common/3rd/src/3gpp.c:1441:(.text+0x536c): relocation truncated to fit: R_MIPS_CALL16 against `asn1Init_ngap_AMFRegionID'
/home/loongson/work/common/3rd/lib//3gpp.o: In function `asn1PE_ngap_SliceSupportItem':
/home/loongson/work/common/3rd/src/3gpp.c:2898:(.text+0xaf04): relocation truncated to fit: R_MIPS_CALL16 against `asn1PE_ngap_SliceSupportItem_iE_Extensions'
/home/loongson/work/common/3rd/lib//3gpp.o: In function `asn1PD_ngap_SliceSupportItem':
/home/loongson/work/common/3rd/src/3gpp.c:2961:(.text+0xb430): relocation truncated to fit: R_MIPS_CALL16 against `asn1PD_ngap_S_NSSAI'
/home/loongson/work/common/3rd/lib//3gpp.o: In function `asn1PD_ngap_PLMNSupportItem':
/home/loongson/work/common/3rd/src/3gpp.c:3446:(.text+0xd348): relocation truncated to fit: R_MIPS_CALL16 against `asn1PD_ngap_SliceSupportList'
/home/loongson/work/common/3rd/src/3gpp.c:3457:(.text+0xd3f8): relocation truncated to fit: R_MIPS_CALL16 against `asn1PD_ngap_PLMNSupportItem_iE_Extensions'
/home/loongson/work/common/3rd/lib//3gpp.o: In function `asn1PD_ngap_EndpointIPAddressAndPort':
/home/loongson/work/common/3rd/src/3gpp.c:3978:(.text+0xf458): relocation truncated to fit: R_MIPS_CALL16 against `asn1PD_ngap_TransportLayerAddress'
/home/loongson/work/common/3rd/src/3gpp.c:3986:(.text+0xf4e8): relocation truncated to fit: R_MIPS_CALL16 against `asn1PD_ngap_PortNumber'
/home/loongson/work/common/3rd/src/3gpp.c:3997:(.text+0xf598): relocation truncated to fit: R_MIPS_CALL16 against `asn1PD_ngap_EndpointIPAddressAndPort_iE_Extensions'
/home/loongson/work/common/3rd/lib//3gpp.o: In function `asn1PD_ngap_CPTransportLayerInformation':
/home/loongson/work/common/3rd/src/3gpp.c:4322:(.text+0x107d4): relocation truncated to fit: R_MIPS_CALL16 against `asn1PD_ngap_TransportLayerAddress'
/home/loongson/work/common/3rd/lib//3gpp.o: In function `asn1PE_ngap_AMF_TNLAssociationToRemoveItem_iE_Extensions':
/home/loongson/work/common/3rd/src/3gpp.c:5309:(.text+0x142f8): relocation truncated to fit: R_MIPS_CALL16 against `asn1PE_ngap_AMF_TNLAssociationToRemoveItem_iE_Extensions_element'
/home/loongson/work/common/3rd/lib//3gpp.o: In function `asn1PD_ngap_AMF_TNLAssociationToUpdateItem_iE_Extensions':
/home/loongson/work/common/3rd/src/3gpp.c:5820:(.text+0x1637c): additional relocation overflows omitted from the output
collect2: error: ld returned 1 exit status
Makefile:28: recipe for target '/home/loongson/work/common/3rd/lib/libasn.so' failed
make: *** [/home/loongson/work/common/3rd/lib/libasn.so] Error 1
build failed
build failed

解决方法:
这个mips平台才有的问题,使用-mxgot, 重新编译即可。需要确保每个*.c*.o 的过程都使用 -mxgot 参数。

gcc 中关于 mxgot的参数说明:
https://gcc.gnu.org/onlinedocs/gcc-4.9.4/gcc/MIPS-Options.html#MIPS-Options

-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 only works if the GOT is smaller than about 64k. Anything larger causes 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. This works with very large GOTs, although the code is also less efficient, since it takes 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.

These options have no effect unless GCC is generating position independent code.
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值