Skip to contentSkip to conversation

xfsprogs: fix static build problems caused by liburcu

PATCH In review Theodore Ts'o 2 participants 3 messages Jan 8, 2022 – Jan 9, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xfsprogs: fix static build problems caused by liburcu

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.

---
 copy/Makefile      | 4 ++--
 db/Makefile        | 4 ++--
 growfs/Makefile    | 4 ++--
 logprint/Makefile  | 4 ++--
 mdrestore/Makefile | 3 +--
 mkfs/Makefile      | 4 ++--
 repair/Makefile    | 2 +-
 scrub/Makefile     | 4 ++--
 8 files changed, 14 insertions(+), 15 deletions(-)
copy/Makefile +2 -2
index 1b00cd0d..55160f84 100644
@@ -9,8 +9,8 @@ LTCOMMAND = xfs_copy
 CFILES = xfs_copy.c
 HFILES = xfs_copy.h
 
-LLDLIBS = $(LIBXFS) $(LIBXLOG) $(LIBFROG) $(LIBUUID) $(LIBPTHREAD) $(LIBRT) \
-	  $(LIBURCU)
+LLDLIBS = $(LIBXFS) $(LIBXLOG) $(LIBFROG) $(LIBUUID) $(LIBRT) $(LIBURCU) \
+	  $(LIBPTHREAD)
 LTDEPENDENCIES = $(LIBXFS) $(LIBXLOG) $(LIBFROG)
 LLDFLAGS = -static-libtool-libs
 
db/Makefile +2 -2
index 5c017898..b2e01174 100644
@@ -18,8 +18,8 @@ CFILES = $(HFILES:.h=.c) btdump.c btheight.c convert.c info.c namei.c \
 	timelimit.c
 LSRCFILES = xfs_admin.sh xfs_ncheck.sh xfs_metadump.sh
 
-LLDLIBS	= $(LIBXFS) $(LIBXLOG) $(LIBFROG) $(LIBUUID) $(LIBRT) $(LIBPTHREAD) \
-	  $(LIBURCU)
+LLDLIBS	= $(LIBXFS) $(LIBXLOG) $(LIBFROG) $(LIBUUID) $(LIBRT) $(LIBURCU) \
+	  $(LIBPTHREAD)
 LTDEPENDENCIES = $(LIBXFS) $(LIBXLOG) $(LIBFROG)
 LLDFLAGS += -static-libtool-libs
 
growfs/Makefile +2 -2
index 08601de7..2f4cc66a 100644
@@ -9,8 +9,8 @@ LTCOMMAND = xfs_growfs
 
 CFILES = xfs_growfs.c
 
-LLDLIBS = $(LIBXFS) $(LIBXCMD) $(LIBFROG) $(LIBUUID) $(LIBRT) $(LIBPTHREAD) \
-	  $(LIBURCU)
+LLDLIBS = $(LIBXFS) $(LIBXCMD) $(LIBFROG) $(LIBUUID) $(LIBRT) $(LIBURCU) \
+	  $(LIBPTHREAD)
 
 ifeq ($(ENABLE_EDITLINE),yes)
 LLDLIBS += $(LIBEDITLINE) $(LIBTERMCAP)
logprint/Makefile +2 -2
index cdedbd0d..bbbed5d2 100644
@@ -12,8 +12,8 @@ CFILES = logprint.c \
 	 log_copy.c log_dump.c log_misc.c \
 	 log_print_all.c log_print_trans.c log_redo.c
 
-LLDLIBS	= $(LIBXFS) $(LIBXLOG) $(LIBFROG) $(LIBUUID) $(LIBRT) $(LIBPTHREAD) \
-	  $(LIBURCU)
+LLDLIBS	= $(LIBXFS) $(LIBXLOG) $(LIBFROG) $(LIBUUID) $(LIBRT) $(LIBURCU) \
+	  $(LIBPTHREAD)
 LTDEPENDENCIES = $(LIBXFS) $(LIBXLOG) $(LIBFROG)
 LLDFLAGS = -static-libtool-libs
 
mdrestore/Makefile +1 -2
index 8f28ddab..4a932efb 100644
@@ -8,8 +8,7 @@ include $(TOPDIR)/include/builddefs
 LTCOMMAND = xfs_mdrestore
 CFILES = xfs_mdrestore.c
 
-LLDLIBS = $(LIBXFS) $(LIBFROG) $(LIBRT) $(LIBPTHREAD) $(LIBUUID) \
-	  $(LIBURCU)
+LLDLIBS = $(LIBXFS) $(LIBFROG) $(LIBRT) $(LIBUUID) $(LIBURCU) $(LIBPTHREAD)
 LTDEPENDENCIES = $(LIBXFS) $(LIBFROG)
 LLDFLAGS = -static
 
mkfs/Makefile +2 -2
index 811ba9db..9f6a4fad 100644
@@ -10,8 +10,8 @@ LTCOMMAND = mkfs.xfs
 HFILES =
 CFILES = proto.c xfs_mkfs.c
 
-LLDLIBS += $(LIBXFS) $(LIBXCMD) $(LIBFROG) $(LIBRT) $(LIBPTHREAD) $(LIBBLKID) \
-	$(LIBUUID) $(LIBINIH) $(LIBURCU)
+LLDLIBS += $(LIBXFS) $(LIBXCMD) $(LIBFROG) $(LIBRT) $(LIBBLKID) \
+	$(LIBUUID) $(LIBINIH) $(LIBURCU) $(LIBPTHREAD)
 LTDEPENDENCIES += $(LIBXFS) $(LIBXCMD) $(LIBFROG)
 LLDFLAGS = -static-libtool-libs
 
repair/Makefile +1 -1
index 47536ca1..2c40e59a 100644
@@ -72,7 +72,7 @@ CFILES = \
 	xfs_repair.c
 
 LLDLIBS = $(LIBXFS) $(LIBXLOG) $(LIBXCMD) $(LIBFROG) $(LIBUUID) $(LIBRT) \
-	$(LIBPTHREAD) $(LIBBLKID) $(LIBURCU)
+	$(LIBBLKID) $(LIBURCU) $(LIBPTHREAD)
 LTDEPENDENCIES = $(LIBXFS) $(LIBXLOG) $(LIBXCMD) $(LIBFROG)
 LLDFLAGS = -static-libtool-libs
 
scrub/Makefile +2 -2
index 849e3afd..fd6bb679 100644
@@ -71,8 +71,8 @@ spacemap.c \
 vfs.c \
 xfs_scrub.c
 
-LLDLIBS += $(LIBHANDLE) $(LIBFROG) $(LIBPTHREAD) $(LIBICU_LIBS) $(LIBRT) \
-	$(LIBURCU)
+LLDLIBS += $(LIBHANDLE) $(LIBFROG) $(LIBICU_LIBS) $(LIBRT) $(LIBURCU) \
+	$(LIBPTHREAD)
 LTDEPENDENCIES += $(LIBHANDLE) $(LIBFROG)
 LLDFLAGS = -static
 
Signature · 1 line
2.31.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Theodore Ts'o

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.

Ugh, I keep forgetting that ld wants library dependencies in reverse order nowadays...

--D

Quoted 131 lines
---
 copy/Makefile      | 4 ++--
 db/Makefile        | 4 ++--
 growfs/Makefile    | 4 ++--
 logprint/Makefile  | 4 ++--
 mdrestore/Makefile | 3 +--
 mkfs/Makefile      | 4 ++--
 repair/Makefile    | 2 +-
 scrub/Makefile     | 4 ++--
 8 files changed, 14 insertions(+), 15 deletions(-)
copy/Makefile +2 -2
index 1b00cd0d..55160f84 100644
@@ -9,8 +9,8 @@ LTCOMMAND = xfs_copy
 CFILES = xfs_copy.c
 HFILES = xfs_copy.h
 
-LLDLIBS = $(LIBXFS) $(LIBXLOG) $(LIBFROG) $(LIBUUID) $(LIBPTHREAD) $(LIBRT) \
-	  $(LIBURCU)
+LLDLIBS = $(LIBXFS) $(LIBXLOG) $(LIBFROG) $(LIBUUID) $(LIBRT) $(LIBURCU) \
+	  $(LIBPTHREAD)
 LTDEPENDENCIES = $(LIBXFS) $(LIBXLOG) $(LIBFROG)
 LLDFLAGS = -static-libtool-libs
 
db/Makefile +2 -2
index 5c017898..b2e01174 100644
@@ -18,8 +18,8 @@ CFILES = $(HFILES:.h=.c) btdump.c btheight.c convert.c info.c namei.c \
 	timelimit.c
 LSRCFILES = xfs_admin.sh xfs_ncheck.sh xfs_metadump.sh
 
-LLDLIBS	= $(LIBXFS) $(LIBXLOG) $(LIBFROG) $(LIBUUID) $(LIBRT) $(LIBPTHREAD) \
-	  $(LIBURCU)
+LLDLIBS	= $(LIBXFS) $(LIBXLOG) $(LIBFROG) $(LIBUUID) $(LIBRT) $(LIBURCU) \
+	  $(LIBPTHREAD)
 LTDEPENDENCIES = $(LIBXFS) $(LIBXLOG) $(LIBFROG)
 LLDFLAGS += -static-libtool-libs
 
growfs/Makefile +2 -2
index 08601de7..2f4cc66a 100644
@@ -9,8 +9,8 @@ LTCOMMAND = xfs_growfs
 
 CFILES = xfs_growfs.c
 
-LLDLIBS = $(LIBXFS) $(LIBXCMD) $(LIBFROG) $(LIBUUID) $(LIBRT) $(LIBPTHREAD) \
-	  $(LIBURCU)
+LLDLIBS = $(LIBXFS) $(LIBXCMD) $(LIBFROG) $(LIBUUID) $(LIBRT) $(LIBURCU) \
+	  $(LIBPTHREAD)
 
 ifeq ($(ENABLE_EDITLINE),yes)
 LLDLIBS += $(LIBEDITLINE) $(LIBTERMCAP)
logprint/Makefile +2 -2
index cdedbd0d..bbbed5d2 100644
@@ -12,8 +12,8 @@ CFILES = logprint.c \
 	 log_copy.c log_dump.c log_misc.c \
 	 log_print_all.c log_print_trans.c log_redo.c
 
-LLDLIBS	= $(LIBXFS) $(LIBXLOG) $(LIBFROG) $(LIBUUID) $(LIBRT) $(LIBPTHREAD) \
-	  $(LIBURCU)
+LLDLIBS	= $(LIBXFS) $(LIBXLOG) $(LIBFROG) $(LIBUUID) $(LIBRT) $(LIBURCU) \
+	  $(LIBPTHREAD)
 LTDEPENDENCIES = $(LIBXFS) $(LIBXLOG) $(LIBFROG)
 LLDFLAGS = -static-libtool-libs
 
mdrestore/Makefile +1 -2
index 8f28ddab..4a932efb 100644
@@ -8,8 +8,7 @@ include $(TOPDIR)/include/builddefs
 LTCOMMAND = xfs_mdrestore
 CFILES = xfs_mdrestore.c
 
-LLDLIBS = $(LIBXFS) $(LIBFROG) $(LIBRT) $(LIBPTHREAD) $(LIBUUID) \
-	  $(LIBURCU)
+LLDLIBS = $(LIBXFS) $(LIBFROG) $(LIBRT) $(LIBUUID) $(LIBURCU) $(LIBPTHREAD)
 LTDEPENDENCIES = $(LIBXFS) $(LIBFROG)
 LLDFLAGS = -static
 
mkfs/Makefile +2 -2
index 811ba9db..9f6a4fad 100644
@@ -10,8 +10,8 @@ LTCOMMAND = mkfs.xfs
 HFILES =
 CFILES = proto.c xfs_mkfs.c
 
-LLDLIBS += $(LIBXFS) $(LIBXCMD) $(LIBFROG) $(LIBRT) $(LIBPTHREAD) $(LIBBLKID) \
-	$(LIBUUID) $(LIBINIH) $(LIBURCU)
+LLDLIBS += $(LIBXFS) $(LIBXCMD) $(LIBFROG) $(LIBRT) $(LIBBLKID) \
+	$(LIBUUID) $(LIBINIH) $(LIBURCU) $(LIBPTHREAD)
 LTDEPENDENCIES += $(LIBXFS) $(LIBXCMD) $(LIBFROG)
 LLDFLAGS = -static-libtool-libs
 
repair/Makefile +1 -1
index 47536ca1..2c40e59a 100644
@@ -72,7 +72,7 @@ CFILES = \
 	xfs_repair.c
 
 LLDLIBS = $(LIBXFS) $(LIBXLOG) $(LIBXCMD) $(LIBFROG) $(LIBUUID) $(LIBRT) \
-	$(LIBPTHREAD) $(LIBBLKID) $(LIBURCU)
+	$(LIBBLKID) $(LIBURCU) $(LIBPTHREAD)
 LTDEPENDENCIES = $(LIBXFS) $(LIBXLOG) $(LIBXCMD) $(LIBFROG)
 LLDFLAGS = -static-libtool-libs
 
scrub/Makefile +2 -2
index 849e3afd..fd6bb679 100644
@@ -71,8 +71,8 @@ spacemap.c \
 vfs.c \
 xfs_scrub.c
 
-LLDLIBS += $(LIBHANDLE) $(LIBFROG) $(LIBPTHREAD) $(LIBICU_LIBS) $(LIBRT) \
-	$(LIBURCU)
+LLDLIBS += $(LIBHANDLE) $(LIBFROG) $(LIBICU_LIBS) $(LIBRT) $(LIBURCU) \
+	$(LIBPTHREAD)
 LTDEPENDENCIES += $(LIBHANDLE) $(LIBFROG)
 LLDFLAGS = -static
 
Signature · 1 line
2.31.0
#2 lore raw
Quoted 11 lines · Darrick J. Wong
Quoted 7 lines · Theodore Ts'o

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.

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