842 Chapter 41
Figure 41-1 shows the compilation and linking steps involved in producing a shared
library with an embedded soname, linking a program against that shared library,
and creating the soname symbolic link needed to run the program.Figure 41-1: Creating a shared library and linking a program against itFigure 41-2 shows the steps that occur when the program created in Figure 41-1 is
loaded into memory in preparation for execution.To find out which shared libraries a process is currently using, we can list the
contents of the corresponding Linux-specific /proc/PID/maps file (Section 48.5).ELF header
(other info)
soname=libbar.so
(other info)$ gcc -g -c \
-fPIC -Wall \
mod1.c mod2.c mod3.c$ gcc -shared -o libfoo.so \
-Wl,-soname,libbar.so \
mod1.o mod2.o mod3.o$ gcc -o prog \
prog.c libfoo.somod1.o codemod1.olibfoo.somod2.o codemod2.omod3.o codemod3.oprog.o codeprog libbar.somod2.o code$ ln -s libfoo.so \
libbar.somod1.o codemod3.o codeProgram header “libfoo.so”
Shared object dependencies:
/lib/ld-linux.so.2
libbar.so1(^34)
2