This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: PATCH: LDFLAGS handling in V3

On Jul 27, 2005, Mark Mitchell <> wrote:

> However, since the linker is actually libtool, rather than the
> ordinary linker, I think that the LDFLAGS should be prefixed with
> "-Wl,".

That depends on whether the arguments are for the linker proper or for
the driver.  -Wl, should only be applied to flags that are for the
linker.  Current versions of libtool actually distinguish between
-Xlinker (same as -Wl,) and -XCClinker, to solve this ambiguity.  The
problem at hand is that, at least on some platforms, libtool has to
run the linker directly, instead of cc, and then the -XCClinker flags
will be silently dropped anyway.  I'd hope this is not the case of any
GCC ports, but I haven't been paying attention for quite a while to
know for sure.

I'm afraid there's no easy way out for this problem.  Because of this
very issue, I've long suggested automake to introduce LTLDFLAGS,
defaulting that to LDFLAGS, but using it instead of $(LDFLAGS) in
libtool link commands, such that users can override LTLDFLAGS as
appropriate.  Unfortunately, this hasn't happened, so we have to
introduce such kludges in our trees.

> + # The LDFLAGS we receive from the top-level Makefile are designed directly 
> + # for the linker, so we must tell libtool to pass them along explicitly.
> + LIBTOOLLDFLAGS = `for ldflag in $(LDFLAGS); do echo "-Wl,$$ldflag"; done`

It would have to be more complex than this, to preserve quoting of
flags and avoid mangling of comma-containing ldflags
(-Xlinker/-XCClinker are safer in this regard).  I'd really prefer to
defer such transformation to the user, given how tricky it is, or
implement it as a separate, reusable script, that takes care of all
issues, and that can even attempt to be clever and recognize some
GCC-specific flags, choosing the right -X*linker flag.

Alexandre Oliva
Red Hat Compiler Engineer   aoliva@{,}
Free Software Evangelist  oliva@{,}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]