Because the call to dlerror() may actually want to print something, which turns into a deadlock
as showcased in #49223.
Instead rely on further call to dlsym to clear dlerror internal state if they
need to check the return status.
Differential D128992
[sanitizer] Don't call dlerror() after swift_demangle lookup through dlsym serge-sans-paille on Jul 1 2022, 7:05 AM. Authored by
Details Because the call to dlerror() may actually want to print something, which turns into a deadlock Instead rely on further call to dlsym to clear dlerror internal state if they
Diff Detail
Event Timeline
Comment Actions For the technicalities, I agree with Vitaly. However, @rsundahl has discovered that the whole "strong overrides weak symbol across dylibs" pattern isn't reliably anymore. See here: https://reviews.llvm.org/D127929 Also: does this still work right now? Should depend on the swift runtime dylib defining a weak symbol/being marked as in participating in weak symbol lookup. Can we promise that the Swift runtime dylib will always define a weak symbol?
Comment Actions There are very significant differences between Linux, Windows and Darwin w.r.t. how weak symbols are (possibly) overridden by so-called "strong" symbols. The discussion with @MaskRay in https://reviews.llvm.org/D127929 is worth a look for context but I would encourage moving in the other direction, completely away from weak symbols and/or any expectation that the loader will "do what we want it to do". Comment Actions The file handles ELF systems and macOS. It doesn't deal with Windows. Comment Actions Another approach: make sure swift_demangle is setup before or after symbol lookup, but not during interception. Comment Actions Please update description, as this approach does not match, it still uses dlsym. Can you show a pseudo-stack trace of the case you are trying to solve? Comment Actions title is still "Don't lookup swift_demangle through dlsym"
legit but unnecessary. Most code in sanitizer does not call dlerror after dlsym.
We don't check dlerror here, so it's up to the next caller to clear it before next dlsym, and only if they care about dlerror. Comment Actions compiler-rt/lib/interception/interception_linux.cpp is the main and very early origin of dlsym calls for sanitizers
|
Unrelated to the patch, but this is used only in sanitizer_symbolizer_mac.cpp, so it's better to be moved there.