-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Could threadSanitizer be used with static linked lib #701
Comments
Should work. Did you link with -fsanitize=thread as well? If yes, please provide exact sequence of commands you execute and/or reproducer. |
Yes, I linked with -fsanitize=thread as well. The Makefile is very large, I added -fsanitize=thread to the tail of CC=xxx CPP= xxxx and LD = xxx. Should the .a file be recompiled with -fsanitize=thread? |
Do you link static binary or dynamic? If static, try add '-static-libtsan' to your link flags. |
Then it should work. Try to create a minimal repro. It will be much easier to figure out what happens then. |
Still don't work. some errors are: |
A small repo worked when I use the following command: I cannot figure out why it didn't work for the big project. |
But you did not link any uninstrumented static libraries to the binary. Though, I did not expect it to make any difference. Re linker "undefined reference" errors: that happens because tsan runtime is not linked. Does it happen when you link executable or shared library? Can you capture linker command line and post here? |
Thank you. I rechecked the linker command, and found out that I missed -fsanitize=thread when I modifyed it last time. I added it to the Makefile, the link process failed with error: |
xxx.a is your prebuilt shared library, right? |
Yes, I think my compiler doesn't support, and my boss won't let me update it. XXX.a is generated by cmake, which is wrote by someone else, I have not idea how to add -fPIC to it.. |
No, I am not a cmake expert, sorry. Maybe it also supports something like CFLAGS? |
Thank you all the same. After Compile with -fPIC, the linker doesn't report that error. |
Sanitizers are not compatible with tcmalloc (and other malloc replacement libraries) as they replace malloc themselves. So just remove libtcmalloc.a from linker command when building with sanitizers. |
Hi, I succeed in linking the program finally. One thing I don't understand is that, some of my XXX.a lib need to be recompiled with -fPIC, while some of them don't need, Why? |
Great!
int foo(int x) { return x + 1; } will not involve any relocations and will position-independent (though, I did not try). |
From the link command showed when linking, the .a files are surely linked into the binary. Those files are all about logs, I don't have the source code. |
You are welcome. |
Last night when I was on the bed, I thought of a question. If one dynamic lib xxxx.so which uses tcmalloc, is used in my project, is it necessary for me to recompile it without tcmalloc? |
What do you mean "uses tcmalloc"? tcmalloc is usually LD_PRELOADed, or just linked into the final executable. There is usually no need to depend/use tcmalloc explicitly, it's just a malloc replacement. Dynamic libraries use malloc and depend on libc.so. |
In a Makefile of one of my old project, the linking commands include line like this: |
Yes, explicit linking of libtcmalloc.a needs to be removed. |
Well, OK.. |
When I run the binary file, it takes 300+% cpu, 97T VIRT, 2.6g RES .... All the processes have no response... |
-fPIC can slightly affect performance.
Is it a binary built with tsan? |
Yes, it's a binary built with tsan. (gdb) c (gdb) bt max CPU 680+%..... |
So libio64 waits on a mutex. Who is holding the mutex? |
It seems that some threads need to write to a message queue concurrently, and while a thread is waiting for the mutex, it would call usleep from /lib64/libtsan.so.0. Each Time I press 'Ctrl C' and 'thread apply all bt' to see the stack, the stack is more or less the same. The virtual memory watched from top command is always 97.001t, 500%~600%, or even more CPU is occupied. My gcc version is 4.8.5. |
Then maybe it works, but very slowly. Would it be possible to replace the mutex with pthread_mutex_t under tsan? |
The mutex_spinlock is in a dynamic library provided by the platform team in our company. It was written by some old guys in 2002. It is provided in the form of .so, no one in my team has its source code, and they say that the source code is top secret....(faint). So maybe it's hard to replace it. |
An old project which is linked with some xx.a file, can I add thead sanitizer to this project?
When I did so, a lot of undefined referenced __tsan_func_entry printed.
What should I do?
The text was updated successfully, but these errors were encountered: