mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Daniel Santos <daniel.santos@pobox.com>
To: Nick Desaulniers <ndesaulniers@google.com>,
	Kees Cook <keescook@chromium.org>
Cc: Masahiro Yamada <yamada.masahiro@socionext.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	james.hogan@imgtec.com, joe@ovn.org,
	Rusty Russell <rusty@rustcorp.com.au>,
	Arnd Bergmann <arnd@arndb.de>,
	sparse@chrisli.org, linux-sparse@vger.kernel.org,
	LKML <linux-kernel@vger.kernel.org>,
	George Burgess <gbiv@google.com>,
	James Y Knight <jyknight@google.com>
Subject: Re: [RFC PATCH] compiler.h: give up __compiletime_assert_fallback()
Date: Tue, 21 Aug 2018 03:11:18 -0500	[thread overview]
Message-ID: <6b25ce92-7ffa-9fdb-c114-e7aa8f987b06@pobox.com> (raw)
In-Reply-To: <CAKwvOdmPF29ywp-qx7dBTQoZPEE29QwqZL4Un==Z3T_nm0u8cQ@mail.gmail.com>

On 08/19/2018 03:25 PM, Nick Desaulniers wrote:
> + gbiv who wrote this cool paste (showing alternatives to
> _Static_assert, which is supported by both compilers in -std=gnu89,
> but not until gcc 4.6): https://godbolt.org/g/DuLsxu
>
> I can't help but think that BUILD_BUG_ON_MSG should use
> _Static_assert, then have fallbacks for gcc < 4.6.

Unfortunately _Static_assert is a woefully inadequate replacement
because it requires a C constant expression.  Example:

    int a = 1;
    _Static_assert(a == 1, "a != 1");

results in "error: expression in static assertion is not constant." 
Language standards tend to shy away from defining implementation details
like optimizations, but we need to have completed a good data flow
analysis and constant propagation in order to do BUILD_BUG_ON_MSG, et.
al.; this is why they only work when optimizations are enabled.  As the
optimizer improves, new expressions can be used with BUILD_BUG_ON*.  I
did an analysis of this back in 2012 of how various types of variables
could be resolved to constants at compile-time and how that evolved from
gcc 3.4 to 4.7:

https://drive.google.com/open?id=1cQRAAOzjFy6Aw7CDc4QauHvd_spVkd5a

This changed again when -findirect-inline was added -- i.e.,
BUILD_BUG_ON could be used on parameters of inline functions even when
called by pointer, although the caller needed __flatten in some cases --
a bit messy.

Daniel

  parent reply	other threads:[~2018-08-21  8:11 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-19  5:51 Masahiro Yamada
2018-08-19 16:13 ` Kees Cook
2018-08-19 20:25   ` Nick Desaulniers
2018-08-19 20:28     ` Linus Torvalds
2018-08-19 20:36       ` Nick Desaulniers
2018-08-19 20:52         ` Linus Torvalds
2018-08-21  8:11     ` Daniel Santos [this message]
2018-08-25 18:11       ` Masahiro Yamada
2018-08-21 16:15     ` Masahiro Yamada
2018-08-21 19:04       ` Kees Cook

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=6b25ce92-7ffa-9fdb-c114-e7aa8f987b06@pobox.com \
    --to=daniel.santos@pobox.com \
    --cc=akpm@linux-foundation.org \
    --cc=arnd@arndb.de \
    --cc=gbiv@google.com \
    --cc=james.hogan@imgtec.com \
    --cc=joe@ovn.org \
    --cc=jyknight@google.com \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sparse@vger.kernel.org \
    --cc=ndesaulniers@google.com \
    --cc=rusty@rustcorp.com.au \
    --cc=sparse@chrisli.org \
    --cc=torvalds@linux-foundation.org \
    --cc=yamada.masahiro@socionext.com \
    /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

all inboxes | Powered by JetHome®