Subject: Re: finding the linker with gcc3
To: None <tech-pkg@NetBSD.org>
From: James K. Lowden <jklowden@schemamania.org>
List: tech-pkg
Date: 03/28/2004 15:46:51
On Sun, 28 Mar 2004, Frederick Bruckman <fredb@immanent.net> wrote:
> On Sun, 28 Mar 2004, James K. Lowden wrote:
> 
> > I am using gcc3-c++-3.3.2 and have had some problems because
> > /usr/pkg/gcc3/bin/c++ was using /usr/bin/ld instead of
> > /usr/pkg/bin/ld.
> >
> > I had assumed pkgsrc would take steps to cause the gcc3 compilers to
> > use the "right" linker.  Having reviewed the gcc docs, I understand
> > there's no"right", but I still think it's a little queer that pkgsrc
> > compilers don't automatically use the linker installed by pkgsrc.
> >
> > Anyone who fails to tie the new compiler to the new linker is apt to
> > trip on "Dwarf" errors, at least on i386 machines.
> 
> By "new", do you mean ld 2.14? "binutils" and "gcc" are distributed by
> separate entities, so there's no exact correspondence.

By "new" I meant "ld(1) from pkgsrc/devel/binutils".  In my case, yes, I'm
using 2.14:

$ (ld --version; /usr/pkg/bin/ld --version) | grep ld
GNU ld 2.11.2
GNU ld version 2.14 20030612

I don't know how someone is supposed to know what version of ld he needs,
without the aid of google.  From time to time, I'm sure the compiler folks
make changes that they know will mandate linker changes, but I couldn't
find any statement in the gcc3 info pages or README, etc. indicating the
minimum GNU linker version known to work.  

> > I'm not sure there's a good answer.  It's not strictly necessary make
> > binutils a dependency of the gcc3 tools, and without a pkgsrc
> > dependency it would be irresponsible to configure gcc3 to use
> > /usr/pkg/bin/ld.  I looked for a way to make it prefer /usr/pkg/bin/ld
> > and fallback to/usr/bin/ld -- which seems like it would DTRT most of
> > the time -- but I didn't find a way.
> 
> The real problem is, the binutils package may well be older than the
> one in the tree, or if not that, exactly the same, and it's annoying
> when pkgsrc install multiple versions of the same program.
> 
> Look in "lang/gcc3-c/Makefile.common" at the addition of
> --with-as=fullpath, conditionally on ${USE_BINUTILS} being set. If
> we're pulling in binutils anyhow, we might as hardcode the path to
> "ld", too, with --with-ld. We should probably just switch the test
> from "${AS}" to "{LD}, and bump the version tested for to 2.14.

That sounds right to me, given the limitations of the linker-finding
strategy and pkgsrc's dependency rules.  

All I can say is that I wouldn't have looked for a make variable to govern
which linker gcc3 would invoke.  Only belatedly did I understand that gcc3
didn't include a linker of its own (call me na´ve, sure), and in any case
I figured "export LD=/usr/pkg/bin/ld" should suffice.  I actually think
it's a bit goofy that gcc doesn't inspect that environment variable,
becuase I understand ${LD} to be widely used for that purpose.  IMO, it
should at least be possible to build gcc3 such that it honors that
variable unless some "--no-LD-VAR" switch is thrown.  

Thanks, Frederick.

--jkl