All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Theodore Ts'o" <tytso@mit.edu>
To: "Darrick J. Wong" <djwong@kernel.org>
Cc: Eric Sandeen <sandeen@sandeen.net>, linux-xfs@vger.kernel.org
Subject: Re: [PATCH] xfsprogs: fix static build problems caused by liburcu
Date: Sat, 8 Jan 2022 23:13:40 -0500	[thread overview]
Message-ID: <Ydpg9H7t/hJq0Dz+@mit.edu> (raw)
In-Reply-To: <20220108232338.GV656707@magnolia>

On Sat, Jan 08, 2022 at 03:23:38PM -0800, Darrick J. Wong wrote:
> On Sat, Jan 08, 2022 at 02:57:39PM -0500, Theodore Ts'o wrote:
> > The liburcu library has a dependency on pthreads.  Hence, in order for
> > static builds of xfsprogs to work, $(LIBPTHREAD) needs to appear
> > *after* $(LUBURCU) in LLDLIBS.  Otherwise, static links of xfs_* will
> > fail due to undefined references of pthread_create, pthread_exit,
> > et. al.
> > 
> > Signed-off-by: Theodore Ts'o <tytso@mit.edu>
> 
> Ugh, I keep forgetting that ld wants library dependencies in reverse
> order nowadays...

Actually, for static linking this has always been the case.  For
example if foo_init() in libfoo calls bar_init() from libbar, you have
to specify the order as "-lfoo -lbar".  That's because the static
linker processes the libraries once, in command-line order.  So when
the program uses (and thus pulls in foo_init), the linker searches
-lfoo to find foo_init, and then looks at what symbols it needs, and
then will start searching the rest of the libraries to find bar_init,
which it will find only if -lbar is specified after -lfoo.

The problem is we've gotten spoiled by ELF shared libraries, where the
symbols are resolved as they are needed, so when main() calls
foo_init() at runtime, only then will the shared linker look for
bar_init(), which it will find regardless of wheter the libraries are
specified as "-lfoo -lbar" or "-lbar -lfoo".

So in general, libraries which are used by other libraries, but which
have no dependenciees of their own, should be listed last.  This
includes libraries such as -lpthread, -lsocket on Solaris, -lnsl (if
you use NIS/Yellow Pages), etc. --- but you'll only notice if you try
static linking.

Cheers,

					- Ted

      reply	other threads:[~2022-01-09  4:13 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-08 19:57 [PATCH] xfsprogs: fix static build problems caused by liburcu Theodore Ts'o
2022-01-08 23:23 ` Darrick J. Wong
2022-01-09  4:13   ` Theodore Ts'o [this message]

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=Ydpg9H7t/hJq0Dz+@mit.edu \
    --to=tytso@mit.edu \
    --cc=djwong@kernel.org \
    --cc=linux-xfs@vger.kernel.org \
    --cc=sandeen@sandeen.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.