-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
[Bug]: missing Mutex::Dtor on linux? #1624
Comments
I ended up building a version of abseil (published in a separate channel) with the following patch: diff --git a/absl/synchronization/mutex.cc b/absl/synchronization/mutex.cc
index cb3c7e74..76d561df 100644
--- a/absl/synchronization/mutex.cc
+++ b/absl/synchronization/mutex.cc
@@ -731,12 +731,10 @@ static unsigned TsanFlags(Mutex::MuHow how) {
}
#endif
-#if defined(__APPLE__) || defined(ABSL_BUILD_DLL)
// When building a dll symbol export lists may reference the destructor
// and want it to be an exported symbol rather than an inline function.
// Some apple builds also do dynamic library build but don't say it explicitly.
Mutex::~Mutex() { Dtor(); }
-#endif
#if !defined(NDEBUG) || defined(ABSL_HAVE_THREAD_SANITIZER)
void Mutex::Dtor() {
diff --git a/absl/synchronization/mutex.h b/absl/synchronization/mutex.h
index d53a22bb..2cd5a1e4 100644
--- a/absl/synchronization/mutex.h
+++ b/absl/synchronization/mutex.h
@@ -1064,11 +1064,6 @@ inline Mutex::Mutex() : mu_(0) {
inline constexpr Mutex::Mutex(absl::ConstInitType) : mu_(0) {}
-#if !defined(__APPLE__) && !defined(ABSL_BUILD_DLL)
-ABSL_ATTRIBUTE_ALWAYS_INLINE
-inline Mutex::~Mutex() { Dtor(); }
-#endif
-
#if defined(NDEBUG) && !defined(ABSL_HAVE_THREAD_SANITIZER)
// Use default (empty) destructor in release build for performance reasons.
// We need to mark both Dtor and ~Mutex as always inline for inconsistent With this, the grpc example compiles again. |
Could this simply be a case of the shared library case on linux not being covered correctly? |
@derekmauro @dvyukov, could you comment about the (un-)inlining of the Mutex destructor, or alternatively, chime in on the linked grpc issue if their usage of the Mutex is somehow not supported? |
Do you use bazel or cmake build? I am not an expert on all open-source absl build modes. I see this code does something similar: abseil-cpp/absl/base/internal/thread_identity.h Lines 249 to 252 in 14b8a4e
and it also checks ABSL_CONSUME_DLL. Should we check ABSL_CONSUME_DLL here as well? Though, not sure how this is related to consuming dll's. I see that this: abseil-cpp/absl/copts/AbseilConfigureCopts.cmake Lines 6 to 9 in 14b8a4e
exports ABSL_BUILD_DLL only for Windows (MSVC). Is there a macro for BUILD_SHARED_LIBS mode? Perhaps we should check that macro? |
Hey @dvyukov, thanks for the response. We're using CMake to build, which correctly sets My understanding is that this mechanism originally was intended (only?) for Now the problem only appears on Linux, where usually, It would be functionally equivalent to the patch I posted above, which I already tested successfully. |
If I read your first patch correctly, it effectively undoes the optimization, so it's not good. I am not expect on absl build modes and macros, especially used in open-source. So I will defer this to absl maintainers. @derekmauro do you know who can say what's the right fix for this? |
I'll take a look when I can. Please be patient. |
My intention was not to suggest that the patch should be merged, what I meant was that for our specific scenario (builds against a shared abseil) the removal of the
I hope that a first ping after a week is not considered excessive. 😅 It is blocking a lot of work in our distribution though, so I was mainly looking for overall direction, rather than a fix. For now, I don't even know if this is an issue in abseil or in grpc, but I'm assuming that lots of places implicitly use the Mutex, and since all our builds are shared, I expect this to be too much to fix everywhere on the side of abseil-consumers (though perhaps I'm wrong though and it's grpc-specific after all!). The upshot is that I'm looking towards just uninlining the Dtor (in our distribution) for 20240116.x, which should at least unblock us for now, and we can then reconsider for the summer release. If you think I should hold off on that for |
I haven't tried this, but I ran the build "in my head" (which tends to be unreliable). I think it is likely caused by mixing an installed absl library built with This is one of those build modes I would like to say is not supported, as I regularly have to tell people when they only instrument half of their builds with sanitizers, but the fact of the matter is that with One option which I really don't like is to patch this for open-source users, but keep @dvyukov's optimization for internal Google users only. This would be an annoying maintainability problem. I'll have to test it to see how bad it actually looks. |
Thank you for the response! This is an interesting case, because we do set It's surprising to me that the logic here is Lines 91 to 100 in 2f9e432
rather than, say #ifdef(DEBUG)
<debug-case>
#else
<nodebug-case>
#fi The latter would not open up that footgun of a vanilla build (no options) having a different ABI than one with
I understand, though the realities of a distribution are that we have to use pre-built artefacts. If that means that we have to put |
OK, I misdiagnosed that (probably trying to fit your analysis subconsciously) -- the compiler setup is the same in all cases, so we do set |
Yet another update: while our compiler setup is the same ( |
I have also an issue with the inlined desctructor, but on windows when building static libs of abseil. |
Does this build include inconsistent NDEBUG defines (as @derekmauro mentioned here #1624 (comment))? |
Not that I am aware of. The ortools cmake machinery is quite complex so I cannot easily verify that, maybe I find the time to dig into that more. Another possibility could be a wrongly set or logically incorrect usage of the flag BUILD_ABSL_DLL. |
I'd like to add, for anyone coming across similar problems, that not defining the NDEBUG macro in your Release build will cause very cryptic errors at the linker stage; in my case, a dependency on grpc (and therefore protobuf and abseil) managed via vcpkg in an MSbuild project on Windows produced ODR Violation linker errors exactly in Mutex::Dtor. It wasn't until I randomly stumbled across this exact thread after hours of increasingly desperate internet searches that I noticed the missing NDEBUG definition on my command line. Obvious error in retrospect, but tracing that down backwards from the link stage to the preprocessor was pretty nightmarish. It feels like this should be mentioned in documentation somewhere, so other developers don't have to go through that ordeal. Maybe this comment will help someone directly or serve as a starting point for this information to be more visible to library users. |
my 2 cents for @EddyXorb and @dvyukov
|
Not sure if this is the same issue, but I'm also seeing something when building certain targets with CMake:
Unfortunately the workaround of not inlining Dtor didn't seem to work for me. Interesting this only appears to happen with a few targets, namely our Catch2 unit tests. |
Describe the issue
While conda-forge/grpc-cpp-feedstock#348 grpc with
-DgRPC_ABSL_PROVIDER="package"
in conda-forge against abseil 20240116.0, the sanity check of compiling an example against the library fails:Previously I had opened #1614 and grpc/grpc#35854, but it now looks like this might be related to f3760b4. In particular, the following looks like a likely culprit
abseil-cpp/absl/synchronization/mutex.cc
Lines 734 to 739 in 119e0d3
I'm not sure what grpc does that (apparently) invalidates the assumptions explained in the commit message of that change.
Steps to reproduce the problem
Build https://github.com/grpc/grpc with
-DgRPC_ABSL_PROVIDER="package"
against abseil 20240116.0 and then compile the grpc helloworld example. It would also be possible to replay the recipe we have in conda-forge.What version of Abseil are you using?
20240116.0
What operating system and version are you using?
Linux
What compiler and version are you using?
GCC 12
What build system are you using?
CMake
Additional context
No response
The text was updated successfully, but these errors were encountered: