简体   繁体   English

Linux共享库中缺少函数

[英]Missing functions in Linux shared library

I'm supporting a Linux program that allows users to write their own .so file based plugins that are loaded at runtime with dlopen(). 我正在支持一个Linux程序,它允许用户编写自己的基于.so文件的插件,这些插件在运行时使用dlopen()加载。 Sometimes a user will forget to include a C++ file in the makefile that contains necessary function definitions. 有时用户会忘记在makefile中包含一个包含必要函数定义的C ++文件。 When the plugin manager uses dlsym() to load an exported function from the plugin that depends on one of these missing function definitions, I get a null function address. 当插件管理器使用dlsym()从插件加载导出的函数时,它依赖于这些缺失的函数定义之一,我得到一个空函数地址。

My question: How can I detect this error ahead of time? 我的问题:我怎样才能提前发现这个错误? I've tried the -z defs and -Wno-undef linker flags, but they don't generate an error. 我已经尝试了-z defs和-Wno-undef链接器标志,但它们不会生成错误。 I've tried the nm, readelf, and objdump commands with various flags but the undefined functions don't show up in the symbol tables at all. 我已尝试使用各种标志的nm,readelf和objdump命令,但未定义的函数根本不会出现在符号表中。 Any suggestions? 有什么建议? Thanks! 谢谢!

i suspect the null function address is mostly the result of using some third party library in the .so file and when the linux program does dlopen(), it can not locate the third party and then null function address is returned 我怀疑null函数地址主要是在.so文件中使用某些第三方库的结果,当linux程序执行dlopen()时,它找不到第三方,然后返回null函数地址

i suggest try nm command on both "good" and "bad" .so files and look for the pattern of symbols with ' U ' (undefined symbol) "bad" .so file would have more ' U ' 我建议对“好”和“坏”.so文件尝试nm命令,并查找带有'U'(未定义符号)“坏”的符号模式.so文件会有更多'U'

see also Unresolved external symbol in object files and Linux shared library that uses a shared library undefined symbol 另请参见目标文件中未解析的外部符号使用共享库未定义符号的Linux共享库

--no-undefined / -z defs documentation: --no-undefined / -z defs文档:

Undefined symbols in shared libraries are still allowed. 仍允许共享库中的未定义符号。

Use another flag: --no-allow-shlib-undefined : 使用另一个标志: --no-allow-shlib-undefined

Allows or disallows undefined symbols in shared libraries. 允许或禁止共享库中的未定义符号。 This switch is similar to --no-undefined except that it determines the behaviour when the undefined symbols are in a shared library rather than a regular object file. 此开关类似于--no-undefined但它确定未定义符号位于共享库而不是常规对象文件中时的行为。 It does not affect how undefined symbols in regular object files are handled. 它不会影响常规对象文件中未定义的符号的处理方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM