platform_bionic/linker
Nick Kralevich d89ce40d8e linker: add -Wl,--exclude-libs,ALL to LDFLAGS
The linker is essentially a shared library, and incorporates
it's own copy of libc. Even though it's unnecessary, currently
/system/bin/linker is exporting various libc symbols (only to
apps which explicitly dlopen /system/bin/linker)

Add --exclude-libs,ALL, which tells the static linker to mark
all of the imported libc symbols as hidden. This reduces the
size of /system/bin/linker from 92K to 67K with no obvious
loss in functionality.

  $ adb shell ls -l /system/bin/linker
  -rwxrwxrwx root     root        92260 2013-01-16 16:52 linker

  $ adb shell ls -l /system/bin/linker
  -rwxrwxrwx root     root        67660 2013-01-16 16:49 linker

Documentation on exclude-libs can be found at
http://sourceware.org/binutils/docs-2.21/ld/Options.html

Change-Id: I4508287770e4b7a845def2e6b4af969f9c866c6a
2013-01-16 16:43:58 -08:00
..
arch Fix x86 dynamic linker build. 2012-12-18 18:13:19 -08:00
Android.mk linker: add -Wl,--exclude-libs,ALL to LDFLAGS 2013-01-16 16:43:58 -08:00
debugger.cpp Make dynamic linker debugging always available. 2012-11-02 13:46:23 -07:00
dlfcn.cpp Support System.loadLibrary for libraries with transitive dependencies. 2012-12-20 14:42:14 -08:00
linker.cpp Revert "stack protector: use AT_RANDOM" 2013-01-16 13:16:42 -08:00
linker.h Support System.loadLibrary for libraries with transitive dependencies. 2012-12-20 14:42:14 -08:00
linker_debug.h Tone down some of the overly-verbose linker logging. 2012-11-05 09:11:43 -08:00
linker_environ.cpp Filter ANDROID_PROPERTY_WORKSPACE 2013-01-15 16:02:03 -08:00
linker_environ.h Cleaning the linker environment as we initialize it requires less API. 2012-11-02 12:40:11 -07:00
linker_format.cpp Fix format_number. 2012-12-20 19:00:48 -08:00
linker_format.h Make dynamic linker debugging always available. 2012-11-02 13:46:23 -07:00
linker_phdr.cpp [MIPS] Set DT_DEBUG dyntab entry if it is writable 2013-01-14 09:30:25 -08:00
linker_phdr.h [MIPS] Set DT_DEBUG dyntab entry if it is writable 2013-01-14 09:30:25 -08: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 Make dynamic linker debugging always available. 2012-11-02 13:46:23 -07:00
rt.cpp More dynamic linker cleanup. 2012-10-30 16:35:38 -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:
----------

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".