BUILD_BUG_ON improvements
Subsystems (3)
The following changes since commit b8a7f3cd7e8212e5c572178ff3b5a514861036a5:
Linus Torvalds (1):
Merge branch 'master' of git://git.kernel.org/.../viro/vfs-2.6
are available in the git repository at:
ssh://master.kernel.org/pub/scm/linux/kernel/git/rusty/linux-2.6-for-linus.git BUILD_BUG_ON
Rusty Russell (3):
BUILD_BUG_ON: make it handle more cases Remove MAYBE_BUILD_BUG_ON
kernel.h: move BUILD_BUG_ON et al inside __KERNEL__
include/linux/gfp.h | 2 +- include/linux/kernel.h | 80 +++++++++++++++++++++++++---------------- include/linux/kmemcheck.h | 2 +- include/linux/virtio_config.h | 5 ++- 4 files changed, 55 insertions(+), 34 deletions(-)
commit a7a9f439b8380b930a47a0b17b217f87458844f6
Author: Rusty Russell <[email protected]> Date: Fri Dec 18 12:32:55 2009 -0600
BUILD_BUG_ON: make it handle more cases
BUILD_BUG_ON used to use the optimizer to do code elimination or fail at link time; it was changed to first the size of a negative array (a nicer compile time error), then (in 8c87df457cb58fe75b9b893007917cf8095660a0) to a bitfield.
bitfields: needs a literal constant at parse time, and can't be put under
"if (__builtin_constant_p(x))" for example.
negative array: can handle anything, but if the compiler can't tell it's
a constant, silently has no effect.
link time: breaks link if the compiler can't determine the value, but the
linker output is not usually as informative as a compiler error.
If we use the negative-array-size method *and* the link time trick, we get the ability to use BUILD_BUG_ON() under __builtin_constant_p() branches, and maximal ability for the compiler to detect errors at build time.
include/linux/kernel.h | 33 +++++++++++++++++++++++++++------ 1 files changed, 27 insertions(+), 6 deletions(-)
commit 7f6d9e683ab862e7b102d65766c131bc6136e6ca
Author: Rusty Russell <[email protected]> Date: Fri Dec 18 12:32:57 2009 -0600
Remove MAYBE_BUILD_BUG_ON
Now BUILD_BUG_ON() can handle optimizable constants, we don't need MAYBE_BUILD_BUG_ON any more.
include/linux/gfp.h | 2 +- include/linux/kernel.h | 1 - include/linux/kmemcheck.h | 2 +- include/linux/virtio_config.h | 5 ++++- 4 files changed, 6 insertions(+), 4 deletions(-)
commit 10b483dd7905f59062f7aa2986a1d4c7f5129dc3
Author: Rusty Russell <[email protected]> Date: Fri Dec 18 12:32:58 2009 -0600
kernel.h: move BUILD_BUG_ON et al inside __KERNEL__
Recent warning caused by change in BUILD_BUG_ON:
usr/include/linux/kernel.h:53: userspace cannot call function or variable defined in the kernel
Macros no longer accessible to userspace:
BUILD_BUG_ON_ZERO, BUILD_BUG_ON_NULL, BUILD_BUG_ON, __FUNCTION__, NUMA_BUILD, REBUILD_DUE_TO_FTRACE_MCOUNT_RECORD.
(The last two were in #ifdef CONFIG anyway, so already useless).
Also, avoid silly re-test of __KERNEL__ immediately below.
include/linux/kernel.h | 50 +++++++++++++++++++++++------------------------ 1 files changed, 24 insertions(+), 26 deletions(-)
include/linux/gfp.h +1 -1
@@ -220,7 +220,7 @@ static inline enum zone_type gfp_zone(gfp_t flags) ((1 <<ZONES_SHIFT ) -1 );if (__builtin_constant_p (bit)) -MAYBE_BUILD_BUG_ON ((GFP_ZONE_BAD >> bit) &1 ); +BUILD_BUG_ON ((GFP_ZONE_BAD >> bit) &1 );else {#ifdef CONFIG_DEBUG_VM BUG_ON ((GFP_ZONE_BAD >> bit) &1 );
include/linux/kernel.h +49 -31
94 lines not on this page · raw message
include/linux/kmemcheck.h +1 -1
@@ -152,7 +152,7 @@ static inline bool kmemcheck_is_obj_initialized(unsigned long addr, size_t size) \ _n = (long) &((ptr)->name##_end) \ - (long) &((ptr)->name##_begin); \ -MAYBE_BUILD_BUG_ON (_n <0 ); \ +BUILD_BUG_ON (_n <0 ); \ \ kmemcheck_mark_initialized(&((ptr)->name##_begin), _n); \ }while (0 )
include/linux/virtio_config.h +4 -1
@@ -109,7 +109,10 @@ static inline bool virtio_has_feature(const struct virtio_device *vdev, unsigned int fbit) {/* Did you forget to fix assumptions on max features? */ -MAYBE_BUILD_BUG_ON (fbit >=32 ); +if (__builtin_constant_p (fbit)) +BUILD_BUG_ON (fbit >=32 ); +else +BUG_ON (fbit >=32 );if (fbit <VIRTIO_TRANSPORT_F_START )virtio_check_driver_offered_feature (vdev, fbit);