-
-
Notifications
You must be signed in to change notification settings - Fork 185
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
NDEBUG flag breaks binary compatibility, which can cause mysterious crashes #272
Comments
Hi @kosak! Good find. I think you're right. I'm happy with option 1. When you make the PR, maybe you can add a CMake flag ( |
Two full days I've spent narrowing down a test case in jank, thinking this was due to UB in Clang 19's JIT compilation. After ruling everything else out, I could only reproduce the issue with immer containers. I didn't spot the issue myself, and I wasn't close to doing so. Fortunately I did take a look at the open issues, though. @kosak, you're a saint. Thanks for finding this and making the issue. For me, the way it showed up is that jank is compiled with optimizations for release builds, but it doesn't enable optimizations by default for JIT compiled code (those functions can be later optimized on demand). I can work around this for now by just defining |
Thank you for the kind words. I'm so glad it helped you! Regarding "saint", recently I've been feeling pretty guilty for not following up with a fix. I could finally put something together or if someone else wants to do that, that's fine too. |
The fix is all yours, if you're up for it, my dude. 🙇 |
@kosak a fix would be very welcome! |
Code in
immer/config.hpp
causesIMMER_TAGGED_NODE
to be set to 0 or 1 according to whetherNDEBUG
is defined. This in turn affects the definition ofimmer::detail::rbts::node
; in particular whether or notimpl_data_t
contains akind_t kind
field.This can cause problems if user code compiled with
NDEBUG
set is linked to other code compiled withoutNDEBUG
, because the Immer data structures are not binary compatible between these two versions.This situation can arise in a complicated build system where libraries are built by different build steps. Even though ideally one should try to have a coherent set of flags in all cases, I think people expect
NDEBUG
to be harmless, at most controlling whether assertions are enabled or perhaps turning on some log messages. In my opinion it would be surprising to learn thatNDEBUG
would break binary compatibility. In my company's case we had Rcpp building some of our code and it used anNDEBUG
flag in its build steps.In the example below, the code in
main.cpp
doesn't even call the code inutil.cpp
, bututil.cpp
poisons the binary, causingmain.cpp
to crash. Steps to reproduce:Command:
This can be a tricky thing to diagnose and debug. In my opinion, Immer ought to do one of two things. Either:
IMMER_TAGGED_NODE
(norIMMER_ENABLE_DEBUG_SIZE_HEAP
); if the programmer wants these behaviors they should have to set those flags explicitly and not get them viaNDEBUG
.or:
node
data structure and any code referencing thenode
data structure). This would have the nice property that the two versions could coexist side-by-side and in the worst case an inconsistency would lead to a link error rather than a mysterious crash.If you agree, I would be happy to contribute code for item 1 or 2, once I know what your preference is.
The text was updated successfully, but these errors were encountered: