make use of ld --as-needed

Started by Neil Conwayover 21 years ago5 messagespatches
Jump to latest
#1Neil Conway
neilc@samurai.com

The issue has been raised in the past that our build system links each
executable against the maximal set of libraries it might need. So for
example, if one executable requires `libreadline', all executables are
linked against it.

The easiest fix is to make use of GNU ld's --as-needed flag, which
ignores linker arguments that are not actually needed by the specified
object files. The attached patch modifies configure to check for this
flag (when using GNU ld), and if ld supports it, adds the flag to
LDFLAGS (we need to do the check since only relatively recent versions
of GNU ld support this capability). The patch only checks for GNU ld:
does anyone know if any other linkers support this capability, and if
so, what flags need to be specified to enable it?

I haven't had a chance to test this on a non-GNU-ld system, but I will
do so before applying. Barring any objections, I'll apply this tomorrow.

-Neil

Attachments:

ld_as_needed-1.patchtext/x-patch; name=ld_as_needed-1.patchDownload+89-8
#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Neil Conway (#1)
Re: make use of ld --as-needed

Neil Conway <neilc@samurai.com> writes:

The easiest fix is to make use of GNU ld's --as-needed flag, which
ignores linker arguments that are not actually needed by the specified
object files. The attached patch modifies configure to check for this
flag (when using GNU ld),

Minor gripe --- what's the motivation for moving this down as you did?
Seems like if there's something wrong there, it would justify rather
more rearrangements in the order of tests than just this.

Also, please s/same platforms/some platforms/

regards, tom lane

#3Neil Conway
neilc@samurai.com
In reply to: Tom Lane (#2)
Re: make use of ld --as-needed

Tom Lane wrote:

Minor gripe --- what's the motivation for moving this down as you did?

What do you mean by "this"? I moved the AC_MSG_NOTICEs for CPPFLAGS and
LDFLAGS down below the --as-needed check, since the --as-needed check
may modify LDFLAGS.

Also, please s/same platforms/some platforms/

Thanks for catching that.

-Neil

#4Tom Lane
tgl@sss.pgh.pa.us
In reply to: Neil Conway (#3)
Re: make use of ld --as-needed

Neil Conway <neilc@samurai.com> writes:

Tom Lane wrote:

Minor gripe --- what's the motivation for moving this down as you did?

What do you mean by "this"? I moved the AC_MSG_NOTICEs for CPPFLAGS and
LDFLAGS down below the --as-needed check, since the --as-needed check
may modify LDFLAGS.

Well, I guess the question is why you put the --as-needed check where
you did, rather than above the existing AC_MSG_NOTICE displays. If it
has an interaction with the intervening tests, what is that exactly?
Surely finding "tar" for instance is not related.

regards, tom lane

#5Neil Conway
neilc@samurai.com
In reply to: Tom Lane (#4)
Re: make use of ld --as-needed

Tom Lane wrote:

Well, I guess the question is why you put the --as-needed check where
you did, rather than above the existing AC_MSG_NOTICE displays. If it
has an interaction with the intervening tests, what is that exactly?

PGAC_PROG_LD needs to be invoked to figure out if we're using gnu ld.
That's the only dependency AFAIK, so I'll move the --as-needed check to
before AC_PROG_RANLIB -- that is more logical.

-Neil