Re: [PATCH, RFC] libxfs: check the size of on-disk data structures

Christoph Hellwig
2023-11-10T18:00:24Z

On Thu, Nov 09, 2023 at 11:52:33AM -0800, Darrick J. Wong wrote:
> > +#ifndef BUILD_BUG_ON_MSG
> > +#define BUILD_BUG_ON_MSG(a, b) BUILD_BUG_ON(a)
>
> How difficult would it be to port the complex kernel macros that
> actually result in the message being emitted in the gcc error output?
>
> It's helpful that when the kernel build breaks, the robots will report
> exactly which field/struct/whatever tripped, which makes it easier to
> start figuring out where things went wrong on some weird architecture.

I did try to pull the entire compile time assert machinery from
the kernels compiler_types.h in, especially as atomic.h already uses
a differnet part of it. After it pulled in two more depdendencies
I gave up, but in principle it should be entirely doable.

> Otherwise I'm all for porting xfs_ondisk.h to xfsprogs. IIRC I tried
> that a long time ago and Dave or someone said xfs/122 was the answer.

I'd much prefer to do it in C code and inside the libxfs we build.
If we can agree on that and on killing off xfs/122 I'll look into
porting the more complex compile time assert.

The other option would be to switch to using static_assert from C11,
which doesn't allow a custom message, but at least the default message
isn't confusing as hell.