dlopen

Loading Linux libraries at runtime

感情迁移 提交于 2019-12-06 04:14:35
问题 I think a major design flaw in Linux is the shared object hell when it comes to distributing programs in binary instead of source code form. Here is my specific problem: I want to publish a Linux program in ELF binary form that should run on as many distributions as possible so my mandatory dependencies are as low as it gets: The only libraries required under any circumstances are libpthread, libX11, librt and libm (and glibc of course). I'm linking dynamically against these libraries when I

RTLD_LOCAL and dynamic_cast on Linux

三世轮回 提交于 2019-12-06 04:10:35
问题 We have a plugin that is constructed of a few shared libraries in our application that we need to update while the application is running. For performance reasons we load and start using the new plugin before unloading the old plugin and only when all threads are done using the old plugin we unload it. Since the libraries of the new plugin and the old plugin have the same symbols in them we dlopen() with RTLD_LOCAL . If we don't the new plugin call from internal functions by accident to

valgrind giving error but unable to find location

霸气de小男生 提交于 2019-12-06 03:55:15
I have started using valgrind just one day ago as suggested by someone on SO itself .Its an amazing tool but today i got an issue with it.It gives the following error : definitely lost bytes but unable to tell the location of error. Here is the output of valgrind : udit@udit-Dabba ~ $ valgrind --leak-check=full sendip -v -p ipv6 -f file.txt -6s ::1 -p ah -as 0x20 -aq 0x40 -ak "yugal" -am xorauth.so -p udp -us 21 - ud 21 ::2 ==12885== Memcheck, a memory error detector ==12885== Copyright (C) 2002-2010, and GNU GPL'd, by Julian Seward et al. ==12885== Using Valgrind-3.6.1 and LibVEX; rerun with

Why does an std::any_cast of a passed std::any inside a dlopen'd function raise an error

纵然是瞬间 提交于 2019-12-06 03:42:35
I am toying around with c++17 and plugins, and I have run into an error that I cannot get around. In the following MWE I can call a local function that takes a std::any , and everything works as expected when I try to read the contents. When I load this exact same function through a plugin (dlopen), it correctly sees the type on the any, but it cannot std::any_cast the contents. Any help would be greatly appreciated in figuring out what is causing this error. Here is my environment, MWE, and resulting error. >> g++ --version g++ (GCC) 7.1.1 20170526 (Red Hat 7.1.1-2) Copyright (C) 2017 Free

dlopen a dynamic library from a static library, when the dynamic library uses symbols of the static one

瘦欲@ 提交于 2019-12-06 02:38:10
问题 This question is closely related to dlopen a dynamic library from a static library linux C++, but contains a further complication (and uses C++ instead of C): I have an application that links against a static library (.a) and that library uses the dlopen function to load dynamic libraries (.so). In addition, the dynamic libraries call functions defined in the static one. Is there a way to compile this without linking the dynamic libraries against the static one or vice versa? Here comes what

How to intercept file system access inside dlopen()?

♀尐吖头ヾ 提交于 2019-12-06 01:49:58
问题 I want to intercept all file system access that occurs inside of dlopen(). At first, it would seem like LD_PRELOAD or -Wl,-wrap, would be viable solutions, but I have had trouble making them work due to some technical reasons: ld.so has already mapped its own symbols by the time LD_PRELOAD is processed. It's not critical for me to intercept the initial loading, but the _dl_* worker functions are resolved at this time, so future calls go through them. I think LD_PRELOAD is too late. Somehow

Use dlinfo to print all symbols in a library

风格不统一 提交于 2019-12-06 00:19:46
I have a C++ class that uses dlopen to load a library. As an exercise I was trying to dump all of the symbol names from the loaded library. I've used dlinfo to load the linkmap via RTDL_DI_LINKMAP : struct link_map { ElfW(Addr) l_addr; /* Base address shared object is loaded at. */ char *l_name; /* Absolute file name object was found in. */ ElfW(Dyn) *l_ld; /* Dynamic section of the shared object. */ struct link_map *l_next, *l_prev; /* Chain of loaded objects. */ }; This provides me a linked list of libraries that have been loaded by the dlopen call. I then thought that I could process the l

dlopen/dlsym/dlclose (dlfcn.h) causes memory leak

筅森魡賤 提交于 2019-12-05 20:52:49
When using the dlfcn family like so: #include <stdio.h> #include <dlfcn.h> typedef int(*timefunc_t)(void*); int main() { timefunc_t fun; void* handle; handle = dlopen("libc.so.6", RTLD_LAZY); fun = (timefunc_t)dlsym(handle, "time"); printf("time=%d\n", fun(NULL)); dlclose(handle); return 0; } It causes a Memory leak: ==28803== Memcheck, a memory error detector ==28803== Copyright (C) 2002-2010, and GNU GPL'd, by Julian Seward et al. ==28803== Using Valgrind-3.6.1 and LibVEX; rerun with -h for copyright info ==28803== Command: ./dl ==28803== time=1309249569 ==28803== ==28803== HEAP SUMMARY: =

Linux下显示运行时链接(运行时加载)

六月ゝ 毕业季﹏ 提交于 2019-12-05 14:56:10
目录 介绍 如何加载动态库 dlopen() 第一个参数: 被加载动态库的路径 第二个参数: flag表示函数符号的解析方式 dlopen 返回值 dlsym() 参数: 返回值 符号优先级 dlerror() dlclose() show code 内容学习自《 程序员的自我修养 链接装载与库》 如果只是想知道如何使用如何加载动态库和那4个函数的使用,可以直接从如何加载动态库开始看。 介绍 支持动态链接的系统往往都支持一种更加灵活的模块加载方式,叫做显式运行时链接(Explicit Run-time Linking),有时候也叫做运行时加载。也就是让程序自己在运行时控制加载指定的模块,并且可以在不需要该模块时将其卸载。从前面我们了解到的来看,如果动态链接器可以在运行时将共享模块装载进内存并且可以进行重定位等操作,那么这种运行时加载在理论上也是很容易实现的。而且一般的共享对象不需要进行任何修改就可以进行运行时装载,这种共享对象往往被叫做动态装载库(Dynamic Loading Library),其实本质上它跟一般的共享对象没什么区别,只是程序开发者使用它的角度不同。 这种运行时加载使得程序的模块组织变得很灵活,可以用来实现一些诸如插件、驱动等功能。当程序需要用到某个插件或者驱动的时候,才将相应的模块装载进来,而不需要从一开始就将他们全部装载进来,从而减少了程序启动时间和内存使用

How to use dlsym reliably when you have duplicated symbols?

走远了吗. 提交于 2019-12-05 07:58:38
Good evening, I'm currently working on a Plugin system in C++/Linux based on the Plux.net model. To keep it simple, I basicly declare a symbol (lets call it pluginInformation) with extern C (to unmangle) and my plugin manager look for that symbol in the pre configured imports (.so). The thing is that the main application declares the same symbol, not only that but any dependency it have may have the symbol aswell. (since in this pluginInformation, modules can publish plugs and/or slots). So when my PluginManager starts, it first try to find the symbol in the main program (passing NULL to