Re: Linux, X, ld, gcc, linking, shared libraries and stuff
- From: Frank Kotler <fbkotler@xxxxxxxxxxx>
- Date: Tue, 12 Apr 2005 04:43:21 -0400
Sorry for the delayed reply... I've been meaning to do some
"research" first, but haven't gotten around to it... I ought
to make some reply, anyway...
"T.M. Sommers" wrote:
>
> Frank Kotler wrote:
> >
> > Apparently, we need to tell ld the "Interpreter" ("-I") or
> > "--dynamic-linker" to use - "-I" is shorter :)
> >
> > ld -s -o example2 example2.o -I /lib/ld-linux.so.2 -lX11
> > -L/usr/X11R6/lib
> >
> > Works cherry for me!
>
> That is odd.
Always seems odd to me if anything works - especially first
try :)
> GNU ld on FreeBSD knows all about the dynamic
> linker without being told. I am very surprised that GNU ld on
> Linux is not that smart.
That seems to be the case. As you point out in another post,
it appears to be a "configuration issue" - we could compile
ourselves a version of ld that *did* use the "right" dynamic
linker, if we wanted to. But the "regular Linux ld" seems to
use a default that, on my system, doesn't exist. This could
quite reasonably be considered a "bug", I think.
In any case, I think you've answered a question I had about
how you'd do dynamic linking on BSD - "ld-linux" didn't seem
like a good candidate :) BSD's ld "knows"... good... that's
easy.
> Are you sure that is the real problem?
Not at all. I learned the "-I" switch as "that's how you do
it", rather than as a "solution to a problem". I had no idea
that ld *had* a default until Beth posted about her problem.
Now that I look, a plain "text dump" of the executable shows
"ld-linux.so.1" if no "-I" switch is used...
> Try linking the program without specifying the dynamic linker,
> and use objdump or whatever to look at the .interp section. If
> that is correct, then specifying the dynamic linker is just
> masking the real problem.
>
> You might want to try seeing if the problem occurs when you use
> libc only, not the X libraries.
It does. Without the "-I" switch, ld links without
complaint, but running the executable gives a "no such file
or directory" message - presumably /lib/ld-linux.so.1... I
guess...
What *isn't* required, if only libc is used, is any "-L"
switch...
> It is also possible that there is some problem with the
> installation of ld. Dynamic linking requires some configuration;
> hints files, default library paths, and the like. It is
> conceivable that something along those lines is wrong that has
> not been discovered because so few people call ld directly.
I was under the impression that /etc/ld.so.conf was an
important file for dynamic linking. I thought that if I
added "/usr/X11R6/lib" there, I wouldn't need to specify
that path with the "-L" switch... but it's already there,
and I *do* need it - but libc apparently *is* found without
specifying where... More to learn here, for sure!
> I would also urge you to use the C startup and cleanup code if
> you are linking to C libraries. That code exists for a reason;
> some library functions depend on it.
That seems right. I'm a bit surprised that it works at all
without it. I would expect that "global errno", for one
obvious example, might be defined in the startup code. I
would expect a complaint from ld about an "unresolved
external". But it seems to work. As we know, "it works"
doesn't mean "it's right". I might be reporting errors
someplace that's "mostly harmless" today, but will blow up
tomorrow. My "experiments" into "what I can get away with"
are by no means well-tested, but so far I haven't noticed
any ill effects from the missing startup code. At the very
least, I ought to put reading the source for the C
startup/cleanup routines on my rather elusive "todo list"...
Not satisfied with dynamic linking, I've tried using
"dlopen", "dlsym", and "dlclose"... to open and use a
"shared library" on the fly (to do very simple-minded
things). Idiotic code - dynamically links dllib.so (which
drags in libc) to get dlopen to open Seadhert's
"libsimple.so" example to use "print_out"... Again, it
"seems to work". Just a "proof of concept" - the idea being
to write "homemade" dlopen/dlsym/dlclose replacements,
eventually, and do away with the dynamic linker entirely...
Haven't gotten beyond the "first try" yet...
BTW, thanks for "name dropping" those book recommendations -
I probably won't get around to reading them, but I
acknowledge that I "should"... So many things to learn, so
little ambition...
Best,
Frank
.
- Follow-Ups:
- Re: Linux, X, ld, gcc, linking, shared libraries and stuff
- From: Beth
- Re: Linux, X, ld, gcc, linking, shared libraries and stuff
- From: T.M. Sommers
- Re: Linux, X, ld, gcc, linking, shared libraries and stuff
- References:
- Re: Linux, X, ld, gcc, linking, shared libraries and stuff
- From: T.M. Sommers
- Re: Linux, X, ld, gcc, linking, shared libraries and stuff
- Prev by Date: Re: HAY BETOV, why are you so jealous of FASM ?
- Next by Date: Re: Linux, X, ld, gcc, linking, shared libraries and stuff
- Previous by thread: Re: Linux, X, ld, gcc, linking, shared libraries and stuff
- Next by thread: Re: Linux, X, ld, gcc, linking, shared libraries and stuff
- Index(es):
Relevant Pages
|