Search code examples
linuxdynamicdynamic-linkinggnu-coreutils

chgrp and linked libraries


According on the ldd linux command on /bin/chgrp the only necessary library for its execution is libc.so. When chgrp is debugged with gdb I've noticed that other libraries are actually loaded, such as:

/lib/x86_64-linux-gnu/libnss_compat.so.2
/lib/x86_64-linux-gnu/libnsl.so.1
/lib/x86_64-linux-gnu/libnss_nis.so.2
/lib/x86_64-linux-gnu/libnss_files.so.2

Why these libraries do not compare in the ldd output?

Also: they do not compare in the DYNAMIC section of libc.so, how are they located and loaded? (I've checked the DYNAMIC section of libc.so with readelf and these libraries are not there)


Solution

  • The various libnss libraries are loaded dynamically by libc, via dlopen, when you run the program. Which libraries are loaded is determined by the contents of /etc/nsswitch.conf. See the Name Service Switch documentation for more details.