dlerror: Undefined symbol “_nss_cache_cycle_prevention_function” on FreeBSD 7.2

爱⌒轻易说出口 提交于 2019-12-24 09:52:57

问题


I have an ANSI C program that dynamically loads a .so file using dlopen() passing RTLD_LAZY. I receive

Undefined symbol "_nss_cache_cycle_prevention_function"

warnings whenever the .so file is accessed in FreeBSD 7.2. nss_cache_cycle_prevention_function() is not one of my program's functions and I imagine must be coming from FreeBSD. This might also be a problem on Linux too although I am not experiencing the issue there. I would prefer not to load FreeBSD specific header files into my program. I would like to either include this function in a portable way or suppress these warnings.


回答1:


What do you mean saying "I receive warning"? Does your program examine the value returned by dlerror() and prints it if it is not NULL?

The _nss_cache_cycle_prevention_function is a marker symbol which is used by nsdispatch(3) on FreeBSD to determine whether to employ the services of nscd(8), the name service caching daemon. It is perfectly normal that it does not exist in an executable or a shared library.

But when nsdispatch(3) executes dlsym(3), and the symbol is not found, the error will be set. And dlerror(3) returns the description of the last error, and not the description of the error of the last call. I suspect that's what you are hitting.

The solution (quite portable) would be to:

  • for dlopen(3), check its return value before using dlerror() to see whether there was an error at all;
  • for dlsym(3), since NULL is a valid return value, to call dlerror() in a void context before the call to dlsym(3); that will clear any previous error, so that whatever the second call to dlerror(3) returns later on can be trusted.

In general, it will not harm anything to call an empty dlerror() before any other dl* calls.



来源:https://stackoverflow.com/questions/3559147/dlerror-undefined-symbol-nss-cache-cycle-prevention-function-on-freebsd-7-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!