Zusammenfassung der Ressource
102.3 Manage
shared libraries
- shared libraries, also
known as shared objects:
- pieces of
compiled
- reusable code
like functions or
classes
- are recurrently
used by various
programs
- explain what
shared
libraries
- How to identify
them and where
they are found
- how to configure
their storage
locations
- 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
- options
ldconfig
- ldconfig -v
- /usr/local/lib: /lib/x86_64-linux-gnu:
libfuse.so.2 -> libfuse.so.2.9.7
libidn.so.11 -> libidn.so.11.6.16
- So we can see, for example, how
libfuse.so.2 is linked to the actual
shared object file libfuse.so.2.9.7.
- sudo ldconfig -p
- 1094 libs found in the cache
`/etc/ld.so.cache' libzvbi.so.0
(libc6,x86-64) =>
/usr/lib/x86_64-linux-gnu/libzvbi.so.0
- sudo ldconfig -p |grep libfuse
libfuse.so.2 (libc6,x86-64) =>
/lib/x86_64-linux-gnu/libfuse.so.2
- $ ls -l /lib/x86_64-linux-gnu/libfuse.so.2 lrwxrwxrwx 1 root root 16 Aug 21 2018
/lib/x86_64-linux-gnu/libfuse.so.2 -> libfuse.so.2.9.7
- LD_LIBRARY_PATH
- variable can be used to
add new paths for
shared libraries
temporarily.
- LD_LIBRARY_PATH=/usr/local/mylib
- echo $LD_LIBRARY_PATH
- export LD_LIBRARY_PATH=/usr/local/mylib
- unset LD_LIBRARY_PATH
- permanente:
/etc/bash.bashrc
or ~/.bashrc.
- Searching for the
Dependencies of
a Particular
Executable
- ldd /usr/bin/git
- To look up the shared
libraries required by a
specific program
- $ ldd /lib/x86_64-linux-gnu/libc.so.6
/lib64/ld-linux-x86-64.so.2 (0x00007fbfed578000)
linux-vdso.so.1 (0x00007fffb7bf5000)
- 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.
- -a,-d,-D,-e,-f,-g,-G,-h,-H,-p,-P,-r,-R,-s,-S,-t,-T,-V,
- 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