Tag: dlopen

dlopen()设置errno吗?

一切都在标题中。 手册页没有说什么。 一些谷歌报告有些人在dlopen之后检查errno,但只是少数并且有各种结果。 该函数确实返回成功/非成功值,但应该如何找出失败的原因。 那么dlopen()设置errno吗? 那么,在哪里定义了不同的errno值? 如果没有,应该用什么来检查导致失败的原因?

什么时候我们应该使用RTLD_DEEPBIND?

我正在尝试链接中提到的问题: https : //sourceware.org/ml/libc-alpha/2009-06/msg00168.html 我在代码中做了一些修改,如下所述: >> Cat libdep.c #include int duplicate = ‘u’; int get_duplicate() { printf(“libdep sees duplicate as: %c\n”, duplicate); printf(“libdep sees duplicate address as: %x\n”, &duplicate); return duplicate; } ————————————————————————————– >> Cat dynamic.c #include extern int duplicate; int run() { duplicate = ‘d’; printf(“dynamic sees duplicate from libdep as: %c\n”, duplicate); printf(“dynamic […]

什么时候gcc __attribute __((构造函数))运行?

假设我有一个带有GCC构造函数的libA.so。 我的程序“程序”依赖于libA.so,所以当我运行它时,libA.so被打开并且它的构造函数被执行。 现在,我还有一个模块libC.so,它也依赖于libA。 我运行dlopen(“libC.so”) , 加载libC,并根据我的实验,也执行libA的构造函数 。 依赖关系看起来像这样: libA有构造函数 libB也有一个构造函数 libC依赖于libA和libB 程序取决于libA 程序通过dlopen()链接libC 现在,当我运行程序时: libA的构造函数在main()启动之前运行 libB的构造函数由dlopen()运行 显然,当它们被加载到内存中时,dlopen会执行库的构造函数。 这是在某处指定的,链接器如何检查哪些库已经加载? (为什么我要问:在一个场合,我有一个构造函数在一些不完全理解的情况下被执行了两次。我是否正确地假设这完全被打破并且在正常情况下不应该发生?)

如何从GNU / Linux中的可执行文件导出特定符号

在通过::dlopen()加载动态库时,可以通过-rdynamic选项从可执行文件导出符号,但它会导出可执行文件的所有符号,从而导致更大的二进制文件大小。 有没有办法只导出特定的function? 例如,我有testlib.cpp和main.cpp如下: testlib.cpp extern void func_export(int i); extern “C” void func_test(void) { func_export(4); } main.cpp中 #include #include void func_export(int i) { ::fprintf(stderr, “%s: %d\n”, __func__, i); } void func_not_export(int i) { ::fprintf(stderr, “%s: %d\n”, __func__, i); } typedef void (*void_func)(void); int main(void) { void* handle = NULL; void_func func = NULL; handle = ::dlopen(“./libtestlib.so”, […]

dlopen / dlsym / dlclose(dlfcn.h)导致内存泄漏

当像这样使用dlfcn系列时: #include #include 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; } 它会导致内存泄漏: ==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 […]

valgrind给出错误但无法找到位置

我已经开始在一天前使用valgrind正如SO本身的人所建议的那样。这是一个了不起的工具,但今天我遇到了一个问题。它给出了以下错误: definitely lost bytes但无法告诉错误的位置。 这是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== […]

在调用dlclose时,共享库中的全局变量会发生什么变化?

如果通过dlopen和dlclose机制使用共享库(或DLL),并且如果创建的共享库有一些全局变量,其内存来自堆,那么当调用dlclose时这些变量和内存会发生什么? 如果在同一个进程中再次调用dlopen,那么行为是什么?

LD_PRELOAD和链接

我有这个小测试atfork_demo.c : #include #include void hello_from_fork_prepare() { printf(“Hello from atfork prepare.\n”); fflush(stdout); } void register_hello_from_fork_prepare() { pthread_atfork(&hello_from_fork_prepare, 0, 0); } 现在,我以两种不同的方式编译它: gcc -shared -fPIC atfork_demo.c -o atfork_demo1.so gcc -shared -fPIC atfork_demo.c -o atfork_demo2.so -lpthread 我的演示主要是atfork_demo_main.c是这样的: #include #include #include int main(int argc, const char** argv) { if(argc <= 1) { printf("usage: … lib.so\n"); return 1; } […]

静态Vs动态库

我读过有关静态和动态库的内容。 我的问题很少说明 dlopen dlclose: Benifit of dlopen is we can start the EXE with out loading the necessary libraries at the begining. Only when we need we will load the libratries and unload it from the memory. 这是动态链接库的行为。 我的问题是,如果我链接库libUtlities ld -o EXE main.o -lUtilities 当我运行EXE时,在我第一次使用这些function之前,libUtlities将被加载到内存中 which i observed in dbx (Solaris debugger) But will not […]

如何正确地将dlsym返回的指针分配给函数指针类型的变量?

我试图在我的代码中使用dlopen()和dlsym()并使用gcc编译它。 这是第一个文件。 /* main.c */ #include int main() { void *handle = dlopen(“./foo.so”, RTLD_NOW); if (handle) { void (*func)() = dlsym(handle, “func”); func(); } return 0; } 这是第二个文件。 /* foo.c */ #include void func() { printf(“hello, world\n”); } 这是我编译和运行代码的方法。 $ gcc -std=c99 -pedantic -Wall -Wextra -shared -fPIC -o foo.so foo.c $ gcc -std=c99 -pedantic -Wall […]