haampie / libtree

ldd as a tree
MIT License
2.67k stars 60 forks source link

A hello world made of with Rust has diferent output with ldd instead with libtree. #89

Closed mdtrooper closed 5 months ago

mdtrooper commented 5 months ago

I tried a small example of hello world.

mdtrooper@portatil:~$ cd /tmp/zzz
mdtrooper@portatil:/tmp/zzz$ ls
Cargo.lock  Cargo.toml  src  target
mdtrooper@portatil:/tmp/zzz$ cat src/main.rs 
fn main() {
    println!("Hello, world!");
}
mdtrooper@portatil:/tmp/zzz$

The output of ldd :

mdtrooper@portatil:/tmp/zzz$ cd target/release/
mdtrooper@portatil:/tmp/zzz/target/release$ ldd zzz
    linux-vdso.so.1 (0x00007ffcbf362000)
    libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007b1ca0e21000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007b1ca0a00000)
    /lib64/ld-linux-x86-64.so.2 (0x00007b1ca0ebc000)
mdtrooper@portatil:/tmp/zzz/target/release$ 

The output of libtree:

mdtrooper@portatil:/tmp/zzz/target/release$ libtree zzz
zzz 
mdtrooper@portatil:/tmp/zzz/target/release$ libtree zzz -v
zzz 
├── libgcc_s.so.1 [ld.so.conf]
├── ld-linux-x86-64.so.2 [ld.so.conf]
└── libc.so.6 [ld.so.conf]
mdtrooper@portatil:/tmp/zzz/target/release$ 

And the info of my system, the libtree is from deb repository:

mdtrooper@portatil:/tmp/zzz/target/release$ lsb_release -a
No LSB modules are available.
Distributor ID: Linuxmint
Description:    Linux Mint 21
Release:    21
Codename:   vanessa
mdtrooper@portatil:/tmp/zzz/target/release$ uname -a
Linux portatil 6.5.0-35-generic #35~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Tue May  7 09:00:52 UTC 2 x86_64 x86_64 x86_64 GNU/Linux
mdtrooper@portatil:/tmp/zzz/target/release$ dpkg -l libtree
Deseado=desconocido(U)/Instalar/eliminaR/Purgar/retener(H)
| Estado=No/Inst/ficheros-Conf/desempaqUetado/medio-conF/medio-inst(H)/espera-disparo(W)/pendienTe-disparo
|/ Err?=(ninguno)/requiere-Reinst (Estado,Err: mayúsc.=malo)
||/ Nombre         Versión      Arquitectura Descripción
+++-==============-============-============-=================================
ii  libtree        3.0.2-2      amd64        ldd as a tree
mdtrooper@portatil:/tmp/zzz/target/release$ libtree --version
3.0.2
mdtrooper@portatil:/tmp/zzz/target/release$ 
petiepooo commented 5 months ago

The only difference of note is the lack of linux-vdso.so.1 in libtree's output.

If you look closely, there is no path associated with linux-vdso, only a memory address. This is because linux-vdso is not actually a file; it is a dynamic stub put in place by the kernel without being explicitly specified by the executable or any of its libraries. From the vdso manpage:

The "vDSO" (virtual dynamic shared object) is a small shared library that the kernel automatically maps into the address space of all user-space applications.

What you see is likely true of all programs, and is not specific to your test program or choice of language. It's because libtree follows the files, where ldd loads the executable as if it is about to run, but then dumps the loaded libraries and exits. Since it's the kernel that maps vdso, not the files specifying a dependency on it, there is your difference.

I'd call this not-a-bug.

mdtrooper commented 5 months ago

Ohh thanks for the explain. I am going to close this issue.