platform_bionic/linker
Evgenii Stepanov d13e9a603f Align-up and randomize shared libraries.
This change implements the following property:
  Any 2**N aligned memory region on size 2**N contains no more than one DSO.

The value N can be configured, with 16 or 18 looking like a good choice.
Additionally, DSOs are loaded at random page-aligned address inside these large
regions.

This change has dual purpose:
1. Larger values of N allow a lot more compact CFI shadow implementation.
   See change I14dfea630de468eb5620e7f55f92b1397ba06217.
   For example, CFI shadow for the system_server process has the following size (RSS, KB):
   152 for N = 12, 32 for N = 16, 16 for N = 18.
2. Extra randomization is good for security.

This change does not result in extra RAM usage, because everything is still page-aligned.
It does result in a bit more VM fragmentation because of the gaps between shared libraries.
As it turns out, this fragmentation is barely noticeable because the kernel creates new mapping
at the highest possible address, and we do enough small mappings to almost completely fill the
gaps (ex. in the Zygote the gaps are filled with .ttf file mappings and thread stacks).

I've measured VM fragmentation as the sum of all VM gaps (unmapped regions) that are larger
than 1MB according to /proc/$PID/maps. On aosp_angler-userdebug, the numbers are (in GB):

                |   N = 12  |  N = 18
system_server   |   521.9   |  521.1
zygote64        |   522.1   |  521.3
zygote32        |   2.55    |  2.55
mediaserver     |   4.00    |  4.00

Change-Id: Ia6df840dd409c82837efd1f263be420d9723c84a
2016-07-19 18:18:22 -07:00
..
arch Fix mips/mips64 build 2014-07-28 21:03:17 -07:00
tests linker: Add unit-test for sleb128_decoder 2016-04-05 16:42:17 -07:00
Android.bp Convert linker from Android.mk to Android.bp 2016-07-15 13:39:29 -07:00
Android.mk Convert linker from Android.mk to Android.bp 2016-07-15 13:39:29 -07:00
dlfcn.cpp linker: Enable debug logging via properties 2016-07-12 14:22:13 -07:00
linked_list.h linker: hide the pointer to soinfo 2016-03-28 13:15:40 -07:00
linker.cpp linker: Enable debug logging via properties 2016-07-12 14:22:13 -07:00
linker.h Align-up and randomize shared libraries. 2016-07-19 18:18:22 -07:00
linker_allocator.cpp Use trivial types to avoid calls to new for globals 2016-07-13 10:33:15 -07:00
linker_allocator.h Unify names for pages allocated for small objects 2016-01-26 17:54:13 -08:00
linker_block_allocator.cpp linker: align allocated blocks to 16 bytes 2016-01-21 14:28:33 -08:00
linker_block_allocator.h General purpose memory allocator for linker. 2015-03-16 11:19:53 -07:00
linker_debug.h linker: implement shared namespaces 2015-12-19 23:38:27 -08:00
linker_gdb_support.cpp Move gdb support functions to a separate file 2016-02-18 12:32:56 -08:00
linker_gdb_support.h Move gdb support functions to a separate file 2016-02-18 12:32:56 -08:00
linker_libc_support.c Implement Library Load Order Randomization 2015-10-22 18:26:07 -07:00
linker_logger.cpp Use trivial types to avoid calls to new for globals 2016-07-13 10:33:15 -07:00
linker_logger.h linker: Enable debug logging via properties 2016-07-12 14:22:13 -07:00
linker_mapped_file_fragment.cpp Move some utility functions to linker_utils 2015-11-20 21:37:51 +00:00
linker_mapped_file_fragment.h refactoring: introduce MappedFileFragment 2015-10-22 18:01:56 -07:00
linker_memory.cpp General purpose memory allocator for linker. 2015-03-16 11:19:53 -07:00
linker_mips.cpp Revert "[MIPS] Link .dex or .oat code lacking .MIPS.abiflags segment" 2016-03-11 17:33:09 +01:00
linker_phdr.cpp Align-up and randomize shared libraries. 2016-07-19 18:18:22 -07:00
linker_phdr.h Do not unmap reserved region on dlclose 2016-01-20 20:57:47 -08:00
linker_reloc_iterators.h Fix long lines and replace macros with functions. 2015-03-31 11:49:25 -07:00
linker_relocs.h Refactor soinfo::relocate 2015-01-09 14:57:53 -08:00
linker_sdk_versions.cpp Improve library lookup logic 2015-06-17 17:16:44 -07:00
linker_sleb128.h linker: Add unit-test for sleb128_decoder 2016-04-05 16:42:17 -07:00
linker_utils.cpp Add permitted_when_isolated_path to linker namespaces 2015-12-09 13:54:01 -08:00
linker_utils.h Add permitted_when_isolated_path to linker namespaces 2015-12-09 13:54:01 -08:00
MODULE_LICENSE_APACHE2 auto import from //depot/cupcake/@135843 2009-03-03 19:28:35 -08:00
NOTICE Regenerate NOTICE files. 2016-05-16 17:46:00 -07:00
rt.cpp More dynamic linker cleanup. 2012-10-30 16:35:38 -07:00