The patch titled Subject: bug.h: Make BUILD_BUG_ON generate compile-time error has been added to the -mm tree. Its filename is bugh-make-build_bug_on-generate-compile-time-error.patch Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/SubmitChecklist when testing your code *** The -mm tree is included into linux-next and is updated there every 3-4 working days ------------------------------------------------------ From: Daniel Santos <daniel.santos@xxxxxxxxx> Subject: bug.h: Make BUILD_BUG_ON generate compile-time error Negative sized arrays wont create a compile-time error in some cases starting with gcc 4.4 (e.g., inlined functions), but gcc 4.3 introduced the error function attribute that will. This patch modifies BUILD_BUG_ON to behave like BUILD_BUG already does, using the error function attribute so that you don't have to build the entire kernel to discover that you have a problem, and then enjoy trying to track it down from a link-time error. Also, we are only including asm/bug.h and then expecting that linux/compiler.h will eventually be included to define __linktime_error (used in BUILD_BUG_ON). This patch includes it directly for clarity and to avoid the possibility of changes in <arch>/*/include/asm/bug.h being changed or not including linux/compiler.h for some reason. Signed-off-by: Daniel Santos <daniel.santos@xxxxxxxxx> Acked-by: Borislav Petkov <bp@xxxxxxxxx> Cc: Andi Kleen <ak@xxxxxxxxxxxxxxx> Cc: David Rientjes <rientjes@xxxxxxxxxx> Cc: Joe Perches <joe@xxxxxxxxxxx> Cc: Josh Triplett <josh@xxxxxxxxxxxxxxxx> Cc: Paul Gortmaker <paul.gortmaker@xxxxxxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- include/linux/bug.h | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff -puN include/linux/bug.h~bugh-make-build_bug_on-generate-compile-time-error include/linux/bug.h --- a/include/linux/bug.h~bugh-make-build_bug_on-generate-compile-time-error +++ a/include/linux/bug.h @@ -2,6 +2,7 @@ #define _LINUX_BUG_H #include <asm/bug.h> +#include <linux/compiler.h> enum bug_trap_type { BUG_TRAP_TYPE_NONE = 0, @@ -43,25 +44,30 @@ struct pt_regs; * @condition: the condition which the compiler should know is false. * * If you have some code which relies on certain constants being equal, or - * other compile-time-evaluated condition, you should use BUILD_BUG_ON to + * some other compile-time-evaluated condition, you should use BUILD_BUG_ON to * detect if someone changes it. * - * The implementation uses gcc's reluctance to create a negative array, but - * gcc (as of 4.4) only emits that error for obvious cases (eg. not arguments - * to inline functions). So as a fallback we use the optimizer; if it can't - * prove the condition is false, it will cause a link error on the undefined - * "__build_bug_on_failed". This error message can be harder to track down - * though, hence the two different methods. + * The implementation uses gcc's reluctance to create a negative array, but gcc + * (as of 4.4) only emits that error for obvious cases (e.g. not arguments to + * inline functions). Luckily, in 4.3 they added the "error" function + * attribute just for this type of case. Thus, we use a negative sized array + * (should always create an error on gcc versions older than 4.4) and then call + * an undefined function with the error attribute (should always create an + * error on gcc 4.3 and later). If for some reason, neither creates a + * compile-time error, we'll still have a link-time error, which is harder to + * track down. */ #ifndef __OPTIMIZE__ #define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)])) #else -extern int __build_bug_on_failed; -#define BUILD_BUG_ON(condition) \ - do { \ - bool __cond = !!(condition); \ - ((void)sizeof(char[1 - 2 * __cond])); \ - if (__cond) __build_bug_on_failed = 1; \ +#define BUILD_BUG_ON(condition) \ + do { \ + bool __cond = !!(condition); \ + extern void __build_bug_on_failed(void) \ + __compiletime_error("BUILD_BUG_ON failed"); \ + if (__cond) \ + __build_bug_on_failed(); \ + ((void)sizeof(char[1 - 2 * __cond])); \ } while(0) #endif _ Patches currently in -mm which might be from daniel.santos@xxxxxxxxx are compiler-gcc4h-reorder-macros-based-upon-gcc-ver.patch compiler-gcch-add-gcc-recommended-gcc_version-macro.patch compiler-gcc34h-use-gcc_version-macro.patch compiler-gcc4h-bugh-remove-duplicate-macros.patch bugh-fix-build_bug_on-macro-in-__checker__.patch bugh-prevent-double-evaulation-of-in-build_bug_on.patch bugh-make-build_bug_on-generate-compile-time-error.patch compilerh-bugh-prevent-double-error-messages-with-build_bug_on.patch bugh-compilerh-introduce-compiletime_assert-build_bug_on_msg.patch -- To unsubscribe from this list: send the line "unsubscribe mm-commits" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html