diff mbox

Makefile: Specify as-needed when building executables

Message ID 20130625161649.51502.55847.stgit@manray.1015granger.net
State Accepted
Headers show

Commit Message

Chuck Lever June 25, 2013, 4:17 p.m. UTC
The "--as-needed" linker flag reduces the number of unused objects
and dependencies in an executable, making it smaller and faster to
load.

Some distributions implicitly specify "--as-needed" when linking
their package builds.  My builds on Fedora appears not to.

To catch build problems before they are committed, let's explicitly
specify --as-needed.

References:

  http://www.gentoo.org/proj/en/qa/asneeded.xml#doc_chap1

  https://sigquit.wordpress.com/tag/gnu-libtool/

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
We might consider something like this for 0.10-devel.  It might be a
little risky for 0.9-stable.

 src/fedfsc/Makefile.am     |    1 +
 src/fedfsd/Makefile.am     |    1 +
 src/mount/Makefile.am      |    1 +
 src/nfsref/Makefile.am     |    1 +
 src/nsdbc/Makefile.am      |    1 +
 src/nsdbparams/Makefile.am |    1 +
 6 files changed, 6 insertions(+)

Comments

David Disseldorp June 26, 2013, 11:26 a.m. UTC | #1
On Tue, 25 Jun 2013 12:17:40 -0400
Chuck Lever <chuck.lever@oracle.com> wrote:

> The "--as-needed" linker flag reduces the number of unused objects
> and dependencies in an executable, making it smaller and faster to
> load.
> 
> Some distributions implicitly specify "--as-needed" when linking
> their package builds.  My builds on Fedora appears not to.
> 
> To catch build problems before they are committed, let's explicitly
> specify --as-needed.
> 
> References:
> 
>   http://www.gentoo.org/proj/en/qa/asneeded.xml#doc_chap1
> 
>   https://sigquit.wordpress.com/tag/gnu-libtool/
> 
> Signed-off-by: Chuck Lever <chuck.lever@oracle.com>

Looks good.
Reviewed-by: David Disseldorp <ddiss@suse.de>

Cheers, David
diff mbox

Patch

diff --git a/src/fedfsc/Makefile.am b/src/fedfsc/Makefile.am
index 20336c0..cafff42 100644
--- a/src/fedfsc/Makefile.am
+++ b/src/fedfsc/Makefile.am
@@ -45,3 +45,4 @@  AM_CFLAGS		= -ggdb -fstrict-aliasing \
 			  -Wall -Wextra -pedantic -Wformat=2 \
 			  -Wstrict-aliasing=2 -Wp,-D_FORTIFY_SOURCE=2
 AM_CPPFLAGS		= -I. -I$(top_srcdir)/src/include -I/usr/include/tirpc
+AM_LDFLAGS		= -Wl,--as-needed
diff --git a/src/fedfsd/Makefile.am b/src/fedfsd/Makefile.am
index f6fdb12..7ee9aea 100644
--- a/src/fedfsd/Makefile.am
+++ b/src/fedfsd/Makefile.am
@@ -42,6 +42,7 @@  AM_CFLAGS		= -ggdb -fstrict-aliasing \
 			  -Wall -Wextra -pedantic -Wformat=2 \
 			  -Wstrict-aliasing=2 -Wp,-D_FORTIFY_SOURCE=2
 AM_CPPFLAGS		= -I. -I$(top_srcdir)/src/include -I/usr/include/tirpc
+AM_LDFLAGS		= -Wl,--as-needed
 
 #######################################################################
 # The following allows the current practice of having
diff --git a/src/mount/Makefile.am b/src/mount/Makefile.am
index 92eb9a2..78513db 100644
--- a/src/mount/Makefile.am
+++ b/src/mount/Makefile.am
@@ -41,3 +41,4 @@  AM_CFLAGS		= -ggdb -fstrict-aliasing \
 			  -Wall -Wextra -pedantic -Wformat=2 \
 			  -Wstrict-aliasing=2 -Wp,-D_FORTIFY_SOURCE=2
 AM_CPPFLAGS		= -I. -I$(top_srcdir)/src/include
+AM_LDFLAGS		= -Wl,--as-needed
diff --git a/src/nfsref/Makefile.am b/src/nfsref/Makefile.am
index f02fe35..3b83f14 100644
--- a/src/nfsref/Makefile.am
+++ b/src/nfsref/Makefile.am
@@ -40,3 +40,4 @@  AM_CFLAGS		= -ggdb -fstrict-aliasing \
 			  -Wall -Wextra -pedantic -Wformat=2 \
 			  -Wstrict-aliasing=2 -Wp,-D_FORTIFY_SOURCE=2
 AM_CPPFLAGS		= -I. -I$(top_srcdir)/src/include
+AM_LDFLAGS		= -Wl,--as-needed
diff --git a/src/nsdbc/Makefile.am b/src/nsdbc/Makefile.am
index f80bed5..69db6cd 100644
--- a/src/nsdbc/Makefile.am
+++ b/src/nsdbc/Makefile.am
@@ -42,3 +42,4 @@  AM_CFLAGS		= -ggdb -fstrict-aliasing \
 			  -Wall -Wextra -pedantic -Wformat=2 \
 			  -Wstrict-aliasing=2 -Wp,-D_FORTIFY_SOURCE=2
 AM_CPPFLAGS		= -I$(top_srcdir)/src/include -I/usr/include/tirpc
+AM_LDFLAGS		= -Wl,--as-needed
diff --git a/src/nsdbparams/Makefile.am b/src/nsdbparams/Makefile.am
index cd347a7..dea3ab1 100644
--- a/src/nsdbparams/Makefile.am
+++ b/src/nsdbparams/Makefile.am
@@ -40,3 +40,4 @@  AM_CFLAGS		= -ggdb -fstrict-aliasing \
 			  -Wall -Wextra -pedantic -Wformat=2 \
 			  -Wstrict-aliasing=2 -Wp,-D_FORTIFY_SOURCE=2
 AM_CPPFLAGS		= -I. -I$(top_srcdir)/src/include -I/usr/include/tirpc
+AM_LDFLAGS		= -Wl,--as-needed