Skip to contentSkip to conversation

libs/gnttab: introduce BUILD_BUG_ON

PATCH Superseded Wei Liu 3 participants 5 messages Jul 13, 2016

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Wei Liu

author
#0 lore raw

PATCH 1/1 libs/gnttab: introduce BUILD_BUG_ON

The implementation is taken from libxc.

---
Cc: Ian Jackson <[email protected]>
Cc: Paulina Szubarczyk <[email protected]>

I could have put it in a header file accessible to all libraries under libs but this construct is only relevant to xengnttab library at the moment so it's put under gnttab/private.h. It can be easily moved to a common place when other libraries under libs require it.

This patch is necessary to unblock Paulina on her gnttab copy work.

---
 tools/libs/gnttab/private.h | 7 +++++++
 1 file changed, 7 insertions(+)
tools/libs/gnttab/private.h +7 -0
index d286c86..da487f2 100644
@@ -4,6 +4,13 @@
 #include <xentoollog.h>
 #include <xengnttab.h>
 
+/* Force a compilation error if condition is true */
+#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(struct { int:-!!(p); }))
+#endif
+
 struct xengntdev_handle {
     xentoollog_logger *logger, *logger_tofree;
     int fd;
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#1 lore raw
Quoted 26 lines · Wei Liu

The implementation is taken from libxc.

---
Cc: Ian Jackson <[email protected]>
Cc: Paulina Szubarczyk <[email protected]>

I could have put it in a header file accessible to all libraries under libs but this construct is only relevant to xengnttab library at the moment so it's put under gnttab/private.h. It can be easily moved to a common place when other libraries under libs require it.

This patch is necessary to unblock Paulina on her gnttab copy work.

---
  tools/libs/gnttab/private.h | 7 +++++++
  1 file changed, 7 insertions(+)
tools/libs/gnttab/private.h +0 -0
index d286c86..da487f2 100644
@@ -4,6 +4,13 @@
  #include <xentoollog.h>
  #include <xengnttab.h>
 

tools/libs/gnttab/private.h line 16

Quoted 10 lines
tools/libs/gnttab/private.h +7 -0
+/* Force a compilation error if condition is true */
+#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(struct { int:-!!(p); }))
+#endif
+
  struct xengntdev_handle {
      xentoollog_logger *logger, *logger_tofree;
      int fd;

Hi Wei,

thank you for the help with the grant copy patch. I have just rebuild Xen and there is a conflict with definition of BUILD_BUG_ON for mini-os build:

In file included from minios.c:33:0:
private.h:9:0: error: "BUILD_BUG_ON" redefined [-Werror]
#define BUILD_BUG_ON(p) ({ _Static_assert(!(p), "!(" #p ")"); })
^
In file included from minios.c:25:0:
xen/extras/mini-os-remote/include/lib.h:58:0: note: this is the location of the previous definition
#define BUILD_BUG_ON(cond) ({ _Static_assert(!(cond), "!(" #cond ")"); })
^
I thought about wrapping the code in #ifndef BUILD_BUG_ON #endif.

Paulina

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

author
#2 lore raw
Quoted 44 lines · Paulina Szubarczyk
Quoted 26 lines · Wei Liu

The implementation is taken from libxc.

---
Cc: Ian Jackson <[email protected]>
Cc: Paulina Szubarczyk <[email protected]>

I could have put it in a header file accessible to all libraries under libs but this construct is only relevant to xengnttab library at the moment so it's put under gnttab/private.h. It can be easily moved to a common place when other libraries under libs require it.

This patch is necessary to unblock Paulina on her gnttab copy work.

---
 tools/libs/gnttab/private.h | 7 +++++++
 1 file changed, 7 insertions(+)
tools/libs/gnttab/private.h +0 -0
index d286c86..da487f2 100644
@@ -4,6 +4,13 @@
 #include <xentoollog.h>
 #include <xengnttab.h>
 

tools/libs/gnttab/private.h line 16

Quoted 10 lines
tools/libs/gnttab/private.h +7 -0
+/* Force a compilation error if condition is true */
+#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(struct { int:-!!(p); }))
+#endif
+
 struct xengntdev_handle {
     xentoollog_logger *logger, *logger_tofree;
     int fd;

Hi Wei,

thank you for the help with the grant copy patch. I have just rebuild Xen and there is a conflict with definition of BUILD_BUG_ON for mini-os build:

Quoted 10 lines

In file included from minios.c:33:0:
private.h:9:0: error: "BUILD_BUG_ON" redefined [-Werror]
#define BUILD_BUG_ON(p) ({ _Static_assert(!(p), "!(" #p ")"); }) ^
In file included from minios.c:25:0:
xen/extras/mini-os-remote/include/lib.h:58:0: note: this is the location of the previous definition
#define BUILD_BUG_ON(cond) ({ _Static_assert(!(cond), "!(" #cond ")"); }) ^
I thought about wrapping the code in #ifndef BUILD_BUG_ON #endif.

We could use a prefix to the one used in gnttab.

Maybe call it XENGNTTAB_BUILD_BUG_ON for now?

All these are just cosmetic. You can modify my patch to use the name above and continue your work. When we finally decide what it should be called you can easily modify your code to adapt.

Wei.

Quoted 2 lines

Paulina

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#3 lore raw
Quoted 54 lines · Wei Liu
Quoted 43 lines · Paulina Szubarczyk
Quoted 26 lines · Wei Liu

The implementation is taken from libxc.

---
Cc: Ian Jackson <[email protected]>
Cc: Paulina Szubarczyk <[email protected]>

I could have put it in a header file accessible to all libraries under libs but this construct is only relevant to xengnttab library at the moment so it's put under gnttab/private.h. It can be easily moved to a common place when other libraries under libs require it.

This patch is necessary to unblock Paulina on her gnttab copy work.

---
 tools/libs/gnttab/private.h | 7 +++++++
 1 file changed, 7 insertions(+)
tools/libs/gnttab/private.h +0 -0
index d286c86..da487f2 100644
@@ -4,6 +4,13 @@
 #include <xentoollog.h>
 #include <xengnttab.h>
 

tools/libs/gnttab/private.h line 16

Quoted 10 lines
tools/libs/gnttab/private.h +7 -0
+/* Force a compilation error if condition is true */
+#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(struct { int:-!!(p); }))
+#endif
+
 struct xengntdev_handle {
     xentoollog_logger *logger, *logger_tofree;
     int fd;

Hi Wei,

thank you for the help with the grant copy patch. I have just rebuild Xen and there is a conflict with definition of BUILD_BUG_ON for mini-os build:

Quoted 10 lines

In file included from minios.c:33:0:
private.h:9:0: error: "BUILD_BUG_ON" redefined [-Werror]
#define BUILD_BUG_ON(p) ({ _Static_assert(!(p), "!(" #p ")"); }) ^
In file included from minios.c:25:0:
xen/extras/mini-os-remote/include/lib.h:58:0: note: this is the location of the previous definition
#define BUILD_BUG_ON(cond) ({ _Static_assert(!(cond), "!(" #cond ")"); }) ^
I thought about wrapping the code in #ifndef BUILD_BUG_ON #endif.

Quoted 3 lines

We could use a prefix to the one used in gnttab.

Maybe call it XENGNTTAB_BUILD_BUG_ON for now?

The contents of gnttabs private.h is entirely up to gnttab.

It is MiniOS (who is poking about in someone elses private.h) with the responsibility not to have a broken build. It needs to do this by not leaking so much stuff into its global namespace.

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

author
#4 lore raw
Quoted 57 lines · Andrew Cooper
Quoted 56 lines · Wei Liu
Quoted 43 lines · Paulina Szubarczyk
Quoted 26 lines · Wei Liu

The implementation is taken from libxc.

---
Cc: Ian Jackson <[email protected]>
Cc: Paulina Szubarczyk <[email protected]>

I could have put it in a header file accessible to all libraries under libs but this construct is only relevant to xengnttab library at the moment so it's put under gnttab/private.h. It can be easily moved to a common place when other libraries under libs require it.

This patch is necessary to unblock Paulina on her gnttab copy work.

---
 tools/libs/gnttab/private.h | 7 +++++++
 1 file changed, 7 insertions(+)
tools/libs/gnttab/private.h +0 -0
index d286c86..da487f2 100644
@@ -4,6 +4,13 @@
 #include <xentoollog.h>
 #include <xengnttab.h>
 

tools/libs/gnttab/private.h line 16

Quoted 10 lines
tools/libs/gnttab/private.h +7 -0
+/* Force a compilation error if condition is true */
+#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(struct { int:-!!(p); }))
+#endif
+
 struct xengntdev_handle {
     xentoollog_logger *logger, *logger_tofree;
     int fd;

Hi Wei,

thank you for the help with the grant copy patch. I have just rebuild Xen and there is a conflict with definition of BUILD_BUG_ON for mini-os build:

Quoted 10 lines

In file included from minios.c:33:0:
private.h:9:0: error: "BUILD_BUG_ON" redefined [-Werror]
#define BUILD_BUG_ON(p) ({ _Static_assert(!(p), "!(" #p ")"); }) ^
In file included from minios.c:25:0:
xen/extras/mini-os-remote/include/lib.h:58:0: note: this is the location of the previous definition
#define BUILD_BUG_ON(cond) ({ _Static_assert(!(cond), "!(" #cond ")"); }) ^
I thought about wrapping the code in #ifndef BUILD_BUG_ON #endif.

We could use a prefix to the one used in gnttab.

Quoted 8 lines
Quoted 1 line

Maybe call it XENGNTTAB_BUILD_BUG_ON for now?

The contents of gnttabs private.h is entirely up to gnttab.

It is MiniOS (who is poking about in someone elses private.h) with the responsibility not to have a broken build. It needs to do this by not leaking so much stuff into its global namespace.

Yeah, I know. It wouldn't hurt to prefix the name anyway.

The mini-os build system problem can be solve separately.

Wei.

Quoted 1 line

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel