Gcc ABI compatibility (lambda captures)


We have an issue where MLIR compiled with clang, exposed to a user building their code with gcc fails: [MLIR] Project compiled using `gcc` links incorrectly to `mlir` compiled with `clang` causing invalid memory access. · Issue #62918 · llvm/llvm-project · GitHub

The issue seems to be around ABI incompatibility on lambda captures. Namely clang and gcc seem to capture with a different order.

What’s clang aim in terms of compatibility with gcc? Is this a bug or expected? If expected, is this case (and others?) documented? Do we have “sanitizers” to defend against this (clang-tidy checks maybe)?


clang is supposed to be ABI compatible with gcc on Linux, barring bugs. (This is target-dependent; on Mac, for example, Apple clang is the platform compiler, so that’s the primary compatibility target.)

For how this particular mismatch happened, see Lambda ABI mismatch · Issue #141 · itanium-cxx-abi/cxx-abi · GitHub ; basically, there’s a hole in the ABI specification, and nobody has spent the time necessary to push the fix forward.

1 Like

Thanks! I filed a bug with gcc: 109963 – ABI: unexpected layout ordering of `this` pointer in lambda capture ; we’ll see where this goes!

1 Like