[PATCH] erofs-utils: enhance static linking for lz4 1.8.x

hsiangkao at aol.com hsiangkao at aol.com
Sun May 31 13:45:10 AEST 2020


From: Gao Xiang <hsiangkao at redhat.com>

Since LZ4_compress_HC_destSize is static linking only on lz4 < 1.9.0,
but usually both lz4 static and dynamic library are available.

Previously, -all-static is used in erofs-utils compilation for such
lz4 versions, but it has conficts with libselinux linking. Use another
workable way [1] I've found instead.

[1] https://stackoverflow.com/questions/8045707/how-to-link-to-the-libabc-a-instead-of-libabc-so
Signed-off-by: Gao Xiang <hsiangkao at redhat.com>
---
 configure.ac     | 9 +++++----
 mkfs/Makefile.am | 2 +-
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/configure.ac b/configure.ac
index 5145971..0f40a84 100644
--- a/configure.ac
+++ b/configure.ac
@@ -188,7 +188,6 @@ test -z $LZ4_LIBS && LZ4_LIBS='-llz4'
 
 if test "x$enable_lz4" = "xyes"; then
   test -z "${with_lz4_incdir}" || LZ4_CFLAGS="-I$with_lz4_incdir $LZ4_CFLAGS"
-  test -z "${with_lz4_libdir}" || LZ4_LIBS="-L$with_lz4_libdir $LZ4_LIBS"
 
   saved_CPPFLAGS=${CPPFLAGS}
   CPPFLAGS="${LZ4_CFLAGS} ${CPPFLAGS}"
@@ -196,6 +195,7 @@ if test "x$enable_lz4" = "xyes"; then
   AC_CHECK_HEADERS([lz4.h],[have_lz4h="yes"], [])
 
   if test "x${have_lz4h}" = "xyes" ; then
+    saved_LIBS="$LIBS"
     saved_LDFLAGS=${LDFLAGS}
     test -z "${with_lz4_libdir}" || LDFLAGS="-L$with_lz4_libdir ${LDFLAGS}"
     AC_CHECK_LIB(lz4, LZ4_compress_destSize, [
@@ -210,6 +210,7 @@ if test "x$enable_lz4" = "xyes"; then
       ])
     ], [AC_MSG_ERROR([Cannot find proper lz4 version (>= 1.8.0)])])
     LDFLAGS=${saved_LDFLAGS}
+    LIBS="${saved_LIBS}"
   fi
   CPPFLAGS=${saved_CPPFLAGS}
 fi
@@ -234,11 +235,11 @@ if test "x${have_lz4}" = "xyes"; then
   fi
 
   if test "x${lz4_force_static}" = "xyes"; then
-    LDFLAGS="-all-static ${LDFLAGS}"
+    LZ4_LIBS="-Wl,-Bstatic -Wl,-whole-archive -Xlinker ${LZ4_LIBS} -Wl,-no-whole-archive -Wl,-Bdynamic"
+    test -z "${with_lz4_libdir}" || LZ4_LIBS="-L${with_lz4_libdir} $LZ4_LIBS"
   else
-    test -z "${with_lz4_libdir}" || LZ4_LIBS="-R ${with_lz4_libdir} $LZ4_LIBS"
+    test -z "${with_lz4_libdir}" || LZ4_LIBS="-R${with_lz4_libdir} $LZ4_LIBS"
   fi
-  LIBS="$LZ4_LIBS $LIBS"
 fi
 
 AC_CONFIG_FILES([Makefile
diff --git a/mkfs/Makefile.am b/mkfs/Makefile.am
index 97ba148..ecc468c 100644
--- a/mkfs/Makefile.am
+++ b/mkfs/Makefile.am
@@ -6,5 +6,5 @@ bin_PROGRAMS     = mkfs.erofs
 AM_CPPFLAGS = ${libuuid_CFLAGS} ${libselinux_CFLAGS}
 mkfs_erofs_SOURCES = main.c
 mkfs_erofs_CFLAGS = -Wall -Werror -I$(top_srcdir)/include
-mkfs_erofs_LDADD = $(top_builddir)/lib/liberofs.la ${libuuid_LIBS} ${libselinux_LIBS}
+mkfs_erofs_LDADD = ${libuuid_LIBS} $(top_builddir)/lib/liberofs.la ${libselinux_LIBS} ${LZ4_LIBS}
 
-- 
2.24.0



More information about the Linux-erofs mailing list