* [PATCH v2] lib: fix multiple strlcpy definition
@ 2017-09-28 18:02 Baruch Siach
2017-09-29 18:58 ` Stephen Hemminger
0 siblings, 1 reply; 3+ messages in thread
From: Baruch Siach @ 2017-09-28 18:02 UTC (permalink / raw)
To: Stephen Hemminger; +Cc: netdev, Phil Sutter, Baruch Siach
Some C libraries, like uClibc and musl, provide BSD compatible
strlcpy(). Add check_strlcpy() to configure, and avoid defining strlcpy
and strlcat when the C library provides them.
This fixes the following static link error with uClibc-ng:
.../sysroot/usr/lib/libc.a(strlcpy.os): In function `strlcpy':
strlcpy.c:(.text+0x0): multiple definition of `strlcpy'
../lib/libutil.a(utils.o):utils.c:(.text+0x1ddc): first defined here
collect2: error: ld returned 1 exit status
Acked-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Baruch Siach <baruch@tkos.co.il>
---
v2: Fix the order of strlcpy parameters
---
configure | 24 ++++++++++++++++++++++++
lib/Makefile | 4 ++++
lib/utils.c | 2 ++
3 files changed, 30 insertions(+)
diff --git a/configure b/configure
index 7be8fb113cc9..e0982f34a992 100755
--- a/configure
+++ b/configure
@@ -326,6 +326,27 @@ EOF
rm -f $TMPDIR/dbtest.c $TMPDIR/dbtest
}
+check_strlcpy()
+{
+ cat >$TMPDIR/strtest.c <<EOF
+#include <string.h>
+int main(int argc, char **argv) {
+ char dst[10];
+ strlcpy(dst, "test", sizeof(dst));
+ return 0;
+}
+EOF
+ $CC -I$INCLUDE -o $TMPDIR/strtest $TMPDIR/strtest.c >/dev/null 2>&1
+ if [ $? -eq 0 ]
+ then
+ echo "no"
+ else
+ echo "NEED_STRLCPY:=y" >>$CONFIG
+ echo "yes"
+ fi
+ rm -f $TMPDIR/strtest.c $TMPDIR/strtest
+}
+
quiet_config()
{
cat <<EOF
@@ -397,6 +418,9 @@ check_mnl
echo -n "Berkeley DB: "
check_berkeley_db
+echo -n "need for strlcpy: "
+check_strlcpy
+
echo
echo -n "docs:"
check_docs
diff --git a/lib/Makefile b/lib/Makefile
index 0fbdf4c31f50..132ad00c3335 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -1,5 +1,9 @@
include ../config.mk
+ifeq ($(NEED_STRLCPY),y)
+ CFLAGS += -DNEED_STRLCPY
+endif
+
CFLAGS += -fPIC
UTILOBJ = utils.o rt_names.o ll_types.o ll_proto.o ll_addr.o \
diff --git a/lib/utils.c b/lib/utils.c
index bbd3cbc46a0e..240e7426a810 100644
--- a/lib/utils.c
+++ b/lib/utils.c
@@ -1231,6 +1231,7 @@ int get_real_family(int rtm_type, int rtm_family)
return rtm_family;
}
+#ifdef NEED_STRLCPY
size_t strlcpy(char *dst, const char *src, size_t size)
{
size_t srclen = strlen(src);
@@ -1253,3 +1254,4 @@ size_t strlcat(char *dst, const char *src, size_t size)
return dlen + strlcpy(dst + dlen, src, size - dlen);
}
+#endif
--
2.14.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] lib: fix multiple strlcpy definition
2017-09-28 18:02 [PATCH v2] lib: fix multiple strlcpy definition Baruch Siach
@ 2017-09-29 18:58 ` Stephen Hemminger
2017-09-30 20:29 ` Baruch Siach
0 siblings, 1 reply; 3+ messages in thread
From: Stephen Hemminger @ 2017-09-29 18:58 UTC (permalink / raw)
To: Baruch Siach; +Cc: netdev, Phil Sutter
On Thu, 28 Sep 2017 21:02:11 +0300
Baruch Siach <baruch@tkos.co.il> wrote:
> Some C libraries, like uClibc and musl, provide BSD compatible
> strlcpy(). Add check_strlcpy() to configure, and avoid defining strlcpy
> and strlcat when the C library provides them.
>
> This fixes the following static link error with uClibc-ng:
>
> .../sysroot/usr/lib/libc.a(strlcpy.os): In function `strlcpy':
> strlcpy.c:(.text+0x0): multiple definition of `strlcpy'
> ../lib/libutil.a(utils.o):utils.c:(.text+0x1ddc): first defined here
> collect2: error: ld returned 1 exit status
>
> Acked-by: Phil Sutter <phil@nwl.cc>
> Signed-off-by: Baruch Siach <baruch@tkos.co.il>
This is OK because it doesn't impact normal glibc too much.
> diff --git a/lib/Makefile b/lib/Makefile
> index 0fbdf4c31f50..132ad00c3335 100644
> --- a/lib/Makefile
> +++ b/lib/Makefile
> @@ -1,5 +1,9 @@
> include ../config.mk
>
> +ifeq ($(NEED_STRLCPY),y)
> + CFLAGS += -DNEED_STRLCPY
> +endif
> +
>
I just removed all the conditional CFLAGS out of subdirectory Makefiles
and moved them into the generated config.mk. Please do that for this
as well and resubmit.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] lib: fix multiple strlcpy definition
2017-09-29 18:58 ` Stephen Hemminger
@ 2017-09-30 20:29 ` Baruch Siach
0 siblings, 0 replies; 3+ messages in thread
From: Baruch Siach @ 2017-09-30 20:29 UTC (permalink / raw)
To: Stephen Hemminger; +Cc: netdev, Phil Sutter
Hi Stephen,
On Fri, Sep 29, 2017 at 11:58:58AM -0700, Stephen Hemminger wrote:
> On Thu, 28 Sep 2017 21:02:11 +0300
> Baruch Siach <baruch@tkos.co.il> wrote:
>
> > Some C libraries, like uClibc and musl, provide BSD compatible
> > strlcpy(). Add check_strlcpy() to configure, and avoid defining strlcpy
> > and strlcat when the C library provides them.
> >
> > This fixes the following static link error with uClibc-ng:
> >
> > .../sysroot/usr/lib/libc.a(strlcpy.os): In function `strlcpy':
> > strlcpy.c:(.text+0x0): multiple definition of `strlcpy'
> > ../lib/libutil.a(utils.o):utils.c:(.text+0x1ddc): first defined here
> > collect2: error: ld returned 1 exit status
> >
> > Acked-by: Phil Sutter <phil@nwl.cc>
> > Signed-off-by: Baruch Siach <baruch@tkos.co.il>
>
> This is OK because it doesn't impact normal glibc too much.
>
> > diff --git a/lib/Makefile b/lib/Makefile
> > index 0fbdf4c31f50..132ad00c3335 100644
> > --- a/lib/Makefile
> > +++ b/lib/Makefile
> > @@ -1,5 +1,9 @@
> > include ../config.mk
> >
> > +ifeq ($(NEED_STRLCPY),y)
> > + CFLAGS += -DNEED_STRLCPY
> > +endif
> > +
>
> I just removed all the conditional CFLAGS out of subdirectory Makefiles
> and moved them into the generated config.mk. Please do that for this
> as well and resubmit.
What code do you refer to? I don't see that as of current master
(e4139268ba96).
baruch
--
http://baruch.siach.name/blog/ ~. .~ Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
- baruch@tkos.co.il - tel: +972.52.368.4656, http://www.tkos.co.il -
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-09-30 20:29 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-09-28 18:02 [PATCH v2] lib: fix multiple strlcpy definition Baruch Siach
2017-09-29 18:58 ` Stephen Hemminger
2017-09-30 20:29 ` Baruch Siach
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox