带 pthread 的电子围栏
我正在开发一个多线程(基于 pthread)项目。该项目使用我正在编写的库。
为了检查它,我将它与 -lefence
链接起来,它给了我 SIGSEGV。在花了很多时间找出问题所在之后,我最终决定在库上搜索错误,即使它的功能非常简单。
作为测试,我尝试编译与 -lefence
链接的测试单元,并得到了 SIGSEGV。该测试不会干扰动态分配的内存,但在不同测试单元中成功的代码除外。
我还注意到 -pthread 标志将内存分配设置为包装。 gcc -dumpspecs | gcc -dumpspecs | gcc -dumpspecs | grep pthread 产生以下结果:
%{posix:-D_POSIX_SOURCE} %{pthread:-D_REENTRANT}
%{pthread:-lpthread} %{shared:-lc} %{!shared:%{mieee-fp:-lieee} %{profile:-lc_p}%{!profile:-lc}}
%{static: %{fmudflap|fmudflapth: --wrap=malloc --wrap=free --wrap=calloc --wrap=realloc --wrap=mmap --wrap=munmap --wrap=alloca} %{fmudflapth: --wrap=pthread_create}} %{fmudflap|fmudflapth: --wrap=main}
libefence 是否不支持多线程?
编辑: 基本上我假设电围栏库取代了常规 libc 的 malloc/free 调用。事实上,它们用线程安全罩包裹起来是没有用的,因为它们再次用不可重入的东西包裹起来。
I'm working on a multithreaded (pthread based) project. The project uses a library that I'm writing.
In order to check it I linked it with -lefence
and it gave me SIGSEGV. After a lot of time spent in figuring out what's wrong, I finally decided to search the error on the library, even if it's functionality is extremely simple.
As test, I've tried to compile the test-unit linking with -lefence
and I got SIGSEGV. The test is not messing with dynamically allocated memory, with the exception of code which, in different test units, succeded.
I noticed also that the -pthread
flag sets the memory allocation as wrapped. gcc -dumpspecs | grep pthread
produces the following:
%{posix:-D_POSIX_SOURCE} %{pthread:-D_REENTRANT}
%{pthread:-lpthread} %{shared:-lc} %{!shared:%{mieee-fp:-lieee} %{profile:-lc_p}%{!profile:-lc}}
%{static: %{fmudflap|fmudflapth: --wrap=malloc --wrap=free --wrap=calloc --wrap=realloc --wrap=mmap --wrap=munmap --wrap=alloca} %{fmudflapth: --wrap=pthread_create}} %{fmudflap|fmudflapth: --wrap=main}
Can it be the case that libefence is not supporting multithreading?
Edit: Basically I'm supposing that the electric fence library replaces the malloc/free calls of the regular libc. The fact that they have been wrapped with a thread-safe hood is useless, since they've wrapped again with non-reentrant stuff.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
检查这两个 - phthread 肯定有问题( https://bugzilla. redhat.com/show_bug.cgi?id=54368 ),但最近有人声称已修复( http://www.mail-archive.com/[电子邮件受保护]/ msg280548.html )还请注意提到了另一个延迟补丁。
Check put these two - it definitely did have a problem with phthread ( https://bugzilla.redhat.com/show_bug.cgi?id=54368 ) but recently someone claimed a fix ( http://www.mail-archive.com/[email protected]/msg280548.html ) Notice also the mention of another, delayed patch.
你尝试过valgrind吗?
Have you tried valgrind?
我只知道电围栏的概念,但你应该能够立即注意到你的缓冲区溢出发生在哪里:
那就是你的溢出!
I only know the concept of Electric fence, but you should be able to notice immediately where your buffer overflow occurs:
and there is your overflow!