diff mbox series

[ovs-dev] compiler: Fix compilation when using VStudio 2015/2017

Message ID 20190403120155.1620-1-aserdean@ovn.org
State Accepted
Headers show
Series [ovs-dev] compiler: Fix compilation when using VStudio 2015/2017 | expand

Commit Message

Alin-Gabriel Serdean April 3, 2019, 12:01 p.m. UTC
This is somewhat a regression of:
https://github.com/openvswitch/ovs/commit/27f141d44d95b4cabfd7eac47ace8d1201668b2c

The main issue using `offsetof` from <stddef.h> via the C compiler from
MSVC 2015/2017 has issues and is buggy:
https://bit.ly/2UvWwti

Until it is fixed, we define our own definition of `offsetof`.

Signed-off-by: Alin Gabriel Serdean <aserdean@ovn.org>
---
 include/openvswitch/compiler.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)

Comments

Ben Pfaff April 13, 2019, 6:39 p.m. UTC | #1
On Wed, Apr 03, 2019 at 03:01:55PM +0300, Alin Gabriel Serdean wrote:
> This is somewhat a regression of:
> https://github.com/openvswitch/ovs/commit/27f141d44d95b4cabfd7eac47ace8d1201668b2c
> 
> The main issue using `offsetof` from <stddef.h> via the C compiler from
> MSVC 2015/2017 has issues and is buggy:
> https://bit.ly/2UvWwti
> 
> Until it is fixed, we define our own definition of `offsetof`.
> 
> Signed-off-by: Alin Gabriel Serdean <aserdean@ovn.org>

Acked-by: Ben Pfaff <blp@ovn.org>
Li,Rongqing via dev April 15, 2019, 11:16 p.m. UTC | #2
Acked-by: Anand Kumar <kumaranand@vmware.com>

Thanks,
Anand Kumar

On 4/3/19, 5:02 AM, "ovs-dev-bounces@openvswitch.org on behalf of Alin Gabriel Serdean" <ovs-dev-bounces@openvswitch.org on behalf of aserdean@ovn.org> wrote:

    This is somewhat a regression of:
    https://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fopenvswitch%2Fovs%2Fcommit%2F27f141d44d95b4cabfd7eac47ace8d1201668b2c&amp;data=02%7C01%7Ckumaranand%40vmware.com%7C8c1a3cec316246469a7408d6b82c379e%7Cb39138ca3cee4b4aa4d6cd83d9dd62f0%7C0%7C0%7C636898897407724956&amp;sdata=ALCufRrll3wawrYBVISSBDuI%2FoLONal%2FnkbH9JwrW1c%3D&amp;reserved=0
    
    The main issue using `offsetof` from <stddef.h> via the C compiler from
    MSVC 2015/2017 has issues and is buggy:
    https://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fbit.ly%2F2UvWwti&amp;data=02%7C01%7Ckumaranand%40vmware.com%7C8c1a3cec316246469a7408d6b82c379e%7Cb39138ca3cee4b4aa4d6cd83d9dd62f0%7C0%7C0%7C636898897407734950&amp;sdata=NqGbZONawrVrvtb57jh%2FYIRxAu4A1blZAYFOpyDtHEQ%3D&amp;reserved=0
    
    Until it is fixed, we define our own definition of `offsetof`.
    
    Signed-off-by: Alin Gabriel Serdean <aserdean@ovn.org>
    ---
     include/openvswitch/compiler.h | 12 ++++++++++++
     1 file changed, 12 insertions(+)
    
    diff --git a/include/openvswitch/compiler.h b/include/openvswitch/compiler.h
    index c7cb9308d..5289a70f6 100644
    --- a/include/openvswitch/compiler.h
    +++ b/include/openvswitch/compiler.h
    @@ -236,6 +236,18 @@
     #define OVS_PREFETCH_WRITE(addr)
     #endif
     
    +/* Since Visual Studio 2015 there has been an effort to make offsetof a
    + * builtin_offsetof, unfortunately both implementation (the regular define and
    + * the built in one) are buggy and cause issues when using them via
    + * the C compiler.
    + * e.g.: https://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fbit.ly%2F2UvWwti&amp;data=02%7C01%7Ckumaranand%40vmware.com%7C8c1a3cec316246469a7408d6b82c379e%7Cb39138ca3cee4b4aa4d6cd83d9dd62f0%7C0%7C0%7C636898897407734950&amp;sdata=NqGbZONawrVrvtb57jh%2FYIRxAu4A1blZAYFOpyDtHEQ%3D&amp;reserved=0
    + */
    +#if _MSC_VER >= 1900
    +#undef offsetof
    +#define offsetof(type, member) \
    +    ((size_t)((char *)&(((type *)0)->member) - (char *)0))
    +#endif
    +
     /* Build assertions.
      *
      * Use BUILD_ASSERT_DECL as a declaration or a statement, or BUILD_ASSERT as
    -- 
    2.21.0.windows.1
    
    _______________________________________________
    dev mailing list
    dev@openvswitch.org
    https://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fmail.openvswitch.org%2Fmailman%2Flistinfo%2Fovs-dev&amp;data=02%7C01%7Ckumaranand%40vmware.com%7C8c1a3cec316246469a7408d6b82c379e%7Cb39138ca3cee4b4aa4d6cd83d9dd62f0%7C0%7C0%7C636898897407734950&amp;sdata=MmmiiH7FfvcAfTB7FUybE6icufW5vebGuY0DqKljnZ8%3D&amp;reserved=0
Alin-Gabriel Serdean April 16, 2019, 2:18 p.m. UTC | #3
Thanks both! I applied this patch as far back as branch-2.9.

> On 16 Apr 2019, at 02:16, Anand Kumar via dev <ovs-dev@openvswitch.org> wrote:
> 
> Acked-by: Anand Kumar <kumaranand@vmware.com>
> 
> Thanks,
> Anand Kumar
> 
>
diff mbox series

Patch

diff --git a/include/openvswitch/compiler.h b/include/openvswitch/compiler.h
index c7cb9308d..5289a70f6 100644
--- a/include/openvswitch/compiler.h
+++ b/include/openvswitch/compiler.h
@@ -236,6 +236,18 @@ 
 #define OVS_PREFETCH_WRITE(addr)
 #endif
 
+/* Since Visual Studio 2015 there has been an effort to make offsetof a
+ * builtin_offsetof, unfortunately both implementation (the regular define and
+ * the built in one) are buggy and cause issues when using them via
+ * the C compiler.
+ * e.g.: https://bit.ly/2UvWwti
+ */
+#if _MSC_VER >= 1900
+#undef offsetof
+#define offsetof(type, member) \
+    ((size_t)((char *)&(((type *)0)->member) - (char *)0))
+#endif
+
 /* Build assertions.
  *
  * Use BUILD_ASSERT_DECL as a declaration or a statement, or BUILD_ASSERT as