This is an archive of the discontinued LLVM Phabricator instance.

[mlir] Change ABI breaking use of NDEBUG to LLVM_ENABLE_ABI_BREAKING_CHECKS
ClosedPublic

Authored by zero9178 on Jul 31 2021, 9:56 AM.

Details

Summary

The DataLayout class currently contains the member layoutStack which is hidden behind a preprocessor region dependant on the NDEBUG macro. Code wise this makes a lot of sense, as the layoutStack is used for extra assertions that users will want when compiling a debug build.
It however has the uncomfortable consequence of leading to a different ABI in Debug and Release builds. This I think is a bit annoying for downstream projects and others as they may want to build against a stable Release of MLIR in Release mode, but be able to debug their own project depending on MLIR.

This patch changes the related uses of NDEBUG to LLVM_ENABLE_ABI_BREAKING_CHECKS. As the macro is computed at configure time of LLVM, it may not change based on compiler settings of a downstream projects like NDEBUG would.


As an aside I'd like to ask if MLIR does bug fix cherry picks onto the release branches? Because if accepted I'd like this patch to be cherry picked on the release/13.x branch if that is okay.

Diff Detail

Event Timeline

zero9178 created this revision.Jul 31 2021, 9:56 AM
zero9178 requested review of this revision.Jul 31 2021, 9:56 AM

This makes a lot of sense to me, I agree with your thought process, and this looks obvious. I think @ftynse is the best reviewer though.

This I think is a bit annoying for downstream projects and others as they may want to build against a stable Release of MLIR in Release mode, but be able to debug their own project depending on MLIR.

If I am following what you’re after, this is explicitly something prevented by LLVM: there are even some symbols that are different between debug and release builds to force a link failure (on my phone right now, can’t give you a pointer)

I'm not sure what you mean. LLVM generally doesn't allow ifdef'ing out chunks of data structures on NDEBUG in headers, specifically to prevent this sort of problem.

I'm not sure what you mean. LLVM generally doesn't allow ifdef'ing out chunks of data structures on NDEBUG in headers, specifically to prevent this sort of problem.

I believe Mehdi is referring to
https://lists.llvm.org/pipermail/llvm-dev/2016-November/107148.html ("an [LLVM] assert build isn’t ABI compatible with a release build")

Ok, I don't recall that patch, and it wasn't merged.

Our general policy is that public headers shouldn't change type layouts when assertions are enabled. We do allow that for "expensive checks" though.

Ok, I don't recall that patch, and it wasn't merged.

It was: https://reviews.llvm.org/D26876 ; but it's irrelevant here actually: I incorrectly brought this aspect in the discussion in this patch. Sorry for the added confusion!
So:

  • An LLVM binary ABI depends on the setting of LLVM_ENABLE_ABI_BREAKING_CHECKS, unsurprisingly.
  • The *default* settings if not specified for this is that it gets enabled with assertions and disabled otherwise.

Corollary: release and debug build of LLVM are incompatible with each other, unless the users building with assertions explicitly sets -DLLVM_ENABLE_ABI_BREAKING_CHECKS=OFF as well.

The use of a separate flag (LLVM_ENABLE_ABI_BREAKING_CHECKS vs NDEBUG) allows to decouple the client app NDEBUG config from LLVM NDEBUG config, the important part is to build against LLVM header configured with the same LLVM_ENABLE_ABI_BREAKING_CHECKS as the LLVM binary.
The thing that trips people is to build their app against a debug build of LLVM, and then try to swap with a release build of LLVM and things breaks.
(But that's not what's asked here....)

Our general policy is that public headers shouldn't change type layouts when assertions are enabled. We do allow that for "expensive checks" though.

Yes your right, the correct fix in this patch is to guard this in DataLayoutInterfaces.h with LLVM_ENABLE_ABI_BREAKING_CHECKS instead of NDEBUG.
@zero9178 can you update accordingly?

As an aside I'd like to ask if MLIR does bug fix cherry picks onto the release branches? Because if accepted I'd like this patch to be cherry picked on the release/13.x branch if that is okay.

We haven't been very active in trying to back port patches in release branches, but we've honored every request and this fix seems to be an obvious candidate! Thanks

zero9178 updated this revision to Diff 363333.Jul 31 2021, 10:44 PM

Address review comments:

Replace the uses of NDEBUG that are dependant on the ABI of DataLayout with the macro LLVM_ENABLE_ABI_BREAKING_CHECKS.

mehdi_amini accepted this revision.Jul 31 2021, 11:22 PM

LG! Thanks.

(Need to change title/description to reflect the change)

This revision is now accepted and ready to land.Jul 31 2021, 11:22 PM
zero9178 retitled this revision from [mlir] Remove ABI breaking use of NDEBUG out of header to [mlir] Change ABI breaking use of NDEBUG to LLVM_ENABLE_ABI_BREAKING_CHECKS.Aug 1 2021, 5:00 AM
zero9178 edited the summary of this revision. (Show Details)
zero9178 edited the summary of this revision. (Show Details)