C/C++ 链接器 CALL16 reloc at xxxxx 不针对全局符号
我在链接时收到这些错误,这两条消息都与同一个目标文件有关。
CALL16 reloc at 0x5f8 not against global symbol
第二条消息
could not read symbols: Bad value
似乎是我收到 CALL16 错误的原因,但文件编译得很好。
有什么解决这个问题的建议吗?
仅供参考,我正在针对 MIPS 目标进行交叉编译并使用 gcc 4.1.2
编辑: 到目前为止没有运气:
这是我使用的标志: -fPIC,-Wl,-rpath,-Wl,-O1
我也尝试过以下操作但没有成功:
-mno-显式-relocs
-mexplicit-relocs
-mlong-calls
-mno-长通话
-mxgot
-mno-xgot
与此同时,我将回到源头并进行更多调查。
I'm getting these errors while linking, both messages have to do with the same object file.
CALL16 reloc at 0x5f8 not against global symbol
and
could not read symbols: Bad value
The 2nd message seems to be the reason I'm getting the CALL16 error, but the file compiles just fine.
Any tips on fixing this?
FYI, I'm cross compiling for a MIPS target and using gcc 4.1.2
EDIT: No luck so far:
Here are my flags used:
-fPIC,-Wl,-rpath,-Wl,-O1
I've also tried the following without success:
-mno-explicit-relocs
-mexplicit-relocs
-mlong-calls
-mno-long-calls
-mxgot
-mno-xgot
Meanwhile, I'll go back to the source at this point and investigate more.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
啊哈!
感谢我的一位同事,我们发现了这个问题。
问题是:
有一个函数的前向声明/原型。
后来在文件中定义了该函数。
这里的问题是在原型中省略了关键字 static。 所以这就像是一个全新的函数被定义了。
GCC 将 CALL16 引用用于可重定位代码。 该文件的汇编代码显示该函数正在使用 CALL16...这是错误的,因为该函数是本地函数。
有趣的是,这段代码用于编译& 与旧版本的 gcc (3.2.2) 的链接很好。
又一个有经验的人学习了。 :)
Aha!
Thanks to a colleague of mine, we found the issue.
Here was the issue:
There was a forward declaration/prototype of a function.
Later on in the file the function was defined.
The issue here was that in the prototype the keyword static was left out. So it was like a whole new function was being defined.
The CALL16 reference is used by gcc for relocatable code. The assembly code of the file showed that CALL16 was being used on this function... Which is wrong, as this function is local.
Interestingly, this code used to compile & link just fine with an older version of gcc (3.2.2).
Another lessoned learned. :)
尝试向编译器添加 -mlong-calls 标志。
另请参阅手册了解更具体的 MIPS 选项。
Try -mlong-calls flag to the compiler.
Also see the manual for more specific MIPS options.