freebsd-dev/cmd
Richard Yao e853ba3519 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 <ryao@gentoo.org>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #4426
2016-03-18 13:31:11 -07:00
..
arc_summary Make arc_summary.py and dbufstat.py compatible with python3 2016-01-07 17:09:59 -08:00
arcstat Update arcstat.py to remove deprecated rmis reference. 2015-12-04 15:28:45 -08:00
dbufstat Make arc_summary.py and dbufstat.py compatible with python3 2016-01-07 17:09:59 -08:00
fsck_zfs Add /sbin/fsck.zfs helper 2013-01-09 16:54:58 -08:00
mount_zfs mount.zfs: use getopt_long instead of getopt to guarantee permutation of argv. 2016-01-25 13:17:18 -08:00
vdev_id Add extra keyword 'slot' to vdev_id.conf 2015-08-30 10:03:56 -07:00
zdb Cleanup linking 2016-03-18 13:31:11 -07:00
zed Ensure zed _finish_daemonize() leaves fds 0-2 open 2016-03-08 17:46:41 -08:00
zfs Cleanup linking 2016-03-18 13:31:11 -07:00
zhack Cleanup linking 2016-03-18 13:31:11 -07:00
zinject Support parallel build trees (VPATH builds) 2015-07-17 13:42:51 -07:00
zpios Add large block support to zpios(1) benchmark 2015-09-22 09:13:20 -07:00
zpool Relax MBR partition scanning requirement 2016-03-10 14:04:58 -08:00
zstreamdump Cleanup linking 2016-03-18 13:31:11 -07:00
ztest Cleanup linking 2016-03-18 13:31:11 -07:00
zvol_id Support parallel build trees (VPATH builds) 2015-07-17 13:42:51 -07:00
Makefile.am Install arc_summary.py 2015-03-03 13:38:17 -08:00