diff mbox series

[v3,1/1] package/zstd: fix build without threads

Message ID 20220612160217.2210177-1-fontaine.fabrice@gmail.com
State Accepted
Headers show
Series [v3,1/1] package/zstd: fix build without threads | expand

Commit Message

Fabrice Fontaine June 12, 2022, 4:02 p.m. UTC
Move libzstd.pc in ZSTD_BUILD_LIBS so it will be suffixed by -nomt
without threads. As a result, libzstd.pc will not contain -pthread in
Libs.Private which will avoid the following static build failure with
zchunk) raised since commit 0f0e913f10caf21f23c2e46f210519a7a3bc0b32:

/home/buildroot/autobuild/instance-2/output-1/host/bin/aarch64_be-buildroot-linux-uclibc-gcc  -o src/unzck src/unzck.p/unzck.c.o src/unzck.p/util_common.c.o -Wl,--as-needed -Wl,--no-undefined -static -Wl,--start-group src/lib/libzck.a -largp /home/buildroot/autobuild/instance-2/output-1/host/aarch64_be-buildroot-linux-uclibc/sysroot/usr/lib/libzstd.a -pthread /home/buildroot/autobuild/instance-2/output-1/host/aarch64_be-buildroot-linux-uclibc/sysroot/usr/lib/libssl.a /home/buildroot/autobuild/instance-2/output-1/host/aarch64_be-buildroot-linux-uclibc/sysroot/usr/lib/libcrypto.a -Wl,--end-group
/home/buildroot/autobuild/instance-2/output-1/host/lib/gcc/aarch64_be-buildroot-linux-uclibc/10.3.0/../../../../aarch64_be-buildroot-linux-uclibc/bin/ld: cannot find -lpthread

Fixes:
 - http://autobuild.buildroot.org/results/481d1979920daaecac48dec763151e124651740f

Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
---
Changes v2 -> v3 (after review of Yann E. Morin):
 - Drop ZSTD_BUILD_LIBS overrides

Changes v1 -> v2:
 - Fix the following check-package error:
   package/zstd/zstd.mk:67: conditional override of variable ZSTD_BUILD_LIBS
   package/zstd/zstd.mk:70: conditional override of variable ZSTD_BUILD_LIBS

 package/zstd/zstd.mk | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

Comments

Yann E. MORIN June 12, 2022, 5:13 p.m. UTC | #1
Fabrice, All,

On 2022-06-12 18:02 +0200, Fabrice Fontaine spake thusly:
> Move libzstd.pc in ZSTD_BUILD_LIBS so it will be suffixed by -nomt
> without threads. As a result, libzstd.pc will not contain -pthread in
> Libs.Private which will avoid the following static build failure with
> zchunk) raised since commit 0f0e913f10caf21f23c2e46f210519a7a3bc0b32:
> 
> /home/buildroot/autobuild/instance-2/output-1/host/bin/aarch64_be-buildroot-linux-uclibc-gcc  -o src/unzck src/unzck.p/unzck.c.o src/unzck.p/util_common.c.o -Wl,--as-needed -Wl,--no-undefined -static -Wl,--start-group src/lib/libzck.a -largp /home/buildroot/autobuild/instance-2/output-1/host/aarch64_be-buildroot-linux-uclibc/sysroot/usr/lib/libzstd.a -pthread /home/buildroot/autobuild/instance-2/output-1/host/aarch64_be-buildroot-linux-uclibc/sysroot/usr/lib/libssl.a /home/buildroot/autobuild/instance-2/output-1/host/aarch64_be-buildroot-linux-uclibc/sysroot/usr/lib/libcrypto.a -Wl,--end-group
> /home/buildroot/autobuild/instance-2/output-1/host/lib/gcc/aarch64_be-buildroot-linux-uclibc/10.3.0/../../../../aarch64_be-buildroot-linux-uclibc/bin/ld: cannot find -lpthread
> 
> Fixes:
>  - http://autobuild.buildroot.org/results/481d1979920daaecac48dec763151e124651740f

So, I was very curious how the weird buildsystem for zstd would cope,
and I am afraid it does not cope well:

    $ wget -O .config 'http://autobuild.buildroot.org/results/481d1979920daaecac48dec763151e124651740f/config'
    $ make menuconfig
        -> switch to a bootlin toolchain (uClibc only, similar to the
           failing build)
    $ make zstd
    $ cat output/host/aarch64_be-buildroot-linux-uclibc/sysroot/usr/lib/pkgconfig/libzstd.pc
    #   ZSTD - standard compression algorithm
    #   Copyright (C) 2014-2016, Yann Collet, Facebook
    #   BSD 2-Clause License
    #   (http://www.opensource.org/licenses/bsd-license.php)

    prefix=/usr
    exec_prefix=${prefix}
    includedir=${prefix}/include
    libdir=${exec_prefix}/lib

    Name: zstd
    Description: fast lossless compression algorithm library
    URL: http://www.zstd.net/
    Version: 1.5.2
    Libs: -L${libdir} -lzstd
    Libs.private: -pthread
    Cflags: -I${includedir}

So, we still have -pthread in Libs.Private, which goes contrary to what
you wrote in the commit message...

And sure enough, the build still fails:

    $ make zchunk
    [success]

Wait, what?

Hold on a sec... What happens without your patch applied?

    $ make clean
    $ make zstd
    $ cat output/host/aarch64_be-buildroot-linux-uclibc/sysroot/usr/lib/pkgconfig/libzstd.pc
    #   ZSTD - standard compression algorithm
    #   Copyright (C) 2014-2016, Yann Collet, Facebook
    #   BSD 2-Clause License
    #   (http://www.opensource.org/licenses/bsd-license.php)

    prefix=/usr
    exec_prefix=${prefix}
    includedir=${prefix}/include
    libdir=${exec_prefix}/lib

    Name: zstd
    Description: fast lossless compression algorithm library
    URL: http://www.zstd.net/
    Version: 1.5.2
    Libs: -L${libdir} -lzstd
    Libs.private: -pthread
    Cflags: -I${includedir}

    $ make zchunk
    [success]

Damned... :-/

Regards,
Yann E. MORIN.

> Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
> ---
> Changes v2 -> v3 (after review of Yann E. Morin):
>  - Drop ZSTD_BUILD_LIBS overrides
> 
> Changes v1 -> v2:
>  - Fix the following check-package error:
>    package/zstd/zstd.mk:67: conditional override of variable ZSTD_BUILD_LIBS
>    package/zstd/zstd.mk:70: conditional override of variable ZSTD_BUILD_LIBS
> 
>  package/zstd/zstd.mk | 18 +++++++++++-------
>  1 file changed, 11 insertions(+), 7 deletions(-)
> 
> diff --git a/package/zstd/zstd.mk b/package/zstd/zstd.mk
> index bef46deae8..75eb6ecc07 100644
> --- a/package/zstd/zstd.mk
> +++ b/package/zstd/zstd.mk
> @@ -38,14 +38,15 @@ endif
>  # zstd will append -O3 after $(CFLAGS), use MOREFLAGS to override again
>  ZSTD_OPTS += MOREFLAGS="$(TARGET_OPTIMIZATION) -D_GNU_SOURCE"
>  
> +ZSTD_BUILD_LIBS_BASENAMES = libzstd.pc
>  ifeq ($(BR2_STATIC_LIBS),y)
> -ZSTD_BUILD_LIBS = libzstd.a
> +ZSTD_BUILD_LIBS_BASENAMES += libzstd.a
>  ZSTD_INSTALL_LIBS = install-static
>  else ifeq ($(BR2_SHARED_LIBS),y)
> -ZSTD_BUILD_LIBS = lib
> +ZSTD_BUILD_LIBS_BASENAMES += lib
>  ZSTD_INSTALL_LIBS = install-shared
>  else
> -ZSTD_BUILD_LIBS = lib
> +ZSTD_BUILD_LIBS_BASENAMES += lib
>  ZSTD_INSTALL_LIBS = install-static install-shared
>  endif
>  
> @@ -63,17 +64,20 @@ endif
>  # purpose.
>  ifeq ($(BR2_TOOLCHAIN_HAS_THREADS),y)
>  ZSTD_OPTS += HAVE_THREAD=1
> -ZSTD_BUILD_LIBS := $(addsuffix -mt,$(ZSTD_BUILD_LIBS))
> +ZSTD_BUILD_LIBS_THREAD_SUFFIX = -mt
>  else
>  ZSTD_OPTS += HAVE_THREAD=0
> -ZSTD_BUILD_LIBS := $(addsuffix -nomt,$(ZSTD_BUILD_LIBS))
> +ZSTD_BUILD_LIBS_THREAD_SUFFIX = -nomt
>  endif
>  # check-package disable OverriddenVariable - override intended
> -ZSTD_BUILD_LIBS := $(addsuffix -release,$(ZSTD_BUILD_LIBS))
> +ZSTD_BUILD_LIBS = \
> +	$(addsuffix -release, \
> +		$(addsuffix $(ZSTD_BUILD_LIBS_THREAD_SUFFIX), \
> +			$(ZSTD_BUILD_LIBS_BASENAMES)))
>  
>  define ZSTD_BUILD_CMDS
>  	$(TARGET_MAKE_ENV) $(TARGET_CONFIGURE_OPTS) $(MAKE) $(ZSTD_OPTS) \
> -		-C $(@D)/lib $(ZSTD_BUILD_LIBS) libzstd.pc
> +		-C $(@D)/lib $(ZSTD_BUILD_LIBS)
>  	$(TARGET_MAKE_ENV) $(TARGET_CONFIGURE_OPTS) $(MAKE) $(ZSTD_OPTS) \
>  		-C $(@D)/programs $(ZSTD_BUILD_PROG_TARGET)
>  endef
> -- 
> 2.35.1
> 
> _______________________________________________
> buildroot mailing list
> buildroot@buildroot.org
> https://lists.buildroot.org/mailman/listinfo/buildroot
Yann E. MORIN June 12, 2022, 5:40 p.m. UTC | #2
Fabrice, All,

On 2022-06-12 19:13 +0200, Yann E. MORIN spake thusly:
> On 2022-06-12 18:02 +0200, Fabrice Fontaine spake thusly:
> > Move libzstd.pc in ZSTD_BUILD_LIBS so it will be suffixed by -nomt
> > without threads. As a result, libzstd.pc will not contain -pthread in
> > Libs.Private which will avoid the following static build failure with
> > zchunk) raised since commit 0f0e913f10caf21f23c2e46f210519a7a3bc0b32:
> > 
> > /home/buildroot/autobuild/instance-2/output-1/host/bin/aarch64_be-buildroot-linux-uclibc-gcc  -o src/unzck src/unzck.p/unzck.c.o src/unzck.p/util_common.c.o -Wl,--as-needed -Wl,--no-undefined -static -Wl,--start-group src/lib/libzck.a -largp /home/buildroot/autobuild/instance-2/output-1/host/aarch64_be-buildroot-linux-uclibc/sysroot/usr/lib/libzstd.a -pthread /home/buildroot/autobuild/instance-2/output-1/host/aarch64_be-buildroot-linux-uclibc/sysroot/usr/lib/libssl.a /home/buildroot/autobuild/instance-2/output-1/host/aarch64_be-buildroot-linux-uclibc/sysroot/usr/lib/libcrypto.a -Wl,--end-group
> > /home/buildroot/autobuild/instance-2/output-1/host/lib/gcc/aarch64_be-buildroot-linux-uclibc/10.3.0/../../../../aarch64_be-buildroot-linux-uclibc/bin/ld: cannot find -lpthread
> > 
> > Fixes:
> >  - http://autobuild.buildroot.org/results/481d1979920daaecac48dec763151e124651740f
> > 
> > Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
> > ---
> > Changes v2 -> v3 (after review of Yann E. Morin):
> >  - Drop ZSTD_BUILD_LIBS overrides
> > 
> > Changes v1 -> v2:
> >  - Fix the following check-package error:
> >    package/zstd/zstd.mk:67: conditional override of variable ZSTD_BUILD_LIBS
> >    package/zstd/zstd.mk:70: conditional override of variable ZSTD_BUILD_LIBS
> > 
> >  package/zstd/zstd.mk | 18 +++++++++++-------
> >  1 file changed, 11 insertions(+), 7 deletions(-)
> > 
> > diff --git a/package/zstd/zstd.mk b/package/zstd/zstd.mk
> > index bef46deae8..75eb6ecc07 100644
> > --- a/package/zstd/zstd.mk
> > +++ b/package/zstd/zstd.mk
> > @@ -38,14 +38,15 @@ endif
> >  # zstd will append -O3 after $(CFLAGS), use MOREFLAGS to override again
> >  ZSTD_OPTS += MOREFLAGS="$(TARGET_OPTIMIZATION) -D_GNU_SOURCE"
                                                   ^^^^^^^^^^^^^^
I forgot to mention: this patch does not aply cleanly, because ^^ is not
in master...

Regards,
Yann E. MORIN.

> > +ZSTD_BUILD_LIBS_BASENAMES = libzstd.pc
> >  ifeq ($(BR2_STATIC_LIBS),y)
> > -ZSTD_BUILD_LIBS = libzstd.a
> > +ZSTD_BUILD_LIBS_BASENAMES += libzstd.a
> >  ZSTD_INSTALL_LIBS = install-static
> >  else ifeq ($(BR2_SHARED_LIBS),y)
> > -ZSTD_BUILD_LIBS = lib
> > +ZSTD_BUILD_LIBS_BASENAMES += lib
> >  ZSTD_INSTALL_LIBS = install-shared
> >  else
> > -ZSTD_BUILD_LIBS = lib
> > +ZSTD_BUILD_LIBS_BASENAMES += lib
> >  ZSTD_INSTALL_LIBS = install-static install-shared
> >  endif
> >  
> > @@ -63,17 +64,20 @@ endif
> >  # purpose.
> >  ifeq ($(BR2_TOOLCHAIN_HAS_THREADS),y)
> >  ZSTD_OPTS += HAVE_THREAD=1
> > -ZSTD_BUILD_LIBS := $(addsuffix -mt,$(ZSTD_BUILD_LIBS))
> > +ZSTD_BUILD_LIBS_THREAD_SUFFIX = -mt
> >  else
> >  ZSTD_OPTS += HAVE_THREAD=0
> > -ZSTD_BUILD_LIBS := $(addsuffix -nomt,$(ZSTD_BUILD_LIBS))
> > +ZSTD_BUILD_LIBS_THREAD_SUFFIX = -nomt
> >  endif
> >  # check-package disable OverriddenVariable - override intended
> > -ZSTD_BUILD_LIBS := $(addsuffix -release,$(ZSTD_BUILD_LIBS))
> > +ZSTD_BUILD_LIBS = \
> > +	$(addsuffix -release, \
> > +		$(addsuffix $(ZSTD_BUILD_LIBS_THREAD_SUFFIX), \
> > +			$(ZSTD_BUILD_LIBS_BASENAMES)))
> >  
> >  define ZSTD_BUILD_CMDS
> >  	$(TARGET_MAKE_ENV) $(TARGET_CONFIGURE_OPTS) $(MAKE) $(ZSTD_OPTS) \
> > -		-C $(@D)/lib $(ZSTD_BUILD_LIBS) libzstd.pc
> > +		-C $(@D)/lib $(ZSTD_BUILD_LIBS)
> >  	$(TARGET_MAKE_ENV) $(TARGET_CONFIGURE_OPTS) $(MAKE) $(ZSTD_OPTS) \
> >  		-C $(@D)/programs $(ZSTD_BUILD_PROG_TARGET)
> >  endef
> > -- 
> > 2.35.1
> > 
> > _______________________________________________
> > buildroot mailing list
> > buildroot@buildroot.org
> > https://lists.buildroot.org/mailman/listinfo/buildroot
> 
> -- 
> .-----------------.--------------------.------------------.--------------------.
> |  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
> | +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
> | +33 561 099 427 `------------.-------:  X  AGAINST      |  \e/  There is no  |
> | http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
> '------------------------------^-------^------------------^--------------------'
> _______________________________________________
> buildroot mailing list
> buildroot@buildroot.org
> https://lists.buildroot.org/mailman/listinfo/buildroot
Fabrice Fontaine June 12, 2022, 6:13 p.m. UTC | #3
Yann,

Le dim. 12 juin 2022 à 19:13, Yann E. MORIN <yann.morin.1998@free.fr> a écrit :
>
> Fabrice, All,
>
> On 2022-06-12 18:02 +0200, Fabrice Fontaine spake thusly:
> > Move libzstd.pc in ZSTD_BUILD_LIBS so it will be suffixed by -nomt
> > without threads. As a result, libzstd.pc will not contain -pthread in
> > Libs.Private which will avoid the following static build failure with
> > zchunk) raised since commit 0f0e913f10caf21f23c2e46f210519a7a3bc0b32:
> >
> > /home/buildroot/autobuild/instance-2/output-1/host/bin/aarch64_be-buildroot-linux-uclibc-gcc  -o src/unzck src/unzck.p/unzck.c.o src/unzck.p/util_common.c.o -Wl,--as-needed -Wl,--no-undefined -static -Wl,--start-group src/lib/libzck.a -largp /home/buildroot/autobuild/instance-2/output-1/host/aarch64_be-buildroot-linux-uclibc/sysroot/usr/lib/libzstd.a -pthread /home/buildroot/autobuild/instance-2/output-1/host/aarch64_be-buildroot-linux-uclibc/sysroot/usr/lib/libssl.a /home/buildroot/autobuild/instance-2/output-1/host/aarch64_be-buildroot-linux-uclibc/sysroot/usr/lib/libcrypto.a -Wl,--end-group
> > /home/buildroot/autobuild/instance-2/output-1/host/lib/gcc/aarch64_be-buildroot-linux-uclibc/10.3.0/../../../../aarch64_be-buildroot-linux-uclibc/bin/ld: cannot find -lpthread
> >
> > Fixes:
> >  - http://autobuild.buildroot.org/results/481d1979920daaecac48dec763151e124651740f
>
> So, I was very curious how the weird buildsystem for zstd would cope,
> and I am afraid it does not cope well:
>
>     $ wget -O .config 'http://autobuild.buildroot.org/results/481d1979920daaecac48dec763151e124651740f/config'
>     $ make menuconfig
>         -> switch to a bootlin toolchain (uClibc only, similar to the
>            failing build)

Why are you switching to a different toolchain instead of using the
same defconfig?
Indeed, to my understanding of
toolchain/toolchain-external/toolchain-external-bootlin/Config.in.options,
all uclibc bootlin toolchains have thread support ...

>     $ make zstd
>     $ cat output/host/aarch64_be-buildroot-linux-uclibc/sysroot/usr/lib/pkgconfig/libzstd.pc
>     #   ZSTD - standard compression algorithm
>     #   Copyright (C) 2014-2016, Yann Collet, Facebook
>     #   BSD 2-Clause License
>     #   (http://www.opensource.org/licenses/bsd-license.php)
>
>     prefix=/usr
>     exec_prefix=${prefix}
>     includedir=${prefix}/include
>     libdir=${exec_prefix}/lib
>
>     Name: zstd
>     Description: fast lossless compression algorithm library
>     URL: http://www.zstd.net/
>     Version: 1.5.2
>     Libs: -L${libdir} -lzstd
>     Libs.private: -pthread
>     Cflags: -I${includedir}
>
> So, we still have -pthread in Libs.Private, which goes contrary to what
> you wrote in the commit message...

With the failing defconfig (which doesn't have threads), I'm able to
reproduce the build failure without my patch and the build success
with my patch.

Libs.private is set from LIBS_PRIVATE:
https://github.com/facebook/zstd/blob/3b1bd91852dd0c031b72c734a3056e205619590b/lib/Makefile#L307

LIBS_PRIVATE is replaced by LDFLAGS_DYNLIB which is set to an empty
value for all targets suffixed by -nomt:
https://github.com/facebook/zstd/blob/3b1bd91852dd0c031b72c734a3056e205619590b/lib/Makefile#L191

If needed, I can send a v4 that applies cleanly on master.

>
> And sure enough, the build still fails:
>
>     $ make zchunk
>     [success]
>
> Wait, what?
>
> Hold on a sec... What happens without your patch applied?
>
>     $ make clean
>     $ make zstd
>     $ cat output/host/aarch64_be-buildroot-linux-uclibc/sysroot/usr/lib/pkgconfig/libzstd.pc
>     #   ZSTD - standard compression algorithm
>     #   Copyright (C) 2014-2016, Yann Collet, Facebook
>     #   BSD 2-Clause License
>     #   (http://www.opensource.org/licenses/bsd-license.php)
>
>     prefix=/usr
>     exec_prefix=${prefix}
>     includedir=${prefix}/include
>     libdir=${exec_prefix}/lib
>
>     Name: zstd
>     Description: fast lossless compression algorithm library
>     URL: http://www.zstd.net/
>     Version: 1.5.2
>     Libs: -L${libdir} -lzstd
>     Libs.private: -pthread
>     Cflags: -I${includedir}
>
>     $ make zchunk
>     [success]
>
> Damned... :-/
>
> Regards,
> Yann E. MORIN.
>
> > Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
> > ---
> > Changes v2 -> v3 (after review of Yann E. Morin):
> >  - Drop ZSTD_BUILD_LIBS overrides
> >
> > Changes v1 -> v2:
> >  - Fix the following check-package error:
> >    package/zstd/zstd.mk:67: conditional override of variable ZSTD_BUILD_LIBS
> >    package/zstd/zstd.mk:70: conditional override of variable ZSTD_BUILD_LIBS
> >
> >  package/zstd/zstd.mk | 18 +++++++++++-------
> >  1 file changed, 11 insertions(+), 7 deletions(-)
> >
> > diff --git a/package/zstd/zstd.mk b/package/zstd/zstd.mk
> > index bef46deae8..75eb6ecc07 100644
> > --- a/package/zstd/zstd.mk
> > +++ b/package/zstd/zstd.mk
> > @@ -38,14 +38,15 @@ endif
> >  # zstd will append -O3 after $(CFLAGS), use MOREFLAGS to override again
> >  ZSTD_OPTS += MOREFLAGS="$(TARGET_OPTIMIZATION) -D_GNU_SOURCE"
> >
> > +ZSTD_BUILD_LIBS_BASENAMES = libzstd.pc
> >  ifeq ($(BR2_STATIC_LIBS),y)
> > -ZSTD_BUILD_LIBS = libzstd.a
> > +ZSTD_BUILD_LIBS_BASENAMES += libzstd.a
> >  ZSTD_INSTALL_LIBS = install-static
> >  else ifeq ($(BR2_SHARED_LIBS),y)
> > -ZSTD_BUILD_LIBS = lib
> > +ZSTD_BUILD_LIBS_BASENAMES += lib
> >  ZSTD_INSTALL_LIBS = install-shared
> >  else
> > -ZSTD_BUILD_LIBS = lib
> > +ZSTD_BUILD_LIBS_BASENAMES += lib
> >  ZSTD_INSTALL_LIBS = install-static install-shared
> >  endif
> >
> > @@ -63,17 +64,20 @@ endif
> >  # purpose.
> >  ifeq ($(BR2_TOOLCHAIN_HAS_THREADS),y)
> >  ZSTD_OPTS += HAVE_THREAD=1
> > -ZSTD_BUILD_LIBS := $(addsuffix -mt,$(ZSTD_BUILD_LIBS))
> > +ZSTD_BUILD_LIBS_THREAD_SUFFIX = -mt
> >  else
> >  ZSTD_OPTS += HAVE_THREAD=0
> > -ZSTD_BUILD_LIBS := $(addsuffix -nomt,$(ZSTD_BUILD_LIBS))
> > +ZSTD_BUILD_LIBS_THREAD_SUFFIX = -nomt
> >  endif
> >  # check-package disable OverriddenVariable - override intended
> > -ZSTD_BUILD_LIBS := $(addsuffix -release,$(ZSTD_BUILD_LIBS))
> > +ZSTD_BUILD_LIBS = \
> > +     $(addsuffix -release, \
> > +             $(addsuffix $(ZSTD_BUILD_LIBS_THREAD_SUFFIX), \
> > +                     $(ZSTD_BUILD_LIBS_BASENAMES)))
> >
> >  define ZSTD_BUILD_CMDS
> >       $(TARGET_MAKE_ENV) $(TARGET_CONFIGURE_OPTS) $(MAKE) $(ZSTD_OPTS) \
> > -             -C $(@D)/lib $(ZSTD_BUILD_LIBS) libzstd.pc
> > +             -C $(@D)/lib $(ZSTD_BUILD_LIBS)
> >       $(TARGET_MAKE_ENV) $(TARGET_CONFIGURE_OPTS) $(MAKE) $(ZSTD_OPTS) \
> >               -C $(@D)/programs $(ZSTD_BUILD_PROG_TARGET)
> >  endef
> > --
> > 2.35.1
> >
> > _______________________________________________
> > buildroot mailing list
> > buildroot@buildroot.org
> > https://lists.buildroot.org/mailman/listinfo/buildroot
>
> --
> .-----------------.--------------------.------------------.--------------------.
> |  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
> | +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
> | +33 561 099 427 `------------.-------:  X  AGAINST      |  \e/  There is no  |
> | http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
> '------------------------------^-------^------------------^--------------------'
Best Regards,

Fabrice
Yann E. MORIN June 12, 2022, 6:47 p.m. UTC | #4
Fabrice, All,

On 2022-06-12 20:13 +0200, Fabrice Fontaine spake thusly:
> Le dim. 12 juin 2022 à 19:13, Yann E. MORIN <yann.morin.1998@free.fr> a écrit :
> > On 2022-06-12 18:02 +0200, Fabrice Fontaine spake thusly:
> > > Move libzstd.pc in ZSTD_BUILD_LIBS so it will be suffixed by -nomt
> > > without threads. As a result, libzstd.pc will not contain -pthread in
> > > Libs.Private which will avoid the following static build failure with
> > > zchunk) raised since commit 0f0e913f10caf21f23c2e46f210519a7a3bc0b32:
> > >
> > > /home/buildroot/autobuild/instance-2/output-1/host/bin/aarch64_be-buildroot-linux-uclibc-gcc  -o src/unzck src/unzck.p/unzck.c.o src/unzck.p/util_common.c.o -Wl,--as-needed -Wl,--no-undefined -static -Wl,--start-group src/lib/libzck.a -largp /home/buildroot/autobuild/instance-2/output-1/host/aarch64_be-buildroot-linux-uclibc/sysroot/usr/lib/libzstd.a -pthread /home/buildroot/autobuild/instance-2/output-1/host/aarch64_be-buildroot-linux-uclibc/sysroot/usr/lib/libssl.a /home/buildroot/autobuild/instance-2/output-1/host/aarch64_be-buildroot-linux-uclibc/sysroot/usr/lib/libcrypto.a -Wl,--end-group
> > > /home/buildroot/autobuild/instance-2/output-1/host/lib/gcc/aarch64_be-buildroot-linux-uclibc/10.3.0/../../../../aarch64_be-buildroot-linux-uclibc/bin/ld: cannot find -lpthread
> > >
> > > Fixes:
> > >  - http://autobuild.buildroot.org/results/481d1979920daaecac48dec763151e124651740f
> > So, I was very curious how the weird buildsystem for zstd would cope,
> > and I am afraid it does not cope well:
> >
> >     $ wget -O .config 'http://autobuild.buildroot.org/results/481d1979920daaecac48dec763151e124651740f/config'
> >     $ make menuconfig
> >         -> switch to a bootlin toolchain (uClibc only, similar to the
> >            failing build)
> Why are you switching to a different toolchain instead of using the
> same defconfig?

To speed up the build...

> Indeed, to my understanding of
> toolchain/toolchain-external/toolchain-external-bootlin/Config.in.options,
> all uclibc bootlin toolchains have thread support ...

Good point. Lemme retry that, then.

> If needed, I can send a v4 that applies cleanly on master.

That will no be necessary, I can fix it up when applying.

However, do you have local changes on zstd, that you will be sending
next?

Regards,
Yann E. MORIN.
Yann E. MORIN June 12, 2022, 7:36 p.m. UTC | #5
Fabrice, All,

On 2022-06-12 18:02 +0200, Fabrice Fontaine spake thusly:
> Move libzstd.pc in ZSTD_BUILD_LIBS so it will be suffixed by -nomt
> without threads. As a result, libzstd.pc will not contain -pthread in
> Libs.Private which will avoid the following static build failure with
> zchunk) raised since commit 0f0e913f10caf21f23c2e46f210519a7a3bc0b32:
> 
> /home/buildroot/autobuild/instance-2/output-1/host/bin/aarch64_be-buildroot-linux-uclibc-gcc  -o src/unzck src/unzck.p/unzck.c.o src/unzck.p/util_common.c.o -Wl,--as-needed -Wl,--no-undefined -static -Wl,--start-group src/lib/libzck.a -largp /home/buildroot/autobuild/instance-2/output-1/host/aarch64_be-buildroot-linux-uclibc/sysroot/usr/lib/libzstd.a -pthread /home/buildroot/autobuild/instance-2/output-1/host/aarch64_be-buildroot-linux-uclibc/sysroot/usr/lib/libssl.a /home/buildroot/autobuild/instance-2/output-1/host/aarch64_be-buildroot-linux-uclibc/sysroot/usr/lib/libcrypto.a -Wl,--end-group
> /home/buildroot/autobuild/instance-2/output-1/host/lib/gcc/aarch64_be-buildroot-linux-uclibc/10.3.0/../../../../aarch64_be-buildroot-linux-uclibc/bin/ld: cannot find -lpthread
> 
> Fixes:
>  - http://autobuild.buildroot.org/results/481d1979920daaecac48dec763151e124651740f
> 
> Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>

So, after all my goofiness, we know that there is no regression on
thread-enabled toolchains.

So...

Applied to master, thanks. And sorry for the confusion...

Regards,
Yann E. MORIN.

> ---
> Changes v2 -> v3 (after review of Yann E. Morin):
>  - Drop ZSTD_BUILD_LIBS overrides
> 
> Changes v1 -> v2:
>  - Fix the following check-package error:
>    package/zstd/zstd.mk:67: conditional override of variable ZSTD_BUILD_LIBS
>    package/zstd/zstd.mk:70: conditional override of variable ZSTD_BUILD_LIBS
> 
>  package/zstd/zstd.mk | 18 +++++++++++-------
>  1 file changed, 11 insertions(+), 7 deletions(-)
> 
> diff --git a/package/zstd/zstd.mk b/package/zstd/zstd.mk
> index bef46deae8..75eb6ecc07 100644
> --- a/package/zstd/zstd.mk
> +++ b/package/zstd/zstd.mk
> @@ -38,14 +38,15 @@ endif
>  # zstd will append -O3 after $(CFLAGS), use MOREFLAGS to override again
>  ZSTD_OPTS += MOREFLAGS="$(TARGET_OPTIMIZATION) -D_GNU_SOURCE"
>  
> +ZSTD_BUILD_LIBS_BASENAMES = libzstd.pc
>  ifeq ($(BR2_STATIC_LIBS),y)
> -ZSTD_BUILD_LIBS = libzstd.a
> +ZSTD_BUILD_LIBS_BASENAMES += libzstd.a
>  ZSTD_INSTALL_LIBS = install-static
>  else ifeq ($(BR2_SHARED_LIBS),y)
> -ZSTD_BUILD_LIBS = lib
> +ZSTD_BUILD_LIBS_BASENAMES += lib
>  ZSTD_INSTALL_LIBS = install-shared
>  else
> -ZSTD_BUILD_LIBS = lib
> +ZSTD_BUILD_LIBS_BASENAMES += lib
>  ZSTD_INSTALL_LIBS = install-static install-shared
>  endif
>  
> @@ -63,17 +64,20 @@ endif
>  # purpose.
>  ifeq ($(BR2_TOOLCHAIN_HAS_THREADS),y)
>  ZSTD_OPTS += HAVE_THREAD=1
> -ZSTD_BUILD_LIBS := $(addsuffix -mt,$(ZSTD_BUILD_LIBS))
> +ZSTD_BUILD_LIBS_THREAD_SUFFIX = -mt
>  else
>  ZSTD_OPTS += HAVE_THREAD=0
> -ZSTD_BUILD_LIBS := $(addsuffix -nomt,$(ZSTD_BUILD_LIBS))
> +ZSTD_BUILD_LIBS_THREAD_SUFFIX = -nomt
>  endif
>  # check-package disable OverriddenVariable - override intended
> -ZSTD_BUILD_LIBS := $(addsuffix -release,$(ZSTD_BUILD_LIBS))
> +ZSTD_BUILD_LIBS = \
> +	$(addsuffix -release, \
> +		$(addsuffix $(ZSTD_BUILD_LIBS_THREAD_SUFFIX), \
> +			$(ZSTD_BUILD_LIBS_BASENAMES)))
>  
>  define ZSTD_BUILD_CMDS
>  	$(TARGET_MAKE_ENV) $(TARGET_CONFIGURE_OPTS) $(MAKE) $(ZSTD_OPTS) \
> -		-C $(@D)/lib $(ZSTD_BUILD_LIBS) libzstd.pc
> +		-C $(@D)/lib $(ZSTD_BUILD_LIBS)
>  	$(TARGET_MAKE_ENV) $(TARGET_CONFIGURE_OPTS) $(MAKE) $(ZSTD_OPTS) \
>  		-C $(@D)/programs $(ZSTD_BUILD_PROG_TARGET)
>  endef
> -- 
> 2.35.1
> 
> _______________________________________________
> buildroot mailing list
> buildroot@buildroot.org
> https://lists.buildroot.org/mailman/listinfo/buildroot
Peter Korsgaard June 19, 2022, 1:40 p.m. UTC | #6
On 12/06/2022 18.02, Fabrice Fontaine wrote:
> Move libzstd.pc in ZSTD_BUILD_LIBS so it will be suffixed by -nomt
> without threads. As a result, libzstd.pc will not contain -pthread in
> Libs.Private which will avoid the following static build failure with
> zchunk) raised since commit 0f0e913f10caf21f23c2e46f210519a7a3bc0b32:
> 
> /home/buildroot/autobuild/instance-2/output-1/host/bin/aarch64_be-buildroot-linux-uclibc-gcc  -o src/unzck src/unzck.p/unzck.c.o src/unzck.p/util_common.c.o -Wl,--as-needed -Wl,--no-undefined -static -Wl,--start-group src/lib/libzck.a -largp /home/buildroot/autobuild/instance-2/output-1/host/aarch64_be-buildroot-linux-uclibc/sysroot/usr/lib/libzstd.a -pthread /home/buildroot/autobuild/instance-2/output-1/host/aarch64_be-buildroot-linux-uclibc/sysroot/usr/lib/libssl.a /home/buildroot/autobuild/instance-2/output-1/host/aarch64_be-buildroot-linux-uclibc/sysroot/usr/lib/libcrypto.a -Wl,--end-group
> /home/buildroot/autobuild/instance-2/output-1/host/lib/gcc/aarch64_be-buildroot-linux-uclibc/10.3.0/../../../../aarch64_be-buildroot-linux-uclibc/bin/ld: cannot find -lpthread
> 
> Fixes:
>   - http://autobuild.buildroot.org/results/481d1979920daaecac48dec763151e124651740f
> 
> Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
> ---
> Changes v2 -> v3 (after review of Yann E. Morin):
>   - Drop ZSTD_BUILD_LIBS overrides
> 
> Changes v1 -> v2:
>   - Fix the following check-package error:
>     package/zstd/zstd.mk:67: conditional override of variable ZSTD_BUILD_LIBS
>     package/zstd/zstd.mk:70: conditional override of variable ZSTD_BUILD_LIBS

Committed to 2022.05.x and 2022.02.x, thanks.
diff mbox series

Patch

diff --git a/package/zstd/zstd.mk b/package/zstd/zstd.mk
index bef46deae8..75eb6ecc07 100644
--- a/package/zstd/zstd.mk
+++ b/package/zstd/zstd.mk
@@ -38,14 +38,15 @@  endif
 # zstd will append -O3 after $(CFLAGS), use MOREFLAGS to override again
 ZSTD_OPTS += MOREFLAGS="$(TARGET_OPTIMIZATION) -D_GNU_SOURCE"
 
+ZSTD_BUILD_LIBS_BASENAMES = libzstd.pc
 ifeq ($(BR2_STATIC_LIBS),y)
-ZSTD_BUILD_LIBS = libzstd.a
+ZSTD_BUILD_LIBS_BASENAMES += libzstd.a
 ZSTD_INSTALL_LIBS = install-static
 else ifeq ($(BR2_SHARED_LIBS),y)
-ZSTD_BUILD_LIBS = lib
+ZSTD_BUILD_LIBS_BASENAMES += lib
 ZSTD_INSTALL_LIBS = install-shared
 else
-ZSTD_BUILD_LIBS = lib
+ZSTD_BUILD_LIBS_BASENAMES += lib
 ZSTD_INSTALL_LIBS = install-static install-shared
 endif
 
@@ -63,17 +64,20 @@  endif
 # purpose.
 ifeq ($(BR2_TOOLCHAIN_HAS_THREADS),y)
 ZSTD_OPTS += HAVE_THREAD=1
-ZSTD_BUILD_LIBS := $(addsuffix -mt,$(ZSTD_BUILD_LIBS))
+ZSTD_BUILD_LIBS_THREAD_SUFFIX = -mt
 else
 ZSTD_OPTS += HAVE_THREAD=0
-ZSTD_BUILD_LIBS := $(addsuffix -nomt,$(ZSTD_BUILD_LIBS))
+ZSTD_BUILD_LIBS_THREAD_SUFFIX = -nomt
 endif
 # check-package disable OverriddenVariable - override intended
-ZSTD_BUILD_LIBS := $(addsuffix -release,$(ZSTD_BUILD_LIBS))
+ZSTD_BUILD_LIBS = \
+	$(addsuffix -release, \
+		$(addsuffix $(ZSTD_BUILD_LIBS_THREAD_SUFFIX), \
+			$(ZSTD_BUILD_LIBS_BASENAMES)))
 
 define ZSTD_BUILD_CMDS
 	$(TARGET_MAKE_ENV) $(TARGET_CONFIGURE_OPTS) $(MAKE) $(ZSTD_OPTS) \
-		-C $(@D)/lib $(ZSTD_BUILD_LIBS) libzstd.pc
+		-C $(@D)/lib $(ZSTD_BUILD_LIBS)
 	$(TARGET_MAKE_ENV) $(TARGET_CONFIGURE_OPTS) $(MAKE) $(ZSTD_OPTS) \
 		-C $(@D)/programs $(ZSTD_BUILD_PROG_TARGET)
 endef