From: Kenny McCormack on
I'm looking at the current version of 'ldd' (in Debian and Debian-like
distros). It is implemented as a shell script, and I am trying to
figure out what the actual active line(s) is/are.

Now, the "poor man's ldd" is simply:

/lib/ld-linux.so.2 --list <binary>

I expected that the shell script version would pretty much be a wrapper
around that, but (AFAICT), it isn't. It seems to call /lib/ld-linux.so.2
with the "--verify" option at one point, but not, (again, AFAICT) with
"--list".

One observable difference between the shell script version and the "poor
man's" version is that if any of the libs aren't found, the "poor man's"
version crashes with an error message, whereas the shell script version
prints "not found" for the missing lib(s), along with the correct lines
for the other lib(s).

So, anyway, my question is: what is the active line, that actually
generates the output, in the shell script version?

--
Just for a change of pace, this sig is *not* an obscure reference to
comp.lang.c...

From: J G Miller on
On Sunday, July 25th, 2010 at 18:44:45h +0000, Kenny McCormack asked:
>
> what is the active line, that actually generates the output,
> in the shell script version?

If you do sh -x /bin/ldd then you will immediately see the answer ...

...

+ RTLD=/lib/ld-linux.so.2

+ break

+ try_trace /lib/ld-linux.so.2 /lib/libc.so.6

+ eval LD_TRACE_LOADED_OBJECTS=1 LD_WARN= LD_BIND_NOW=
LD_LIBRARY_VERSION=$verify_out LD_VERBOSE= "$@"

+ LD_TRACE_LOADED_OBJECTS=1 LD_WARN= LD_BIND_NOW= LD_LIBRARY_VERSION=6
LD_VERBOSE= /lib/ld-linux.so.2 /lib/libc.so.6

/lib/ld-linux.so.2 (0x0027e000)
linux-gate.so.1 => (0x0055b000)

+ exit 0

From: Kenny McCormack on
In article <i2i463$3g6$3(a)news.eternal-september.org>,
J G Miller <miller(a)yoyo.ORG> wrote:
>On Sunday, July 25th, 2010 at 18:44:45h +0000, Kenny McCormack asked:
>>
>> what is the active line, that actually generates the output,
>> in the shell script version?
>
>If you do sh -x /bin/ldd then you will immediately see the answer ...
>
> ...
>
> + RTLD=/lib/ld-linux.so.2
>
> + break
>
> + try_trace /lib/ld-linux.so.2 /lib/libc.so.6
>
> + eval LD_TRACE_LOADED_OBJECTS=1 LD_WARN= LD_BIND_NOW=
> LD_LIBRARY_VERSION=$verify_out LD_VERBOSE= "$@"
>
> + LD_TRACE_LOADED_OBJECTS=1 LD_WARN= LD_BIND_NOW= LD_LIBRARY_VERSION=6
> LD_VERBOSE= /lib/ld-linux.so.2 /lib/libc.so.6
>
> /lib/ld-linux.so.2 (0x0027e000)
> linux-gate.so.1 => (0x0055b000)
>
> + exit 0
>

And, thus, that answer is? (I.e., be less cryptic).

And, how does that differ from using --list?

--
Just for a change of pace, this sig is *not* an obscure reference to
comp.lang.c...

From: Kenny McCormack on
In article <i2i463$3g6$3(a)news.eternal-september.org>,
J G Miller <miller(a)yoyo.ORG> wrote:
>On Sunday, July 25th, 2010 at 18:44:45h +0000, Kenny McCormack asked:
>>
>> what is the active line, that actually generates the output,
>> in the shell script version?
>
>If you do sh -x /bin/ldd then you will immediately see the answer ...
>
> ...
>
> + RTLD=/lib/ld-linux.so.2
>
> + break
>
> + try_trace /lib/ld-linux.so.2 /lib/libc.so.6
>
> + eval LD_TRACE_LOADED_OBJECTS=1 LD_WARN= LD_BIND_NOW=
> LD_LIBRARY_VERSION=$verify_out LD_VERBOSE= "$@"
>
> + LD_TRACE_LOADED_OBJECTS=1 LD_WARN= LD_BIND_NOW= LD_LIBRARY_VERSION=6
> LD_VERBOSE= /lib/ld-linux.so.2 /lib/libc.so.6
>
> /lib/ld-linux.so.2 (0x0027e000)
> linux-gate.so.1 => (0x0055b000)
>
> + exit 0
>

I actually had done that (long ago as it turns out) and determined what
you have determined.

What I don't get is how that line can work. I.e., how can it work
without the --list option? Ah, now I get it! The magic is the:

LD_TRACE_LOADED_OBJECTS=1

which seems to be an alternative to "--list" (with the added
functionality that it doesn't crash if one or more libs aren't found).

--
Just for a change of pace, this sig is *not* an obscure reference to
comp.lang.c...

From: J G Miller on
On Tuesday, July 27th, 2010 at 01:18:22h +0000, Kenny McCormack wrote:
>
> Ah, now I get it! The magic is the:
>
> LD_TRACE_LOADED_OBJECTS=1

See, if you do think about it (try it out etc), you get there in the end ;)