https://blog.csdn.net/ustcxiangchun/article/details/6310085
https://linux.die.net/man/3/dlsym
http://man7.org/linux/man-pages/man3/dlsym.3.html

dlsym()

函数dlsym()接受dlopen()返回的动态库的“句柄” 和以空字符结尾的符号名称,返回将该符号加载到内存中的地址。如果未找到该符号,则在指定的库中,或在加载该库时由dlopen()自动加载的任何 库中,dlsym()返回NULL。(由dlsym()执行的搜索首先遍历这些库的依赖关系树。)由于该符号的值实际上可以为NULL(因此从dlsym()返回的NULL 不必表示错误),因此采用正确的方法测试错误是调用dlerror()清除任何旧的错误条件,然后调用dlsym(),然后再次调用dlerror(),将其返回值保存到变量中,并检查此保存的值是否不为NULL。
有两个特殊的伪句柄,RTLD_DEFAULT和RTLD_NEXT。前者将使用默认的库搜索顺序找到所需符号的第一个匹配项。后者将在当前库之后的搜索顺序中找到功能的下一个出现。这样一来,用户就可以在另一个共享库中为函数提供包装。

今天看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_DEFAULT, dlsym() 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.

dlsym RTLD_DEFAULT和RTLD_NEXT相关推荐

  1. dlsym RTLD_DEFAULT

    今天看alsa-lib的代码,发现一个场景是会调到 dlsym(RTLD_DEFAULT, name); 也就是说,handle=RTLD_DEFAULT,在网上查了下,这种情况下会发生的事情是,会在 ...

  2. 动态链接函数dlsym()的参数RTLD_NEXT使用注意事项

    相比于已知函数的所在动态库,函数dlsym的参数RTLD_NEXT可以在对函数实现所在动态库名称未知的情况下完成对库函数的替代.这提供了巨大的便利.但是凡是有一利必有一弊,在使用该参数时,需要注意一些 ...

  3. 动态库装载及 dlsym的RTLD_NEXT参数详解

    在看公司spp框架代码的时候发现了如下一段宏定义,其中的dlsym函数及其RTLD_NEXT参数的含义不是很明白,于是网上搜了下这里做个记录. #define mt_hook_syscall(name ...

  4. android下运行时动态链接dlopen()和dlsym()的实现

    在android中,就如同在Linux下一样,我们也可以在app中,运行时动态加载一些动态链接库,执行调用其中的函数等操作.实现这一切最终依靠的就是dlopen()等几个函数.关于这几个函数的原型机这 ...

  5. android 禁用dlsym_(转载)android下运行时动态链接dlopen()和dlsym()的实现

    出处:http://my.oschina.net/wolfcs/blog/144412#OSC_h2_1 android下运行时动态链接dlopen()和dlsym()的实现 在android中,就如 ...

  6. 动态库加载函数dlsym 在C/C++编程中的使用

    dlsym函数的功能就是可以从共享库(动态库)中获取符号(全局变量与函数符号)地址,通常用于获取函数符号地址,这样可用于对共享库中函数的包装:下面是函数原型及需要包含的头文件. #include &l ...

  7. Linux下HOOK动态链接库中API的方法

    2012年,我写了一篇介绍Windows系统下Ring3层API的hook方案--<一种注册表沙箱的思路.实现--Hook Nt函数>,其在底层使用了微软的Detours库.5年后,我又遇 ...

  8. 使用LeakTracer检测android NDK C/C++代码中的memory leak

    Memory issue是C/C++开发中比较常遇到,经常带给人比较大困扰,debug起来又常常让人无从下手的一类问题,memory issue主要又分为memory leak,野指针,及其它非法访问 ...

  9. android 禁用dlsym_Android 7.0 dlopen 函数分析

    1. 说明 Android 7.0 后使用 dlopen 函数无法获取 soinfo 对应,因此也无法使用 dlsym 函数去调用第三方的 so 内的函数.这里给出 dlopen() 函数的源码分析. ...

最新文章

  1. 符号说明表怎么做_教会你的孩子正确使用标点符号
  2. sqlserver中的数据类型[转]
  3. 通信电子线路期末复习第三章正弦波振荡器
  4. (*长期更新)软考网络工程师学习笔记——Section 4 物理层的其它知识
  5. 部分不能激活Win 7 的问题分析和解决方案
  6. future java 多线程_Java多线程之Future与FutureTask
  7. Mysql 模糊查询 转义字符
  8. C语言输出有趣的图形,c语言经典游戏程序源代码大全
  9. linux 读取内存颗粒,Linux 读写memory操作,devmem直接访问物理内存地址【转】
  10. 【短信验证】短信验证 短信API使用方法含code【亲测可用】【实用】【超详细】
  11. HackTheBox-Spider WP
  12. 解决:Word在试图打开文件时遇到错误
  13. 读完两个博士是什么体验?Nature专访了3位双料博士
  14. 水瓶座06年3月运程
  15. android 蒲公英 类似平台,Jenkins之android APP打包上传蒲公英平台
  16. 深度学习(3)——softmax回归
  17. matlab利民的逻辑运算符,matlab逻辑运算符
  18. 第14届计算机设计大赛获奖情况,我校学子在第14届中国大学生计算机设计大赛中南赛区再创佳绩...
  19. 白鹭引擎入门教程一(Egret)
  20. go语言模拟网站登录并爬虫

热门文章

  1. Java集合——List接口学习总结
  2. Android 手机距离感知器 代码实现
  3. 三星中国论坛定义科技美学,显示器视觉革新颠覆想象
  4. java中请求响应时间监控
  5. 用Python写一个超级玛丽游戏
  6. vue - vue中使用echart实现柱状图和折线图
  7. 火热的“互联网+医疗” 究竟是谁的菜?
  8. CMake——cmake_minimum_required
  9. 人脸跟踪:Siamese网络结构
  10. 【Ubuntu16.04】安装无线网卡驱动