Buildroot Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
To: buildroot@busybox.net
Subject: [Buildroot] [PATCH 2/2] fwup: link in pthreads for static builds
Date: Fri, 12 Aug 2016 00:06:28 +0200	[thread overview]
Message-ID: <20160812000628.3fc05f4e@free-electrons.com> (raw)
In-Reply-To: <1470868546-8237-2-git-send-email-fhunleth@troodon-software.com>

Hello,

On Wed, 10 Aug 2016 18:35:46 -0400, Frank Hunleth wrote:
> Both libconfuse (via libintl) and libarchive have references to pthreads
> but do not specify pthreads in their pkg-config descriptions. This
> change adds pthreads to the fwup linker options so that the link step
> succeeds.

I've finally taken some time to look into this, and I believe your fix
is not the right fix, and the bug is in fact in uClibc (and I have
already posted a mail on the uClibc mailing list about this).

The fact that libintl and libarchive do *not* link with libpthread is
intentional and actually a feature. As explained in my mail to the
uClibc mailing list [1], the idea is that those libraries don't need
threads, they only need to be thread-safe if threads are used by the
application using them.

So the libc part of the C library contains a stub implementation of
those functions, while the libpthread part of the C library contains
the real implementation.

So, libintl and libarchive are only linked against libc.so. If you make
a regular, non-threaded application, linked against libintl and/or
libarchive, then those libraries will use the stub version of the
pthread functions. This is correct and actually good: your application
is not multi-threaded, so why suffer the cost of acquiring/releasing a
mutex?

If on the other hand, your application is multi-threaded, it will link
against libpthread. In this case, the pthread_mutex_*() calls from
libarchive or libintl will use the real implementation from libpthread,
and those libraries will have a thread-safe behavior.

The problem is that this doesn't work with static linking with uClibc.
I believe it's a uClibc bug, but I'm not entirely sure either.

So, if fwup links fine dynamically (i.e without linking against
pthread), there should be no reason to link it with pthread for static
linking.

[1] http://mailman.uclibc-ng.org/pipermail/devel/2016-August/001132.html

Thomas
-- 
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com

  reply	other threads:[~2016-08-11 22:06 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-10 22:35 [Buildroot] [PATCH 1/2] fwup: bump version to v0.8.2 Frank Hunleth
2016-08-10 22:35 ` [Buildroot] [PATCH 2/2] fwup: link in pthreads for static builds Frank Hunleth
2016-08-11 22:06   ` Thomas Petazzoni [this message]
2016-08-12  2:32     ` Frank Hunleth
2016-08-12  4:54     ` Khem Raj
2016-08-12 13:51       ` Thomas Petazzoni
2016-08-12 15:05         ` Khem Raj
2016-10-16 14:32   ` Thomas Petazzoni
2016-10-16 15:02     ` Frank Hunleth
2016-08-20 13:04 ` [Buildroot] [PATCH 1/2] fwup: bump version to v0.8.2 Thomas Petazzoni

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160812000628.3fc05f4e@free-electrons.com \
    --to=thomas.petazzoni@free-electrons.com \
    --cc=buildroot@busybox.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox