Subject: Re: ld confusion
To: James K.Lowden <jklowden@speakeasy.org>
From: Frederick Bruckman <fredb@immanent.net>
List: netbsd-help
Date: 05/23/2002 22:10:01
On Thu, 23 May 2002, James K.Lowden wrote:

> On Thu, 23 May 2002 21:06:59 -0500 (CDT) Frederick Bruckman
> <fredb@immanent.net> wrote:
> > On Thu, 23 May 2002, James K.Lowden wrote:
> > > patch/patch-aa looks like this:
> > > +    } elsif ($Config::Config{'osname'} eq 'netbsd') {
> > > +       # We need to link with -Wl,-R if we're on NetBSD
> > > +       $linkwith = "-Wl,-R$libdir";
> >
> > "-Wl" is a "gcc" option, which passes the following argument to the
> > linker. Since you're linking directly with "ld", you could just change
> > that to "-R$libdir", then run "make distinfo", to regenerate the
> > patch's checksum. The normal thing, nowadays, is to link always with
> > "gcc"; making the package do so on NetBSD-a.out would be the real fix.
>
> I didn't know about make distinfo.  With patch problems, I rename and hack
> the patch, apply it, and then make.  Now I know better.
>
> Would the maintainer want a pr for this?  I don't know enough about it to
> do it myself (I guess that's obvious!).

*That* method will certainly break on ELF systems, which is to say,
for almost all NetBSD users. NetBSD 1.4.2 is really, really, old. If
you can figure out how to make the binary link with "gcc" instead of
"ld", a patch to do that would be acceptable. My guess is, there's a
condition in there somewhere that invokes "ld" for NetBSD-a.out only.

> > > # ls -l /usr/pkg/lib/*my*
> > > total 546
> > > -rw-r--r--  1 root  wheel  128970 May 23 20:23 libmysqlclient.a
> > > -rwxr-xr-x  1 root  wheel     777 May 23 20:23 libmysqlclient.la
> > > -rwxr-xr-x  1 root  wheel  128259 May 23 20:23 libmysqlclient.so.10.0
> >
> > That's kind of tricky, the way you presented that. We're actually
> > looking at the contents of "/usr/pkg/lib/mysql".
>
> Oy!  I tricked myself, too.  Sorry about that.
>
> > In order to have the
> > run-time linker find the file there, it has to be told to look there.
> > There are other ways to do that, but the best way is to pass the "-R"
> > argument to the NetBSD-a.out linker.
>
> If I understand you, you're saying the Makefile should tell gcc to call
> upon the NetBSD-a.out linker /instead of/ ld?  Or does ld invoke the
> NetBSD linker somehow?  "man -k linker" only turns up ld(1).  If I
> memorize the gcc manual, will all this be clear, or is there somewhere
> else I'm supposed to have looked?

"ld" *is* the a.out linker. I said "the NetBSD-a.out linker", instead
of just "ld", so that people reading this casually will see the word
"a.out" and not be horribly confused. The i386 port switched binary
formats from a.out to ELF with 1.5; m68k and all remaining ports will
be switched for 1.6. Part of the motivation for the switch is to use
the well-maintained GNU linker, which has the same options on all
ports (which are different from many of the obsolete a.out linkers,
all of which were called "ld", too).

> Thanks again. Slowly slowly this stuff is starting to make sense.
> Although to tell the truth, every linking environment I've ever seen has
> been a bear to work with.

I recommend upgrading to a more recent ELF release or snapshot at the
first opportunity. Then, this will all seem like a bad dream. ;-)

Here's more about ELF:

    http://www.netbsd.org/Documentation/elf.html

The "Updating ... from a.out to ELF" part is a bit dated. It's
actually gotten a little easier with the new toolchain:

    ftp://ftp.netbsd.org/pub/NetBSD/arch/mac68k/elf-upgrade/README.ELF-UPGRADE


Frederick