Linux NILFS development
 help / color / mirror / Atom feed
From: Hitoshi Mitake <mitake.hitoshi-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: Ryusuke Konishi
	<konishi.ryusuke-Zyj7fXuS5i5L9jVzuh4AOg@public.gmane.org>
Cc: Hitoshi Mitake
	<mitake.hitoshi-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
	linux-nilfs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	Hitoshi Mitake
	<mitake.hitoshi-Zyj7fXuS5i5L9jVzuh4AOg@public.gmane.org>,
	Vyacheslav Dubeyko
	<slava-yeENwD64cLxBDgjK7y7TUQ@public.gmane.org>
Subject: Re: [PATCH] mkfs: check sizes of important structs at build time
Date: Mon, 06 Jan 2014 00:22:22 +0900	[thread overview]
Message-ID: <87wqiea1xt.wl%mitake.hitoshi@gmail.com> (raw)
In-Reply-To: <20140105.010843.356918311.konishi.ryusuke-Zyj7fXuS5i5L9jVzuh4AOg@public.gmane.org>

At Sun, 05 Jan 2014 01:08:43 +0900 (JST),
Ryusuke Konishi wrote:
> 
> On Sat,  4 Jan 2014 22:29:31 +0900, Hitoshi Mitake wrote:
> > Current nilfs_check_ondisk_sizes() checks sizes of important structs
> > at run time. The checking should be done at build time. This patch
> > adds a new macro, BUILD_BUG_ON(), for this purpose. It is similar to
> > static_assert() of C++11. If an argument is true, the macro causes a
> > bulid error.
> > 
> > Below is an example of BUILD_BUG_ON(). When the checked conditions are
> > true like below:
> > 
> > /* intentional change for testing BUILD_BUG_ON() */
> > 
> > static __attribute__((used)) void nilfs_check_ondisk_sizes(void)
> > {
> > 	BUILD_BUG_ON(sizeof(struct nilfs_inode) > NILFS_MIN_BLOCKSIZE);
> > ...
> > 
> > build process of mkfs.o causes errors like this:
> > 
> > gcc -std=gnu99 -DHAVE_CONFIG_H -I. -I../..  -I../../include  -Wall -g -O2 -MT mkfs.o -MD -MP -MF .deps/mkfs.Tpo -c -o mkfs.o mkfs.c
> > mkfs.c: In function 'nilfs_check_ondisk_sizes':
> > mkfs.c:429:2: error: negative width in bit-field '<anonymous>'
> > mkfs.c:430:2: error: negative width in bit-field '<anonymous>'
> > mkfs.c:431:2: error: negative width in bit-field '<anonymous>'
> > mkfs.c:432:2: error: negative width in bit-field '<anonymous>'
> > mkfs.c:433:2: error: negative width in bit-field '<anonymous>'
> > mkfs.c:434:2: error: negative width in bit-field '<anonymous>'
> > mkfs.c:435:2: error: negative width in bit-field '<anonymous>'
> > 
> > Signed-off-by: Hitoshi Mitake <mitake.hitoshi-Zyj7fXuS5i5L9jVzuh4AOg@public.gmane.org>
> 
> This is an interesting patch.
> 
> I am inclined to apply this since the every test in the
> nilfs_check_ondisk_sizes function is static.
> 
> If we will add a new check that depends on block size in a future, we
> need to add a separate runtime check function as Vyacheslav wrote, but
> I think you are doing right thing.
> 
> One my question is why you used bit operator.  The BUILD_BUG_ON marcro
> of kernel is implemented with negative array index.
> Is there any reason for this ?

If I remember correctly, I found in the BUILD_BUG_ON() in the code of Xen. I
don't have any opinion about how we implement the check. If you like the way of
array with negative length, I will employ it in v2.

BTW, there is another approach of the implementation.

#define static_assert(a, b) do { switch (0) case 0: case (a): ; } while (0)
# from xv6: http://pdos.csail.mit.edu/6.828/2012/xv6.html

This duplicated case of switch statement can be used to implement
BUILD_BUG_ON() (the b can be used as an error message).

Which one do you like?

Thanks,
Hitoshi
--
To unsubscribe from this list: send the line "unsubscribe linux-nilfs" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  parent reply	other threads:[~2014-01-05 15:22 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-04 13:29 [PATCH] mkfs: check sizes of important structs at build time Hitoshi Mitake
     [not found] ` <1388842171-16105-1-git-send-email-mitake.hitoshi-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2014-01-04 14:52   ` Vyacheslav Dubeyko
     [not found]     ` <EF28F22A-C43F-41C9-A5B9-8597C5879E3E-yeENwD64cLxBDgjK7y7TUQ@public.gmane.org>
2014-01-04 13:54       ` Hitoshi Mitake
     [not found]         ` <CAE1WaKLr1EuovgHgXQa1o9LQVk1fRkUXbDrGiKfsdTB347ieqg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-01-04 15:39           ` Vyacheslav Dubeyko
     [not found]             ` <2276BC9A-0688-4566-8FA8-D280E6F71F5F-yeENwD64cLxBDgjK7y7TUQ@public.gmane.org>
2014-01-05 15:17               ` Hitoshi Mitake
2014-01-04 16:08   ` Ryusuke Konishi
     [not found]     ` <20140105.010843.356918311.konishi.ryusuke-Zyj7fXuS5i5L9jVzuh4AOg@public.gmane.org>
2014-01-05 15:22       ` Hitoshi Mitake [this message]
     [not found]         ` <87wqiea1xt.wl%mitake.hitoshi-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2014-01-05 17:17           ` Ryusuke Konishi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87wqiea1xt.wl%mitake.hitoshi@gmail.com \
    --to=mitake.hitoshi-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
    --cc=konishi.ryusuke-Zyj7fXuS5i5L9jVzuh4AOg@public.gmane.org \
    --cc=linux-nilfs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=mitake.hitoshi-Zyj7fXuS5i5L9jVzuh4AOg@public.gmane.org \
    --cc=slava-yeENwD64cLxBDgjK7y7TUQ@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox