platform_bionic/linker
Jean-Baptiste Queru b152dde4ca am 83362689: merge from open-source master
Merge commit '83362689f5b1f6393d376d242fe29541b63ead2d'

* commit '83362689f5b1f6393d376d242fe29541b63ead2d':
  added and modified linker to support SuperH architecture
  Add the BSD sys_signame array.
  added and modified bionic code to support SuperH architecture
2009-11-09 12:07:54 -08:00
..
arch added and modified linker to support SuperH architecture 2009-11-06 10:36:37 +09:00
Android.mk added and modified linker to support SuperH architecture 2009-11-06 10:36:37 +09:00
ba.c bionic/linker: make the buddy allocator compute max_order on its own 2009-10-19 18:10:35 -07:00
ba.h bionic/linker: change the buddy allocator to take a handle to the managed area 2009-10-19 18:10:35 -07:00
debugger.c Prevent spurious EINTR to freeze process debugging 2009-10-16 12:14:04 -07:00
dlfcn.c merge from open-source master 2009-11-09 08:04:48 -08:00
linker.c am 83362689: merge from open-source master 2009-11-09 12:07:54 -08:00
linker.h merge from open-source master 2009-11-09 08:04:48 -08:00
linker_debug.h linker: Make the errors reported by dlopen/dlsym be more useful. 2009-05-27 20:16:19 -07:00
MODULE_LICENSE_APACHE2 auto import from //depot/cupcake/@135843 2009-03-03 19:28:35 -08:00
NOTICE auto import from //depot/cupcake/@135843 2009-03-03 19:28:35 -08:00
README.TXT Fix the parsing of the .fini_array in the dynamic linker (it should happen in reverse order). 2009-05-26 11:16:28 +02:00
rt.c auto import from //depot/cupcake/@135843 2009-03-03 19:28:35 -08:00

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

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

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


Prelinking:
-----------

System libraries in Android are internally prelinked, which means that
any internal relocations within them are stripped from the corresponding
shared object, in order to reduce size and speed up loading.

Such libraries can only be loaded at the very specific virtual memory address
they have been prelinked to (during the build process). The list of prelinked
system libraries and their corresponding virtual memory address is found in
the file:

   build/core/prelink-linux-<arch>.map

It should be updated each time a new system library is added to the
system.

The prelink step happens at build time, and uses the 'soslim' and 'apriori'
tools:

  - 'apriori' is the real prelink tool which removes relocations from the
    shared object, however, it must be given a list of symbols to remove
    from the file.

  - 'soslim' is used to find symbols in an executable ELF file
    and generate a list that can be passed to 'apriori'.

By default, these tools are only used to remove internal symbols from
libraries, though they have been designed to allow more aggressive
optimizations (e.g. 'global' prelinking and symbol stripping, which
prevent replacing individual system libraries though).

You can disable prelinking at build time by modifying your Android.mk with
a line like:

    LOCAL_PRELINK_MODULE := false


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 stroed 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)

      Note: this is generally stroed 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 explicitely 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 explicitely.