diff mbox

[1/2] package.snappy: fix static builds

Message ID 1475348688-1805-1-git-send-email-yann.morin.1998@free.fr
State Accepted
Commit 0e2ee0e6e8076d233402766086aa4c6297c62cb9
Headers show

Commit Message

Yann E. MORIN Oct. 1, 2016, 7:04 p.m. UTC
For some toolchains, libstdc++ uses pthread symbols:

    .../lib/libstdc++.a(eh_alloc.o): In function `__gnu_cxx::__mutex::lock()':
    eh_alloc.cc:(.text._ZN9__gnu_cxx7__mutex4lockEv[_ZN9__gnu_cxx7__mutex4lockEv]+0x2):
    undefined reference to `pthread_mutex_lock'

and a lot of other pthread symbols...

However, when doing a static build, there is no way for the linker what
library to link in, so the build fails miserably if -pthread is not
specified at link time.

Fixes:
    http://autobuild.buildroot.org/results/15e/15ecaa23f0116e8120b3d62e553c838f0303df35/
    http://autobuild.buildroot.org/results/f0a/f0abe301816e39eb4ae26d3e8cd42d90901d5ac5/

Signed-off-by: "Yann E. MORIN" <yann.morin.1998@free.fr>

---
Note: snappy's buildsystem uses libtool, and libsnappy.la does have the
necessary -pthread listed as a "dependency":

   16 # Linker flags that cannot go in dependency_libs.
   17 inherited_linker_flags=' -pthread'

But that is not picked-up by libtool, and I don't know why...
---
 package/snappy/snappy.mk | 8 ++++++++
 1 file changed, 8 insertions(+)

Comments

Peter Korsgaard Oct. 2, 2016, 7:19 p.m. UTC | #1
>>>>> "Yann" == Yann E MORIN <yann.morin.1998@free.fr> writes:

 > For some toolchains, libstdc++ uses pthread symbols:
 >     .../lib/libstdc++.a(eh_alloc.o): In function `__gnu_cxx::__mutex::lock()':
 >     eh_alloc.cc:(.text._ZN9__gnu_cxx7__mutex4lockEv[_ZN9__gnu_cxx7__mutex4lockEv]+0x2):
 >     undefined reference to `pthread_mutex_lock'

 > and a lot of other pthread symbols...

 > However, when doing a static build, there is no way for the linker what
 > library to link in, so the build fails miserably if -pthread is not
 > specified at link time.

 > Fixes:
 >     http://autobuild.buildroot.org/results/15e/15ecaa23f0116e8120b3d62e553c838f0303df35/
 >     http://autobuild.buildroot.org/results/f0a/f0abe301816e39eb4ae26d3e8cd42d90901d5ac5/

 > Signed-off-by: "Yann E. MORIN" <yann.morin.1998@free.fr>

 > ---
 > Note: snappy's buildsystem uses libtool, and libsnappy.la does have the
 > necessary -pthread listed as a "dependency":

 >    16 # Linker flags that cannot go in dependency_libs.
 >    17 inherited_linker_flags=' -pthread'

 > But that is not picked-up by libtool, and I don't know why...

This is arguably a toolchain bug and the thing that fails to link is
just a unit test, so we could also disable it - But OK.

> ---
 >  package/snappy/snappy.mk | 8 ++++++++
 >  1 file changed, 8 insertions(+)

 > diff --git a/package/snappy/snappy.mk b/package/snappy/snappy.mk
 > index b00dddf..3e8d603 100644
 > --- a/package/snappy/snappy.mk
 > +++ b/package/snappy/snappy.mk
 > @@ -16,4 +16,12 @@ SNAPPY_INSTALL_STAGING = YES
 >  # Disable tests
 >  SNAPPY_CONF_OPTS = --disable-gtest
 
 > +# libsnappy links with libstdc++. libstdc++ uses pthread symbols. libstdc++
 > +# does not have a .pc file, and its .la file does not mention -pthread.
 > +# So, static links to libstdc++ will fail if -pthread is not explicity
 > +# linked to. Only do that for static builds.
 > +ifeq ($(BR2_STATIC_LIBS),y)
 > +SNAPPY_CONF_OPTS += LIBS=-pthread
 > +endif

Snappy doesn't depend on threads, so this should only be done if
BR2_TOOLCHAIN_HAS_THREADS.

Committed with that fixed, thanks.
diff mbox

Patch

diff --git a/package/snappy/snappy.mk b/package/snappy/snappy.mk
index b00dddf..3e8d603 100644
--- a/package/snappy/snappy.mk
+++ b/package/snappy/snappy.mk
@@ -16,4 +16,12 @@  SNAPPY_INSTALL_STAGING = YES
 # Disable tests
 SNAPPY_CONF_OPTS = --disable-gtest
 
+# libsnappy links with libstdc++. libstdc++ uses pthread symbols. libstdc++
+# does not have a .pc file, and its .la file does not mention -pthread.
+# So, static links to libstdc++ will fail if -pthread is not explicity
+# linked to. Only do that for static builds.
+ifeq ($(BR2_STATIC_LIBS),y)
+SNAPPY_CONF_OPTS += LIBS=-pthread
+endif
+
 $(eval $(autotools-package))