lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Sun, 30 Sep 2012 18:29:01 -0500
From:	Daniel Santos <danielfsantos@....net>
To:	Josh Triplett <josh@...htriplett.org>
CC:	Daniel Santos <daniel.santos@...ox.com>,
	LKML <linux-kernel@...r.kernel.org>,
	Andi Kleen <ak@...ux.intel.com>,
	Andrea Arcangeli <aarcange@...hat.com>,
	Andrew Morton <akpm@...ux-foundation.org>,
	Christopher Li <sparse@...isli.org>,
	David Daney <david.daney@...ium.com>,
	David Howells <dhowells@...hat.com>,
	Joe Perches <joe@...ches.com>,
	Konstantin Khlebnikov <khlebnikov@...nvz.org>,
	linux-sparse@...r.kernel.org,
	Michel Lespinasse <walken@...gle.com>,
	Paul Gortmaker <paul.gortmaker@...driver.com>,
	Pavel Pisa <pisa@....felk.cvut.cz>,
	Peter Zijlstra <a.p.zijlstra@...llo.nl>,
	Steven Rostedt <rostedt@...dmis.org>
Subject: Re: [PATCH 8/10] bug.h: Make BUILD_BUG_ON generate compile-time error

On 09/28/2012 09:55 PM, Josh Triplett wrote:
> Assuming you don't call BUILD_BUG_ON_MSG more than once per line:
>
> /tmp$ cat test.c
> #define BUILD_BUG_ON_MSG_INTERNAL2(cond, msg, line) \
>     do { \
>         extern void __build_bug_on_failed_ ## line (void) __attribute__((error(msg))); \
>         if (cond) \
>             __build_bug_on_failed_ ## line(); \
>     } while (0)
>
> #define BUILD_BUG_ON_MSG_INTERNAL(cond, msg, line) BUILD_BUG_ON_MSG_INTERNAL2(cond, msg, line)
> #define BUILD_BUG_ON_MSG(cond, msg) BUILD_BUG_ON_MSG_INTERNAL(cond, msg, __LINE__)
>
> void f(void)
> {
>     BUILD_BUG_ON_MSG(0, "test 1");
>     BUILD_BUG_ON_MSG(1, "test 2");
>     BUILD_BUG_ON_MSG(0, "test 3");
>     BUILD_BUG_ON_MSG(1, "test 4");
> }
> /tmp$ gcc -c test.c
> test.c: In function ‘f’:
> test.c:14:119: error: call to ‘__build_bug_on_failed_14’ declared with attribute error: test 2
> test.c:16:119: error: call to ‘__build_bug_on_failed_16’ declared with attribute error: test 4
Thanks! This is very nice!  I've done a little more research and
discovered that there's also a __COUNTER__ macro that is available
in gcc 4.3+.  Before I realized that it was only available in gcc
4.3, I wrote this little macro:

#define _CONCAT1(a, b) a##b
#define CONCAT(a, b) _CONCAT1(a, b)

#ifdef __COUNTER__
# define UNIQUIFY(prefix) CONCAT(prefix, __COUNTER__)
#else
# define UNIQUIFY(prefix) CONCAT(prefix, __LINE__)
#endif

However, this could lead to code might compile on gcc 4.3+, but
not compile prior, so this is bad, right?

Daniel

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ