platform_bionic/linker
Elliott Hughes 8cacc639b6 am 7193731a: Merge "Workaround g++ 4.7 compfail"
* commit '7193731ae6b8083bc7a5e5e468fb98b1dbcf3f3d':
  Workaround g++ 4.7 compfail
2012-10-25 15:20:29 -07:00
..
arch Fix x86 build. 2012-08-08 16:06:51 -07:00
Android.mk am db4fdf1a: Merge "Fix dlerror(3)." 2012-10-12 10:47:59 -07:00
debugger.c Test flags before using "info" 2012-10-03 17:20:06 -07:00
dlfcn.cpp Workaround g++ 4.7 compfail 2012-10-25 17:58:45 +04:00
linker.cpp Make dlerror(3) thread-safe. 2012-10-16 17:58:17 -07:00
linker.h Add link.h for all platforms with dl_phdr_info 2012-08-17 12:44:23 -07:00
linker_debug.h Allow linker to compile with -DLINKER_DEBUG=1 2012-08-24 17:11:45 -07:00
linker_environ.c linker: small code-cleanup 2012-06-13 22:47:20 +02:00
linker_environ.h Clean up the linker a bit, remove prelinking support. 2012-08-07 11:41:10 -07:00
linker_format.c Clean up the linker a bit, remove prelinking support. 2012-08-07 11:41:10 -07:00
linker_format.h Clean up the linker a bit, remove prelinking support. 2012-08-07 11:41:10 -07:00
linker_phdr.c Fix comment typos. 2012-08-15 16:56:00 -07:00
linker_phdr.h linker: avoid clobbering the .dynamic section of shared libs 2012-08-14 19:38:28 +02:00
MODULE_LICENSE_APACHE2 auto import from //depot/cupcake/@135843 2009-03-03 19:28:35 -08:00
NOTICE Regenerate all NOTICE files with the latest version of the script. 2012-08-15 15:43:13 -07:00
README.TXT Clean up the linker a bit, remove prelinking support. 2012-08-07 11:41:10 -07:00
rt.c Unhide rtld_db_dlactivity() 2012-07-02 11:17:04 -07:00

Android Dynamic Linker Design Notes
===================================

Introduction:
-------------

This document provides several notes related to the design of the Android
dynamic linker.


Initialization and Termination functions:
-----------------------------------------

The Unix Sys V Binary Interface standard states that an
executable can have the following entries in its .dynamic
section:

  DT_INIT
      Points to the address of an initialization function
      that must be called when the file is loaded.

  DT_INIT_ARRAY
      Points to an array of function addresses that must be
      called, in-order, to perform initialization. Some of
      the entries in the array can be 0 or -1, and should
      be ignored.

      Note: this is generally stored in a .init_array section

  DT_INIT_ARRAYSZ
      The size of the DT_INITARRAY, if any

  DT_FINI
      Points to the address of a finalization function which
      must be called when the file is unloaded or the process
      terminated.

  DT_FINI_ARRAY
      Same as DT_INITARRAY but for finalizers. Note that the
      functions must be called in reverse-order though

      Note: this is generally stored in a .fini_array section

  DT_FINI_ARRAYSZ
      Size of FT_FINIARRAY

  DT_PREINIT_ARRAY
      An array similar to DT_INIT_ARRAY which must *only* be
      present in executables, not shared libraries, which contains
      a list of functions that need to be called before any other
      initialization function (i.e. DT_INIT and/or DT_INIT_ARRAY)
      in the executable or any of its libraries.

      Note: this is generally stored in a .preinit_array section

  DT_PREINIT_ARRAYSZ
      The size of DT_PREINIT_ARRAY

If both a DT_INIT and DT_INITARRAY entry are present, the DT_INIT
function must be called before the DT_INITARRAY functions.

Consequently, the DT_FINIARRAY must be parsed in reverse order before
the DT_FINI function, if both are available.

Note that the implementation of static C++ constructors is very
much processor dependent, and may use different ELF sections.

On the ARM (see "C++ ABI for ARM" document), the static constructors
must be called explicitly from the DT_INIT_ARRAY, and each one of them
shall register a destructor by calling the special __eabi_atexit()
function (provided by the C library). The DT_FINI_ARRAY is not used
by static C++ destructors.

On x86, the lists of constructors and destructors are placed in special
sections named ".ctors" and ".dtors", and the DT_INIT / DT_FINI functions
are in charge of calling them explicitly.


Debugging:
----------

It is possible to enable debug output in the dynamic linker. To do so,
follow these steps:

1/ Modify the line in Android.mk that says:

    LOCAL_CFLAGS += -DLINKER_DEBUG=0

  Into the following:

    LOCAL_CFLAGS += -DLINKER_DEBUG=1

2/ Force-rebuild the dynamic linker:

    cd bionic/linker
    mm -B

3/ Rebuild a new system image.

You can increase the verbosity of debug traces by defining the DEBUG
environment variable to a numeric value from 0 to 2. This will only
affect new processes being launched.

By default, traces are sent to logcat, with the "linker" tag. You can
change this to go to stdout instead by setting the definition of
LINKER_DEBUG_TO_LOG to 0 in "linker_debug.h".