Skip to contentSkip to conversation

quagga: fix static build with musl

PATCH New Fabrice Fontaine 3 participants 4 messages Dec 1, 2018 – Aug 1, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 quagga: fix static build with musl

zebra library defines optind and opterr which are already defined in libc
Current code is not included if !defined _LIBC && defined __GLIBC__ &&
__GLIBC__ >= 2 && _GNU_GETOPT_INTERFACE_VERSION == GETOPT_INTERFACE_VERSION

However, this fails on musl even if musl provides getopt as a result static linking with musl fails

To fix this issue, add an option to allow the user to disable getopt code and use it in quagga.mk

Fixes:
- http://autobuild.buildroot.org/results/32f93a73379d073abcaf8936ffbb8b5707583024

---
 ...an-option-to-disable-embedded-getopt.patch | 84 +++++++++++++++++++
 package/quagga/quagga.mk                      |  3 +-
 2 files changed, 86 insertions(+), 1 deletion(-)
 create mode 100644 package/quagga/0009-add-an-option-to-disable-embedded-getopt.patch
package/quagga/0009-add-an-option-to-disable-embedded-getopt.patch new file +84 -0
new file mode 100644
index 0000000000..f8b0e7bcfe
@@ -0,0 +1,84 @@
+From 4d09fabe5fb3272d04cf86f4197d75f300af15be Mon Sep 17 00:00:00 2001
+From: Fabrice Fontaine <[email protected]>
+Date: Sat, 1 Dec 2018 22:23:30 +0100
+Subject: [PATCH] add an option to disable embedded getopt
+
+zebra library defines optind and opterr which are already defined in
+libc
+Current code is not included if !defined _LIBC && defined __GLIBC__ &&
+ __GLIBC__ >= 2 && _GNU_GETOPT_INTERFACE_VERSION == GETOPT_INTERFACE_VERSION
+
+However, this fails on musl even if musl provides getopt as a result
+static linking with musl fails
+
+To fix this issue, add an option to allow the user to disable getopt
+code
+
+Fixes:
+ - http://autobuild.buildroot.org/results/32f93a73379d073abcaf8936ffbb8b5707583024
+
+Signed-off-by: Fabrice Fontaine <[email protected]>
+---
+ configure.ac  | 7 +++++++
+ lib/getopt.c  | 4 ++++
+ lib/getopt1.c | 4 ++++
+ 3 files changed, 15 insertions(+)
+
+diff --git a/configure.ac b/configure.ac
+index ed279f48..ace2ed48 100755
+--- a/configure.ac
++++ b/configure.ac
+@@ -360,6 +360,9 @@ AC_ARG_ENABLE([protobuf],
+ AC_ARG_ENABLE([dev_build],
+     AS_HELP_STRING([--enable-dev-build], [build for development]))
+ 
++AC_ARG_ENABLE(embedded-getopt,
++    AS_HELP_STRING([--disable-embedded-getopt], [disable embedded getopt functions]))
++
+ if test x"${enable_gcc_rdynamic}" != x"no" ; then
+   if test x"${enable_gcc_rdynamic}" = x"yes" -o x"$COMPILER" = x"GCC"; then
+     LDFLAGS="${LDFLAGS} -rdynamic"
+@@ -383,6 +386,10 @@ if test "x${enable_dev_build}" = "xyes"; then
+ fi
+ AM_CONDITIONAL([DEV_BUILD], [test "x$enable_dev_build" = "xyes"])
+ 
++if test "${enable_embedded_getopt}" = "yes"; then
++   AC_DEFINE(HAVE_EMBEDDED_GETOPT,,Enable embedded getopt functions)
++fi
++
+ #
+ # Logic for protobuf support.
+ #
+diff --git a/lib/getopt.c b/lib/getopt.c
+index 7a58a8a8..45fe6a7d 100644
+--- a/lib/getopt.c
++++ b/lib/getopt.c
+@@ -58,6 +58,10 @@
+ # endif
+ #endif
+ 
++#if !defined HAVE_EMBEDDED_GETOPT
++# define ELIDE_CODE
++#endif
++
+ #ifndef ELIDE_CODE
+ 
+ 
+diff --git a/lib/getopt1.c b/lib/getopt1.c
+index bd3099e7..b8c87ddc 100644
+--- a/lib/getopt1.c
++++ b/lib/getopt1.c
+@@ -49,6 +49,10 @@
+ #endif
+ #endif
+ 
++#if !defined HAVE_EMBEDDED_GETOPT
++# define ELIDE_CODE
++#endif
++
+ #ifndef ELIDE_CODE
+ 
+ 
+-- 
+2.17.1
+
package/quagga/quagga.mk +2 -1
index 8c2b80631b..cc4cd0a79f 100644
@@ -16,7 +16,8 @@ QUAGGA_LICENSE_FILES = COPYING
 QUAGGA_CONF_OPTS = \
 	--program-transform-name='' \
 	--sysconfdir=/etc/quagga \
-	--localstatedir=/var/run/quagga
+	--localstatedir=/var/run/quagga \
+	--disable-embedded-getopt
 
 # 0002-configure-fix-static-linking-with-readline.patch
 QUAGGA_AUTORECONF = YES
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/1 quagga: fix static build with musl

Hello,

Quoted 2 lines · Fabrice Fontaine

++AC_ARG_ENABLE(embedded-getopt,
++ AS_HELP_STRING([--disable-embedded-getopt], [disable embedded getopt functions]))

Instead of another --enable option, what about auto-detecting if the C library provides getopt() ?

Isn't AC_CHECK_FUNC([getopt]) sufficient ?

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
#2 lore raw

PATCH 1/1 quagga: fix static build with musl

Hello,
Le sam. 1 d?c. 2018 ? 23:19, Thomas Petazzoni
<[email protected]> a ?crit :

Quoted 5 lines

Hello,

On Sat, 1 Dec 2018 22:59:53 +0100, Fabrice Fontaine wrote:

Quoted 7 lines
Quoted 2 lines

++AC_ARG_ENABLE(embedded-getopt,
++ AS_HELP_STRING([--disable-embedded-getopt], [disable embedded getopt functions]))

Instead of another --enable option, what about auto-detecting if the C library provides getopt() ?

Isn't AC_CHECK_FUNC([getopt]) sufficient ?

This was also my first idea but then I saw this comment in their source code:

"The operating system may or may not provide getopt_long(), and if so it may or may not be a version we are willing to use. Our strategy is to declare getopt here, and then provide code unless the supplied version is adequate. The difficult case is when a declaration for getopt is provided, as our declaration must match.

XXX Arguably this version should be named differently, and the local names defined to refer to the system version when we choose to use the system version."

On the other side, this code is very old so I'll just ask for their feedback by filling a bug on their bugzilla, perhaps we could just remove all this code.

Quoted 6 lines

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

Best Regards,

Fabrice

#3 lore raw

PATCH 1/1 quagga: fix static build with musl

In reply to Fabrice Fontaine

Hi Fabrice,

Quoted 8 lines · Fabrice Fontaine

zebra library defines optind and opterr which are already defined in libc
Current code is not included if !defined _LIBC && defined __GLIBC__ &&
__GLIBC__ >= 2 && _GNU_GETOPT_INTERFACE_VERSION == GETOPT_INTERFACE_VERSION

However, this fails on musl even if musl provides getopt as a result static linking with musl fails

Quoted 7 lines

To fix this issue, add an option to allow the user to disable getopt code and use it in quagga.mk

Fixes:
- http://autobuild.buildroot.org/results/32f93a73379d073abcaf8936ffbb8b5707583024

I didn't really like this approach, so I dug into it a little. Turns out that
the real issue is that both quagga's getopt and libc's getopt are pulled in, and the only reason this happens is because getopt() is called by netsnmp but quagga itself doesn't define getopt(). However, we can pass an option to do that.

So I've prepared a patch [1] and marked this one as superseded.

Can you update your bug report in quagga [2] (even though there was absolutely
no response on it for half a year).

Regards,
Arnout

[1] http://patchwork.ozlabs.org/patch/1140624/
[2] https://bugzilla.quagga.net/show_bug.cgi?id=1000