Thread safety in libdwarf #184
-
Hello,
Does this mean it's unsafe to call
Does this mean it's unsafe to use a Dwarf_Debug object produced in thread A in thread B, even if a mutex is used? I would like to be able to call dwarf_init_path from multiple threads simultaneously and work on the Dwarf_Debug objects independently, as well as also being able to use a Dwarf_Debug object produced in a thread other than the one it was produced on but with mutex locks over the resource. |
Beta Was this translation helpful? Give feedback.
Replies: 7 comments
-
My email response has not appeared here. Hmm. On reviewing libdwarf source code, I find only one static array, staticerrlist[] a very special It is possible that if the caller ensures that , on a given Dwarf_Debug (either directly or Many calls in the library not directly referencing a Dwarf_Debug do so indirectly Even a simple global lock per Dwarf_Debug is difficult to implement correctly, |
Beta Was this translation helpful? Give feedback.
-
I would be happy to consult on the library aspect in case you run into |
Beta Was this translation helpful? Give feedback.
-
Just asking: you using C11 locks or ??? |
Beta Was this translation helpful? Give feedback.
-
Might libdwarf somehow get a thread-id and (if built for such) verify the current |
Beta Was this translation helpful? Give feedback.
-
Thank you so much for the replies and taking the time to look into the issue. For my use case I think worst case scenario I can lock around all calls to libdwarf just to be safe. I'm writing most of the code working with the library in C++11 and was planning on using std::mutex's. For context I'm working on a stack tracing library. For most users traces should be infrequent but there are cases where I could imagine multiple threads simultaneously requesting traces. I'm doing a lot of caching of the contents of dwarf symbols, mainly creating a lookup table for subprograms. The main thing threads would be querying at the same time is dwarf_srclines_from_linecontext / dwarf_lineaddr / dwarf_lineendsequence. Possibly some walking of the children nodes of a subprogram might be needed depending on if I add support for resolving inlined calls. But all that said, I think I am happy locking around libdwarf calls for now. I would be interested in knowing if line table access and die access can be thread safe. |
Beta Was this translation helpful? Give feedback.
-
dwarf_lineaddr() dwarf_lineendsequence() and similar where one passes in dwarf_srclines_from_linecontext() is similar in that the line context Hence locking is required for all of these. The updates involved There are options here I am not mentioning. A Choice one can make with libdwarf Versions of these functions that just returned an integer error code through a pointer would |
Beta Was this translation helpful? Give feedback.
-
Thank you so much! |
Beta Was this translation helpful? Give feedback.
My email response has not appeared here. Hmm.
On reviewing libdwarf source code, I find only one static array, staticerrlist[] a very special
thing for cases with a NULL dbg (and not fussy, it is just there to give dwarf_finish() a
way to free things that could not be in a Dwarf_Debug error allocation.
It is possible that if the caller ensures that , on a given Dwarf_Debug (either directly or
indirectly) only one thread at a time refers to that Dwarf_Debug, that multiple threads
could use libdwarf. But libdwarf, as currently written, is NOT locking anything
or doing anything for thread safety other than ensuring all data used by a Dwarf_Debug
is recorded in that dbg, not recorded in stati…