-
Notifications
You must be signed in to change notification settings - Fork 15.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
Fix #9947: make the ABI identical between debug and non-debug builds #10271
Conversation
@@ -77,15 +77,19 @@ class PROTOBUF_EXPORT InternalMetadata { | |||
GOOGLE_DCHECK(!is_message_owned || arena != nullptr); | |||
} | |||
|
|||
#if defined(NDEBUG) || defined(_MSC_VER) | |||
// To keep the ABI identical between debug and non-debug builds, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You probably know this, but just in case. This preserves the ABI, but would make it an ODR violation to link code with NDEBUG
and without NDEBUG
. The ODR rules require that all definitions of an inline function be identical:
Each such definition shall consist of the same sequence of tokens, where the definition of a closure type
is considered to consist of the sequence of tokens of the corresponding lambda-expression.
I am not sure how to quote the standard, but this draft:
https://isocpp.org/files/papers/N4860.pdf
"6.3 One-definition rule", paragraph 13.8
I am well aware that such violations of the ODR are mostly harmless.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it was already stated on the linked issue as a reason to not bother with the ABI problem.
However, as you also noted, all Unix compilers pretty much have to deal nicely with this as the practice of building in debug mode against non-debug dependencies is extremely widespread. So the compiler/linker will end up selecting one implementation over another; which one exactly doesn't really matter in practice (the only difference being the added debug checks).
Windows is different and there you pretty much have to match the build mode accross all dependencies for other reasons.
Code looks ok. Kicking off a test cycle of our CI. I am seeing some unrelated C# failures already and have pinged the person responsible for those. |
We have a 21.x release coming later this week (god willing and the creek don't rise). I will make sure this gets into it. |
#10272 should have fixed the distcheck errors so you will need to rebase on top of that |
e7eaff8
to
0574167
Compare
Ok, I rebased. |
Thank you @fowles ! |
No problem. I do want to be clear that this is never a configuration we will officially support. We will continue to review PRs on a best effort basis for it, but you are in the danger zone. I am sorry that a bunch of my earlier communication on this made it seem like a very hard "no" and not more of "you are in the land of dragons and we will only go so far with you". |
It sounds like this requirement could be made explicit by ensuring that Lines 79 to 81 in 3b456bf
Apparently |
Wouldn't that make it quite difficult to use |
@adamnovak ideally, when compiling with asserts enabled you would also compile protobuf with asserts enabled. (We actually have a bunch of extra asserts that will help users catch bugs in their handling of protobuffers) |
Yes, and for that matter I'm very grateful that @fowles opted for still best-effort supporting this. Ideally protobuf would not choose a macro that clashes with a |
I am not opposed to having a |
I think Protobuf could still keep using the NDEBUG macro name internally if there were a way to make sure it had the right state in the Protobuf headers, independent of the state it needs to have in the application code that includes them. One way to do this would be to frame the places where the ABI depends on Something like: Leading header (include after all other Protobuf headers in Protobuf headers with variable ABIs):
Trailing header (include at the end of all Protobuf headers that include the leading header):
Then in use it would look like:
If you set it up like that, Then if Whatever the final answer is, it probably would want to work well with CMake's |
No description provided.