|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH] 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.
Signed-off-by: Wei Liu <wei.liu2@xxxxxxxxxx>
---
Cc: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
Cc: Paulina Szubarczyk <paulinaszubarczyk@xxxxxxxxx>
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
diff --git a/tools/firmware/hvmloader/rombios.c
b/tools/firmware/hvmloader/rombios.c
index 9acf03f..1e853ec 100644
--- a/tools/firmware/hvmloader/rombios.c
+++ b/tools/firmware/hvmloader/rombios.c
@@ -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
diff --git a/tools/firmware/hvmloader/smbios.c
b/tools/firmware/hvmloader/smbios.c
index 210c7b0..0e61bd1 100644
--- a/tools/firmware/hvmloader/smbios.c
+++ b/tools/firmware/hvmloader/smbios.c
@@ -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
diff --git a/tools/firmware/hvmloader/util.h b/tools/firmware/hvmloader/util.h
index 0fb266e..94292d6 100644
--- a/tools/firmware/hvmloader/util.h
+++ b/tools/firmware/hvmloader/util.h
@@ -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; })
diff --git a/tools/include/xen-tools/libs.h b/tools/include/xen-tools/libs.h
new file mode 100644
index 0000000..9d8b4ab
--- /dev/null
+++ b/tools/include/xen-tools/libs.h
@@ -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__ */
diff --git a/tools/libxc/xc_core_arm.c b/tools/libxc/xc_core_arm.c
index d8570fd..362c1a7 100644
--- a/tools/libxc/xc_core_arm.c
+++ b/tools/libxc/xc_core_arm.c
@@ -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;
diff --git a/tools/libxc/xc_cpuid_x86.c b/tools/libxc/xc_cpuid_x86.c
index fbbac9e..de06b32 100644
--- a/tools/libxc/xc_cpuid_x86.c
+++ b/tools/libxc/xc_cpuid_x86.c
@@ -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 )
diff --git a/tools/libxc/xc_dom_arm.c b/tools/libxc/xc_dom_arm.c
index 64a8b67..a7e839e 100644
--- a/tools/libxc/xc_dom_arm.c
+++ b/tools/libxc/xc_dom_arm.c
@@ -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);
diff --git a/tools/libxc/xc_dom_bzimageloader.c
b/tools/libxc/xc_dom_bzimageloader.c
index 33ba06b..a7d70cc 100644
--- a/tools/libxc/xc_dom_bzimageloader.c
+++ b/tools/libxc/xc_dom_bzimageloader.c
@@ -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 )
diff --git a/tools/libxc/xc_pm.c b/tools/libxc/xc_pm.c
index 5b38cf1..ae917bc 100644
--- a/tools/libxc/xc_pm.c
+++ b/tools/libxc/xc_pm.c
@@ -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));
}
diff --git a/tools/libxc/xc_private.h b/tools/libxc/xc_private.h
index 75b761c..97445ae 100644
--- a/tools/libxc/xc_private.h
+++ b/tools/libxc/xc_private.h
@@ -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]))
diff --git a/tools/libxc/xc_sr_common.c b/tools/libxc/xc_sr_common.c
index b228a15..48fa676 100644
--- a/tools/libxc/xc_sr_common.c
+++ b/tools/libxc/xc_sr_common.c
@@ -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);
}
/*
diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
index 7510031..a8fb23e 100644
--- a/tools/libxl/libxl_internal.h
+++ b/tools/libxl/libxl_internal.h
@@ -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"
diff --git a/tools/libxl/libxl_psr.c b/tools/libxl/libxl_psr.c
index 99733f6..786183c 100644
--- a/tools/libxl/libxl_psr.c
+++ b/tools/libxl/libxl_psr.c
@@ -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)
--
2.1.4
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
https://lists.xen.org/xen-devel
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |