Site hosted by Angelfire.com: Build your free website today!

Hands-on Projects for the Linux Graphics Subsystem

New book from Christos Karayiannis

Available in Amazon Kindle format at:

amazon.com   amazon.co.uk   amazon.de   amazon.es   amazon.fr   amazon.it

The Virtual Address Space of the X Server and the Modules

Virtual address of the X server

As we previously noticed, in section 3.2.2.5, backtraces show the virtual address of the X server, which is the current process we examine, near the address 0x8048000. As we read from the Linux Documentation Project this is the address that a Linux Process is Loaded:

It is a simple C program that prints ``hello world'' and then exits. The header describes it as an ELF image with two physical headers (e_phnum is 2) starting 52 bytes (e_phoff) from the start of the image file. The first physical header describes the executable code in the image. It goes at virtual address 0x8048000 and there is 65532 bytes of it. This is because it is a statically linked image which contains all of the library code for the printf() call to output ``hello world''. The entry point for the image, the first instruction for the program, is not at the start of the image but at virtual address 0x8048090 (e_entry). The code starts immediately after the second physical header. This physical header describes the data for the program and is to be loaded into virtual memory at address 0x8059BB8. This data is both readable and writeable. You will notice that the size of the data in the file is 2200 bytes (p_filesz) whereas its size in memory is 4248 bytes. This because the first 2200 bytes contain pre-initialized data and the next 2048 bytes contain data that will be initialized by the executing code.

What is so special about 0x8048000 it is explained at The magic of the Elf:

0x8048000 is not a natural constant, but happens to be the default base address of ELF executables produced by ld(1) on i386.

With the following command in my Ubuntu system I find the process id (pid) of the X process (the X server): ld is the GNU linker.

$ ps xa | grep /usr/bin/X
At the time it run it outputed 783. Next I find from the proc pseudo-filesystem the X server maps as:
$sudo cat/proc/783/maps
The output from this is:

00110000-00117000 r-xp 00000000 07:00 396837     /usr/lib/libpciaccess.so.0.10.8
00117000-00118000 r--p 00007000 07:00 396837     /usr/lib/libpciaccess.so.0.10.8
00118000-00119000 rw-p 00008000 07:00 396837     /usr/lib/libpciaccess.so.0.10.8
00119000-0013d000 r-xp 00000000 07:00 655896     /lib/tls/i686/cmov/libm-2.11.1.so
0013d000-0013e000 r--p 00023000 07:00 655896     /lib/tls/i686/cmov/libm-2.11.1.so
0013e000-0013f000 rw-p 00024000 07:00 655896     /lib/tls/i686/cmov/libm-2.11.1.so
0013f000-00152000 r-xp 00000000 07:00 524641     /lib/libz.so.1.2.3.3
00152000-00153000 r--p 00012000 07:00 524641     /lib/libz.so.1.2.3.3
00153000-00154000 rw-p 00013000 07:00 524641     /lib/libz.so.1.2.3.3
00154000-00164000 r-xp 00000000 07:00 524491     /lib/libbz2.so.1.0.4
00164000-00165000 r--p 0000f000 07:00 524491     /lib/libbz2.so.1.0.4
00165000-00166000 rw-p 00010000 07:00 524491     /lib/libbz2.so.1.0.4
00166000-0016b000 r-xp 00000000 07:00 396370     /usr/lib/libfontenc.so.1.0.0
0016b000-0016c000 r--p 00004000 07:00 396370     /usr/lib/libfontenc.so.1.0.0
0016c000-0016d000 rw-p 00005000 07:00 396370     /usr/lib/libfontenc.so.1.0.0
0016d000-0018a000 r-xp 00000000 07:00 524526     /lib/libgcc_s.so.1
0018a000-0018b000 r--p 0001c000 07:00 524526     /lib/libgcc_s.so.1
0018b000-0018c000 rw-p 0001d000 07:00 524526     /lib/libgcc_s.so.1
0018f000-00193000 r-xp 00000000 07:00 396087     /usr/lib/libXdmcp.so.6.0.0
00193000-00194000 r--p 00003000 07:00 396087     /usr/lib/libXdmcp.so.6.0.0
00194000-00195000 rw-p 00004000 07:00 396087     /usr/lib/libXdmcp.so.6.0.0
00195000-00199000 r-xp 00000000 07:00 788622     /usr/lib/xorg/modules/extensions/libdbe.so
00199000-0019a000 r--p 00003000 07:00 788622     /usr/lib/xorg/modules/extensions/libdbe.so
0019a000-0019b000 rw-p 00004000 07:00 788622     /usr/lib/xorg/modules/extensions/libdbe.so
0019b000-001a1000 r-xp 00000000 07:00 788627     /usr/lib/xorg/modules/extensions/librecord.so
001a1000-001a2000 r--p 00005000 07:00 788627     /usr/lib/xorg/modules/extensions/librecord.so
001a2000-001a3000 rw-p 00006000 07:00 788627     /usr/lib/xorg/modules/extensions/librecord.so
001a3000-001a5000 r-xp 00000000 07:00 788624     /usr/lib/xorg/modules/extensions/libdri2.so
001a5000-001a6000 r--p 00002000 07:00 788624     /usr/lib/xorg/modules/extensions/libdri2.so
001a6000-001a7000 rw-p 00003000 07:00 788624     /usr/lib/xorg/modules/extensions/libdri2.so
001a7000-001ac000 r-xp 00000000 07:00 662253     /usr/lib/xorg/modules/drivers/vesa_drv.so
001ac000-001ad000 r--p 00004000 07:00 662253     /usr/lib/xorg/modules/drivers/vesa_drv.so
001ad000-001ae000 rw-p 00005000 07:00 662253     /usr/lib/xorg/modules/drivers/vesa_drv.so
001ae000-001b3000 r-xp 00000000 07:00 662212     /usr/lib/xorg/modules/libvbe.so
001b3000-001b4000 r--p 00004000 07:00 662212     /usr/lib/xorg/modules/libvbe.so
001b4000-001b5000 rw-p 00005000 07:00 662212     /usr/lib/xorg/modules/libvbe.so
001b5000-001ba000 r-xp 00000000 07:00 662210     /usr/lib/xorg/modules/libshadow.so
001ba000-001bb000 r--p 00004000 07:00 662210     /usr/lib/xorg/modules/libshadow.so
001bb000-001bc000 rw-p 00005000 07:00 662210     /usr/lib/xorg/modules/libshadow.so
001bc000-001c5000 r-xp 00000000 07:00 788628     /usr/lib/xorg/modules/input/evdev_drv.so
001c5000-001c6000 r--p 00008000 07:00 788628     /usr/lib/xorg/modules/input/evdev_drv.so
001c6000-001c7000 rw-p 00009000 07:00 788628     /usr/lib/xorg/modules/input/evdev_drv.so
001c7000-001cd000 r-xp 00000000 07:00 655901     /lib/tls/i686/cmov/libnss_compat-2.11.1.so
001cd000-001ce000 r--p 00006000 07:00 655901     /lib/tls/i686/cmov/libnss_compat-2.11.1.so
001ce000-001cf000 rw-p 00007000 07:00 655901     /lib/tls/i686/cmov/libnss_compat-2.11.1.so
001d3000-001e8000 r-xp 00000000 07:00 655914     /lib/tls/i686/cmov/libpthread-2.11.1.so
001e8000-001e9000 r--p 00014000 07:00 655914     /lib/tls/i686/cmov/libpthread-2.11.1.so
001e9000-001ea000 rw-p 00015000 07:00 655914     /lib/tls/i686/cmov/libpthread-2.11.1.so
001ea000-001ec000 rw-p 00000000 00:00 0 
001ec000-0023b000 r-xp 00000000 07:00 788626     /usr/lib/xorg/modules/extensions/libglx.so
0023b000-0023c000 r--p 0004e000 07:00 788626     /usr/lib/xorg/modules/extensions/libglx.so
0023c000-0023f000 rw-p 0004f000 07:00 788626     /usr/lib/xorg/modules/extensions/libglx.so
0023f000-0025b000 r-xp 00000000 07:00 662208     /usr/lib/xorg/modules/libfb.so
0025b000-0025c000 r--p 0001c000 07:00 662208     /usr/lib/xorg/modules/libfb.so
0025c000-0025d000 rw-p 0001d000 07:00 662208     /usr/lib/xorg/modules/libfb.so
0025d000-00281000 r-xp 00000000 07:00 524519     /lib/libexpat.so.1.5.2
00281000-00283000 r--p 00024000 07:00 524519     /lib/libexpat.so.1.5.2
00283000-00284000 rw-p 00026000 07:00 524519     /lib/libexpat.so.1.5.2
00284000-00297000 r-xp 00000000 07:00 655899     /lib/tls/i686/cmov/libnsl-2.11.1.so
00297000-00298000 r--p 00012000 07:00 655899     /lib/tls/i686/cmov/libnsl-2.11.1.so
00298000-00299000 rw-p 00013000 07:00 655899     /lib/tls/i686/cmov/libnsl-2.11.1.so
00299000-0029b000 rw-p 00000000 00:00 0 
0029b000-002a3000 r-xp 00000000 07:00 655909     /lib/tls/i686/cmov/libnss_nis-2.11.1.so
002a3000-002a4000 r--p 00007000 07:00 655909     /lib/tls/i686/cmov/libnss_nis-2.11.1.so
002a4000-002a5000 rw-p 00008000 07:00 655909     /lib/tls/i686/cmov/libnss_nis-2.11.1.so
002a7000-002aa000 r-xp 00000000 07:00 524532     /lib/libgpg-error.so.0.4.0
002aa000-002ab000 r--p 00002000 07:00 524532     /lib/libgpg-error.so.0.4.0
002ab000-002ac000 rw-p 00003000 07:00 524532     /lib/libgpg-error.so.0.4.0
00316000-00322000 r-xp 00000000 07:00 788630     /usr/lib/xorg/modules/input/synaptics_drv.so
00322000-00323000 r--p 0000b000 07:00 788630     /usr/lib/xorg/modules/input/synaptics_drv.so
00323000-00324000 rw-p 0000c000 07:00 788630     /usr/lib/xorg/modules/input/synaptics_drv.so
0032b000-0047e000 r-xp 00000000 07:00 655888     /lib/tls/i686/cmov/libc-2.11.1.so
0047e000-0047f000 ---p 00153000 07:00 655888     /lib/tls/i686/cmov/libc-2.11.1.so
0047f000-00481000 r--p 00153000 07:00 655888     /lib/tls/i686/cmov/libc-2.11.1.so
00481000-00482000 rw-p 00155000 07:00 655888     /lib/tls/i686/cmov/libc-2.11.1.so
00482000-00485000 rw-p 00000000 00:00 0 
004ef000-0050b000 r-xp 00000000 07:00 662209     /usr/lib/xorg/modules/libint10.so
0050b000-0050c000 r--p 0001c000 07:00 662209     /usr/lib/xorg/modules/libint10.so
0050c000-0050d000 rw-p 0001d000 07:00 662209     /usr/lib/xorg/modules/libint10.so
00596000-00598000 r-xp 00000000 07:00 396076     /usr/lib/libXau.so.6.0.0
00598000-00599000 r--p 00001000 07:00 396076     /usr/lib/libXau.so.6.0.0
00599000-0059a000 rw-p 00002000 07:00 396076     /usr/lib/libXau.so.6.0.0
0061c000-00637000 r-xp 00000000 07:00 524468     /lib/ld-2.11.1.so
00637000-00638000 r--p 0001a000 07:00 524468     /lib/ld-2.11.1.so
00638000-00639000 rw-p 0001b000 07:00 524468     /lib/ld-2.11.1.so
00660000-006d1000 r-xp 00000000 07:00 396376     /usr/lib/libfreetype.so.6.3.22
006d1000-006d5000 r--p 00070000 07:00 396376     /usr/lib/libfreetype.so.6.3.22
006d5000-006d6000 rw-p 00074000 07:00 396376     /usr/lib/libfreetype.so.6.3.22
006d6000-008ec000 r-xp 00000000 07:00 398244     /usr/lib/dri/swrast_dri.so
008ec000-008f0000 r--p 00215000 07:00 398244     /usr/lib/dri/swrast_dri.so
008f0000-008f2000 rw-p 00219000 07:00 398244     /usr/lib/dri/swrast_dri.so
008f2000-00901000 rw-p 00000000 00:00 0 
0090d000-00916000 r-xp 00000000 07:00 524509     /lib/libdrm.so.2.4.0
00916000-00917000 r--p 00008000 07:00 524509     /lib/libdrm.so.2.4.0
00917000-00918000 rw-p 00009000 07:00 524509     /lib/libdrm.so.2.4.0
0098b000-00995000 r-xp 00000000 07:00 524624     /lib/libudev.so.0.6.1
00995000-00996000 r--p 00009000 07:00 524624     /lib/libudev.so.0.6.1
00996000-00997000 rw-p 0000a000 07:00 524624     /lib/libudev.so.0.6.1
00b81000-00b97000 r-xp 00000000 07:00 788625     /usr/lib/xorg/modules/extensions/libextmod.so
00b97000-00b98000 r--p 00015000 07:00 788625     /usr/lib/xorg/modules/extensions/libextmod.so
00b98000-00b99000 rw-p 00016000 07:00 788625     /usr/lib/xorg/modules/extensions/libextmod.so
00c20000-00c21000 r-xp 00000000 00:00 0          [vdso]
00c64000-00c9a000 r-xp 00000000 07:00 396093     /usr/lib/libXfont.so.1.4.1
00c9a000-00c9b000 r--p 00035000 07:00 396093     /usr/lib/libXfont.so.1.4.1
00c9b000-00c9c000 rw-p 00036000 07:00 396093     /usr/lib/libXfont.so.1.4.1
00c9c000-00c9d000 rw-p 00000000 00:00 0 
00cfb000-00d52000 r-xp 00000000 07:00 396847     /usr/lib/libpixman-1.so.0.16.4
00d52000-00d54000 r--p 00057000 07:00 396847     /usr/lib/libpixman-1.so.0.16.4
00d54000-00d55000 rw-p 00059000 07:00 396847     /usr/lib/libpixman-1.so.0.16.4
00d81000-00d89000 r-xp 00000000 07:00 788623     /usr/lib/xorg/modules/extensions/libdri.so
00d89000-00d8a000 r--p 00007000 07:00 788623     /usr/lib/xorg/modules/extensions/libdri.so
00d8a000-00d8b000 rw-p 00008000 07:00 788623     /usr/lib/xorg/modules/extensions/libdri.so
00e0c000-00e0e000 r-xp 00000000 07:00 655894     /lib/tls/i686/cmov/libdl-2.11.1.so
00e0e000-00e0f000 r--p 00001000 07:00 655894     /lib/tls/i686/cmov/libdl-2.11.1.so
00e0f000-00e10000 rw-p 00002000 07:00 655894     /lib/tls/i686/cmov/libdl-2.11.1.so
00e10000-00e1a000 r-xp 00000000 07:00 655905     /lib/tls/i686/cmov/libnss_files-2.11.1.so
00e1a000-00e1b000 r--p 00009000 07:00 655905     /lib/tls/i686/cmov/libnss_files-2.11.1.so
00e1b000-00e1c000 rw-p 0000a000 07:00 655905     /lib/tls/i686/cmov/libnss_files-2.11.1.so
00e27000-00e97000 r-xp 00000000 07:00 524528     /lib/libgcrypt.so.11.5.2
00e97000-00e98000 r--p 00070000 07:00 524528     /lib/libgcrypt.so.11.5.2
00e98000-00e9a000 rw-p 00071000 07:00 524528     /lib/libgcrypt.so.11.5.2
00f37000-00f3e000 r-xp 00000000 07:00 655918     /lib/tls/i686/cmov/librt-2.11.1.so
00f3e000-00f3f000 r--p 00006000 07:00 655918     /lib/tls/i686/cmov/librt-2.11.1.so
00f3f000-00f40000 rw-p 00007000 07:00 655918     /lib/tls/i686/cmov/librt-2.11.1.so
08048000-081e7000 r-xp 00000000 07:00 393235     /usr/bin/Xorg
081e7000-081e9000 r--p 0019e000 07:00 393235     /usr/bin/Xorg
081e9000-081f4000 rw-p 001a0000 07:00 393235     /usr/bin/Xorg
081f4000-081ff000 rw-p 00000000 00:00 0 
083a6000-08818000 rw-p 00000000 00:00 0          [heap]
b369c000-b566c000 rw-s e8000000 00:00 7279       /sys/devices/pci0000:00/0000:00:02.0/resource0
b61d7000-b6237000 rw-s 00000000 00:04 655376     /SYSV00000000 (deleted)
b6237000-b6297000 rw-s 00000000 00:04 622607     /SYSV00000000 (deleted)
b63c6000-b66c7000 rw-p 00000000 00:00 0 
b680a000-b686a000 rw-s 00000000 00:04 753683     /SYSV00000000 (deleted)
b69ca000-b6a2a000 rw-s 00000000 00:04 720914     /SYSV00000000 (deleted)
b6a2a000-b6a8a000 rw-s 00000000 00:04 688145     /SYSV00000000 (deleted)
b6a8a000-b6aea000 rw-s 00000000 00:04 589838     /SYSV00000000 (deleted)
b6aea000-b6b4a000 rw-s 00000000 00:04 557069     /SYSV00000000 (deleted)
b6b4a000-b6baa000 rw-s 00000000 00:04 524300     /SYSV00000000 (deleted)
b6baa000-b6c0a000 rw-s 00000000 00:04 491531     /SYSV00000000 (deleted)
b6c0a000-b6c6a000 rw-s 00000000 00:04 458762     /SYSV00000000 (deleted)
b6c6a000-b6cca000 rw-s 00000000 00:04 425993     /SYSV00000000 (deleted)
b6cca000-b6d2a000 rw-s 00000000 00:04 393224     /SYSV00000000 (deleted)
b6d2a000-b6d8a000 rw-s 00000000 00:04 360455     /SYSV00000000 (deleted)
b6d8a000-b6dea000 rw-s 00000000 00:04 327686     /SYSV00000000 (deleted)
b6dea000-b6e4a000 rw-s 00000000 00:04 294917     /SYSV00000000 (deleted)
b6e4a000-b6eaa000 rw-s 00000000 00:04 262148     /SYSV00000000 (deleted)
b6eaa000-b6f0a000 rw-s 00000000 00:04 229379     /SYSV00000000 (deleted)
b6f0a000-b6f6a000 rw-s 00000000 00:04 196610     /SYSV00000000 (deleted)
b6f6a000-b6fca000 rw-s 00000000 00:04 163841     /SYSV00000000 (deleted)
b6fca000-b702a000 rw-s 00000000 00:04 131072     /SYSV00000000 (deleted)
b702a000-b762c000 rw-p 00000000 00:00 0 
b762c000-b763c000 rw-s 000a0000 00:05 790        /dev/mem
b763c000-b767c000 rw-s 000c0000 00:05 790        /dev/mem
b767c000-b769c000 rw-s 000a0000 00:05 790        /dev/mem
b769c000-b7792000 rw-p 00000000 00:00 0 
b779f000-b77a2000 rw-p 00000000 00:00 0 
bfb08000-bfb2b000 rw-p 00000000 00:00 0          [stack]

With red characters we indicate the starting address of the X server process ('/usr/bin/Xorg'), which is 0x8048000.

From the man page of proc we read a short description of the previous output:

/proc/[number]/maps
    A file containing the currently mapped memory regions and their access permissions.

    The format is:

    address           perms offset  dev   inode      pathname
    08048000-08056000 r-xp 00000000 03:0c 64593      /usr/sbin/gpm
    08056000-08058000 rw-p 0000d000 03:0c 64593      /usr/sbin/gpm
    08058000-0805b000 rwxp 00000000 00:00 0
    40000000-40013000 r-xp 00000000 03:0c 4165       /lib/ld-2.2.4.so
    40013000-40015000 rw-p 00012000 03:0c 4165       /lib/ld-2.2.4.so
    4001f000-40135000 r-xp 00000000 03:0c 45494      /lib/libc-2.2.4.so
    40135000-4013e000 rw-p 00115000 03:0c 45494      /lib/libc-2.2.4.so
    4013e000-40142000 rw-p 00000000 00:00 0
    bffff000-c0000000 rwxp 00000000 00:00 0
where address is the address space in the process that it occupies, perms is a set of permissions:
    r = read
    w = write
    x = execute
    s = shared
    p = private (copy on write)
offset is the offset into the file/whatever, dev is the device (major:minor), and inode is the inode on that device. 0 indicates that no inode is associated with the memory region, as the case would be with bss.

It may look strange that the shared library mapping in my Ubuntu system starts from virtual address 0x110000, since more references on the subject place it at 0x40000000. Consider for instance the following image from the Linux Journal:

Recent Linux distributions probably manage to make use of some of the unused space, just below the memory address 0x8048000. Several backtraces can be found in the web that also use address 0x110000 for loading shared libraries, for instance this link. See also this link for a short explanation.

The shared libraries mapping

To capture the moment that a specific virtual memory region were assigned to a shared library we use the strace utility. From the strace man page we read:

It intercepts and records the system calls which are called by a process and the signals which are received by a process.

As with the previous X Server debugging in section 3.2.2.5.1 we have to run strace remotely from another workstasion, otherwise the X Window frozes (temporarily this time). Also since we have to observe the virtual memory mapping that take place at the start of the X server we have to start a new X server. There are several ways to do that, including the startx and xinit commands, I simply use the following from the command line:

sudo /usr/bin/X :1
I use sudo because I need root privilege to start the X Server and also since this is the second server in my system I use display 1. Previously with the following command:
ps xa | grep X
I had found the X server process' name /usr/bin/X.

To verify that the second server works fine I run:

xterm -display localhost:1.0
and using Ctrl+Alt+F8 I swap to the second display which naturally includes only the process we started for this display, the xterm terminal. To return to the first display, if needed I use the combination Ctrl+Alt+F7. From the xterm I run the scrot utility to capture the second display contents, in order to illustrate them in the following image:


The second display uses no window manager

After verifying that the second X server works fine I use the kill command to terminate the second X server and this time I start it remotely from the second machine using a telnet client. From the command line to connect with my Linux laptop (192.168.1.101) I run:

telnet 192.168.1.101
and after logging in I run:
sudo strace -fo logfile /usr/bin/X :1
With the previous command I use strace to examine the system calls of the X server (/usr/bin/X) from the time the X server starts. The output is recorder to logfile. Since this is a big file I use the head command to trim the first 200 lines of this as:
head -n 200 logfile > logfile1
Next I use the ps command to find the process id of the second X server:
ps xa | grep X
This was 2134 at the specific time.

I use from the first X server terminal the following command

sudo cat /proc/2134/maps > logfile2
which as we previously saw it shows among other the shared library mapping of the second server.

To examine the mapping of the address 0x110000 we could use the grep command as:

cat logfile1 | grep -B 3 110000
cat logfile2 | grep -B 3 110000
and see that at both files as expected at this address it is mapped the library libbz2.so.

Next we show the part of the logfile1 that include the address 0x110000 and also logfile2. We use as case study libbz2.so the shared library mapped at the lower address in my system, 0x110000, to show the process of mapping libbz2.so at 0x110000 when the second X server started (shown in logfile1) the actual mapping as appears for the second X server at current time (logfile2).

For logfile1 we have:

This is a part of logfile1, the output of strace /usr/bin/X :1
2134  open("/lib/tls/i686/cmov/librt.so.1", O_RDONLY) = 3
2134  read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0\300\30\0\0004\0\0\0"..., 512) = 512
2134  fstat64(3, {st_mode=S_IFREG|0644, st_size=30684, ...}) = 0
2134  mmap2(NULL, 33364, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x6ac000
2134  mmap2(0x6b3000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x6) = 0x6b3000
2134  close(3)                          = 0
2134  access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
2134  open("/lib/tls/i686/cmov/libc.so.6", O_RDONLY) = 3
2134  read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0000m\1\0004\0\0\0"..., 512) = 512
2134  fstat64(3, {st_mode=S_IFREG|0755, st_size=1405508, ...}) = 0
2134  mmap2(NULL, 1415592, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0xb70000
2134  mprotect(0xcc3000, 4096, PROT_NONE) = 0
2134  mmap2(0xcc4000, 12288, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x153) = 0xcc4000
2134  mmap2(0xcc7000, 10664, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0xcc7000
2134  close(3)                          = 0
2134  access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
2134  open("/lib/libz.so.1", O_RDONLY)  = 3
2134  read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0\240\31\0\0004\0\0\0"..., 512) = 512
2134  fstat64(3, {st_mode=S_IFREG|0644, st_size=79512, ...}) = 0
2134  mmap2(NULL, 82188, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0xa4c000
2134  mmap2(0xa5f000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x12) = 0xa5f000
2134  close(3)                          = 0
2134  access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
2134  open("/usr/lib/libfreetype.so.6", O_RDONLY) = 3
2134  read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0000o\0\0004\0\0\0"..., 512) = 512
2134  fstat64(3, {st_mode=S_IFREG|0644, st_size=476612, ...}) = 0
2134  mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb77c2000
2134  mmap2(NULL, 479388, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x729000
2134  mmap2(0x79a000, 20480, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x70) = 0x79a000
2134  close(3)                          = 0
2134  access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
2134  open("/lib/libbz2.so.1.0", O_RDONLY) = 3
2134  read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0`\21\0\0004\0\0\0"..., 512) = 512
2134  fstat64(3, {st_mode=S_IFREG|0644, st_size=70076, ...}) = 0
2134  mmap2(NULL, 72936, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x110000
2134  mmap2(0x120000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0xf) = 0x120000
2134  close(3)                          = 0
2134  access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
2134  open("/usr/lib/libfontenc.so.1", O_RDONLY) = 3
2134  read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0\20\16\0\0004\0\0\0"..., 512) = 512
2134  fstat64(3, {st_mode=S_IFREG|0644, st_size=24024, ...}) = 0
2134  mmap2(NULL, 28096, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x235000
2134  mmap2(0x23a000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x4) = 0x23a000
2134  close(3)                          = 0
2134  access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
2134  open("/lib/libgpg-error.so.0", O_RDONLY) = 3
2134  read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0p\6\0\0004\0\0\0"..., 512) = 512
2134  fstat64(3, {st_mode=S_IFREG|0644, st_size=13604, ...}) = 0
2134  mmap2(NULL, 16432, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x122000
2134  mmap2(0x125000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x2) = 0x125000
2134  close(3)                          = 0
2134  mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb77c1000
2134  mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb77c0000

For logfile2 we have:

logfile2 is the output of cat /proc/pid/maps

00110000-00120000 r-xp 00000000 07:00 524491     /lib/libbz2.so.1.0.4
00120000-00121000 r--p 0000f000 07:00 524491     /lib/libbz2.so.1.0.4
00121000-00122000 rw-p 00010000 07:00 524491     /lib/libbz2.so.1.0.4
00122000-00125000 r-xp 00000000 07:00 524532     /lib/libgpg-error.so.0.4.0
00125000-00126000 r--p 00002000 07:00 524532     /lib/libgpg-error.so.0.4.0
00126000-00127000 rw-p 00003000 07:00 524532     /lib/libgpg-error.so.0.4.0
00127000-0012b000 r-xp 00000000 07:00 788622     /usr/lib/xorg/modules/extensions/libdbe.so
0012b000-0012c000 r--p 00003000 07:00 788622     /usr/lib/xorg/modules/extensions/libdbe.so
0012c000-0012d000 rw-p 00004000 07:00 788622     /usr/lib/xorg/modules/extensions/libdbe.so
00135000-0014a000 r-xp 00000000 07:00 655914     /lib/tls/i686/cmov/libpthread-2.11.1.so
0014a000-0014b000 r--p 00014000 07:00 655914     /lib/tls/i686/cmov/libpthread-2.11.1.so
0014b000-0014c000 rw-p 00015000 07:00 655914     /lib/tls/i686/cmov/libpthread-2.11.1.so
0014c000-0014e000 rw-p 00000000 00:00 0 
0014e000-001a5000 r-xp 00000000 07:00 396847     /usr/lib/libpixman-1.so.0.16.4
001a5000-001a7000 r--p 00057000 07:00 396847     /usr/lib/libpixman-1.so.0.16.4
001a7000-001a8000 rw-p 00059000 07:00 396847     /usr/lib/libpixman-1.so.0.16.4
001a9000-001bf000 r-xp 00000000 07:00 788625     /usr/lib/xorg/modules/extensions/libextmod.so
001bf000-001c0000 r--p 00015000 07:00 788625     /usr/lib/xorg/modules/extensions/libextmod.so
001c0000-001c1000 rw-p 00016000 07:00 788625     /usr/lib/xorg/modules/extensions/libextmod.so
001c1000-00210000 r-xp 00000000 07:00 788626     /usr/lib/xorg/modules/extensions/libglx.so
00210000-00211000 r--p 0004e000 07:00 788626     /usr/lib/xorg/modules/extensions/libglx.so
00211000-00214000 rw-p 0004f000 07:00 788626     /usr/lib/xorg/modules/extensions/libglx.so
00214000-0021d000 r-xp 00000000 07:00 524509     /lib/libdrm.so.2.4.0
0021d000-0021e000 r--p 00008000 07:00 524509     /lib/libdrm.so.2.4.0
0021e000-0021f000 rw-p 00009000 07:00 524509     /lib/libdrm.so.2.4.0
0021f000-00228000 r-xp 00000000 07:00 788628     /usr/lib/xorg/modules/input/evdev_drv.so
00228000-00229000 r--p 00008000 07:00 788628     /usr/lib/xorg/modules/input/evdev_drv.so
00229000-0022a000 rw-p 00009000 07:00 788628     /usr/lib/xorg/modules/input/evdev_drv.so
00235000-0023a000 r-xp 00000000 07:00 396370     /usr/lib/libfontenc.so.1.0.0
0023a000-0023b000 r--p 00004000 07:00 396370     /usr/lib/libfontenc.so.1.0.0
0023b000-0023c000 rw-p 00005000 07:00 396370     /usr/lib/libfontenc.so.1.0.0
0023c000-00258000 r-xp 00000000 07:00 662209     /usr/lib/xorg/modules/libint10.so
00258000-00259000 r--p 0001c000 07:00 662209     /usr/lib/xorg/modules/libint10.so
00259000-0025a000 rw-p 0001d000 07:00 662209     /usr/lib/xorg/modules/libint10.so
0025c000-00261000 r-xp 00000000 07:00 662212     /usr/lib/xorg/modules/libvbe.so
00261000-00262000 r--p 00004000 07:00 662212     /usr/lib/xorg/modules/libvbe.so
00262000-00263000 rw-p 00005000 07:00 662212     /usr/lib/xorg/modules/libvbe.so
00263000-0027f000 r-xp 00000000 07:00 662208     /usr/lib/xorg/modules/libfb.so
0027f000-00280000 r--p 0001c000 07:00 662208     /usr/lib/xorg/modules/libfb.so
00280000-00281000 rw-p 0001d000 07:00 662208     /usr/lib/xorg/modules/libfb.so
00281000-0028d000 r-xp 00000000 07:00 788630     /usr/lib/xorg/modules/input/synaptics_drv.so
0028d000-0028e000 r--p 0000b000 07:00 788630     /usr/lib/xorg/modules/input/synaptics_drv.so
0028e000-0028f000 rw-p 0000c000 07:00 788630     /usr/lib/xorg/modules/input/synaptics_drv.so
00326000-0032c000 r-xp 00000000 07:00 788627     /usr/lib/xorg/modules/extensions/librecord.so
0032c000-0032d000 r--p 00005000 07:00 788627     /usr/lib/xorg/modules/extensions/librecord.so
0032d000-0032e000 rw-p 00006000 07:00 788627     /usr/lib/xorg/modules/extensions/librecord.so
003c8000-003cc000 r-xp 00000000 07:00 396087     /usr/lib/libXdmcp.so.6.0.0
003cc000-003cd000 r--p 00003000 07:00 396087     /usr/lib/libXdmcp.so.6.0.0
003cd000-003ce000 rw-p 00004000 07:00 396087     /usr/lib/libXdmcp.so.6.0.0
00437000-0043e000 r-xp 00000000 07:00 396837     /usr/lib/libpciaccess.so.0.10.8
0043e000-0043f000 r--p 00007000 07:00 396837     /usr/lib/libpciaccess.so.0.10.8
0043f000-00440000 rw-p 00008000 07:00 396837     /usr/lib/libpciaccess.so.0.10.8
00490000-00495000 r-xp 00000000 07:00 662253     /usr/lib/xorg/modules/drivers/vesa_drv.so
00495000-00496000 r--p 00004000 07:00 662253     /usr/lib/xorg/modules/drivers/vesa_drv.so
00496000-00497000 rw-p 00005000 07:00 662253     /usr/lib/xorg/modules/drivers/vesa_drv.so
004c8000-00538000 r-xp 00000000 07:00 524528     /lib/libgcrypt.so.11.5.2
00538000-00539000 r--p 00070000 07:00 524528     /lib/libgcrypt.so.11.5.2
00539000-0053b000 rw-p 00071000 07:00 524528     /lib/libgcrypt.so.11.5.2
00548000-0054a000 r-xp 00000000 07:00 396076     /usr/lib/libXau.so.6.0.0
0054a000-0054b000 r--p 00001000 07:00 396076     /usr/lib/libXau.so.6.0.0
0054b000-0054c000 rw-p 00002000 07:00 396076     /usr/lib/libXau.so.6.0.0
006ac000-006b3000 r-xp 00000000 07:00 655918     /lib/tls/i686/cmov/librt-2.11.1.so
006b3000-006b4000 r--p 00006000 07:00 655918     /lib/tls/i686/cmov/librt-2.11.1.so
006b4000-006b5000 rw-p 00007000 07:00 655918     /lib/tls/i686/cmov/librt-2.11.1.so
006e6000-0070a000 r-xp 00000000 07:00 524519     /lib/libexpat.so.1.5.2
0070a000-0070c000 r--p 00024000 07:00 524519     /lib/libexpat.so.1.5.2
0070c000-0070d000 rw-p 00026000 07:00 524519     /lib/libexpat.so.1.5.2
00729000-0079a000 r-xp 00000000 07:00 396376     /usr/lib/libfreetype.so.6.3.22
0079a000-0079e000 r--p 00070000 07:00 396376     /usr/lib/libfreetype.so.6.3.22
0079e000-0079f000 rw-p 00074000 07:00 396376     /usr/lib/libfreetype.so.6.3.22
007ac000-007b1000 r-xp 00000000 07:00 662210     /usr/lib/xorg/modules/libshadow.so
007b1000-007b2000 r--p 00004000 07:00 662210     /usr/lib/xorg/modules/libshadow.so
007b2000-007b3000 rw-p 00005000 07:00 662210     /usr/lib/xorg/modules/libshadow.so
007c3000-007c4000 r-xp 00000000 00:00 0          [vdso]
007da000-007dc000 r-xp 00000000 07:00 788624     /usr/lib/xorg/modules/extensions/libdri2.so
007dc000-007dd000 r--p 00002000 07:00 788624     /usr/lib/xorg/modules/extensions/libdri2.so
007dd000-007de000 rw-p 00003000 07:00 788624     /usr/lib/xorg/modules/extensions/libdri2.so
0082a000-00847000 r-xp 00000000 07:00 524526     /lib/libgcc_s.so.1
00847000-00848000 r--p 0001c000 07:00 524526     /lib/libgcc_s.so.1
00848000-00849000 rw-p 0001d000 07:00 524526     /lib/libgcc_s.so.1
008f7000-008ff000 r-xp 00000000 07:00 788623     /usr/lib/xorg/modules/extensions/libdri.so
008ff000-00900000 r--p 00007000 07:00 788623     /usr/lib/xorg/modules/extensions/libdri.so
00900000-00901000 rw-p 00008000 07:00 788623     /usr/lib/xorg/modules/extensions/libdri.so
0092e000-00964000 r-xp 00000000 07:00 396093     /usr/lib/libXfont.so.1.4.1
00964000-00965000 r--p 00035000 07:00 396093     /usr/lib/libXfont.so.1.4.1
00965000-00966000 rw-p 00036000 07:00 396093     /usr/lib/libXfont.so.1.4.1
00966000-00967000 rw-p 00000000 00:00 0 
00a4c000-00a5f000 r-xp 00000000 07:00 524641     /lib/libz.so.1.2.3.3
00a5f000-00a60000 r--p 00012000 07:00 524641     /lib/libz.so.1.2.3.3
00a60000-00a61000 rw-p 00013000 07:00 524641     /lib/libz.so.1.2.3.3
00b3b000-00b45000 r-xp 00000000 07:00 524624     /lib/libudev.so.0.6.1
00b45000-00b46000 r--p 00009000 07:00 524624     /lib/libudev.so.0.6.1
00b46000-00b47000 rw-p 0000a000 07:00 524624     /lib/libudev.so.0.6.1
00b70000-00cc3000 r-xp 00000000 07:00 655888     /lib/tls/i686/cmov/libc-2.11.1.so
00cc3000-00cc4000 ---p 00153000 07:00 655888     /lib/tls/i686/cmov/libc-2.11.1.so
00cc4000-00cc6000 r--p 00153000 07:00 655888     /lib/tls/i686/cmov/libc-2.11.1.so
00cc6000-00cc7000 rw-p 00155000 07:00 655888     /lib/tls/i686/cmov/libc-2.11.1.so
00cc7000-00cca000 rw-p 00000000 00:00 0 
00d79000-00d94000 r-xp 00000000 07:00 524468     /lib/ld-2.11.1.so
00d94000-00d95000 r--p 0001a000 07:00 524468     /lib/ld-2.11.1.so
00d95000-00d96000 rw-p 0001b000 07:00 524468     /lib/ld-2.11.1.so
00db5000-00dd9000 r-xp 00000000 07:00 655896     /lib/tls/i686/cmov/libm-2.11.1.so
00dd9000-00dda000 r--p 00023000 07:00 655896     /lib/tls/i686/cmov/libm-2.11.1.so
00dda000-00ddb000 rw-p 00024000 07:00 655896     /lib/tls/i686/cmov/libm-2.11.1.so
00f43000-00f45000 r-xp 00000000 07:00 655894     /lib/tls/i686/cmov/libdl-2.11.1.so
00f45000-00f46000 r--p 00001000 07:00 655894     /lib/tls/i686/cmov/libdl-2.11.1.so
00f46000-00f47000 rw-p 00002000 07:00 655894     /lib/tls/i686/cmov/libdl-2.11.1.so
00f47000-0115d000 r-xp 00000000 07:00 398244     /usr/lib/dri/swrast_dri.so
0115d000-01161000 r--p 00215000 07:00 398244     /usr/lib/dri/swrast_dri.so
01161000-01163000 rw-p 00219000 07:00 398244     /usr/lib/dri/swrast_dri.so
01163000-01172000 rw-p 00000000 00:00 0 
08048000-081e7000 r-xp 00000000 07:00 393235     /usr/bin/Xorg
081e7000-081e9000 r--p 0019e000 07:00 393235     /usr/bin/Xorg
081e9000-081f4000 rw-p 001a0000 07:00 393235     /usr/bin/Xorg
081f4000-081ff000 rw-p 00000000 00:00 0 
09adf000-09d60000 rw-p 00000000 00:00 0          [heap]
b36cf000-b569f000 rw-s e8000000 00:00 7279       /sys/devices/pci0000:00/0000:00:02.0/resource0
b735e000-b765f000 rw-p 00000000 00:00 0 
b765f000-b766f000 rw-s 000a0000 00:05 790        /dev/mem
b766f000-b76af000 rw-s 000c0000 00:05 790        /dev/mem
b76af000-b76cf000 rw-s 000a0000 00:05 790        /dev/mem
b76cf000-b77c5000 rw-p 00000000 00:00 0 
b77d2000-b77d5000 rw-p 00000000 00:00 0 
bfed4000-bfef5000 rw-p 00000000 00:00 0          [stack]

Notice that the output of /proc/<pid>/maps is different from the previous at the start of the current section, where at virtual address 0x110000 it was mapped libpciaccess.so instead of libbz2.so. Each time we start a process the shared library mapping of the process is different.

mmap

To understand the process of mapping the shared libraries with the mmap system call, previously we made use of the strace utility. The following text from linuxquestions.org analyses the strace output:

output

Here is an example output from strace that we are going to analyze:

open("/lib64/libexpat.so.1", O_RDONLY)  = 6
read(6, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0@>\0\0\0\0\0\0"..., 832) = 832
fstat(6, {st_mode=S_IFREG|0755, st_size=170240, ...}) = 0 
mmap(NULL, 2265264, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 6, 0) = 0x7f5d5ced6000

analysis

The above example consists of 4 lines that can be analyzed like this:

open("/lib64/libexpat.so.1", O_RDONLY)  = 6
This first line performs the syscall open on the file /lib64/libexpat.so.1. The file shall be opened read-only (O_RDONLY). This call returns the file descriptor 6. /lib64/libexpat.so.1 is now file number 6. You can get this information from man 2 open.
read(6, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0@>\0\0\0\0\0\0"..., 832) = 832
The above line reads from the file number 6. The file content is character 177, then the string ELF, then character 2, 1, 1, 0 and so on.
fstat(6, {st_mode=S_IFREG|0755, st_size=170240, ...}) = 0
Here, fstat tells that file number 6 (/lib64/libexpat.so.1) is a regular file.
mmap(NULL, 2265264, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 6, 0) = 0x7f5d5ced6000
The above line performs the syscall mmap. See man 2 mmap about the parameters - if you do you will find out that the file with descriptor number 6 is mapped to memory at address 0x7f5d5ced6000.

For more info mmap() see Linux Device Drivers.