how to search for the
shared libraries on
which a particular
program depends.
Concept of
Shared
Libraries
software libraries are
collections of code that are
intended to be used by many
different programs;
To build an executable file
from a program’s source
code
compiler gnerate
Codigo Objeto
Linker Generate
Codigo
Executable
Dinamico
not copy any
library code into
the program file.
Library Used
By Progrms
Multiples
Resources
Economic
Static
Library
Linked in
Program
Heavy
Dependencia
Resolved
Shared Object File
Naming
Conventions
The name of a shared library, also
known as soname, follows a pattern
which is made up of three elements:
so (which stands for
“shared object”)
Library name
(normally
prefixed by lib)
Version number
of the library
Here an example:
libpthread.so.0
By contrast, static
library names end in
.a, e.g. libpthread.a.
Exampes Of
Shared
Libraries
glibc (GNU C
library) i
On a Debian GNU/Linux
9.9 system, its file is
named libc.so.6
Such rather general file names are
normally symbolic links that point to the
actual file containing a library, whose
name contains the exact version number
ls -l /lib/x86_64-linux-gnu/libc.so.6
lrwxrwxrwx 1 root root 12 feb 6
22:17 /lib/x86_64-linux-gnu/libc.so.6
-> libc-2.24.so
libreadline
which allows users to edit
command lines as they are
typed in and includes support
for both Emacs and vi editing
mode
libcrypt
which contains
functions related to
encryption, hashing,
and encodin
libcurl
which is a
multiprotocol file
transfer library
/lib /lib32
/lib64
/usr/lib
/usr/local/lib
Locaciones
Configuration of
Shared Library
Paths
The references contained in
dynamically linked programs
are resolved by the dynamic
link
ld.so
ld-linux.so
The dynamic linker
searches for libraries
in a number of
directories
Library Path
The library path
is configured in
the /etc
directory
/etc/ld.so.conf
$ cat /etc/ld.so.conf
include
/etc/ld.so.conf.d/*.conf
/etc/ld.so.conf.d/*.conf
$ ls /etc/ld.so.conf.d/
libc.conf
x86_64-linux-gnu.conf
$ cat /etc/ld.so.conf.d/x86_64-linux-gnu.conf
# Multiarch support /lib/x86_64-linux-gnu
/usr/lib/x86_64-linux-gnu
ldconfig command
set of symbolic links
that help to locate the
individual libraries
finally of updating
the cache file
/etc/ld.so.cache
ldd to search for the
dependencies of a
shared object:
ldd -u /usr/bin/git
ldd prints the unused
direct dependencies
readelf
Display information about
ELF files (ELF stands for
executable and linkable
format)
-h:This will display the top-level headers -
-S: To display information about the different sections of the process’ address space.
-s: To display symbols table.
-n: To display core notes
-r: To display relocation section.
-d:To display the dynamic section.
-v:To get the version of the readelf command.
objdump
Print information
from object files.
Display the contents of the overall file header using -f option. ...
Display the contents of the section headers using -h option. ...
Display the contents of all headers using -x option. ...Display
assembler contents of executable sections using -d option.Display
assembler contents of all sections using -D option.
Use objdump con el -p (o --private-headers) y grep para imprimir las
dependencias de glibc: objdump -p /lib/x86_64-linux-gnu/libc.so.6 |
grep NEEDED
Use objdump con el -p (o --private-headers) y grep para
imprimir el soname de glibc: objdump -p
/lib/x86_64-linux-gnu/libc.so.6 | grep SONAME
Use objdump con el -p (o --private-headers) y grep para
imprimir las dependencias de Bash: objdump -p /bin/bash
| grep NEEDED
objdump -p /lib/x86_64-linux-gnu/libc.so.6
grep NEEDED
grep soname
objdump -p /bin/bash | grep NEEDED
Comandos
objdump: Imprime
información de
archivos de objetos.
ls:Lista el
contenido de un
directorio.
cat: Concatena
archivos e imprime
en la salida
estándar.
sudo: Hace que el superusuario
ejecute el comando con
privilegios administrativos.
ldconfig: Configura enlaces de
tiempo de ejecución del
vinculador dinámico.
echo: Muestra el valor de la
variable de entorno.
export Valor de exportación de la
variable de entorno a shells
secundarios.
unset Elimina
variables de
entorno.
ldd Imprime dependencias de
objetos compartidos de un
programa.
readelf Muestra
información sobre archivos
ELF (ELF significa executable
and linkable format).
Ha desarrollado un software y desea agregar un nuevo
directorio de biblioteca compartida a su sistema
(/opt/lib/mylib). Escriba su ruta absoluta en un archivo
llamado mylib.conf.
¿En qué directorio debe
almacenar este archivo?
/etc/ld.so.conf.d
¿Qué comando debe ejecutar
para que los cambios sean
totalmente efectivos? ldconfig
¿Qué comando usaría para listar las
bibliotecas compartidas requeridas por
kill? ldd /bin/kill