dlsym参数RTLD_DEFAULT、RTLD_NEXT

来源:互联网 发布:网络纸牌赌博游戏机 编辑:程序博客网 时间:2024/05/17 03:22

今天看alsa-lib的代码,发现一个场景是会调到

dlsym(RTLD_DEFAULT, name);

也就是说,handle=RTLD_DEFAULT,在网上查了下,这种情况下会发生的事情是,会在当前进程中按照 default library search order搜索name这个symbol,网上的介绍摘录如下:

 

http://www.qnx.de/developers/docs/6.4.0/neutrino/lib_ref/d/dlsym.html?lang=cn

If handle is a handle returned by dlopen(), you must not have closed that shared object by calling dlclose(). The dlsym() functions also searches for the named symbol in the objects loaded as part of the dependencies for that object.

 

If handle is RTLD_DEFAULTdlsym() searches all objects in the current process, in load-order.

 

In the case of RTLD_DEFAULT, if the objects being searched were loaded with dlopen()dlsym() searches the object only if the caller is part of the same dependency hierarchy, or if the object was loaded with global search access (using the RTLD_GLOBAL mode).

 

 

http://www.linux.com/learn/docs/man/2818-dlsym3

dlsym()

The function dlsym() takes a "handle" of a dynamic library returned by dlopen() and the null-terminated symbol name, returning the address where that symbol is loaded into memory. If the symbol is not found, in the specified library or any of the libraries that were automatically loaded by dlopen() when that library was loaded, dlsym() returns NULL. (The search performed by dlsym() is breadth first through the dependency tree of these libraries.) Since the value of the symbol could actually be NULL (so that a NULL return from dlsym() need not indicate an error), the correct way to test for an error is to call dlerror() to clear any old error conditions, then call dlsym(), and then call dlerror() again, saving its return value into a variable, and check whether this saved value is not NULL.

There are two special pseudo-handles, RTLD_DEFAULT and RTLD_NEXT. The former will find the first occurrence of the desired symbol using the default library search order. The latter will find the next occurrence of a function in the search order after the current library. This allows one to provide a wrapper around a function in another shared library.  


http://blog.csdn.net/ustcxiangchun/article/details/6310085

http://pubs.opengroup.org/onlinepubs/009695399/functions/dlsym.html


0 0
原创粉丝点击