diff options
author | Richard Yao <[email protected]> | 2016-03-15 13:28:07 -0400 |
---|---|---|
committer | Brian Behlendorf <[email protected]> | 2016-03-18 13:31:11 -0700 |
commit | e853ba351935135487621f79211e87d5f2e39205 (patch) | |
tree | 3aa1fb9fa0cc11861c63911f4f6b9815851e4a3d /config/user-zlib.m4 | |
parent | a1bc34c0a7929130577e4c9dd418845674dd35c3 (diff) |
Cleanup linking
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 <[email protected]>
Signed-off-by: Brian Behlendorf <[email protected]>
Closes #4426
Diffstat (limited to 'config/user-zlib.m4')
-rw-r--r-- | config/user-zlib.m4 | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/config/user-zlib.m4 b/config/user-zlib.m4 index a48361662..82c0962e4 100644 --- a/config/user-zlib.m4 +++ b/config/user-zlib.m4 @@ -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"]) |