All of lore.kernel.org
 help / color / mirror / Atom feed
* [Buildroot] [PATCH v2] package/ndisc6: fix compilation for glibc < 2.19
@ 2020-05-09 19:09 Vadym Kochan
  2020-05-16 14:17 ` Thomas Petazzoni
  0 siblings, 1 reply; 3+ messages in thread
From: Vadym Kochan @ 2020-05-09 19:09 UTC (permalink / raw)
  To: buildroot

glibc version before 2.19 version allows to use BSD-mode via #define
_BSD_SOURCE, it defines another one

    __FAVOR_BSD

which provides BSD-style tcp/udp headers where fields are different than
in GNU version.

In glibc > 2.18 there is no such ability to use BSD mode, but it
supports both kinds of tcp/udp headers because of using __extension__
union.

Since trace-{udp,tcp}.c uses BSD-style tcp/udp headers, it fails on
toolchains with glibc < 2.19 version.

So fix it by defining __FAVOR_BSD define only for tcp/udp headers.

Fixes: http://autobuild.buildroot.net/results/d05d5471d10a2b6634711ccad75d7f86d222cc31

Signed-off-by: Vadym Kochan <vadim4j@gmail.com>
---

v2:
    Fix wrong description which refers to particular codesourcery
    toolchain instead to the glibc which is the real root cause of the
    issue.

 ...x-compilation-with-glibc-which-uses-.patch | 46 +++++++++++++++++++
 1 file changed, 46 insertions(+)
 create mode 100644 package/ndisc6/0002-trace-udp-tcp-fix-compilation-with-glibc-which-uses-.patch

diff --git a/package/ndisc6/0002-trace-udp-tcp-fix-compilation-with-glibc-which-uses-.patch b/package/ndisc6/0002-trace-udp-tcp-fix-compilation-with-glibc-which-uses-.patch
new file mode 100644
index 0000000000..299cefbb79
--- /dev/null
+++ b/package/ndisc6/0002-trace-udp-tcp-fix-compilation-with-glibc-which-uses-.patch
@@ -0,0 +1,46 @@
+From c87e9800e24d0afbebb385b049c7e7024a9c6555 Mon Sep 17 00:00:00 2001
+From: Vadym Kochan <vadim4j@gmail.com>
+Date: Sat, 9 May 2020 19:29:24 +0300
+Subject: [PATCH] trace-{udp,tcp}: fix compilation with glibc which uses
+ __FAVOR_BSD
+
+Use __FAVOR_BSD define to enable BSD-like tcp/udp headers for glibc
+versions older than 2.19, because later glibc implementations uses:
+
+    __extension__ union
+
+to provide both headers variants.
+
+Signed-off-by: Vadym Kochan <vadim4j@gmail.com>
+---
+ src/trace-tcp.c | 1 +
+ src/trace-udp.c | 1 +
+ 2 files changed, 2 insertions(+)
+
+diff --git a/src/trace-tcp.c b/src/trace-tcp.c
+index 1b367ae..5d6ab8f 100644
+--- a/src/trace-tcp.c
++++ b/src/trace-tcp.c
+@@ -33,6 +33,7 @@
+ #include <unistd.h> // getpid()
+ #include <sys/socket.h> // SOCK_STREAM
+ #include <netinet/in.h>
++#define __FAVOR_BSD
+ #include <netinet/tcp.h>
+ 
+ #include "traceroute.h"
+diff --git a/src/trace-udp.c b/src/trace-udp.c
+index aa9364e..6b287ec 100644
+--- a/src/trace-udp.c
++++ b/src/trace-udp.c
+@@ -32,6 +32,7 @@
+ #include <sys/types.h>
+ #include <sys/socket.h> // SOCK_DGRAM
+ #include <netinet/in.h>
++#define __FAVOR_BSD
+ #include <netinet/udp.h>
+ 
+ #include "traceroute.h"
+-- 
+2.26.2
+
-- 
2.26.2

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [Buildroot] [PATCH v2] package/ndisc6: fix compilation for glibc < 2.19
  2020-05-09 19:09 [Buildroot] [PATCH v2] package/ndisc6: fix compilation for glibc < 2.19 Vadym Kochan
@ 2020-05-16 14:17 ` Thomas Petazzoni
  2020-05-16 15:13   ` vadim4j at gmail.com
  0 siblings, 1 reply; 3+ messages in thread
From: Thomas Petazzoni @ 2020-05-16 14:17 UTC (permalink / raw)
  To: buildroot

Hello Vadym,

On Sat,  9 May 2020 22:09:47 +0300
Vadym Kochan <vadim4j@gmail.com> wrote:

> glibc version before 2.19 version allows to use BSD-mode via #define
> _BSD_SOURCE, it defines another one
> 
>     __FAVOR_BSD
> 
> which provides BSD-style tcp/udp headers where fields are different than
> in GNU version.
> 
> In glibc > 2.18 there is no such ability to use BSD mode, but it
> supports both kinds of tcp/udp headers because of using __extension__
> union.
> 
> Since trace-{udp,tcp}.c uses BSD-style tcp/udp headers, it fails on
> toolchains with glibc < 2.19 version.
> 
> So fix it by defining __FAVOR_BSD define only for tcp/udp headers.

Defining __FAVOR_BSD is not correct, and the whole explanation is a bit
confused I believe.

The <features.h> macros that start with two underscores, such as
__FAVOR_BSD are internal defines, they are not meant to be defined/used
by code using the C library, but only by the C library internally.

Instead, what needs to be done is:

#define _BSD_SOURCE

next to the existing #define _DEFAULT_SOURCE.

For one of the two files, #undef _GNU_SOURCE is present, which is good,
it will have to be added as to the other file for that fix to work.

From man feature_test_macros:

       _BSD_SOURCE (deprecated since glibc 2.20)

               Defining this macro with any value causes header files
               to expose BSD-derived definitions.

               In glibc versions up to and including 2.18, defining
               this macro also causes BSD  definitions  to  be
               preferred  in  some  situations  where  standards
               conflict,  unless  one  or  more of _SVID_SOURCE,
               _POSIX_SOURCE, _POSIX_C_SOURCE, _XOPEN_SOURCE,
               _XOPEN_SOURCE_EXTENDED, or _GNU_SOURCE is defined, in
               which case BSD definitions are disfavored.  Since glibc
               2.19, _BSD_SOURCE no longer causes BSD defi? nitions to
               be preferred in case of conflicts.

               Since glibc 2.20, this macro is deprecated.  It now has
               the same effect as defining _DEFAULT_SOURCE, but
               generates a compile-time warning (unless _DEFAULT_SOURCE
               is also defined).  Use _DEFAULT_SOURCE instead.  To
               allow code that requires _BSD_SOURCE in glibc 2.19 and
               earlier and  _DEFAULT_SOURCE  in glibc 2.20 and later to
               compile without warnings, define both _BSD_SOURCE and
               _DEFAULT_SOURCE.

See the last paragraph? They see you should define both _BSD_SOURCE and
_DEFAULT_SOURCE.

Could you fix your patch, and the commit log, and send an updated
version?

Thanks a lot!

Thomas
-- 
Thomas Petazzoni, CTO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Buildroot] [PATCH v2] package/ndisc6: fix compilation for glibc < 2.19
  2020-05-16 14:17 ` Thomas Petazzoni
@ 2020-05-16 15:13   ` vadim4j at gmail.com
  0 siblings, 0 replies; 3+ messages in thread
From: vadim4j at gmail.com @ 2020-05-16 15:13 UTC (permalink / raw)
  To: buildroot

On Sat, May 16, 2020 at 04:17:00PM +0200, Thomas Petazzoni wrote:
> Hello Vadym,
> 
> On Sat,  9 May 2020 22:09:47 +0300
> Vadym Kochan <vadim4j@gmail.com> wrote:
> 
> > glibc version before 2.19 version allows to use BSD-mode via #define
> > _BSD_SOURCE, it defines another one
> > 
> >     __FAVOR_BSD
> > 
> > which provides BSD-style tcp/udp headers where fields are different than
> > in GNU version.
> > 
> > In glibc > 2.18 there is no such ability to use BSD mode, but it
> > supports both kinds of tcp/udp headers because of using __extension__
> > union.
> > 
> > Since trace-{udp,tcp}.c uses BSD-style tcp/udp headers, it fails on
> > toolchains with glibc < 2.19 version.
> > 
> > So fix it by defining __FAVOR_BSD define only for tcp/udp headers.
> 
> Defining __FAVOR_BSD is not correct, and the whole explanation is a bit
> confused I believe.
> 
> The <features.h> macros that start with two underscores, such as
> __FAVOR_BSD are internal defines, they are not meant to be defined/used
> by code using the C library, but only by the C library internally.
> 
> Instead, what needs to be done is:
> 
> #define _BSD_SOURCE
> 
> next to the existing #define _DEFAULT_SOURCE.
> 
> For one of the two files, #undef _GNU_SOURCE is present, which is good,
> it will have to be added as to the other file for that fix to work.
> 
> From man feature_test_macros:
> 
>        _BSD_SOURCE (deprecated since glibc 2.20)
> 
>                Defining this macro with any value causes header files
>                to expose BSD-derived definitions.
> 
>                In glibc versions up to and including 2.18, defining
>                this macro also causes BSD  definitions  to  be
>                preferred  in  some  situations  where  standards
>                conflict,  unless  one  or  more of _SVID_SOURCE,
>                _POSIX_SOURCE, _POSIX_C_SOURCE, _XOPEN_SOURCE,
>                _XOPEN_SOURCE_EXTENDED, or _GNU_SOURCE is defined, in
>                which case BSD definitions are disfavored.  Since glibc
>                2.19, _BSD_SOURCE no longer causes BSD defi? nitions to
>                be preferred in case of conflicts.
> 
>                Since glibc 2.20, this macro is deprecated.  It now has
>                the same effect as defining _DEFAULT_SOURCE, but
>                generates a compile-time warning (unless _DEFAULT_SOURCE
>                is also defined).  Use _DEFAULT_SOURCE instead.  To
>                allow code that requires _BSD_SOURCE in glibc 2.19 and
>                earlier and  _DEFAULT_SOURCE  in glibc 2.20 and later to
>                compile without warnings, define both _BSD_SOURCE and
>                _DEFAULT_SOURCE.
> 
> See the last paragraph? They see you should define both _BSD_SOURCE and
> _DEFAULT_SOURCE.
> 
> Could you fix your patch, and the commit log, and send an updated
> version?
Sure!

> 
> Thanks a lot!
> 
> Thomas
> -- 
> Thomas Petazzoni, CTO, Bootlin
> Embedded Linux and Kernel engineering
> https://bootlin.com

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-05-16 15:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-09 19:09 [Buildroot] [PATCH v2] package/ndisc6: fix compilation for glibc < 2.19 Vadym Kochan
2020-05-16 14:17 ` Thomas Petazzoni
2020-05-16 15:13   ` vadim4j at gmail.com

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.