Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Library deployment vs unused direct dependencies

I tried to find out which libraries Qt Assistant needs for deployment. I used ldd on Linux for this.

I found that ldd provides an option -u to "print unused dependencies". This sounds like there is some kind of dependency that is not (always) needed for deployment. So I ran two more ldd commands:

~$ ldd -u ~/Qt/5.10.0/gcc_64/bin/assistant 
Unused direct dependencies:
        /lib/x86_64-linux-gnu/libQt5Network.so.5
        /lib/x86_64-linux-gnu/libQt5Sql.so.5
        /lib/x86_64-linux-gnu/mesa/libGL.so.1
        /lib/x86_64-linux-gnu/libpthread.so.0
        /lib/x86_64-linux-gnu/libm.so.6
        /lib/x86_64-linux-gnu/libgcc_s.so.1

~$ ldd -r -u ~/Qt/5.10.0/gcc_64/bin/assistant 
Unused direct dependencies:
        /lib/x86_64-linux-gnu/libQt5Network.so.5
        /lib/x86_64-linux-gnu/mesa/libGL.so.1
        /lib/x86_64-linux-gnu/libpthread.so.0
        /lib/x86_64-linux-gnu/libm.so.6
        /lib/x86_64-linux-gnu/libgcc_s.so.1

I tried to find out what is going on but I didn't fully understand it.

My questions are:

  • What is an unused direct dependency (this sounds contradictory to me)?
  • Is it possible to find out if Qt Assistant actually requires an unused direct dependency (other then starting it and waiting for an error)?
  • What exactly is the difference between the above command lines? Why
    does the first list libQt5Sql but the second doesn't?
like image 237
Silicomancer Avatar asked May 07 '18 12:05

Silicomancer


1 Answers

It is printing because of -u switch. in man page of ldd

-u, --unused
          Print unused direct dependencies.  (Since glibc 2.3.4.)

What is an unused direct dependency (this sounds contradictory to me)?

It is IMHO -> Library you built binary which was not necessary. i.e.

gcc -L<LD_PATH> -Wall -o assistant assistant.c -lA -lB -lC

it will list all A B C as dependency but they may not be actually used in binary. Mostly the cause is universal LDFLAGS in Makefile.

Is it possible to find out if Qt Assistant actually requires an unused direct dependency (other then starting it and waiting for an error)?

NO I think as it may be used only when you will call particular function. there is also a chance you can use this an won't see error. Still if you decides to do so. there is a insane way. listing all functions called and then checking which all libraries are need. (no sure of this but I think based on similar logic ldd prints this.) according man page ldd may run binary. So basically can be a scenario you mentioned. but not extensively.

 Be aware,  however,  that  in some circumstances, some versions of
 ldd may attempt to obtain the dependency information by directly 
 executing  the program.  Thus, you should never employ ldd on an
 untrusted executable,
 since this may result in the execution  of  arbitrary  code.

What exactly is the difference between the above command lines? Why does the first list libQt5Sql but the second doesn't?

Differance is -r

       -r, --function-relocs
          Perform relocations for both data  objects  and  functions,  and
          report any missing objects or functions (ELF only).

In short it processes loaded library functions. It is suggested to use ldd -u -r in this bug on redhat. to know more about Relocation Processing read this oracle doc.

like image 193
Devidas Avatar answered Nov 12 '22 19:11

Devidas