tools: lift BUILD_BUG_ON to a tools header file
PATCH 1/1 tools: lift BUILD_BUG_ON to a tools header file
Only define BUILD_BUG_ON when there isn't one already, because mini-os currently leaks that.
---
Cc: Ian Jackson <[email protected]>
Cc: Paulina Szubarczyk <[email protected]>
This is a patch taken out of my branch to clean up some build system issues. It is still a bit ugly because BUILD_BUG_ON is conditionally defined to work around mini-os leaking BUILD_BUG_ON.
Either this patch or "[PATCH v2] libs/gnttab: introduce XENGNTTAB_BUILD_BUG_ON" should be taken to unblock Paulina's work.
--- tools/firmware/hvmloader/rombios.c | 1 + tools/firmware/hvmloader/smbios.c | 1 + tools/firmware/hvmloader/util.h | 1 - tools/include/xen-tools/libs.h | 11 +++++++++++ tools/libxc/xc_core_arm.c | 4 +++- tools/libxc/xc_cpuid_x86.c | 15 ++++++++------- tools/libxc/xc_dom_arm.c | 3 ++- tools/libxc/xc_dom_bzimageloader.c | 4 +++- tools/libxc/xc_pm.c | 6 ++++-- tools/libxc/xc_private.h | 7 ------- tools/libxc/xc_sr_common.c | 24 +++++++++++++----------- tools/libxl/libxl_internal.h | 8 -------- tools/libxl/libxl_psr.c | 1 + 13 files changed, 47 insertions(+), 39 deletions(-) create mode 100644 tools/include/xen-tools/libs.h
tools/firmware/hvmloader/rombios.c +1 -0
@@ -31,6 +31,7 @@#include "option_rom.h" #include <xen/hvm/params.h> +#include <xen-tools/libs.h> #define ROM_INCLUDE_ROMBIOS #define ROM_INCLUDE_VGABIOS
tools/firmware/hvmloader/smbios.c +1 -0
@@ -26,6 +26,7 @@#include "util.h" #include "hypercall.h" #include <xen/hvm/hvm_xs_strings.h> +#include <xen-tools/libs.h> /* SBMIOS handle base values */ #define SMBIOS_HANDLE_TYPE0 0x0000
tools/firmware/hvmloader/util.h +0 -1
@@ -41,7 +41,6 @@ void __assert_failed(char *assertion, char *file, int line)void __bug (char *file,int line) __attribute__((noreturn));#define BUG () __bug(__FILE__, __LINE__)#define BUG_ON (p) do { if (p) BUG(); } while (0) -#define BUILD_BUG_ON (p) ((void)sizeof(char[1 - 2 * !!(p)]))#define min_t (type,x,y) \ ({ type __x = (x); type __y = (y); __x < __y ? __x: __y; })
tools/include/xen-tools/libs.h new file +11 -0
@@ -0,0 +1,11 @@ +#ifndef __XEN_TOOLS_LIBS__ + +#ifndef BUILD_BUG_ON +#if __GNUC__ >4 || (__GNUC__ ==4 && __GNUC_MINOR__ >=6 ) +#define BUILD_BUG_ON (p) ({ _Static_assert(!(p), "!(" #p ")"); }) +#else +#define BUILD_BUG_ON (p) ((void)sizeof(char[1 - 2 * !!(p)])) +#endif +#endif + +#endif /* __XEN_TOOLS_LIBS__ */
tools/libxc/xc_core_arm.c +3 -1
@@ -19,6 +19,8 @@#include "xg_private.h" #include "xc_core.h" +#include <xen-tools/libs.h> +int xc_core_arch_gpfn_may_present (struct xc_core_arch_context *arch_ctxt,unsigned long pfn)
@@ -101,7 +103,7 @@ xc_core_arch_get_scratch_gpfn(xc_interface *xch, domid_t domid,* The Grant Table region space is not used until the guest is * booting. Use the first page for the scratch pfn. */ -XC_BUILD_BUG_ON (GUEST_GNTTAB_SIZE <XC_PAGE_SIZE ); +BUILD_BUG_ON (GUEST_GNTTAB_SIZE <XC_PAGE_SIZE ); *gpfn =GUEST_GNTTAB_BASE >>XC_PAGE_SHIFT ;
tools/libxc/xc_cpuid_x86.c +8 -7
@@ -25,6 +25,7 @@#include "xc_private.h" #include "xc_bitops.h" #include <xen/hvm/params.h> +#include <xen-tools/libs.h> enum {#define XEN_CPUFEATURE(name, value) X86_FEATURE_##name = value,
@@ -98,12 +99,12 @@ const uint32_t *xc_get_static_cpu_featuremask( hvm_hap[FEATURESET_NR_ENTRIES ] =INIT_HVM_HAP_FEATURES , deep_features[FEATURESET_NR_ENTRIES ] =INIT_DEEP_FEATURES ; -XC_BUILD_BUG_ON (ARRAY_SIZE (known) !=FEATURESET_NR_ENTRIES ); -XC_BUILD_BUG_ON (ARRAY_SIZE (special) !=FEATURESET_NR_ENTRIES ); -XC_BUILD_BUG_ON (ARRAY_SIZE (pv) !=FEATURESET_NR_ENTRIES ); -XC_BUILD_BUG_ON (ARRAY_SIZE (hvm_shadow) !=FEATURESET_NR_ENTRIES ); -XC_BUILD_BUG_ON (ARRAY_SIZE (hvm_hap) !=FEATURESET_NR_ENTRIES ); -XC_BUILD_BUG_ON (ARRAY_SIZE (deep_features) !=FEATURESET_NR_ENTRIES ); +BUILD_BUG_ON (ARRAY_SIZE (known) !=FEATURESET_NR_ENTRIES ); +BUILD_BUG_ON (ARRAY_SIZE (special) !=FEATURESET_NR_ENTRIES ); +BUILD_BUG_ON (ARRAY_SIZE (pv) !=FEATURESET_NR_ENTRIES ); +BUILD_BUG_ON (ARRAY_SIZE (hvm_shadow) !=FEATURESET_NR_ENTRIES ); +BUILD_BUG_ON (ARRAY_SIZE (hvm_hap) !=FEATURESET_NR_ENTRIES ); +BUILD_BUG_ON (ARRAY_SIZE (deep_features) !=FEATURESET_NR_ENTRIES );switch ( mask ) {
@@ -139,7 +140,7 @@ const uint32_t *xc_get_feature_deep_deps(uint32_t feature)unsigned int start =0 , end =ARRAY_SIZE (deep_deps); -XC_BUILD_BUG_ON (ARRAY_SIZE (deep_deps) !=NR_DEEP_DEPS ); +BUILD_BUG_ON (ARRAY_SIZE (deep_deps) !=NR_DEEP_DEPS );/* deep_deps[] is sorted. Perform a binary search. */ while ( start < end )
tools/libxc/xc_dom_arm.c +2 -1
@@ -21,6 +21,7 @@#include <xen/xen.h> #include <xen/io/protocols.h> +#include <xen-tools/libs.h> #include "xg_private.h" #include "xc_dom.h"
@@ -69,7 +70,7 @@ static int alloc_magic_pages(struct xc_dom_image *dom)const xen_pfn_t base =GUEST_MAGIC_BASE >>XC_PAGE_SHIFT ;xen_pfn_t p2m[NR_MAGIC_PAGES ]; -XC_BUILD_BUG_ON (NR_MAGIC_PAGES >GUEST_MAGIC_SIZE >>XC_PAGE_SHIFT ); +BUILD_BUG_ON (NR_MAGIC_PAGES >GUEST_MAGIC_SIZE >>XC_PAGE_SHIFT );DOMPRINTF_CALLED (dom->xch);
tools/libxc/xc_dom_bzimageloader.c +3 -1
@@ -34,6 +34,8 @@#include "xg_private.h" #include "xc_dom_decompress.h" +#include <xen-tools/libs.h> +#ifndef __MINIOS__#if defined(HAVE_BZLIB )
@@ -418,7 +420,7 @@ static int xc_try_lzo1x_decode(* lzo_uint should match size_t. Check that this is the case to be * sure we won't overflow various lzo_uint fields. */ -XC_BUILD_BUG_ON (sizeof (lzo_uint) !=sizeof (size_t )); +BUILD_BUG_ON (sizeof (lzo_uint) !=sizeof (size_t )); ret =lzo_init ();if ( ret !=LZO_E_OK )
tools/libxc/xc_pm.c +4 -2
@@ -21,6 +21,8 @@#include <stdbool.h> #include "xc_private.h" +#include <xen-tools/libs.h> +/* * Get PM statistic info */
@@ -274,8 +276,8 @@ int xc_get_cpufreq_para(xc_interface *xch, int cpuid, sys_para->scaling_governor, CPUFREQ_NAME_LEN);/* copy to user_para no matter what cpufreq governor */ -XC_BUILD_BUG_ON (sizeof (((struct xc_get_cpufreq_para *)0 )->u) != -sizeof (((struct xen_get_cpufreq_para *)0 )->u)); +BUILD_BUG_ON (sizeof (((struct xc_get_cpufreq_para *)0 )->u) != +sizeof (((struct xen_get_cpufreq_para *)0 )->u));memcpy (&user_para->u, &sys_para->u,sizeof (sys_para->u)); }
tools/libxc/xc_private.h +0 -7
@@ -72,13 +72,6 @@ struct iovec {#define PAGE_SIZE XC_PAGE_SIZE#define PAGE_MASK XC_PAGE_MASK -/* Force a compilation error if condition is true */ -#if __GNUC__ >4 || (__GNUC__ ==4 && __GNUC_MINOR__ >=6 ) -#define XC_BUILD_BUG_ON (p) ({ _Static_assert(!(p), "!(" #p ")"); }) -#else -#define XC_BUILD_BUG_ON (p) ((void)sizeof(struct { int:-!!(p); })) -#endif -#ifndef ARRAY_SIZE /* MiniOS leaks ARRAY_SIZE into our namespace as part of a * stubdom build. It shouldn't... */ #define ARRAY_SIZE (a) (sizeof(a) / sizeof(a[0]))
tools/libxc/xc_sr_common.c +13 -11
@@ -2,6 +2,8 @@#include "xc_sr_common.h" +#include <xen-tools/libs.h> +static const char *dhdr_types[] = { [DHDR_TYPE_X86_PV ] ="x86 PV" ,
@@ -140,17 +142,17 @@ int read_record(struct xc_sr_context *ctx, int fd, struct xc_sr_record *rec)static void __attribute__((unused))build_assertions (void ) { -XC_BUILD_BUG_ON (sizeof (struct xc_sr_ihdr ) !=24 ); -XC_BUILD_BUG_ON (sizeof (struct xc_sr_dhdr ) !=16 ); -XC_BUILD_BUG_ON (sizeof (struct xc_sr_rhdr ) !=8 ); - -XC_BUILD_BUG_ON (sizeof (struct xc_sr_rec_page_data_header ) !=8 ); -XC_BUILD_BUG_ON (sizeof (struct xc_sr_rec_x86_pv_info ) !=8 ); -XC_BUILD_BUG_ON (sizeof (struct xc_sr_rec_x86_pv_p2m_frames ) !=8 ); -XC_BUILD_BUG_ON (sizeof (struct xc_sr_rec_x86_pv_vcpu_hdr ) !=8 ); -XC_BUILD_BUG_ON (sizeof (struct xc_sr_rec_tsc_info ) !=24 ); -XC_BUILD_BUG_ON (sizeof (struct xc_sr_rec_hvm_params_entry ) !=16 ); -XC_BUILD_BUG_ON (sizeof (struct xc_sr_rec_hvm_params ) !=8 ); +BUILD_BUG_ON (sizeof (struct xc_sr_ihdr ) !=24 ); +BUILD_BUG_ON (sizeof (struct xc_sr_dhdr ) !=16 ); +BUILD_BUG_ON (sizeof (struct xc_sr_rhdr ) !=8 ); + +BUILD_BUG_ON (sizeof (struct xc_sr_rec_page_data_header ) !=8 ); +BUILD_BUG_ON (sizeof (struct xc_sr_rec_x86_pv_info ) !=8 ); +BUILD_BUG_ON (sizeof (struct xc_sr_rec_x86_pv_p2m_frames ) !=8 ); +BUILD_BUG_ON (sizeof (struct xc_sr_rec_x86_pv_vcpu_hdr ) !=8 ); +BUILD_BUG_ON (sizeof (struct xc_sr_rec_tsc_info ) !=24 ); +BUILD_BUG_ON (sizeof (struct xc_sr_rec_hvm_params_entry ) !=16 ); +BUILD_BUG_ON (sizeof (struct xc_sr_rec_hvm_params ) !=8 ); }/*
tools/libxl/libxl_internal.h +0 -8
@@ -4148,14 +4148,6 @@ int libxl__string_parse_json(libxl__gc *gc, const libxl__json_object *o,int libxl__random_bytes (libxl__gc *gc,uint8_t *buf,size_t len); -/* -* Compile time assertion -*/ -#if __GNUC__ >4 || (__GNUC__ ==4 && __GNUC_MINOR__ >=6 ) -#define BUILD_BUG_ON (p) ({ _Static_assert(!(p), "!(" #p ")"); }) -#else -#define BUILD_BUG_ON (p) ((void)sizeof(char[1 - 2 * !!(p)])) -#endif #include "_libxl_types_private.h" #include "_libxl_types_internal_private.h"
tools/libxl/libxl_psr.c +1 -0
@@ -16,6 +16,7 @@#include "libxl_osdeps.h" /* must come before any other headers */ #include "libxl_internal.h" +#include <xen-tools/libs.h> #define IA32_QM_CTR_ERROR_MASK (0x3ul << 62)
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Wei Liu writes ("[PATCH] tools: lift BUILD_BUG_ON to a tools header file"):
Quoted 11 lines
Only define
BUILD_BUG_ONwhen there isn't one already, because mini-os currently leaks that.Signed-off-by Wei Liu <[email protected]>---
Cc: Ian Jackson <[email protected]>
Cc: Paulina Szubarczyk <[email protected]>This is a patch taken out of my branch to clean up some build system issues. It is still a bit ugly because
BUILD_BUG_ONis conditionally defined to work around mini-os leakingBUILD_BUG_ON.
Thanks!
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 9 lines · Ian Jackson
Wei Liu writes ("[PATCH] tools: lift
BUILD_BUG_ONto a tools header file"):Quoted 8 lines
Only define
BUILD_BUG_ONwhen there isn't one already, because mini-os currently leaks that.Signed-off-by Wei Liu <[email protected]>---
Cc: Ian Jackson <[email protected]>
Cc: Paulina Szubarczyk <[email protected]>
Quoted 7 lines
Quoted 3 lines
This is a patch taken out of my branch to clean up some build system issues. It is still a bit ugly because
BUILD_BUG_ONis conditionally defined to work around mini-os leakingBUILD_BUG_ON.Thanks!
Acked-by Ian Jackson <[email protected]>
Pushed, thanks.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 12 lines · Wei Liu
Only define
BUILD_BUG_ONwhen there isn't one already, because mini-os currently leaks that.Signed-off-by Wei Liu <[email protected]>---
Cc: Ian Jackson <[email protected]>
Cc: Paulina Szubarczyk <[email protected]>This is a patch taken out of my branch to clean up some build system issues. It is still a bit ugly because
BUILD_BUG_ONis conditionally defined to work around mini-os leakingBUILD_BUG_ON.
Quoted 6 lines
Either this patch or "[PATCH v2] libs/gnttab: introduce
XENGNTTAB_BUILD_BUG_ON" should be taken to unblock Paulina's work.--- tools/firmware/hvmloader/rombios.c | 1 + tools/firmware/hvmloader/smbios.c | 1 + tools/firmware/hvmloader/util.h | 1 -
Oops, I just realise that these changes need an ack from Jan / Andrew.
Jan and Andrew: Since I can do a partial revert if you're not happy with those changes.
Sorry for not having CC'ed you two earlier.
Wei.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 19 lines · Wei Liu
Quoted 12 lines · Wei Liu
Only define
BUILD_BUG_ONwhen there isn't one already, because mini-os currently leaks that.Signed-off-by Wei Liu <[email protected]>---
Cc: Ian Jackson <[email protected]>
Cc: Paulina Szubarczyk <[email protected]>This is a patch taken out of my branch to clean up some build system issues. It is still a bit ugly because
BUILD_BUG_ONis conditionally defined to work around mini-os leakingBUILD_BUG_ON.Quoted 6 lines
Either this patch or "[PATCH v2] libs/gnttab: introduce
XENGNTTAB_BUILD_BUG_ON" should be taken to unblock Paulina's work.--- tools/firmware/hvmloader/rombios.c | 1 + tools/firmware/hvmloader/smbios.c | 1 + tools/firmware/hvmloader/util.h | 1 -
Quoted 6 lines
Oops, I just realise that these changes need an ack from Jan / Andrew.
Jan and Andrew: Since I can do a partial revert if you're not happy with those changes.
Sorry for not having CC'ed you two earlier.
HVMLoader really should be standalone IMO.
However, while you are fixing that, can you also fix the broken header guard for xen-tools/libs.h ?
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 25 lines · Andrew Cooper
Quoted 24 lines · Wei Liu
Quoted 12 lines · Wei Liu
Only define
BUILD_BUG_ONwhen there isn't one already, because mini-os currently leaks that.Signed-off-by Wei Liu <[email protected]>---
Cc: Ian Jackson <[email protected]>
Cc: Paulina Szubarczyk <[email protected]>This is a patch taken out of my branch to clean up some build system issues. It is still a bit ugly because
BUILD_BUG_ONis conditionally defined to work around mini-os leakingBUILD_BUG_ON.Quoted 6 lines
Either this patch or "[PATCH v2] libs/gnttab: introduce
XENGNTTAB_BUILD_BUG_ON" should be taken to unblock Paulina's work.--- tools/firmware/hvmloader/rombios.c | 1 + tools/firmware/hvmloader/smbios.c | 1 + tools/firmware/hvmloader/util.h | 1 -Oops, I just realise that these changes need an ack from Jan / Andrew.
Jan and Andrew: Since I can do a partial revert if you're not happy with those changes.
Quoted 7 lines
Quoted 1 line
Sorry for not having CC'ed you two earlier.
HVMLoader really should be standalone IMO.
However, while you are fixing that, can you also fix the broken header guard for
xen-tools/libs.h?
Sure, first thing tomorrow.
Wei.
Quoted 1 line
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 21 lines
Quoted 1 line
Quoted 1 line · On 19.09.16 at 18:48, <[email protected]> wrote:
Quoted 19 lines · Wei Liu
Quoted 18 lines · Wei Liu
Only define
BUILD_BUG_ONwhen there isn't one already, because mini-os currently leaks that.Signed-off-by Wei Liu <[email protected]>---
Cc: Ian Jackson <[email protected]>
Cc: Paulina Szubarczyk <[email protected]>This is a patch taken out of my branch to clean up some build system issues. It is still a bit ugly because
BUILD_BUG_ONis conditionally defined to work around mini-os leakingBUILD_BUG_ON.Either this patch or "[PATCH v2] libs/gnttab: introduce
XENGNTTAB_BUILD_BUG_ON" should be taken to unblock Paulina's work.--- tools/firmware/hvmloader/rombios.c | 1 + tools/firmware/hvmloader/smbios.c | 1 + tools/firmware/hvmloader/util.h | 1 -
Quoted 8 lines
Quoted 6 lines
Oops, I just realise that these changes need an ack from Jan / Andrew.
Jan and Andrew: Since I can do a partial revert if you're not happy with those changes.
Sorry for not having CC'ed you two earlier.
HVMLoader really should be standalone IMO.
I agree, i.e. the suggest partial revert should be done and has my ack.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel