]> git.proxmox.com Git - mirror_zfs.git/commitdiff
Cleanup linking
authorRichard Yao <ryao@gentoo.org>
Tue, 15 Mar 2016 17:28:07 +0000 (13:28 -0400)
committerBrian Behlendorf <behlendorf1@llnl.gov>
Fri, 18 Mar 2016 20:31:11 +0000 (13:31 -0700)
I noticed during code review of zfsonlinux/zfs#4385 that the author of a
commit had peppered the various Makefile.am files with `$(TIRPC_LIBS)`
when putting it into `lib/libspl/Makefile.am` should have sufficed. Upon
further examination, it seems that he had copied what we do with
`$(ZLIB)`. We also have a bit of that with `-ldl` too.  Unfortunately,
what we do is wrong, so lets fix it to set a good example for future
contributors.

In addition, we have multiple `-lz` and `-luuid` passed to the compiler
because each `AC_CHECK_LIB` adds it to `$LIBS`. That is somewhat
annoying to see, so we switch to `AC_SEARCH_LIBS` to avoid it.  This is
consistent with the recommendation to use `AC_SEARCH_LIBS` over
`AC_CHECK_LIB` by autotools upstream:

https://www.gnu.org/software/autoconf/manual/autoconf-2.66/html_node/Libraries.html

In an ideal world, this would translate into improvements in ELF's
`DT_NEEDED` entries, but that is not the case because of a couple of
bugs in libtool.

The first bug causes libtool to overlink by using static link
dependencies for dynamic linking:

https://wiki.mageia.org/en/Overlinking_issues_in_packaging#libtool_issues

The workaround for this should be to pass `-Wl,--as-needed` in
`LDFLAGS`. That leads us to the second bug, where libtool passes
`LDFLAGS` after the libraries are specified and `ld` will only honor
`--as-needed` on libraries specified before it:

https://sigquit.wordpress.com/2011/02/16/why-asneeded-doesnt-work-as-expected-for-your-libraries-on-your-autotools-project/

There are a few possible workarounds for the second bug. One is to
either patch the compiler spec file to specify `-Wl,--as-needed` or pass
`-Wl,--as-needed` via `CC` like `CC='gcc -Wl,--as-needed'` so that it is
specified early. Another is to patch ltmain.sh like Gentoo does:

https://gitweb.gentoo.org/repo/gentoo.git/tree/eclass/ELT-patches/as-needed

Without one of those workarounds, this cleanup provides no benefit in
terms of `DT_NEEDED` entry generation. It should still be an improvement
because it nicely simplifies the code while encouraging good habits when
patching autotools scripts.

Signed-off-by: Richard Yao <ryao@gentoo.org>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #4426

cmd/zdb/Makefile.am
cmd/zfs/Makefile.am
cmd/zhack/Makefile.am
cmd/zstreamdump/Makefile.am
cmd/ztest/Makefile.am
config/user-libuuid.m4
config/user-zlib.m4
lib/libefi/Makefile.am
lib/libzfs/Makefile.am

index c22186a10f9699a8c30c4283f3b61202a8a1a285..eb8e6777f5e7a861f856fe35ef6002fcedc5d929 100644 (file)
@@ -18,5 +18,3 @@ zdb_LDADD = \
        $(top_builddir)/lib/libzpool/libzpool.la \
        $(top_builddir)/lib/libzfs/libzfs.la \
        $(top_builddir)/lib/libzfs_core/libzfs_core.la
-
-zdb_LDADD += $(ZLIB)
index 3cac73da6198279c71f96eedf037d75ab384f7c8..e40909516d576e186bf886b56c2cf8d2cb412262 100644 (file)
@@ -19,5 +19,4 @@ zfs_LDADD = \
        $(top_builddir)/lib/libzfs/libzfs.la \
        $(top_builddir)/lib/libzfs_core/libzfs_core.la
 
-zfs_LDADD += $(ZLIB)
 zfs_LDFLAGS = -pthread
index 53e324142f3834d11eebfa886f0b93e32d0afb2f..a7bce5ddee43d25278767937a1fa2fdec2c7c70f 100644 (file)
@@ -15,5 +15,3 @@ zhack_LDADD = \
        $(top_builddir)/lib/libzpool/libzpool.la \
        $(top_builddir)/lib/libzfs/libzfs.la \
        $(top_builddir)/lib/libzfs_core/libzfs_core.la
-
-zhack_LDADD += $(ZLIB)
index 654863adb14548f8d322187c4c7db1ff15b99ddf..b46958d65af7ace41254db3ae376a837836e7337 100644 (file)
@@ -15,5 +15,3 @@ zstreamdump_LDADD = \
        $(top_builddir)/lib/libzpool/libzpool.la \
        $(top_builddir)/lib/libzfs/libzfs.la \
        $(top_builddir)/lib/libzfs_core/libzfs_core.la
-
-zstreamdump_LDADD += $(ZLIB)
index e3be39a0c26217a9f0d2ef7b8ad6cc8aae08fdc5..a2f3b5a6b8a2131844206d66cfacec1de5c5d894 100644 (file)
@@ -19,4 +19,4 @@ ztest_LDADD = \
        $(top_builddir)/lib/libzfs/libzfs.la \
        $(top_builddir)/lib/libzfs_core/libzfs_core.la
 
-ztest_LDADD += -lm -ldl
+ztest_LDADD += -lm
index aba375a22820e7c2967438ca0904bbb31f1c1ec8..f0da671a3f612fed160dd370edad7031a6cd5f53 100644 (file)
@@ -7,10 +7,10 @@ AC_DEFUN([ZFS_AC_CONFIG_USER_LIBUUID], [
        AC_CHECK_HEADER([uuid/uuid.h], [], [AC_MSG_FAILURE([
        *** uuid/uuid.h missing, libuuid-devel package required])])
 
-       AC_CHECK_LIB([uuid], [uuid_generate], [], [AC_MSG_FAILURE([
+       AC_SEARCH_LIBS([uuid_generate], [uuid], [], [AC_MSG_FAILURE([
        *** uuid_generate() missing, libuuid-devel package required])])
 
-       AC_CHECK_LIB([uuid], [uuid_is_null], [], [AC_MSG_FAILURE([
+       AC_SEARCH_LIBS([uuid_is_null], [uuid], [], [AC_MSG_FAILURE([
        *** uuid_is_null() missing, libuuid-devel package required])])
 
        AC_SUBST([LIBUUID], ["-luuid"])
index a48361662e4fa3b3daa9b19604969f94ee89101a..82c0962e4517d811972061a4287b3674d0cb2cf1 100644 (file)
@@ -7,13 +7,13 @@ AC_DEFUN([ZFS_AC_CONFIG_USER_ZLIB], [
        AC_CHECK_HEADER([zlib.h], [], [AC_MSG_FAILURE([
        *** zlib.h missing, zlib-devel package required])])
 
-       AC_CHECK_LIB([z], [compress2], [], [AC_MSG_FAILURE([
+       AC_SEARCH_LIBS([compress2], [z], [], [AC_MSG_FAILURE([
        *** compress2() missing, zlib-devel package required])])
 
-       AC_CHECK_LIB([z], [uncompress], [], [AC_MSG_FAILURE([
+       AC_SEARCH_LIBS([uncompress], [z], [], [AC_MSG_FAILURE([
        *** uncompress() missing, zlib-devel package required])])
 
-       AC_CHECK_LIB([z], [crc32], [], [AC_MSG_FAILURE([
+       AC_SEARCH_LIBS([crc32], [z], [], [AC_MSG_FAILURE([
        *** crc32() missing, zlib-devel package required])])
 
        AC_SUBST([ZLIB], ["-lz"])
index 60863a81317dea1262d0c2ffba95c3ba17881100..f0c05ee6c44cc4976b162ad711420e19e0278c7f 100644 (file)
@@ -17,6 +17,6 @@ nodist_libefi_la_SOURCES = \
        $(USER_C) \
        $(KERNEL_C)
 
-libefi_la_LIBADD = $(LIBUUID) $(ZLIB)
+libefi_la_LIBADD = $(LIBUUID)
 
 EXTRA_DIST = $(USER_C)
index b0c69875877c584077c591a0789f786e5880b3c8..a9e2d99fca69917e2282346c93a420b35b85f0d0 100644 (file)
@@ -36,7 +36,7 @@ libzfs_la_LIBADD = \
        $(top_builddir)/lib/libnvpair/libnvpair.la \
        $(top_builddir)/lib/libzpool/libzpool.la
 
-libzfs_la_LIBADD += -lm -ldl $(LIBBLKID)
+libzfs_la_LIBADD += -lm $(LIBBLKID)
 libzfs_la_LDFLAGS = -version-info 2:0:0
 
 EXTRA_DIST = $(libzfs_pc_DATA) $(USER_C)