History log of /bionic/linker/linker.cpp
Revision Date Author Comments
bda20e78f0f314dbbf0f0bbcf0740cf2d6a4b85e 24-May-2016 Dimitry Ivanov <dimitry@google.com> Correctly handle the case of empty LD_PRELOAD entries

Previous android versions ignored empty entries for LD_PRELOAD

Bug: http://b/28936779
Change-Id: I757478fe0c604ee378186511cb13b757fd9a9864
(cherry picked from commit d799b2bb7e9335786ab4596757d871e4a7722ff0)
f1d4a4959880eaf0f9c789c43c1bae383a605d9f 24-May-2016 Dimitry Ivanov <dimitry@google.com> Fix comments since we are keeping grey-list in N

Also add warning about removing access to greylisted libs
in the future Android releases.

Bug: http://b/26427993
Change-Id: I1aaa94e3bde09ab0f6594e9170d479cdb3e77d42
3c9624a2687a93db087544f2a2c53374bdb20bcc 23-May-2016 Dimitry Ivanov <dimitry@google.com> Do not resolve caller_ns when it is not needed

create_namespace resolves caller namespace only
when caller did not explicitly specify parent namespace.

This saves about 25 microseconds for the case when
parent_namepsace is not null (for example when creating
second classloader for the app).

Bug: http://b/28801010
Change-Id: I50ded272c931db701e5a1d8c88ed5ffb13416539
(cherry picked from commit 5240863ed559cb4c2b121ddfbf6b3d78ac15e38f)
a5c1c8e820ec3057f798f675bf8af19a4a29b396 19-May-2016 Dimitry Ivanov <dimitry@google.com> Do not check zip-entry validity on create_namespace

This operation is the most expensive one and since it is
unlikely that the zip-entry name is invalid (given that it
is constructed by the platform) - it can removed.

The worst case scenario is dlopen() of non-existing libraries
taking more time. And this use-case is not on the critical path.

Bug: http://b/28801010
Change-Id: I10a6b0bf342404ab72f0f5102ebf19f6c06ee6bf
49cfc899a3708fae9175e44c0c02cd479fda8b36 13-May-2016 Dimitry Ivanov <dimitry@google.com> linker: Allow caller to specify parent namespace

This change enables apps to share libraries opened
with RTLD_GLOBAL between different classloader namespaces.

The new parameter to create_namespace allows native_loader
to instruct the linker to share libraries belonging to
global group from a specified namespace instead of
using the caller_ns.

Bug: http://b/28560538
Bug: https://code.google.com/p/android/issues/detail?id=208458
Change-Id: I5d0c62730bbed19cdeb16c7559c74aa262a2475f
(cherry picked from commit fc2da53440383fe1026e0eb287d643b577c2707d)
dcaef3710df817db5652a1f3ab4646f43f5cd3ee 17-May-2016 Dimitry Ivanov <dimitry@google.com> Fix dlopen of main executable by absolute path

This CL adds initialization of inode for the main executable
which enables linker to resolve the correct soinfo when
application calls dlopen with absolute path to the
main executable.

Bug: http://b/28420266
Change-Id: I102e07bde454bd44c6e46075e3faeeb5092830d8
(cherry picked from commit 2ba1cf39ae6087249a839ec7b3793d4d4fa75438)
bee8572ca373f626ebe6cbcdd490808c054feb49 05-May-2016 Dimitry Ivanov <dimitry@google.com> Fix linker crash on trying to unload main executable

Linker crashed if linking of the main executable fails
instead of aborting with readable error message.

This patch modifies unload to soinfo_unload it all at once
in this particular case. This helps avoid situations when
one of the libraries on the DT_NEEDED list of main executable
has gotten unloaded by previous library unload because it
DT_NEEDED it too.

Example (consider following dependency tree):
main_executable
|-> liba.so
|-> libb.so
|-> libb.so

The list of the libraries need to be unloaded in this case
is [liba.so, libb.so], but if linker does unload one by one
by the time it gets to libb.so - the soinfo for the library
is already unloaded (and the segments were unmapped).

Passing everything as an array helps soinfo_unload to check
if a library was already unloaded by looking into local_unload_list.

Bug: http://b/28565608
Change-Id: I7199290e10a186057dcf3b7b68dbce954af7dba1
(cherry picked from commit 83fcb542088db7874a387f4f41caac2019821fd2)
19b5e8cd5d5f6e8825ced4a7b37c87590fd244e6 28-Apr-2016 Dimitry Ivanov <dimitry@google.com> Add libvorbisidec.so to the grey-list

Bug: http://b/28403395
Change-Id: Ic718b1eea4616ca87b94eee211717c4475082cab
0551c1d47bad202ce6dd90757067bc0fd217497a 11-Apr-2016 Dimitry Ivanov <dimitry@google.com> Remove dangling links in secondary namespaces

linker didn't remove link to the soinfo from shared
namespaces on soinfo_unload, because it didn't keep
record of all namespaces the library is added to.

This change adds test for this and also fixes the
problem by introducing list of secondary namespaces
to soinfo, which is used to remove soinfo in
soinfo::remove_all_links().

Bug: http://b/28115950
Change-Id: Ifbf6e54f92fa6e88f86b6a8dd6dc22d4553afd22
(cherry picked from commit aca299ac4721809d6fc61e25c505bb59acd23fbc)
79abce42146b27d523f309e0a1bc9f50175191cb 13-Apr-2016 Dimitry Ivanov <dimitry@google.com> linker: unload RTLD_NODELETE libraries when loading fails

Linker was not unloading libraries marked with RTLD_NODELETE
even when there was a error on load. For example when one of
dt_needed libraries was not found.

Bug: http://b/27911891
Change-Id: Ibc0bf110aa41fbfdc9f327ad8c364f2e3600af71
8e3a3fb4f2b7b5183c00e299e9ab17fffced1124 12-Apr-2016 Dimitry Ivanov <dimitry@google.com> Add libgui.so to the grey-list

Bug: http://b/28151000
Change-Id: I7ba8f78df7dbf32de4839cc5a95ef10e8444715c
5981d5beaf768fa5c65e89bafcba0f5462649d41 08-Apr-2016 Dimitry Ivanov <dimitry@google.com> Add libexpat.so to the grey-list

Bug: http://b/28071598
Change-Id: I5545a06edfd8e0ab5b011392860ddccd6c04677f
38b88a4a6475160e64d963f7aa48c882d876737d 01-Apr-2016 Elliott Hughes <enh@google.com> Use consistent quoting in linker messages.

Using single quotes can be more convenient -- because there's no need to
escape -- but the vast majority of existing quoting was done with double
quotes, so move in that direction.

Bug: http://b/27524191
Change-Id: I8f58593120e4c8aeaec45e16fc0178e9c162454d
b3ee859bbd6ce5ff9ed252bb00ff0b6c452d0373 22-Mar-2016 Yabin Cui <yabinc@google.com> CloseArchive() to free memory when OpenArchive fails.

Bug: 26962895
Change-Id: I42418eee320ddae857b42572690316c53f638e85
(cherry picked from commit 722072d65abb1b9fa709f5c7ae8afd98ef5ab7af)
9ce09e423f24823d52f19ab8247e078977100132 12-Nov-2015 Mingwei Shi <mingwei.shi@intel.com> libc: implement kernel vdso syscalls for i386

This patch uses __kernel_vsyscall instead of "int 0x80"
as the syscall entry point. AT_SYSINFO points to
an adapter to mask the arch specific difference and gives a
performance boost on i386 architecture.

Bug: http://b/27533895
Change-ID: Ib340c604d02c6c25714a95793737e3cfdc3fc5d7
Signed-off-by: Mingwei Shi <mingwei.shi@intel.com>

(cherry picked from commit be910529322b461148debefd50b9e0d67ae84f8e)
ae74e8750b9dae51b24a22fdb4b0e0a2d84f37b9 24-Mar-2016 Dimitry Ivanov <dimitry@google.com> linker: hide the pointer to soinfo

Handle no longer is a pointer to soinfo of
a corresponding library. This is done to
prevent access to linker internal fields.

Bug: http://b/25593965
Change-Id: I62bff0d0e5b2dc842e6bf0babb30fcc4c000be24
(cherry picked from commit d88e1f350111b3dfd71c6492321f0503cb5540db)
9acb3b747ce2e9a526cc6510029a6b432f551856 02-Mar-2016 Dimitry Ivanov <dimitry@google.com> Do not add linker the _r_debug.r_map on link_image

Bug: http://b/27533895
Change-Id: Idd0fb06a5d9f400c0608ae532cc4c575211810fa
(cherry picked from commit e97d8ed70e44db619de9975a43ed2d1509653d74)
b6ac9aa6f7ee8b71587d31d094645d322abc9640 18-Feb-2016 Dimitry Ivanov <dimitry@google.com> Improvements to dynamic linker messages

Error messages now include executable name,
also linker doesn't abort if called on itself.

Bug: http://b/27533895
Change-Id: Ia17dd540919544b28062ed71751a1d79ee865206
(cherry picked from commit 9f0a6954c602e63f85746237e1a333b4571d757d)
ed70f6a2a03c3d172d3770039e65dc262d5b4075 18-Feb-2016 Dimitry Ivanov <dimitry@google.com> Move gdb support functions to a separate file

Move gdb support functions and variables to
linker_gdb_support.h/cpp

Bug: http://b/27533895
Change-Id: I96c6592a7055715b18f1137367470fe80987263f
(cherry picked from commit 6b788eeff2ea0019849517e796b762ae790ca142)
0f478e8b445a34f04916a79bae1b466e9256014a 18-Feb-2016 Dimitry Ivanov <dimitry@google.com> Use insert_link_map_into_debug_map for executable

Use insert_link_map_into_debug_map to insert the main
executable's link_map to r_debug

Bug: http://b/27533895
Change-Id: I0eacb3f030ea3eb16ed50ad2011d604beece2d03
(cherry picked from commit f3064e4bc7f4dee351bc2eb9272db3e9792dc683)
fefb4d3dcdbc01aabaa83f2da7c0388f6918b886 17-Feb-2016 Dimitry Ivanov <dimitry@google.com> Update a comment for init_linker_info_for_gdb

Bug: http://b/27533895
Change-Id: I8e2895ecfcc6f77a180c3735342afc93be5923d3
(cherry picked from commit 6400129628ef24adb57fc4822d4fd54b8967701b)
05b60b24d9317ba84225fb21fc153cee47997e45 16-Feb-2016 Dimitry Ivanov <dimitry@google.com> Initialize linker link_map for gdb directly

Remove unnecessary construction of soinfo when
initializing linker link_map for gdb.

Bug: http://b/27533895
Change-Id: Idf32cee56309aa9c9cf260efbd17a9deae9a756b
(cherry picked from commit 8d22dd53feddcc7a84e1cc481f171fd4dfe095a1)
19930d5f6ef39e660d0cdab5e17445a7d3ed1310 15-Mar-2016 Dimitry Ivanov <dimitry@google.com> Remove missing DT_SONAME warning from the toast

Bug: http://b/27613086
Change-Id: I9410f07dbde002d936319516313b27f9794dd597
31e910c4070cdb014f2b312fefea2eae6c768906 04-Mar-2016 Dimitry Ivanov <dimitry@google.com> Add libsqlite.so to the grey-list

Bug: http://b/27152660
Bug: http://b/26394120
Change-Id: I9f8f6eb8cf0d81ddf1b7769e306c08b927f3dad1
350bdad61cc6551db649fcaeb8642f4a1d6b139a 01-Mar-2016 Dimitry Ivanov <dimitry@google.com> linker: print "not accessible" error message to the log

Print properties of the namespace on "library is not accessible"
error to better diagnose problems with native library accessiblity

Bug: http://b/27406143
Change-Id: Icf3d6c604f09dfa015de863fdb1267d343930d2a
df91dc2c192aa2789320c500037d28c919daa820 26-Feb-2016 Dimitry Ivanov <dimitry@google.com> Add android_dlwarning() method

This is temporary method intended to use
for a toast message on preview and beta
releases. Will be removed before the
production release.

Bug: http://b/27365747
Change-Id: I39cc716bb82863ae761b6821bcec77cce6db3781
b8e376906718fd4ea1ec7c9be258c99ec40900a9 12-Feb-2016 Dimitry Ivanov <dimitry@google.com> Fix is_greylisted check in case of an absolute path

Some apps are explicitly calling System.loadLibrary(.)
for internal platform libraries like cutils.

Bug: http://b/27100558
Change-Id: I765cf3fc542778d3b487069c9955d367840b3c05
88f5111123d9900fc4da05435aa8416a6f9f9bcd 02-Feb-2016 Dimitry Ivanov <dimitry@google.com> linker: Change the library search order

Look into "/system/lib" before "/vendor/lib", this way
we can ensure that in case of name conflict /system libraries
take precedence.

Change-Id: Ifacdc9dc7a4e175853f499ed09782b2257f09e5a
f53e7de4e97673195ef2faf52f777352660de2a8 01-Feb-2016 Dimitry Ivanov <dimitry@google.com> linker: check if needed_by is nullptr

Check if needed_by is nullptr in the grey-list warning
also print the name of the library making call to dlopen()

Bug: http://b/26749878
Change-Id: I4e16223a3e3d8d1539f855a0b3f199c5529027e0
1005748da1ee257f4ba64a4ef1cae7ce05bdf946 29-Jan-2016 Dimitry Ivanov <dimitry@google.com> Do not allow System.load() of external libraries

The greylisting mechanism had a bug that allowed
loading any library using absolute path from java code.

It mistakenly assumed they are needed by greylisted
system library when in fact it is dlopen() call from
libnativeloader.

This patch fixes this problem by checking that the library is in
fact dt_needed and it is not a dlopen call.

Bug: http://b/26394120
Bug: http://b/22548808
Change-Id: Ia3d4c19e77b04d09a6c3047d684d0c04bd5c785e
a2a05016a0f2c8869c17a5dc616afa4b8247305c 26-Jan-2016 Dimitry Ivanov <dimitry@google.com> Add libskia.so to the grey-list.

Bug: http://b/26768182
Change-Id: I3a624861f38a3b40902f44ab728d5e9e64a74f7e
f45b0e9edee72e97106c4b3d393b9bf1582303b3 15-Jan-2016 Dimitry Ivanov <dimitry@google.com> Do not unmap reserved region on dlclose

dlclose used to unmap the part of the reserved region
for ANDROID_DLEXT_RESERVED_ADDRESS that was neccessary
to map PT_LOAD segments. With this change dlclose
replaces mapped PT_LOAD segments with a PROT_NONE,
MAP_ANONYMOUS | MAP_NORESERVE.

Previously caller was unmapping the reserved region after
the failed dlclose which led to race condition when someone
else reused the region freed by dlclose but before the unmap
by the chromium code.

Bug: http://code.google.com/p/chromium/issues/detail?id=568880
Change-Id: I0f5eaa2bf6641f83dde469b631c518482acc59a2
895d8f6e5b8c760b2325a6d414569c5da4bdeeb5 12-Jan-2016 Dimitry Ivanov <dimitry@google.com> Greylist libui.so

Bug: http://b/26494034
Bug: http://b/26394120
Change-Id: Ie857b753061ff31aee1fafc4919cc8faed5e3f5d
78dfc4017de453f5a11ca86492d359931fdda997 12-Jan-2016 Dimitry Ivanov <dimitry@google.com> Greylist libui.so

Bug: http://b/26494034
Bug: http://b/26394120
Change-Id: Ie857b753061ff31aee1fafc4919cc8faed5e3f5d
dc2bee906668f28266881bac9464b65201a09bf2 12-Jan-2016 Dimitry Ivanov <dimitry@google.com> Add the name of needed_by library to the warning

Bug: http://b/26394120
Change-Id: I8dbf1d0d879e967563ad3158ee3c0e4284dfa533
f1db47a1b36ead958a237117860c20997e8d1d16 11-Jan-2016 Dimitry Ivanov <dimitry@google.com> Limit greylisting to apps targeting sdk version<=23

Bug: http://b/26394120
Change-Id: Ida7afd944cebca7170591e4181a9d5941ea2e422
7d27af70fafc6208082b99144e1e690cae243fe8 08-Jan-2016 Dimitry Ivanov <dimitry@google.com> Refine greylist to exclude transitively DT_NEEDED libraries

Bug: http://b/26394120
Change-Id: I6d63ed3ea11811c08846c19d7ca74e80e3848f3e
36ac45f783ed7668a483697025c0447d1c6fa955 08-Jan-2016 Dimitry Ivanov <dimitry@google.com> Refine greylist to exclude transitively DT_NEEDED libraries

Bug: http://b/26394120
Change-Id: I6d63ed3ea11811c08846c19d7ca74e80e3848f3e
d6ee917a85245259a8fe8cdfecd4b8e48029b7d0 07-Jan-2016 Dimitry Ivanov <dimitry@google.com> Greylist some of internal native libraries

This change is workaround for the http://b/26394120
greylisting the libraries used by some popular apps
to keep them working on dogfood builds. It will
be removed before the release.

Bug: http://b/26394120
Change-Id: I4e588b81da59f6f667aa9d2ef7e715d6607b9a36
a8bda26ec948dbd39ad648492f110edeb269f768 07-Jan-2016 Dimitry Ivanov <dimitry@google.com> Greylist some of internal native libraries

This change is workaround for the http://b/26394120
greylisting the libraries used by some popular apps
to keep them working on dogfood builds. It will
be removed before the release.

Bug: http://b/26394120
Change-Id: I4e588b81da59f6f667aa9d2ef7e715d6607b9a36
42d949ff9d2956e25f84e537f43a8f93ecb37baf 07-Jan-2016 Elliott Hughes <enh@google.com> Defend against -fstack-protector in libc startup.

Exactly which functions get a stack protector is up to the compiler, so
let's separate the code that sets up the environment stack protection
requires and explicitly build it with -fno-stack-protector.

Bug: http://b/26276517
Change-Id: I8719e23ead1f1e81715c32c1335da868f68369b5
116b5698d4fc9d037e3fda5b66e0ca5bb50b4ea7 05-Jan-2016 Elliott Hughes <enh@google.com> Clarify which linker we are.

Also, we're not a debugger.

Also include LD_LIBRARY_PATH and LD_PRELOAD because they would have helped
diagnose a recent issue.

Change-Id: I7237a7236b7140ab49483c02efa705317d07bd3f
7331fe18d7ffd550996e07b534bc7a6cf625afa5 14-Dec-2015 Dimitry Ivanov <dimitry@google.com> linker: implement shared namespaces

Shared namespaces clone the list of loaded native
libraries from the caller namespace. This allows
classloaders for bundled apps to share already loaded
libraries with default namespace.

Bug: http://b/22548808
Bug: http://b/26165097
Change-Id: I8949d45937fdb38e1f586ff0679003adac0d9dad
(cherry picked from commit e78deef364d952dd1141a2f3067a12060aaf11e6)
e78deef364d952dd1141a2f3067a12060aaf11e6 14-Dec-2015 Dimitry Ivanov <dimitry@google.com> linker: implement shared namespaces

Shared namespaces clone the list of loaded native
libraries from the caller namespace. This allows
classloaders for bundled apps to share already loaded
libraries with default namespace.

Bug: http://b/22548808
Bug: http://b/26165097
Change-Id: I8949d45937fdb38e1f586ff0679003adac0d9dad
9cf99cbad89c8495828788ce693a99ced434f66f 11-Dec-2015 Dimitry Ivanov <dimitry@google.com> linker: add dlvsym(3)

This changes implements dlvsym - dlsym for versioned symbols.

Bug: http://b/22865643
Change-Id: Ic90a60d512104261a1416c43f9100f0d88e3b46f
4a2c5aa30ceea2aaf8dcaee2feb4879978af4fce 11-Dec-2015 Dimitry Ivanov <dimitry@google.com> Move dlsym and dladdr implementation to linker.cpp

Bug: http://b/25716705
Bug: http://b/22865643
Change-Id: If22fc1eda219f676b5fcc06490f7901d21d1749c
284ae3559ed909613b189b98bdc3efab94373a30 08-Dec-2015 Dimitry Ivanov <dimitry@google.com> Add permitted_when_isolated_path to linker namespaces

The permitted_when_isolated_path is a way to white-list
directories not present in search-path. It is ignored for
not isolated namespaces.

Bug: http://b/25853516
Bug: http://b/22548808
Change-Id: Ib1538037268eea69323ea49968a34a4a1d1938a5
db43526581c6d2cfdd0fedfd451e1a2e72b4b7a3 09-Dec-2015 Dimitry Ivanov <dimitry@google.com> Revert "Ensure that readlink has access to /proc/self/fd"

This reverts commit 4e50d0247b9ace095e371865fad08b1a59672e3a.

Bug: http://b/24912743
Change-Id: I5d32c670f0e16aec9c74add143158e919a301673
40728bccbcba5ff1bf5979bd8d3b4446fb162ead 09-Dec-2015 Dimitry Ivanov <dimitry@google.com> Revert "Add /odm/lib to shared lib search path"

This reverts commit f74b041cce75091b922151d4fa57e63c8a6caf4b.

Bug: 25654402
Change-Id: I77386ea3655868d7cd1a8130afbc95e70549389e
22840aab47763c88598b32d1edcac4d8b3ef21f0 05-Dec-2015 Dimitry Ivanov <dimitry@google.com> Allow dlopening public libs using absolute path

dlopen on isolated namespaces should be able to open
public libraries using absolute path not only soname.

Bug: http://b/25853820
Change-Id: If574a67853dc51226f0f376e9e2d108316002f84
939a7e01197858fdb8463bb5a8284ba501a3e882 05-Dec-2015 Elliott Hughes <enh@google.com> Track rename from base/ to android-base/.

Change-Id: I0a4592945400b1fa6892bf7c1fa8659fd711efa3
1ffec1cc4d0e283bb1ff6f49843769a3493b8d73 23-Nov-2015 Dmitriy Ivanov <dimitry@google.com> Introduce anonymous namespace

The anonymous namespace is introduced to
handle cases when linker can not find the
caller. This usually happens when caller
code was not loaded by dynamic linker;
for example mono-generated code.

Bug: http://b/25844435
Bug: http://b/22548808
Change-Id: I9e5b1d23c1c75bc78548d68e79216a6a943a33cf
ff35b1e659547644fb14f890eeec880cf4bafc4e 18-Nov-2015 Junichi Uekawa <uekawa@google.com> Do not depend on host bits to get the right size to write.

x86_64 32-bit or 64-bit relocations do not depend on ELF bit size, they
are 32-bit or 64-bit respectively.

Known compiler that emits such code is nacl-clang which emits
R_X86_64_PC32 which should write 32 bits but ended up writing 64 bits.

Change-Id: Ibb6b484c0fea6a7e291362148e8ac749d6674529
f74b041cce75091b922151d4fa57e63c8a6caf4b 12-Nov-2015 Hung-ying Tyan <tyanh@google.com> Add /odm/lib to shared lib search path

ODM's shared libs should live in /odm/lib on the ODM partition.

BUG: 25654402
Change-Id: I3f5c26f208af87ff2817e490e51d0b4f5b8ec98e
3cc35e224c6fe6bb82685ff8b2758553563e2a05 18-Nov-2015 Dmitriy Ivanov <dimitry@google.com> Ignore target sdk version for the public namespace

This fixes the bug with using the libraries loaded
prior to android_set_target_sdk_version call.

Bug: http://b/22548808
Change-Id: I3ca2d367b0fa930a437bbb65f780834803d2ef0a
fbfba640682b94e61632a58a0544f14ed6a57908 16-Nov-2015 Dmitriy Ivanov <dimitry@google.com> Remove the warning about empty LD_LIBRARY_PATH

Change-Id: I3eca11512d8055ab94dd0a6badcd83ce6440d675
d9b08a0bc082643b97fc9b11e0715e95be603c4c 16-Nov-2015 Dmitriy Ivanov <dimitry@google.com> Fix arm64 and x86 builds

Change-Id: Ic3746b2f200f42218b6ac857c1631e873c767c17
42d5fcb9f494eb45de3b6bf759f4a18076e84728 30-Oct-2015 Dmitriy Ivanov <dimitry@google.com> Introducing linker namespaces

Bug: http://b/22548808
Change-Id: Ia3af3c0a167f1d16447a3d83bb045d143319b1e1
fd7a91e69263a991f65fa458ff33de0670b4fd81 06-Nov-2015 Dmitriy Ivanov <dimitry@google.com> linker: cleanup solist after unsuccessful read

Bug: http://b/25560017
Change-Id: I03c5a1d7aed34c480d341aacfb3b1afdfa037b99
126af757c6d6a6447c19236df8d98ba07f21996f 08-Oct-2015 Dmitriy Ivanov <dimitry@google.com> Implement load at fixed address feature

Bug: http://b/24683631
Change-Id: I3a39ab526c8f9e213339b60e135e5459d0f41381
4f7a7ad3fed2ea90d454ec9f3cabfffb0deda8c4 15-Oct-2015 Dmitriy Ivanov <dimitry@google.com> Implement Library Load Order Randomization

Bug: http://b/24047022
Change-Id: I36e05b403bfbaae8542a95147f9114a8b9c8ac0e
77f91c6d99c25fce4fbf9704aa6f7232fb624ff4 15-Oct-2015 Dmitriy Ivanov <dimitry@google.com> Fix R_AARCH64_ABS/PREL relocations

According to specification arm64 relocations
should not use *reloc value.

See http://infocenter.arm.com/help/topic/com.arm.doc.ihi0056b/IHI0056B_aaelf64.pdf
section 4.6.5

Bug: http://b/24977219
Bug: http://b/24527155
Change-Id: I3813255771f408ba957963c6ad56ed08e5110d83
4e50d0247b9ace095e371865fad08b1a59672e3a 14-Oct-2015 Dmitriy Ivanov <dimitry@google.com> Ensure that readlink has access to /proc/self/fd

/proc/self/fd is not available when PR_DUMPABLE is set to 0
which is default for the user builds. It leads to permission
denials on readlink.

This change fixes the problem by setting PR_DUMPABLE flag to 1
for readlink and restoring it's previous value after the call.

Bug: http://b/24912743
Change-Id: I3fd179c5c6b56af96d6a15ee597024ccb15e1a13
(cherry picked from commit cf92738fa5dee24050028a1235f815f2a0fd33b5)
cf92738fa5dee24050028a1235f815f2a0fd33b5 14-Oct-2015 Dmitriy Ivanov <dimitry@google.com> Ensure that readlink has access to /proc/self/fd

/proc/self/fd is not available when PR_DUMPABLE is set to 0
which is default for the user builds. It leads to permission
denials on readlink.

This change fixes the problem by setting PR_DUMPABLE flag to 1
for readlink and restoring it's previous value after the call.

Bug: http://b/24912743
Change-Id: I3fd179c5c6b56af96d6a15ee597024ccb15e1a13
fae39d2bf9fb6f08da4a095f5fe3ff093bcdbee8 13-Oct-2015 Dmitriy Ivanov <dimitry@google.com> Log dlopen failures caused by text relocations

Some apps will fail to load native libraries with
text relocations when switching target sdk version to M.
It could be hard to diagnose because some of them
suppress dlerror and/or UnsatisfiedLinkError.

This change unconditionally logs the error message making
the cause of the failure more visible to developers.

Bug: http://b/24876001
Change-Id: I0477a0d1307d0879000f3a3a43b974b4cf34bdb2
(cherry picked from commit f32b689d3dbe7a1317bce58d1d9bef9bba173c66)
5dce8948b65cf9c2d81165056d914b999bb3a4d8 13-Oct-2015 Dmitriy Ivanov <dimitry@google.com> Replace auto -> const auto&/auto&&

Change-Id: Ie484e5a296b5dd222a9545d8539d40d97a6c158c
f32b689d3dbe7a1317bce58d1d9bef9bba173c66 13-Oct-2015 Dmitriy Ivanov <dimitry@google.com> Log dlopen failures caused by text relocations

Some apps will fail to load native libraries with
text relocations when switching target sdk version to M.
It could be hard to diagnose because some of them
suppress dlerror and/or UnsatisfiedLinkError.

This change unconditionally logs the error message making
the cause of the failure more visible to developers.

Bug: http://b/24876001
Change-Id: I0477a0d1307d0879000f3a3a43b974b4cf34bdb2
6f2d3104c82f81c1f0123a3cfb25ae670841d0ba 13-Oct-2015 Lazar Trsic <Lazar.Trsic@imgtec.com> Correctly resolve realpath for absolute paths

Introduced by: https://android-review.googlesource.com/174475

Change-Id: I44e00040b28be167d5141454f919340afec6084e
93c0f5ee00d1357247fda333c9d49c8673c9c83b 06-Oct-2015 Josh Gao <jmgao@google.com> Move VDSO pointers to a shared globals struct.

Change-Id: I01cbc9cf0917dc1fac52d9205bda2c68529d12ef
8068786ae67835291521e52f39c695e40f3ad20d 09-Oct-2015 Dmitriy Ivanov <dimitry@google.com> Remove textrels support for platform libs

Bug: http://b/20013628
Change-Id: Ia9382c7113e09bb6aed65072543e4ebe33026cf8
a828a2f8e6fd5271787a7dea4c682cbf54425a14 02-Sep-2015 Torne (Richard Coles) <torne@google.com> linker: don't pass dlextinfo to dependent loads.

Don't pass the parent load's dlextinfo to dependent loads, since this
causes the linker to try to load the dependencies using the same
addresses/relro/fds/etc as the main library, which is never going to
work. This was how it worked before ae69a95 which broke this.

Bug: 23742664
Change-Id: I53d8cdf0982d8758e6d2ced4864c704cdf74118f
a1feb117e4d5614548574f28dede3443e073512b 02-Oct-2015 Dmitriy Ivanov <dimitry@google.com> Make dt_runpath work for libraries opened from apk

This patch also fixes realpath for libraries opened directly
from apks.

Bug: http://b/21960914
Bug: http://b/21961857
Change-Id: I35ade661c87f1d448191f385811f6e9fd3cacf11
7e039937b84ef8bc86da1dcd91c1a074f05a05bc 01-Oct-2015 Dmitriy Ivanov <dimitry@google.com> Fix the comment

Change-Id: Ic8126cf92d12851cccaa3e2e781f075c9f6c283a
b48275045de93cce292faaf5170af3ead89b3746 29-Sep-2015 Dmitriy Ivanov <dimitry@google.com> Optimize dlopen from a zip file

This change makes dynamic linker reuse ZipArchiveHandles in
ld_library_path on dlopen to optimize the lookup of dt_needed
libraries.

Bug: http://b/21960534
Change-Id: I65f897910d46dd2ffabdcb0b7842db2f127eee30
280d54680d8842df5b0e37ec50acde48957d8e7a 28-Sep-2015 Dmitriy Ivanov <dimitry@google.com> Fix bug number for linker related workarounds

Bug: 24425865
Change-Id: I2021674a9df0e768f312ca024d906302db1c494f
edfc9f63a261994f2565492436607c04df980e21 03-Sep-2015 Dmitriy Ivanov <dimitry@google.com> linker: don't pass dlextinfo to dependent loads

Don't pass the parent load's dlextinfo to dependent loads, since this
causes the linker to try to load the dependencies using the same
addresses/relro/fds/etc as the main library, which is never going to
work. This was how it worked before ae69a95 which broke this.

Bug: http://b/23742664
Bug: http://b/20948231
Bug: http://b/20841817
Change-Id: I340ebae1127666d5c6c6f9c6521b89fb93f15bdd
b447440a4b5e1e300c6cb1a931b3fa1e22900c4f 29-Jul-2015 tony.ys_liu <tony.ys_liu@htc.com> Prevent buffer over-read in linker.cpp's parse_path.

Also, the old behavior of skipping empty entries doesn't match glibc.

Change-Id: I497774377113ab6c5d962e0f20066e2192748f06
ec83a61c8b5e00c67c35c9b8f72031c55e7868b9 26-Jul-2015 Dmitriy Ivanov <dimitry@google.com> Restore protection flags for ifunc during relocs.

IFUNC relocations require executable flag for the load
segment containing .text. When dso has text relocs linker
removes exec which causes crash during ifunc relocations.

This patch fixes this problem by restoring segments protection
for ifunc relocs.

Bug: http://b/22611399
Change-Id: Icbf3be0fec0e42bf805bcad7533e2032a2e11b9c
(cherry picked from commit de0fb393ae8136a5958fe17eee0c6285e2f7f91a)
de0fb393ae8136a5958fe17eee0c6285e2f7f91a 26-Jul-2015 Dmitriy Ivanov <dimitry@google.com> Restore protection flags for ifunc during relocs.

IFUNC relocations require executable flag for the load
segment containing .text. When dso has text relocs linker
removes exec which causes crash during ifunc relocations.

This patch fixes this problem by restoring segments protection
for ifunc relocs.

Bug: http://b/22611399
Change-Id: Icbf3be0fec0e42bf805bcad7533e2032a2e11b9c
d29486343a66cae37fc4fc74ed206fd29f25476b 21-Jul-2015 Elliott Hughes <enh@google.com> Use a less misleading name for the code that sets up the main thread.

Change-Id: I50c1b0a3b633cf8bc40a6bd86f12adb6b91e2888
730ed9dfec37441ae0cbb96f681381da6e113daa 16-Jul-2015 Dmitriy Ivanov <dimitry@google.com> Add constant for zip separator

Change-Id: I1dcbb15ac612fc28e922eb3de8148fcaebbc0820
d640b225ecdd6d2fb74076e9b80ce8afb42e31a0 11-Jul-2015 Evgenii Stepanov <eugenis@google.com> A special linker for ASan executables.

Setup a /system/bin/linker_asan as a symlink to "linker".
Read the linker name from PT_INTERP, and if it is linker_asan,
switch default library lookup paths to the ASan set, which
starts with the path to the instrumented libraries
(/data/lib), followed by /system/lib as a fallback.

This ensures that ASan binaries prefer ASan libraries, when
available. This approach is way better then RPATH/RUNPATH and even
better than LD_LIBRARY_PATH:
- RUNPATH is per-DSO, while default paths are global.
- LD_LIBRARY_PATH is overwritten by android_update_LD_LIBRARY_PATH.
- neither RUNPATH nor LD_LIBRARY_PATH appear in
android_get_LD_LIBRARY_PATH which is used to build java.lang.path.
Having ASan libraries in java.lang.path is a good thing.

Bug: 22355945
Change-Id: I1d2791fbf5740618f18f71a3ae3d873714669d3f
a5bb841df799e10e7d0ae3202b097da8a1c23507 09-Jul-2015 Dmitriy Ivanov <dimitry@google.com> Fix memory-leak on soinfo_free()

Bug: http://b/22290728
Change-Id: I00747056db2cd3ff8b33936278464daed7236536
(cherry picked from commit 609f11b31ecedc4e9f2a1f6017b60b1f51b15c22)
609f11b31ecedc4e9f2a1f6017b60b1f51b15c22 09-Jul-2015 Dmitriy Ivanov <dimitry@google.com> Fix memory-leak on soinfo_free()

Bug: http://b/22290728
Change-Id: I00747056db2cd3ff8b33936278464daed7236536
0cdef7e7f3c6837b56a969120d9098463d1df8d8 07-Jul-2015 Evgenii Stepanov <eugenis@google.com> Respect caller DT_RUNPATH in dlopen().

When dlopen-ing a library, add the caller's DT_RUNPATH to the directory search
list. This fixes dlfcn.dt_runpath in bionic-unit-tests-glibc(32|64).

Bug: 21899363
Change-Id: Ife6a7e192939292cf4dc291b7e6b95945761cde3
c2247478d5bcd6e8fe4d2b58f0bdeff73daa4c80 01-Jul-2015 Dmitriy Ivanov <dimitry@google.com> Improve personality initialization

1. Personality parameter should be unsigned int (not long)
2. Do not reset bits outside of PER_MASK when setting
personality value.
3. Set personality for static executables.

Bug: http://b/21900686
Change-Id: I4c7e34079cbd59b818ce221eed325c05b9bb2303
(cherry picked from commit f643eb38c36eb63f612e20dea09fd43ac6a6b360)
f643eb38c36eb63f612e20dea09fd43ac6a6b360 01-Jul-2015 Dmitriy Ivanov <dimitry@google.com> Improve personality initialization

1. Personality parameter should be unsigned int (not long)
2. Do not reset bits outside of PER_MASK when setting
personality value.
3. Set personality for static executables.

Bug: http://b/21900686
Change-Id: I4c7e34079cbd59b818ce221eed325c05b9bb2303
7271caf93db6897cdbcfca169441045bb52de61b 29-Jun-2015 Dmitriy Ivanov <dimitry@google.com> Lock on dl_interate_phdr

There is possibility of someone dlclosing a library
while dl_iterate_phdr in progress which can lead to
dl_iterate_phdr calling callback with invalid address
if it was unmapped by dlclose.

Bug: http://b/22047255
Change-Id: I3fc0d9fd2c51fb36fd34cb035f37271fa893a7be
(cherry picked from commit f7d5bf334dc4bc5b7399d4c8268e1b0bf676548f)
f7d5bf334dc4bc5b7399d4c8268e1b0bf676548f 29-Jun-2015 Dmitriy Ivanov <dimitry@google.com> Lock on dl_interate_phdr

There is possibility of someone dlclosing a library
while dl_iterate_phdr in progress which can lead to
dl_iterate_phdr calling callback with invalid address
if it was unmapped by dlclose.

Bug: http://b/22047255
Change-Id: I3fc0d9fd2c51fb36fd34cb035f37271fa893a7be
3f987f5b3eeb2e0e94c0d826429dfb418fce945f 26-Jun-2015 Dmitriy Ivanov <dimitry@google.com> Fix crash when trying to load invalid ELF file.

Bug: http://b/22047255
Bug: http://b/22091640
Change-Id: I6c51cff43287a6ac4b25fa9ce6a6fc3d232fd047
(cherry picked from commit 06700b2b5e92a365505b15d0d05e2d5b0706c511)
06700b2b5e92a365505b15d0d05e2d5b0706c511 26-Jun-2015 Dmitriy Ivanov <dimitry@google.com> Fix crash when trying to load invalid ELF file.

Bug: http://b/22047255
Bug: http://b/22091640
Change-Id: I6c51cff43287a6ac4b25fa9ce6a6fc3d232fd047
56f40fbb822b3b3066a490bdb62666039542987a 25-Jun-2015 Yusuke Sato <yusukes@google.com> Rename ZipEntryName to ZipString

This is for https://android-review.googlesource.com/#/c/156771/.

Bug: 21957428
Change-Id: Ida30c28c0fff0b2dadddbdb1aa1999ae3250610b
bc425c73e07dc150d1dcb64889ca7d379dace410 02-Jun-2015 Duane Sand <duane.sand@imgtec.com> [MIPS] Support FR=0 emulation on FR=1 64-bit FP registers

Enables running of older MIPS NDK-built apps on mips64r6.

Works with kernel supporting FRE emulation, and old kernels.

Change-Id: If5e392ed89e9910cd1ccd30e0fd5c4a5acea2c7d
cc838904642c60f29e915ab3eb6b736782b32923 24-Jun-2015 Dimitry Ivanov <dimitry@google.com> Revert "[MIPS] Support FR=0 emulation on FR=1 64-bit FP registers"

This reverts commit d02ec08427b006e80191ce60690ce48a788fb832.

Bug: http://b/22045439
Change-Id: Iaf10ff1e2948083cce0098f29d5b87b32bfae1b7
fb3357e2eb9366d87a8da96e1a0744c9b1f22af9 24-Jun-2015 Dimitry Ivanov <dimitry@google.com> Revert "[MIPS] Support FR=0 emulation on FR=1 64-bit FP registers"

This reverts commit 40d9e7bf842423e328cda58e21ff5fc0cbab5c8a.

Bug: http://b/22045439
Change-Id: Ia9c56f65d35e404332a462f46460335cef39f0a4
40d9e7bf842423e328cda58e21ff5fc0cbab5c8a 02-Jun-2015 Duane Sand <duane.sand@imgtec.com> [MIPS] Support FR=0 emulation on FR=1 64-bit FP registers

Enables running of older MIPS NDK-built apps on mips64r6.

Works with kernel supporting FRE emulation, and old kernels.

Bug: http://b/21555893
Change-Id: I13923fe62cd83ad1d337f13a50f2eda2dfdd906f
(cherry picked from commit d02ec08427b006e80191ce60690ce48a788fb832)
e4ad91f86a47b39612e030a162f4793cb3421d31 13-Jun-2015 Dmitriy Ivanov <dimitry@google.com> Remove text-relocs support for apps targeting M+

Remove support of text-relocations for apps targeting sdk version > 22

Bug: http://b/20013628
Change-Id: I2127739544480c747315e32df15dfbd1b79de4f5
(cherry picked from commit 3e6f7807541bab8157f9c26e55829fd193683349)
d02ec08427b006e80191ce60690ce48a788fb832 02-Jun-2015 Duane Sand <duane.sand@imgtec.com> [MIPS] Support FR=0 emulation on FR=1 64-bit FP registers

Enables running of older MIPS NDK-built apps on mips64r6.

Works with kernel supporting FRE emulation, and old kernels.

Change-Id: I13923fe62cd83ad1d337f13a50f2eda2dfdd906f
a9703332f6a2983ca40781e1e943c539d053d814 17-Jun-2015 Dmitriy Ivanov <dimitry@google.com> Improve library lookup logic

Linker tries to open a library even if it can
be found by soname. This only happens if the
library was previously opened under different
target sdk version.

Bug: http://b/21876587
Bug: http://b/21153477
Bug: http://b/21171302
Bug: https://code.google.com/p/android/issues/detail?id=160921
Change-Id: I7dbbcc3b49933bffd89ca0af55371e1a1f2bf4c2
(cherry picked from commit 28154f5c56dc4a64270cae2374b47a168d1bd7fa)
28154f5c56dc4a64270cae2374b47a168d1bd7fa 17-Jun-2015 Dmitriy Ivanov <dimitry@google.com> Improve library lookup logic

Linker tries to open a library even if it can
be found by soname. This only happens if the
library was previously opened under different
target sdk version.

Bug: http://b/21876587
Bug: http://b/21153477
Bug: http://b/21171302
Bug: https://code.google.com/p/android/issues/detail?id=160921
Change-Id: I7dbbcc3b49933bffd89ca0af55371e1a1f2bf4c2
d2c81ed000c08d6b5e98a65e488ca74e9516be97 17-Jun-2015 Dimitry Ivanov <dimitry@google.com> Revert "Improve library lookup logic"

This reverts commit 455c145e3c451b2b6dc00663e4040d79acefd496.

Bug: http://b/21876587
Bug: http://b/21153477
Bug: http://b/21171302
Bug: https://code.google.com/p/android/issues/detail?id=160921
Change-Id: Iad21ddfc1ac749d12bcb52384a8d937b307dd03b
1eba2f4ce1f8bf44c707a0df4a0799c5714957ac 17-Jun-2015 Dimitry Ivanov <dimitry@google.com> Revert "Improve library lookup logic"

This reverts commit ea4ef52fa46602a5853df0e5b1ddd71b194d54ce.

Bug: http://b/21876587
Bug: http://b/21153477
Bug: http://b/21171302
Bug: https://code.google.com/p/android/issues/detail?id=160921
Change-Id: I23ddbd69294023c56c9cbabad29d26c8f736ab43
455c145e3c451b2b6dc00663e4040d79acefd496 17-Jun-2015 Dmitriy Ivanov <dimitry@google.com> Improve library lookup logic

Linker tries to open a library even if it can
be found by soname. This only happens if the
library was previously opened under different
target sdk version.

Bug: http://b/21876587
Bug: http://b/21153477
Bug: http://b/21171302
Bug: https://code.google.com/p/android/issues/detail?id=160921
Change-Id: I769a04b6b1368a107d43f399297be14050338bbc
(cherry picked from commit ea4ef52fa46602a5853df0e5b1ddd71b194d54ce)
ea4ef52fa46602a5853df0e5b1ddd71b194d54ce 17-Jun-2015 Dmitriy Ivanov <dimitry@google.com> Improve library lookup logic

Linker tries to open a library even if it can
be found by soname. This only happens if the
library was previously opened under different
target sdk version.

Bug: http://b/21876587
Bug: http://b/21153477
Bug: http://b/21171302
Bug: https://code.google.com/p/android/issues/detail?id=160921
Change-Id: I769a04b6b1368a107d43f399297be14050338bbc
3e6f7807541bab8157f9c26e55829fd193683349 13-Jun-2015 Dmitriy Ivanov <dimitry@google.com> Remove text-relocs support for apps targeting M+

Remove support of text-relocations for apps targeting sdk version > 22

Bug: http://b/20013628
Change-Id: I2127739544480c747315e32df15dfbd1b79de4f5
402a75060dcd194c1991a15df2aba51f0d868ac3 09-Jun-2015 Dmitriy Ivanov <dimitry@google.com> Make path to apk compliant with jar url format

Bug: http://b/21726698
Bug: http://b/8076853
Change-Id: I8c1942a98fe3119746b4dc9f60a7ff215ea7009c
(cherry picked from commit 524f1f1efe0cb32714c61e26f21701ac952b9e42)
38263dd91a4b68e2ad0afe458c9a20cb360dafeb 11-Jun-2015 Dmitriy Ivanov <dimitry@google.com> Fix l_addr for the linker

Bug: http://b/21765603
Change-Id: I97710ef2436eac2160e29ba3e4521f6e63a1907c
(cherry picked from commit 175dae92d78cc6338125a49ea8dbabbd2f22ddf0)
175dae92d78cc6338125a49ea8dbabbd2f22ddf0 11-Jun-2015 Dmitriy Ivanov <dimitry@google.com> Fix l_addr for the linker

Bug: http://b/21765603
Change-Id: I97710ef2436eac2160e29ba3e4521f6e63a1907c
6865082ca6d887766c6651ed2d079dca56a99d32 10-Jun-2015 Evgenii Stepanov <eugenis@google.com> Support DT_RUNPATH in the linker.

Only $ORIGIN substitution is supported, but not linux-specific $LIB
or $PLATFORM.

Change-Id: I5814a016c7c91afba080230a547a863686e7c2b9
66c3b2db2f036ee55e06c1a861d0da82c5f10b3d 09-Jun-2015 Elliott Hughes <enh@google.com> Statically linked executables should honor AT_SECURE.

Bug: http://b/19647373
Change-Id: I10e7682d9cec26a523f1a3597ca5326c3ca42ebe
(cherry picked from commit 1801db3d3fe17df543e721b9fb355e5c882dc6cc)
07f4f5f9edc33d22c41f51224f8be0c0a51e5b6b 08-Jun-2015 Dmitriy Ivanov <dimitry@google.com> Check if strtab exists before using it

Bug: http://b/21696087
Change-Id: I1e22d5fd6fe2faead332249493123c9a085081e9
(cherry picked from commit 624b8f17a1ce9b968f11e73231733442a07ac001)
1801db3d3fe17df543e721b9fb355e5c882dc6cc 09-Jun-2015 Elliott Hughes <enh@google.com> Statically linked executables should honor AT_SECURE.

Bug: http://b/19647373
Change-Id: I10e7682d9cec26a523f1a3597ca5326c3ca42ebe
524f1f1efe0cb32714c61e26f21701ac952b9e42 09-Jun-2015 Dmitriy Ivanov <dimitry@google.com> Make path to apk compliant with jar url format

Bug: http://b/21726698
Bug: http://b/8076853
Change-Id: I8c1942a98fe3119746b4dc9f60a7ff215ea7009c
624b8f17a1ce9b968f11e73231733442a07ac001 08-Jun-2015 Dmitriy Ivanov <dimitry@google.com> Check if strtab exists before using it

Bug: http://b/21696087
Change-Id: I1e22d5fd6fe2faead332249493123c9a085081e9
1913352c6b3501893dfb45189754970f9dc6e7bb 03-Jun-2015 Dmitriy Ivanov <dimitry@google.com> Backward compatibility for dlsym(RTLD_DEFAULT, ...)

Do not skip RTLD_LOCAL libraries in dlsym(RTLD_DEFAULT, ...)
if the library is opened by application with target api level <= 22

Bug: http://b/21565766
Bug: http://b/17512583
Change-Id: Ic45ed1e4f53e84cba9d74cab6b0049c0c7aa8423
(cherry picked from commit 04f7e3e955ba7de5f449c995e667659319dc1cce)
04f7e3e955ba7de5f449c995e667659319dc1cce 03-Jun-2015 Dmitriy Ivanov <dimitry@google.com> Backward compatibility for dlsym(RTLD_DEFAULT, ...)

Do not skip RTLD_LOCAL libraries in dlsym(RTLD_DEFAULT, ...)
if the library is opened by application with target api level <= 22

Bug: http://b/21565766
Bug: http://b/17512583
Change-Id: Ic45ed1e4f53e84cba9d74cab6b0049c0c7aa8423
75108f4f830b533aced792d35e52841bf597f960 02-Jun-2015 Dmitriy Ivanov <dimitry@google.com> Work around for libraries without dt_soname

Applies only for apps targeting sdk version <= 22

Bug: http://b/21565766
Change-Id: If0bf2229dc1341e9ca09f9a05d0890515273d5a2
(cherry picked from commit 38c37d6705f420ecac4146c11d79bee6e0ca8a03)
38c37d6705f420ecac4146c11d79bee6e0ca8a03 02-Jun-2015 Dmitriy Ivanov <dimitry@google.com> Work around for libraries without dt_soname

Applies only for apps targeting sdk version <= 22

Bug: http://b/21565766
Change-Id: If0bf2229dc1341e9ca09f9a05d0890515273d5a2
c4ebe60e1a2fc165ff11442765325628e27f2a05 30-May-2015 Dmitriy Ivanov <dimitry@google.com> Fix dlsym(handle_of_main_executable, ...)

According to man dlopen(3) and posix docs in the case when si is handle
of the main executable we need to search not only in the executable and its
dependencies but also in all libraries loaded with RTLD_GLOBAL.

see also: http://pubs.opengroup.org/onlinepubs/9699919799/functions/dlopen.html

Bug: http://b/21528224
Bug: http://b/17512583
Bug: https://code.google.com/p/android/issues/detail?id=173822
Change-Id: Ib2801367ba48b6f3704da89a6d9f5e6911430013
(cherry picked from commit f439b5a3186ca0fef1092f45770abc716da9d87a)
f439b5a3186ca0fef1092f45770abc716da9d87a 30-May-2015 Dmitriy Ivanov <dimitry@google.com> Fix dlsym(handle_of_main_executable, ...)

According to man dlopen(3) and posix docs in the case when si is handle
of the main executable we need to search not only in the executable and its
dependencies but also in all libraries loaded with RTLD_GLOBAL.

see also: http://pubs.opengroup.org/onlinepubs/9699919799/functions/dlopen.html

Bug: http://b/21528224
Bug: http://b/17512583
Bug: https://code.google.com/p/android/issues/detail?id=173822
Change-Id: Ib2801367ba48b6f3704da89a6d9f5e6911430013
ca10ac6dd45f73752e8822fee606d83116a5721a 28-May-2015 Dmitriy Ivanov <dimitry@google.com> Improve some of error/warning messages

Bug: http://b/20464031
Change-Id: I948141c46f9e054fc45f5934153dee56ce3cd558
(cherry picked from commit 087005f37e02b48809746947159d824493885b1e)
4a7c3af054fdb525c8e458434f57f20696f43e31 28-May-2015 Dmitriy Ivanov <dimitry@google.com> Work around incorrect dt_needed entries

This applies for apps targeting sdk<=22 and
only for lp32 platforms.

Bug: http://b/21364029
Change-Id: I903e81c9ccda2a8beaba1d132d68c77d30a4cdb2
(cherry picked from commit d974e8804689058714dc4fe9adcb57ee9a6996a8)
d974e8804689058714dc4fe9adcb57ee9a6996a8 28-May-2015 Dmitriy Ivanov <dimitry@google.com> Work around incorrect dt_needed entries

This applies for apps targeting sdk<=22 and
only for lp32 platforms.

Bug: http://b/21364029
Change-Id: I903e81c9ccda2a8beaba1d132d68c77d30a4cdb2
087005f37e02b48809746947159d824493885b1e 28-May-2015 Dmitriy Ivanov <dimitry@google.com> Improve some of error/warning messages

Bug: http://b/20464031
Change-Id: I948141c46f9e054fc45f5934153dee56ce3cd558
15309fde91b3989a1af139db422acf68e16a9258 22-May-2015 Dmitriy Ivanov <dimitry@google.com> Fix RTLD_NEXT lookup for the local_group

Linker used to skip RTLD_NEXT within local_group when
caller->next is nullptr (which represents load order
but not the order within local_group dependency tree)

Bug: http://b/21380474
Change-Id: I178fc4657b19bceb871635b177c1df67855b1708
(cherry picked from commit b96ac41b32e61799c48f3fd07831cc168b95068d)
b96ac41b32e61799c48f3fd07831cc168b95068d 22-May-2015 Dmitriy Ivanov <dimitry@google.com> Fix RTLD_NEXT lookup for the local_group

Linker used to skip RTLD_NEXT within local_group when
caller->next is nullptr (which represents load order
but not the order within local_group dependency tree)

Bug: http://b/21380474
Change-Id: I178fc4657b19bceb871635b177c1df67855b1708
9185e04f72c16d2a66d92ac89b38ee926d7f706b 16-May-2015 Dmitriy Ivanov <dimitry@google.com> Apply work around b/19059885 to x86

Bug: http://b/19059885
Bug: http://b/21203348
Change-Id: Ic375e9f877d68de8f866d17362879a7dde638465
(cherry picked from commit 69a5fb951d69689dedd83cb033ae3dcd0ef05b65)
69a5fb951d69689dedd83cb033ae3dcd0ef05b65 16-May-2015 Dmitriy Ivanov <dimitry@google.com> Apply work around b/19059885 to x86

Bug: http://b/19059885
Bug: http://b/21203348
Change-Id: Ic375e9f877d68de8f866d17362879a7dde638465
fa7ba6227f918dadca787a78ed3269bf86fd234d 16-May-2015 Elliott Hughes <enh@google.com> Don't use TEMP_FAILURE_RETRY on close in bionic.

Bug: http://b/20501816
Change-Id: Id64b5109cc2b165fa0351b6edbb865a5e5058008
(cherry picked from commit 4e8ef698d0d76be3f8d75de32701e6e6327c1fbd)
4e8ef698d0d76be3f8d75de32701e6e6327c1fbd 16-May-2015 Elliott Hughes <enh@google.com> Don't use TEMP_FAILURE_RETRY on close in bionic.

Bug: http://b/20501816
Change-Id: Id64b5109cc2b165fa0351b6edbb865a5e5058008
2a44cfbd7d64596795836e9ae6f6c642869d6d78 23-Apr-2015 Spencer Low <CompareAndSwap@gmail.com> ScopedFd: Don't use TEMP_FAILURE_RETRY() with close()

According to the comments in Posix_close(), TEMP_FAILURE_RETRY() should
not be used with close():

https://android.googlesource.com/platform/libcore/+/462bdac45c10f43d88d8f07f6994e272a27c14a2%5E%21/#F12

Kill ScopedFd by simplifying the single caller.

Bug: http://b/20501816
Change-Id: I248c40b8c2fc95f1938a6edfc245c81847fc44af
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
(cherry picked from commit 0346ad7a4fb6e253317577ee8b9cc79d958f4349)
0346ad7a4fb6e253317577ee8b9cc79d958f4349 23-Apr-2015 Spencer Low <CompareAndSwap@gmail.com> ScopedFd: Don't use TEMP_FAILURE_RETRY() with close()

According to the comments in Posix_close(), TEMP_FAILURE_RETRY() should
not be used with close():

https://android.googlesource.com/platform/libcore/+/462bdac45c10f43d88d8f07f6994e272a27c14a2%5E%21/#F12

Kill ScopedFd by simplifying the single caller.

Change-Id: I248c40b8c2fc95f1938a6edfc245c81847fc44af
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
4bac6ea463a8f20793f5c1425965729ded1419fe 12-May-2015 Dmitriy Ivanov <dimitry@google.com> Improved dlsym tests and fixes to linker

Answers the question: what if dependent library
was preloaded with RTLD_LOCAL flag.

Also add test for RTLD_NEXT within local_group.

Bug: http://b/17512583
Change-Id: I79e081e68b3a8c0ed8980d4275a06515fea94ec9
(cherry picked from commit 697bd9fd38ab078a117ad9a5777cf286c467b9b9)
697bd9fd38ab078a117ad9a5777cf286c467b9b9 12-May-2015 Dmitriy Ivanov <dimitry@google.com> Improved dlsym tests and fixes to linker

Answers the question: what if dependent library
was preloaded with RTLD_LOCAL flag.

Also add test for RTLD_NEXT within local_group.

Bug: http://b/17512583
Change-Id: I79e081e68b3a8c0ed8980d4275a06515fea94ec9
b3c01d05387e8576edcb0df1ad80a326d1d3a418 07-May-2015 Dmitriy Ivanov <dimitry@google.com> Use realpath for log and error messages

Bug: http://b/20885931
Change-Id: Ida8ab7982ca75fa73da13c4cb10a6b2e53bc2c8e
(cherry picked from commit 3edb9182ff2fddfa2d835aab0cad151616f2eac5)
3edb9182ff2fddfa2d835aab0cad151616f2eac5 07-May-2015 Dmitriy Ivanov <dimitry@google.com> Use realpath for log and error messages

Bug: http://b/20885931
Change-Id: Ida8ab7982ca75fa73da13c4cb10a6b2e53bc2c8e
406d99665c71cf95af278c3244eb80745daaa0ea 06-May-2015 Dmitriy Ivanov <dimitry@google.com> VersionTracker: Ignore libraries without soname

Bug: http://b/20872443
Change-Id: I7bd076885c1feae39af6ea64c9442bcc5ae5a1dc
(cherry picked from commit 8264afb37778bea2a3c6e9aa7144f4877401c3f8)
8264afb37778bea2a3c6e9aa7144f4877401c3f8 06-May-2015 Dmitriy Ivanov <dimitry@google.com> VersionTracker: Ignore libraries without soname

Bug: http://b/20872443
Change-Id: I7bd076885c1feae39af6ea64c9442bcc5ae5a1dc
dc145b510640202a60b0dfaef9d56cd8fc1c05a9 01-May-2015 Dmitriy Ivanov <dimitry@google.com> Lookup version info when relocating mips got

Bug: http://b/20693971
Bug: http://b/20139821
Change-Id: I28bd3bc44dafe048761b2c598facfe20320128c4
(cherry picked from commit f39cb63603da949325b4d186e870d0c3de01eb30)
f92a417d07d70730fda15d7d98d36968a6a7362e 01-May-2015 Dmitriy Ivanov <dimitry@google.com> Refactoring: move VersionTracker to link_image

Use one instance of VersionTracker per link (instead of 2).

Change-Id: I6860013df65f5969975c82ebdae8bd90a82e0a82
(cherry picked from commit 7e4bbbae4a1e2034e6fa47ac2b0e1e7ca970acf0)
f39cb63603da949325b4d186e870d0c3de01eb30 01-May-2015 Dmitriy Ivanov <dimitry@google.com> Lookup version info when relocating mips got

Bug: http://b/20693971
Bug: http://b/20139821
Change-Id: I28bd3bc44dafe048761b2c598facfe20320128c4
7e4bbbae4a1e2034e6fa47ac2b0e1e7ca970acf0 01-May-2015 Dmitriy Ivanov <dimitry@google.com> Refactoring: move VersionTracker to link_image

Use one instance of VersionTracker per link (instead of 2).

Change-Id: I6860013df65f5969975c82ebdae8bd90a82e0a82
114bd835a756f782c119ed7f76b6cacb2cd723dc 01-May-2015 Dmitriy Ivanov <dimitry@google.com> Refactoring: extract lookup_version_info(..)

Change-Id: I47f9c21a1738dc520fd83281c8227dc3a7e79650
(cherry picked from commit 31b408d2c2e070c35838e7859ca4a4e5eb0c45fc)
31b408d2c2e070c35838e7859ca4a4e5eb0c45fc 01-May-2015 Dmitriy Ivanov <dimitry@google.com> Refactoring: extract lookup_version_info(..)

Change-Id: I47f9c21a1738dc520fd83281c8227dc3a7e79650
0b9e1c6051a6c75bf9040fd1da6109988900d0ac 29-Apr-2015 Dmitriy Ivanov <dimitry@google.com> linker: initialize system properties

Bug: http://b/20567629
Bug: https://code.google.com/p/chromium/issues/detail?id=478886
Change-Id: I8d2d89b749015e7fcd6e7ea646911f2e617dd1ba
(cherry picked from commit b4e5067cab9f17fa76bd7695f41a0b5070e10df8)
53ba6636178b7fb5d837b52aa6b2983263e3df4e 29-Apr-2015 Dmitriy Ivanov <dimitry@google.com> Fix LD_PRELOAD for dlopen()

We did not set DF_1_GLOBAL flag for LD_PRELOADed
libraries which led to the situation when ld_preloads
where ignored during on dlopen()

Change-Id: I696b3b2506a8ed4c0984ad2c803210a7a4f8e686
(cherry picked from commit f8093a9485402584f75b774ddf2ca051fa9b8aad)
f8093a9485402584f75b774ddf2ca051fa9b8aad 29-Apr-2015 Dmitriy Ivanov <dimitry@google.com> Fix LD_PRELOAD for dlopen()

We did not set DF_1_GLOBAL flag for LD_PRELOADed
libraries which led to the situation when ld_preloads
where ignored during on dlopen()

Change-Id: I696b3b2506a8ed4c0984ad2c803210a7a4f8e686
b4e5067cab9f17fa76bd7695f41a0b5070e10df8 29-Apr-2015 Dmitriy Ivanov <dimitry@google.com> linker: initialize system properties

Bug: http://b/20567629
Bug: https://code.google.com/p/chromium/issues/detail?id=478886
Change-Id: I8d2d89b749015e7fcd6e7ea646911f2e617dd1ba
2ea504fed199a63c7f24f7fd3233affe5b6c940f 27-Apr-2015 Dmitriy Ivanov <dimitry@google.com> Remove outdated warning

It is ok to use malloc in linker.

Bug: http://b/20567629
Change-Id: I54183dbe8ebcd223a44e710e511c339688a65dba
18870d350c29c83bdcecbe5cf3715b2c800275f7 22-Apr-2015 Dmitriy Ivanov <dimitry@google.com> Always use signed leb128 decoder

Relocation packer no longer encodes relocation tables
using unsigned leb128: https://android-review.googlesource.com/147745

Bug: http://b/18051137
Change-Id: I620b7188e5f3dd9d5123431aa1fc7feca76be607
3d7bea1fa00342f2a18331ea33a4b6e3332b3b02 21-Apr-2015 Dmitriy Ivanov <dimitry@google.com> Add library name to error message

Change-Id: I079e6f1dd95fe9cae2135fcd7358c51f8b584ac9
2a815361448d01b0f4e575f507ce31913214c536 09-Apr-2015 Dmitriy Ivanov <dimitry@google.com> Support symbol versioning

Bug: http://b/20139821
Change-Id: I64122a0fb0960c20b2ce614161b7ab048456b681
aae859cc3ca127d890e853cbf12b731e05624a22 31-Mar-2015 Dmitriy Ivanov <dimitry@google.com> Add realpath for soinfo

This change adds realpath to soinfo and
extends limit on filenames from 128 to PATH_MAX.

It also removes soinfo::name field, linker uses
dt_soname instead.

Bug: http://b/19818481
Bug: https://code.google.com/p/android/issues/detail?id=80336
Change-Id: I9cff4cb5bda3ee2bc74e1bbded9594ea7fbe2a08
9b82136b987bc01224e3b42732334ea27c97d188 03-Apr-2015 Dmitriy Ivanov <dimitry@google.com> Add ANDROID_DLEXT_FORCE_LOAD flag

This flag allows to force loading of the library
in the case when for some reason multiple ELF files
share the same filename (because the already-loaded
library has been removed and overwritten, for example).

Change-Id: I798d44409ee13d63eaa75d685e99c4d028d2b0c1
76ac1acdacc045cf1e56504e011dca68137dcd61 01-Apr-2015 Dmitriy Ivanov <dimitry@google.com> Look into local group on dlsym with RTLD_DEFAULT

Fix dlsym to look into local group when called with
RTLD_DEFAULT and RTLD_NEXT.

Bug: 17512583
Change-Id: I541354e89539c712af2ea4ec751e546913027084
56be6ed9e4ac99fdd920090ee89c57e3cf55e885 01-Apr-2015 Dimitry Ivanov <dimitry@google.com> Revert "Remove text-relocation support for lp32"

This reverts commit cb00add1b382d1e3045876d7e1ccbee2fdce976b.

Bug: 20020312
Bug: 20013628
Change-Id: I8baa3d4b6c7fef50c9e2531257d5b96762099eb3
cb00add1b382d1e3045876d7e1ccbee2fdce976b 01-Apr-2015 Dmitriy Ivanov <dimitry@google.com> Remove text-relocation support for lp32

Bug: 20013628
Change-Id: Idaf8012f00ee1304d429c3b42f9ebc6b648c55b8
20d89cb5b0d5eb7546a8fe8da44bbd91564dbdda 31-Mar-2015 Dmitriy Ivanov <dimitry@google.com> Fix long lines and replace macros with functions.

Change-Id: I4e1cab488d5b2c8e4289da617350a86e72a4ba12
d165f56fb69f39e41bc2c952bf51c3eb3b127d2e 24-Mar-2015 Dmitriy Ivanov <dimitry@google.com> Replace fixed arrays with vectors

This effectively removes limit on length and count
of LD_LIBRARY_PATH and LD_PRELOAD entries.

Change-Id: Ie7ea34a50d99c4018f9dd1a33aaebc4049a7f424
618f1a36f8635fa0f2d60c621fbf79ead2c3f3de 18-Mar-2015 Dmitriy Ivanov <dimitry@google.com> Implement lookup by DT_SONAME

This CL also fixes SEARCH_NAME hack and resolves
https://code.google.com/p/android/issues/detail?id=6670
once and for all.

Bug: https://code.google.com/p/android/issues/detail?id=6670
Change-Id: I9b8d6a672cd722f30fbfbb40cdee8d9b39cfe56e
e44fffd7f9b93b9ec9836cfc7acedf7e21107f8f 18-Mar-2015 Dmitriy Ivanov <dimitry@google.com> Fix library lookup for filenames with slash.

If filename contains a slash, then it is interpreted
as a (relative or absolute) pathname.

Bug: https://code.google.com/p/android/issues/detail?id=6670
Change-Id: Iba57d638301f3089ad47ba083edca2dd36b801ed
aef719510a57274e73ca02ab5ecdc5bf17d3985c 16-Jan-2015 Simon Baldwin <simonb@google.com> Support loading shared libraries from zip files

Add code to support loading shared libraries directly from within
APK files.

Extends the linker's handling of LD_LIBRARY_PATH, DT_RUNPATH, etc
to allow elements to be either directories as normal, or ZIP
format files. For ZIP, the ZIP subdirectory string is separated
from the path to file by '!'.

For example, if DT_NEEDED is libchrome.so and Chrome.apk is the
Android ARM APK then the path element

/system/app/Chrome.apk!lib/armeabi-v7a

would cause the linker to load lib/armeabi-v7a/libchrome.so
directly from inside Chrome.apk. For loading to succeed,
libchrome.so must be 'stored' and not compressed in Chrome.apk,
and must be page aligned within the file.

Motivation:
Chromium tracking issue:
https://code.google.com/p/chromium/issues/detail?id=390618

Bug: 8076853
Change-Id: Ic49046600b1417eae3ee8f37ee98c8ac1ecc19e7
19656ce5376c95ce0deebc4d0c6af1bb8d740934 11-Mar-2015 Dmitriy Ivanov <dimitry@google.com> General purpose memory allocator for linker.

Add basic general purpose memory allocator to
linker in order to enable usage of other libraries
like libziparchive.

Change-Id: I4a680ebb36ed5ba67c61249f81dba9f567808434
600bc3cb9342fbb1dc16ea25f5b676ce072e3e1b 10-Mar-2015 Dmitriy Ivanov <dimitry@google.com> Rename LinkerAllocator and LinkerAllocatorPage

Change-Id: I87d80fbcd4ec26c0ee4f601b9c4c64f600418dd9
c9ce70d7838b6aae074fc3615cdf04e5c9ac612a 10-Mar-2015 Dmitriy Ivanov <dimitry@google.com> Refactoring: rename linker_allocator files

Change-Id: Ifc08e64b3a85205f072b7abab1149c7ab71e2f75
3597b8055da090ef3f1ee662e96dcb952bba2c30 09-Mar-2015 Dmitriy Ivanov <dimitry@google.com> Store fields for gnu_hash separately

Kindle app relies on soinfo's sysv hash
fields while linking native libraries.

This change allows to keep sysv hash fields
intact for the libraries linked with --hash-style=both.

Bug: 19059885
Change-Id: I12528652955638f1a6586bda99e111bb1c8aa7a3
6bb01b6e6365ced7ca23c9ebecfaf1ea159d5ae2 07-Mar-2015 Nick Kralevich <nnk@google.com> linker: Allow an app to update it's own LD_LIBRARY_PATH

When the kernel executes a program which is setuid, setgid, has
file capabilities, or causes an SELinux domain transition, the
AT_SECURE flag is set. This flag instructs the dynamic linker to
prune any dangerous environment variables passed across security
boundaries.

For SELinux in particular, whether this flag is set depends on the
the "noatsecure" process permission. If that permission does not
exist, then AT_SECURE=1 whenever a domain transition occurs.

In https://android-review.googlesource.com/129971 , Android stopped
using noatsecure when executing init services. In
https://android-review.googlesource.com/130610 , init was flipped
back into SELinux enforcing mode, making ag/129971 active. The
combination of those two changes ensured that AT_SECURE=1 was
set when executing init spawned services.

In particular, AT_SECURE=1 is set when init executes zygote. Due to
the forking nature of zygote, AT_SECURE remains untouched when
executing zygote's children.

This causes problems for the code added in
https://android-review.googlesource.com/48409 . Specifically, if
AT_SECURE=1, an attempt to call android_update_LD_LIBRARY_PATH()
is silently ignored. This causes problems when art tries to adjust
the LD_LIBRARY_PATH for Android apps. Ultimately, apps are unable
to find shared libraries they depend on.

As discussed in bug 7896159, there's no security reason for
preventing an application from updating it's own LD_LIBRARY_PATH.
We only need to prune LD_LIBRARY_PATH when transitioning across
security boundaries, but not when we're entirely within a security
boundary.

Remove the AT_SECURE check within do_android_update_LD_LIBRARY_PATH().
It's unneeded and prevents an application from modifying it's own
LD_LIBRARY_PATH. This allows an application to specify a location
where it's dlopen()ed shared libraries should be loaded from.

There is no change to AT_SECURE handling in
__sanitize_environment_variables(). We continue to honor it there
to prevent using security sensitive environment variables across
an exec boundary.

Bug: 19559835
Change-Id: If4af2ee8e84265aaa0c93de8b281208b20d7942a
18a6956b76a071097fc658c5fe13ef010e31864a 05-Feb-2015 Dmitriy Ivanov <dimitry@google.com> Add support for packed relocations.

Change-Id: I796a4ce86d3fccb8361c19889419c96147ee3c9f
fa26eee77685e8dee7986e62a7d263003f5bd25a 04-Feb-2015 Dmitriy Ivanov <dimitry@google.com> Refactoring: introduce reloc_iterators

Replace rel/rela array with reloc_iterators.

Change-Id: I6165d062e0390b6bc60da2e8279aabbedf828ec9
c6292ea39cce054175e4f9f797c05aeb8da0ac4b 14-Feb-2015 Dmitriy Ivanov <dimitry@google.com> Fix: DT_DEBUG was acting as DT_REL on mips64

Change-Id: I88827aa07d75d06d606c987e6270fcca3ae6216f
8e5538193915885ea859ac90a72b46ab04440cea 14-Nov-2013 Chris Dearman <chris.dearman> linker: Use load_bias to adjust search address in elf_addr_lookup

load_bias is the delta between a symbols address in memory and the value
contained in the symbol table.

Change-Id: I35c87b69025b64f7e4a1418ca766618f4533fb3e
279a22f96e639e76c801bdb39aee5576f2280fe0 23-Jan-2015 Dmitriy Ivanov <dimitry@google.com> Minimize calls to mprotect

Implement refcounter based data protection guard
to avoid unnecessary calls to mprotect when dlopen/dlclose
is called from a constructor.

Bug: 19124318
Big: 7941716
Change-Id: Id221b84ce75443094f99756dc9950b0a1dc87222
611f95689e1012283bd11917003d3740d3ce532d 23-Jan-2015 Elliott Hughes <enh@google.com> Add a log message to make the transition from linker to user code clear.

Handy when looking at strace output for seeing "where does my code start?",
though you'll need to set LD_DEBUG=1 (or greater) and constructors will
already have run (but you can set LD_DEBUG to a higher value to track that).

Change-Id: I82d53a7123b39febf5b2a956de83c8a30f229651
1649e7ee5b9bb4122be67903d55c4c8cc0549bba 23-Jan-2015 Dmitriy Ivanov <dimitry@google.com> Enable -Wold-style-cast warnings for linker

And fix old style casts.

Change-Id: I37e7a3e3fd852528ea76f02d967c7bd8cd5b06c9
114ff69f1753c7fe4d749f8fb0c082b80e0d43f4 14-Jan-2015 Dmitriy Ivanov <dimitry@google.com> Refactoring: move mips reloc to separate method

Change-Id: I712614853e3f0e515f5c2bdd8f0aaa5feeae8e55
bcc04d0069a919a6ac4a2b378e15dd0a50c46aec 13-Jan-2015 Dmitriy Ivanov <dimitry@google.com> Refactoring: unify relocate function

Use one relocate for all platforms.

Change-Id: I43e75162c5b29105e651defc11a511e168368736
1b694693b47785c5350916eafc9200cf9aa4a920 13-Jan-2015 Dmitriy Ivanov <dimitry@google.com> Refactoring: use generic reloc constants

Change-Id: I94dd6256b1b4509b6ea696a3aff17a3991529468
d338aac19c91bf06f529364f0d1ca3ba8b98bd13 13-Jan-2015 Dimitry Ivanov <dimitry@google.com> Revert "Refactoring: use generic reloc constants"

This reverts commit 265a60a0d285a733d9d98f53672bce668803b434.

Change-Id: I6d46db0ac03cda44ed1e20f6084a552e0089eb14
265a60a0d285a733d9d98f53672bce668803b434 13-Jan-2015 Dmitriy Ivanov <dimitry@google.com> Refactoring: use generic reloc constants

Change-Id: I67918a1a926164a38a5a47f2264390632eb42905
cefef7dab67472d59d45ef1d002a20edf8edde75 09-Jan-2015 Dmitriy Ivanov <dimitry@google.com> Refactor soinfo::relocate

Move common relocation types outside of ifdefs

Change-Id: I713800ce123a18178b5ac80c0b3c7bd6b21a02c2
bfa15e464ecfb43d93e468f166d91e4e6265f300 08-Jan-2015 Dmitriy Ivanov <dimitry@google.com> Set linux 32bit personality for 32 bit processes

Bug: 18069809
Change-Id: Ie143d56b0f8f03510dc451649291067e1add1d2f
6718125ac71cca5d1868c33017bbc29059491349 08-Jan-2015 Dmitriy Ivanov <dimitry@google.com> Print error when prelink fails for main executable

Bug: 18931021
Change-Id: Ib6c39a409161b20a10c3485272c73bc2abd4ee4f
(cherry picked from commit d9e211ca1fcf8bb78a1e1de9e54fe7c8d0a01518)
d9e211ca1fcf8bb78a1e1de9e54fe7c8d0a01518 07-Jan-2015 Dmitriy Ivanov <dimitry@google.com> Print error when prelink fails for main executable

Bug: 18931021
Change-Id: Ieefdcf60f1506af522714300030754a4ed61c08e
688157295f55edbfddb2277e7bdf5635f6be591a 19-Dec-2014 Raghu Gandham <raghu.gandham@imgtec.com> Add support for DT_MIPS_RLD_MAP2 tag.

Position Independent Executables cannot communicate with GDB using DT_MIPS_RLD_TAG.
Hence a new tag DT_MIPS_RLD_MAP2 got introduced to fix the issue.

Change-Id: I77ce3faf1ef2e121003b804ecd291abb25cfbb56
Signed-off-by: Nikola Veljkovic<Nikola.Veljkovic@imgtec.com>
5ae82cba595d15e955aafb8da3fca9c5bcdeb551 03-Dec-2014 Dmitriy Ivanov <dimitry@google.com> Fix soinfo_unload

1. Take into consideration that the local_group_root_
is not set for all of not linked libraries.
2. We need to check visited list earlier to avoid double
soinfo_free.

Change-Id: Iabc0a06a97c63f7e6bd4641731f50bb1466fed4f
20463e3e53d6e9e23a7267e08da0e01bf8780fde 02-Dec-2014 Dmitriy Ivanov <dimitry@google.com> Fix mips build

Change-Id: Iddbf06784d19556a55d833e20a68e6ccf5a7c5be
ab972b9adf8789a9e1b03129cd7f0c22e6bba117 29-Nov-2014 Dmitriy Ivanov <dimitry@google.com> Count references for groups instead of instances

Count references on the group level to avoid
partially unloading function that might be
referenced by other libraries in the local_group

Bonus: with this change we can correctly unload recursively
linked libraries. is_recursive check is removed.

Also dynamic executables (not .so) with 0 DT_NEEDED libraries
are now correctly linked.

Change-Id: Idfa83baef402840599b93a875f2881d9f020dbcd
e831433fe1173cd4eb2bc44b977a373425e615a6 02-Dec-2014 Alexander Ivchenko <alexander.ivchenko@intel.com> Resolve "unused DT entry" warnings for DT_VERNEED and DT_VERNEEDNUM.

Change-Id: Id18310811a6d183878a1d4d26cc2498f4fd00c55
Signed-off-by: Alexander Ivchenko <alexander.ivchenko@intel.com>
a2547055f25db614601ee8651f2e42ece01f7842 18-Nov-2014 Dmitriy Ivanov <dimitry@google.com> Fix jump to unmapped memory on atexit

Split d-tor calls and soinfo_free to 2 separate steps

Bug: 18338888
Change-Id: Idbcb7242ade16fa18cba7fe30505ebd8d6023622
047b5934b5f1c62502fc9262ce634529c6cc1420 13-Nov-2014 Dmitriy Ivanov <dimitry@google.com> Rename soinfo methods and fields

Change-Id: If68fbe287d3ad954238b1688f71013371f3f7fae
889409168322920ab6cddeb93f506c983d8b5878 13-Nov-2014 Dmitriy Ivanov <dimitry@google.com> Fix mips build

Change-Id: I58b01db38ab9a397a8bd77c1296aac12957c21da
ec18ce06f2d007be40ad6f043058f5a4c7236573 10-Nov-2014 Dmitriy Ivanov <dimitry@google.com> Add support for hash-style=gnu

Change-Id: I171434a587420895feac8a9b1ad2342087197568
16f7f8d2503a9033a09a4d7e857561d63471bb82 04-Nov-2014 Yabin Cui <yabinc@google.com> check invalid file offset when loading library

Bug: 18178121
Bug: 18078224

Change-Id: I5254433d54645db68e9b83d5095dc2bf9d8531bc
0416d88f9c90dcb1b97947a27a7c05f3627484c4 04-Nov-2014 Dmitriy Ivanov <dimitry@google.com> Revert "Revert "Fix symbol lookup order during relocation""

This reverts commit f947be2889639defc6424b1813ccc779528b7598.
1c095774c0527027bf3f7013ba15e9913d5f1853 04-Nov-2014 Dmitriy Ivanov <dimitry@google.com> Revert "Revert "Fix mips build""

This reverts commit 4402804c35c5c5992c728c6f3cee3bdbd325819e.
a42dfda53acc6127b5046672686b67a66be168eb 04-Nov-2014 Dmitriy Ivanov <dimitry@google.com> Revert "Revert "Remove unnecessary lookups during relocations""

This reverts commit eae09772558016836f1356816f4d1d0be498d74c.
c343cac62bfd2933e36357b206fdd81da7610164 04-Nov-2014 Dmitriy Ivanov <dimitry@google.com> Revert "Revert "Fix relocation to look for symbols in local group""

This reverts commit 00dce525530c5d26c20750863f3e9890b468787a.
7ca96a075b778f1fa2ad265350879238cbcb4d09 04-Nov-2014 Dmitriy Ivanov <dimitry@google.com> Revert "Revert "Add RTLD_NODELETE flag support""

This reverts commit 69c5d108a5cb44167a04d42ffdad6a39648ed235.
68a555b57e2bed1292bf28609be693a95b5fdc6b 04-Nov-2014 Dmitriy Ivanov <dimitry@google.com> Revert "Revert "Fix dlsym() to take into account RTLD_GLOBAL/LOCAL""

This reverts commit 9d3382d97a2cdc8c8f78c7825ece16f09292fc36.
9d3382d97a2cdc8c8f78c7825ece16f09292fc36 04-Nov-2014 Dmitriy Ivanov <dimitry@google.com> Revert "Fix dlsym() to take into account RTLD_GLOBAL/LOCAL"

This reverts commit c85e82dde5c4b2accc50a9e17740b9005dfbae6a.

Bug: 18222321
Bug: 18211780
Change-Id: I32f4048bd5ea85dc8a3dfccce8cf141b241ab692
69c5d108a5cb44167a04d42ffdad6a39648ed235 04-Nov-2014 Dmitriy Ivanov <dimitry@google.com> Revert "Add RTLD_NODELETE flag support"

This reverts commit c87f65d2cd0690d81665f8b241c1d763f72b6f80.

Bug: 18222321
Bug: 18211780
Change-Id: I00252e26a28a41ab9f1e2dd3b32f0f80d86297f1
00dce525530c5d26c20750863f3e9890b468787a 04-Nov-2014 Dmitriy Ivanov <dimitry@google.com> Revert "Fix relocation to look for symbols in local group"

This reverts commit fd2747bb585fc51b5ad56db09c0e9b66c7091a92.

Bug: 18222321
Bug: 18211780
Change-Id: I2d4ebab1e73b7277161af76b99f8249825b22d65
eae09772558016836f1356816f4d1d0be498d74c 04-Nov-2014 Dmitriy Ivanov <dimitry@google.com> Revert "Remove unnecessary lookups during relocations"

This reverts commit 6442dbd3bcadbd5e522465743a8d8cf56338ae1c.

Bug: 18222321
Bug: 18211780
Change-Id: I87b18a32238a1f75afe56149221b6691f50d9f56
4402804c35c5c5992c728c6f3cee3bdbd325819e 04-Nov-2014 Dmitriy Ivanov <dimitry@google.com> Revert "Fix mips build"

This reverts commit bf3d5ef5fd240d4c5fbde1b32f9084dbc720840b.

Bug: 18222321
Bug: 18211780
Change-Id: I902ed888197b358c77303f1acb6d5ffd7ae6dcd3
f947be2889639defc6424b1813ccc779528b7598 04-Nov-2014 Dmitriy Ivanov <dimitry@google.com> Revert "Fix symbol lookup order during relocation"

This reverts commit 976402cca13a1f4f3aa988fd301575e134ef5f2c.

Bug: 18222321
Bug: 18211780
Change-Id: Iafdd3d843db7b1cf288be9a0232022816622c944
9fb216f844bb15c8e8f27c5ac0490a2f6faacb57 01-Nov-2014 Dmitriy Ivanov <dimitry@google.com> Revert "Use local copy of the library name on dlopen"

This reverts commit da8e591c3996879e41dc5f70b77d1b0fe6f9c225.

Change-Id: I3fd6f235b18c232af5cc5ecd481851486d7d68f6
976402cca13a1f4f3aa988fd301575e134ef5f2c 28-Aug-2014 Dmitriy Ivanov <dimitry@google.com> Fix symbol lookup order during relocation

Relocate symbol against DF_1_GLOBAL shared libraries
loaded before this shared library. This includes
main executable, ld_preloads and other libraries
that have DF_1_GLOBAL flag set.

Bug: 2643900
Bug: 15432753
Bug: 18186310

(cherry picked from commit d225a5e65223b375a63548c4b780f04d8f3d7b60)

Change-Id: I4e889cdf2dfbf8230b0790053d311ee6b0d0ee2d
bf3d5ef5fd240d4c5fbde1b32f9084dbc720840b 23-Oct-2014 Dmitriy Ivanov <dimitry@google.com> Fix mips build

Bug: 18186310

(cherry picked from commit 90b74fb8671db6f5512821a033e12a6248e5c804)

Change-Id: I8d4ed254e5c421b65b62c401abdb1ee07e5dc3b2
6442dbd3bcadbd5e522465743a8d8cf56338ae1c 23-Oct-2014 Dmitriy Ivanov <dimitry@google.com> Remove unnecessary lookups during relocations

local_group includes this library and its dependencies.

Bug: 18186310

(cherry picked from commit e47b3f8456fc34ac136e9fddef59a9ae37febcbe)

Change-Id: I93c2d873e924df7319569307444bf603d7d27bf0
fd2747bb585fc51b5ad56db09c0e9b66c7091a92 21-Oct-2014 Dmitriy Ivanov <dimitry@google.com> Fix relocation to look for symbols in local group

The local group is a sequence of libraries in default (breadth-first)
order. It allows RTLD_LOCALLY loaded library to correctly relocate
symbols within its group (see test-cases).

Local group lookup is performed after main executable and ld_preloads.

Bug: 2643900
Bug: 15432753
Bug: 18186310

(cherry picked from commit cfa97f172dc1b10d650fefbb6ccffd88ce72a5fb)

Change-Id: I5fa8c673f929e4652c738912c7ae078d7ec286d2
e4bc6f026a10648756da031b5d765c78c9e70864 15-Oct-2014 Dmitriy Ivanov <dimitry@google.com> Ignore DT_BIND_NOW (0x18)

Bug: 18186310
Bug: 17552334

(cherry picked from commit ea6eae182ad64312f80b9adddac511d8938e23e7)

Change-Id: I07d6f6fbb462fea329581d0da02f6d88be1c262f
1d3e81a9e7795a320406cd903ef1767072ae122e 06-Oct-2014 Dmitriy Ivanov <dimitry@google.com> Resolve "unused DT entry" warnings for x86_64

Bug: 18186310

(cherry picked from commit 513e29e16f16a6ffa1636ba282d599fd6b437aeb)

Change-Id: I1e4c5af2cdc09dc978c7a78fcdcf8796c919751e
c87f65d2cd0690d81665f8b241c1d763f72b6f80 20-May-2014 Dmitriy Ivanov <dimitry@google.com> Add RTLD_NODELETE flag support

Bug: 18186310
Bug: https://code.google.com/p/android/issues/detail?id=64069

(cherry picked from commit 1b20dafdbe65e43b9f4c95057e8482380833ea91)

Change-Id: Ic02eec22a7c322ece65eb40730a3404f611526b1
210ff1b27b67bd2aa29b35a46f48430b7714a802 01-Oct-2014 Dmitriy Ivanov <dimitry@google.com> Fix mips build

Bug: 18186310

(cherry picked from commit ecf532fa1cfe91ca946243c11ef154c602870ba6)

Change-Id: Ia12f2fa28c8cd3204eb7d6b4c7d872f4e81fb8ef
0f47d9c1ce3e75709f9d6ecb6b540bb518ee323a 30-Sep-2014 Dmitriy Ivanov <dimitry@google.com> Fix unused DT entry warnings.

DT_STRSZ Implement strtab boundary checks
DT_FLAGS_1 Warn if flags other than DF_1_NOW|DF_1_GLOBAL are set

Bug: 17552334
Bug: 18186310

(cherry picked from commit 6cdeb5234d7f4523fe9d83974f265d80f10512a6)

Change-Id: I7ffc7bc600798308a77ad949a644949b64250ae2
f90e21004e57e46b49c3338781eb3d58cc4bb517 29-Sep-2014 Dmitriy Ivanov <dimitry@google.com> Return has_DT_SYMBOLIC flag.

This reverts commit 8f61d991831f0ea515fa50a5c38dbbcfbab0dd28

Despite the fact that static linker does all the work while linking
-Bsymbolic executables, according to the SCO doc following DT_SYMBOLIC
and DF_SYMBOLIC flags is still a requirement for the dynamic linker
as well.

(see http://www.sco.com/developers/gabi/2012-12-31/ch5.dynamic.html)

Bug: 18186310

(cherry picked from commit 96bc37f2e1093416a432135265fd7a4db6c3df17)

Change-Id: Ie217be4f3305d877066e4cfe91975ae1c7768330
d5eb10875affb316c4dfc3b6ceb91df244518956 18-Sep-2014 Dmitriy Ivanov <dimitry@google.com> Temporary disable DL_WARNs for unused DT_*

Bug: 17552334
Bug: 18186310

(cherry picked from commit 1b77423eff21e916186fcb208f138e436e9f3052)

Change-Id: I8a9d05195a862bc287fff7156913606f0311b8bb
09608848edf42fb999d08e59c8c81a62a79a6941 17-Sep-2014 Dmitriy Ivanov <dimitry@google.com> Fix 64bit build

Bug: 18186310

(cherry picked from commit f240aa8089ea1574a7d799720efb66528f6ceb99)

Change-Id: Id46f1f9be90a17a58fb44d3540095c8c685c9726
634a045c5c2ca1df35f582ed24bb3af0dc1d7151 17-Sep-2014 Dmitriy Ivanov <dimitry@google.com> Fix some unused DT_ warnings

* DT_PLTGOT - ignored for non-mips
* DT_RELCOUNT/RELACOUNT - ignored
* DT_RELENT/RELAENT - sanity checks
* DT_SYMENT - sanity check
* DT_SONAME - ignore for now.

Bug: 18186310

(cherry picked from commit 4a6e9a835a84aca965f0170f604381dae7f130be)

Change-Id: Ib40095f0770d65628fc7abac5a471378de35ebe7
b364d9538073716a256b37a790ff7bf3ddbb4f1b 16-Sep-2014 Dmitriy Ivanov <dimitry@google.com> Remove has_DT_SYMBOLIC flag

From the elf-spec: "Symbolically bound shared objects are
identified by the .dynamic entry DT_SYMBOLIC. This tag is
informational only; the runtime linker processes symbol
lookups from these objects in the same manner as any
other object."

Bug: 18186310

(cherry picked from commit 8f61d991831f0ea515fa50a5c38dbbcfbab0dd28)

Change-Id: I37024799ac8d1837993c8ae78780a448bedd6539
c85e82dde5c4b2accc50a9e17740b9005dfbae6a 16-Sep-2014 Dmitriy Ivanov <dimitry@google.com> Fix dlsym() to take into account RTLD_GLOBAL/LOCAL

Symbols from libraries opened with RTLD_LOCAL (default)
should not be visible via dlsym(RLTD_DEFAULT/RTLD_NEXT, .)

Bug: 17512583
Bug: 18186310

(cherry picked from commit e8ba50fe0d51fbefee1a8f5bb62bf51d841512c8)

Change-Id: Idf6bbe2233fb2bfc0c88677e7d1fc518fb3f7a8b
926797a8a92a009184556ed45e02f3292066a296 12-Sep-2014 Dmitriy Ivanov <dimitry@google.com> Reformatting

No functional changes.

Bug: 18186310

(cherry picked from commit 6abf624d122bec8c80cc9fe1b692265bf1b28b1b)]

Change-Id: I0acf52d8ee7fe2d4f44bc832cbe9fabe1782f03f
da8e591c3996879e41dc5f70b77d1b0fe6f9c225 31-Oct-2014 Dmitriy Ivanov <dimitry@google.com> Use local copy of the library name on dlopen

Bug: 18052100
Change-Id: Idbc2a3691db3b5525d4e9bca81d78d5f29bc438f
d225a5e65223b375a63548c4b780f04d8f3d7b60 28-Aug-2014 Dmitriy Ivanov <dimitry@google.com> Fix symbol lookup order during relocation

Relocate symbol against DF_1_GLOBAL shared libraries
loaded before this shared library. This includes
main executable, ld_preloads and other libraries
that have DF_1_GLOBAL flag set.

Bug: 2643900
Bug: 15432753
Change-Id: Ia788748be59b739d1c7e62b978e7e255f9e65c7b
c9d16583972a4d329b91960148172d41ed04ab37 24-Oct-2014 Dmitriy Ivanov <dimitry@google.com> Remove unnecessary reinterpret_cast

Change-Id: Id2ddf4e74bc66825206d1287f899d716537a68d0
90b74fb8671db6f5512821a033e12a6248e5c804 23-Oct-2014 Dmitriy Ivanov <dimitry@google.com> Fix mips build

Change-Id: Ia2dc2e07740bdbb91ee92bfea459230015fcc99b
e47b3f8456fc34ac136e9fddef59a9ae37febcbe 23-Oct-2014 Dmitriy Ivanov <dimitry@google.com> Remove unnecessary lookups during relocations

local_group includes this library and its dependencies.

Change-Id: Ib02474b2355bb147de3889f60092cb2f312997ef
cfa97f172dc1b10d650fefbb6ccffd88ce72a5fb 21-Oct-2014 Dmitriy Ivanov <dimitry@google.com> Fix relocation to look for symbols in local group

The local group is a sequence of libraries in default (breadth-first)
order. It allows RTLD_LOCALLY loaded library to correctly relocate
symbols within its group (see test-cases).

Local group lookup is performed after main executable and ld_preloads.

Bug: 2643900
Bug: 15432753
Change-Id: I9bb013b46d17dbb5cbdfb8fef26f552748385541
702ab5b37e77684ee352300d32b078606ee388d0 21-Oct-2014 Dmitriy Ivanov <dimitry@google.com> Rename library_offset to library_fd_offset

replace lseek() and use pread() instead
add test for library_fd_offset > file_size case

Bug: 17762003

(cherry picked from commit a6c1279098f24a675d0df74ce1946f5d534b425e)

Change-Id: Ie117c745081ee33d07db5341115ff6c8e98b0dec
de01780f46e4e4540c7a1ea7d0302f460c880e9d 04-Oct-2014 Dmitriy Ivanov <dimitry@google.com> Add file_offset parameter to android_extinfo

Bug: 17762003

(cherry picked from commit 07e5bc152d8a3ad4c50808bb86f3c0f2c5e2f514)

Change-Id: I72d527831384ff5dde013a4c8dfe639fbec165f5
a6c1279098f24a675d0df74ce1946f5d534b425e 21-Oct-2014 Dmitriy Ivanov <dimitry@google.com> Rename library_offset to library_fd_offset

replace lseek() and use pread() instead
add test for library_fd_offset > file_size case

Bug: 17762003
Change-Id: I4555f0be635124efe849c1f226985bcba72ffcbd
ea6eae182ad64312f80b9adddac511d8938e23e7 15-Oct-2014 Dmitriy Ivanov <dimitry@google.com> Ignore DT_BIND_NOW (0x18)

Bug: 17552334
Change-Id: Ibe93fd3d6580f369f9a6ef8d235bf0df00fe7607
513e29e16f16a6ffa1636ba282d599fd6b437aeb 06-Oct-2014 Dmitriy Ivanov <dimitry@google.com> Resolve "unused DT entry" warnings for x86_64

Change-Id: I3a2c87bf6e6259313cd9203389623f13b7405ef3
07e5bc152d8a3ad4c50808bb86f3c0f2c5e2f514 04-Oct-2014 Dmitriy Ivanov <dimitry@google.com> Add file_offset parameter to android_extinfo

Bug: 17762003
Change-Id: I8fb267a3155acef3dba534038cf5d1ef00d7154b
04f5f4100cbabc8cf5b57ece0fd490217e1549bd 16-Sep-2014 Ningsheng Jian <ningsheng.jian@arm.com> Fix gdb could not get shared library list issue

Get dynamic flags from phdr table's correct entry rather the first
entry, so that the following DT_DEBUG entry can be set.

Also fix the undefined reference to LoadTask::deleter issue under gcc
-O0 option.

Bug: 17524778

(cherry picked from commit e93be99da0614ff38cbf8b2bb0624ff1dc79b8d0)

Change-Id: I347792dab25c7b19c3fc690e03d20899ce1e26e0
bbf86e6157ab98af7468ce5eb3292b6509a3cabd 02-Oct-2014 Dmitriy Ivanov <dimitry@google.com> Fixes to linker code after the conflict resolution

Change-Id: Icd0728604a865b73e7af0e0aee38971a612935f2
7d971ec14b80cac442aeea8d88e9eb2e3ab6f214 09-Sep-2014 Dmitriy Ivanov <dimitry@google.com> Fix unload of recursively linked library

Expanded test for recursive libs. Fixed bug with unnecessary
soinfo_free of already loaded library.

(cherry picked from commit a6ac54a215d6b64f5cc5a59b66c1dbfbb41ea9f5)

Change-Id: I6907c723d9fbdf6b2777f3f236b1e29b0843edd6
f4cb6313645ef65cc0eea0a439e51b6788cd3439 12-Sep-2014 Dmitriy Ivanov <dimitry@google.com> Add IFUNC support for arm64 and IRELATIVE reloc

There are number of changes in the way IFUNC related relocations are done:
1. IRELATIVE relocations are now supported for x86/x86_64 and arm64.
2. IFUNC relocations are now relying on static linker to generate
them in correct order - this removes necessety of additional
relocation pass for ifuncs.
3. Related to 2: rela?.dyn relocations are preformed before .plt ones.
4. Ifunc are resolved on symbol lookup this approach allowed to avoid
mprotect(PROT_WRITE) call on r-x program segments.

Bug: 17399706
Bug: 17177284

(cherry picked from commit 9aea164457c269c475592da36b4655d45f55c7bc)

Change-Id: Ie19d900fc203beb93faf8943b0d06d534a6de4ad
ef1306d77718cc74a8df5673a15649dea317571d 09-Sep-2014 Dmitriy Ivanov <dimitry@google.com> Refactoring: C++11 style DISABLE_ bionic marcos

Enable the -std=gnu++11 flag for libstdc++ static and
dynamic libs.

ScopeGuard uses DISABLE_ macros instead of '= delete';

(cherry picked from commit d9ff7226613014056c9edd79a68dc5af939107a0)

Change-Id: If2573d080770e18b36b56106f2369f7bb682cd3c
ae69a9584baf8dd6a28065538ca09d1924ebd9e4 06-Sep-2014 Dmitriy Ivanov <dimitry@google.com> Load libraries in breadth-first order

This patch fixes the problem with symbol search order
for dlsym(RTLD_DEFAULT/RTLD_NEXT, .) by loading libraries
and ld_preloads in correct order.

Bug: https://code.google.com/p/android/issues/detail?id=74255
Attempt: 2

(cherry picked from commit 14669a939d113214a4a20b9318fca0992d5453f0)

Change-Id: Id87540c96a2242220967b6fa5d84ddcd829e2b97
c0133a73b6f37b88afc8dafb6f63af03cbb708f6 05-Sep-2014 Dmitriy Ivanov <dimitry@google.com> Revert "Load libraries in breadth-first order"

This reverts commit a3ad450a2e3fb6b3fe359683b247eba20896f646.

(cherry picked from commit 498eb18b82a425f9f30132e4832f327b2ee0e545)

Change-Id: Iec7eab83d0c0ed1604e1e8ea3f9e9d0ce1d29680
8de1ddece0d0b85eafeb86c06cf3a734dadf2b55 05-Sep-2014 Dmitriy Ivanov <dimitry@google.com> Fix order of soinfo links (repairs libcxx tests).

(cherry picked from commit b2a30ee8d209154efc367db11b4167a5d6db605f)

Change-Id: I59c5333bc050cbbea14051cea9220be2f64ee383
59c12a652794273da22907a374222f4fa7d975c6 29-Jul-2014 Dmitriy Ivanov <dimitry@google.com> Load libraries in breadth-first order

This patch fixes the problem with symbol search order
for dlsym(RTLD_DEFAULT/RTLD_NEXT, .) by loading libraries
and ld_preloads in correct order.

Bug: https://code.google.com/p/android/issues/detail?id=74255

(cherry picked from commit a3ad450a2e3fb6b3fe359683b247eba20896f646)

Change-Id: I1125de10272c84e4f075cbc72859c1f6b3e89943
7210c41fdce065a37f29dce7f32880301cce90c2 02-Sep-2014 Dmitriy Ivanov <dimitry@google.com> Encapsulate soinfo_link_image and soinfo_relocate

Also get rid of needed[] array for these functions

(cherry picked from commit 29bbc9dd4c606de9187e46d8899a2a744715c967)

Change-Id: Id208621f66afa2e02a6b3facacee7d874466d81b
ff01f6fcced83b6446136d6ddc9b3a536fab57f7 02-Sep-2014 Dmitriy Ivanov <dimitry@google.com> Introduce size-based r/w allocators

(cherry picked from commit 0cd83ebb0e9784827d9ec0a8028a710e73a28b2b)

Change-Id: Ib037bd5313c9a78b6051482f14e789aa820b4dd1
4d01d08c2935980fbd9de2d7699230db11074453 29-Aug-2014 Dmitriy Ivanov <dimitry@google.com> Erase elements in LinkedList::remove_if

(cherry picked from commit 4bea498544bb1377f610520d7f58856382a6e5fc)

Change-Id: I1ffe248bc2b7572f38fbd987e9c6db5ecbd4559d
cfad7ae9346af5c665a1bc239e1bbe4f679750c6 29-Aug-2014 Dmitriy Ivanov <dimitry@google.com> Replace NULL with nullptr

(cherry picked from commit 851135bf9941b3813adb9b4f43d76e040c4ba157)

Change-Id: Ic4997907680db7472ef38ffb0f0ca66fff37b797
5dfe802d0dedbfce355a7ece5bc77c7346941bb2 27-Aug-2014 Dmitriy Ivanov <dimitry@google.com> Remove unnecessary calls to LinkedList::clear()

(cherry picked from commit 608217e1674d8fd8b334fe18c753b6c4638ed783)

Change-Id: I031359d79b2e77977ace197ef410e41539dc0ce6
93c3f4203c92ece8b97d770af9b675f5ffb90c67 26-Aug-2014 Dmitriy Ivanov <dimitry@google.com> Enable __cxa_atexit && __cxa_finalize for linker

This allows adding destructors to classes used
for global variables.

(cherry picked from commit 14241402de0faa4b244b1bd6b1f0799ce169b880)

Change-Id: I1d8776130d1e01a8c53d23a2949f5010f4c96b16
3bbd218ef1a70e59662e704c59af6dff1f9d1253 22-Aug-2014 Dmitriy Ivanov <dimitry@google.com> Bump soinfo version

This includes:
1. Placing has_ifunc after fields with version = 0
2. Switch to has_min_version(v) function.
3. Minor soinfo initialization refactoring (placement new + ctor)

(cherry picked from commit 0d15094287fe0f288d9c258953143fc1998b6b5a)

Change-Id: Idf135fdd3d4826b5653f32add2adc6db5d4a4f95
bd321c1106ed30a71d55d5c365335dfe552b0883 21-Aug-2014 Dmitriy Ivanov <dimitry@google.com> Run constructors before resolving ifunc functions

Bug: 17177284

(cherry picked from commit 9598b8c415e2fa9f240508185fe8c964b83f538d)

Change-Id: I2c9631ee1cd77f8cf95ec0216a35b605c8786454
31b88da8431096a6df276705046ca7a012fa3530 23-Jul-2014 Brigid Smith <brigidsmith@google.com> Added test for ifunc support in dynamic linker.

ifuncs now work in i386 and x86_64 when called in the same library as
well as in a different library.

Bug:6657325
(cherry picked from commit c5a13efa9bc4264be0a9a9e37c00633af01584ed)

Change-Id: I321d780bc2f9bd1baa749e1acacd2683aefe827b
1b20dafdbe65e43b9f4c95057e8482380833ea91 20-May-2014 Dmitriy Ivanov <dimitry@google.com> Add RTLD_NODELETE flag support

Bug: https://code.google.com/p/android/issues/detail?id=64069
Change-Id: Ie5f90482feae86391172be4b32d6cb7d76f446fb
ecf532fa1cfe91ca946243c11ef154c602870ba6 01-Oct-2014 Dmitriy Ivanov <dimitry@google.com> Fix mips build

Change-Id: I4454e69a982f239b168678c5a681d1078b4bd4f1
6cdeb5234d7f4523fe9d83974f265d80f10512a6 30-Sep-2014 Dmitriy Ivanov <dimitry@google.com> Fix unused DT entry warnings.

DT_STRSZ Implement strtab boundary checks
DT_FLAGS_1 Warn if flags other than DF_1_NOW|DF_1_GLOBAL are set

Bug: 17552334
Change-Id: Iaad29cd52f5b2d7d2f785fb351697906dc1617d9
96bc37f2e1093416a432135265fd7a4db6c3df17 29-Sep-2014 Dmitriy Ivanov <dimitry@google.com> Return has_DT_SYMBOLIC flag.

This reverts commit 8f61d991831f0ea515fa50a5c38dbbcfbab0dd28

Despite the fact that static linker does all the work while linking
-Bsymbolic executables, according to the SCO doc following DT_SYMBOLIC
and DF_SYMBOLIC flags is still a requirement for the dynamic linker
as well.

(see http://www.sco.com/developers/gabi/2012-12-31/ch5.dynamic.html)

Change-Id: I23f6a5e9b662e40cdbc462b64feff912431e800c
e93be99da0614ff38cbf8b2bb0624ff1dc79b8d0 16-Sep-2014 Ningsheng Jian <ningsheng.jian@arm.com> Fix gdb could not get shared library list issue

Get dynamic flags from phdr table's correct entry rather the first
entry, so that the following DT_DEBUG entry can be set.

Also fix the undefined reference to LoadTask::deleter issue under gcc
-O0 option.

Bug: 17524778
Change-Id: I9c679af197b034761fb739d6c980e628ff2ab84c
1b77423eff21e916186fcb208f138e436e9f3052 18-Sep-2014 Dmitriy Ivanov <dimitry@google.com> Temporary disable DL_WARNs for unused DT_*

Bug: 17552334
Change-Id: I2f7b5e4b4d1db96e812a7f86adc929e113d4c11a
f240aa8089ea1574a7d799720efb66528f6ceb99 17-Sep-2014 Dmitriy Ivanov <dimitry@google.com> Fix 64bit build

Change-Id: I6ef55b5951270c46ee5e9a11385bd09e33a9f969
4a6e9a835a84aca965f0170f604381dae7f130be 17-Sep-2014 Dmitriy Ivanov <dimitry@google.com> Fix some unused DT_ warnings

* DT_PLTGOT - ignored for non-mips
* DT_RELCOUNT/RELACOUNT - ignored
* DT_RELENT/RELAENT - sanity checks
* DT_SYMENT - sanity check
* DT_SONAME - ignore for now.

Change-Id: Ied90748d12f733a84f6c38a1250567a2f77608b7
8f61d991831f0ea515fa50a5c38dbbcfbab0dd28 16-Sep-2014 Dmitriy Ivanov <dimitry@google.com> Remove has_DT_SYMBOLIC flag

From the elf-spec: "Symbolically bound shared objects are
identified by the .dynamic entry DT_SYMBOLIC. This tag is
informational only; the runtime linker processes symbol
lookups from these objects in the same manner as any
other object."

Change-Id: I4aae0e502ed9fac096fbf076f4d6b2e055d784f6
e8ba50fe0d51fbefee1a8f5bb62bf51d841512c8 16-Sep-2014 Dmitriy Ivanov <dimitry@google.com> Fix dlsym() to take into account RTLD_GLOBAL/LOCAL

Symbols from libraries opened with RTLD_LOCAL (default)
should not be visible via dlsym(RLTD_DEFAULT/RTLD_NEXT, .)

Bug: 17512583
Change-Id: I1758943081a67cf3d49ba5808e061b8251a91964
6abf624d122bec8c80cc9fe1b692265bf1b28b1b 12-Sep-2014 Dmitriy Ivanov <dimitry@google.com> Reformatting

No functional changes.

Change-Id: If71775e5fc207e91ebd31ba3c5f9d2c13dc8dada
a6ac54a215d6b64f5cc5a59b66c1dbfbb41ea9f5 09-Sep-2014 Dmitriy Ivanov <dimitry@google.com> Fix unload of recursively linked library

Expanded test for recursive libs. Fixed bug with unnecessary
soinfo_free of already loaded library.

Change-Id: I2cc19f2650c8b12a35feeac127ef608ebba44d88
9aea164457c269c475592da36b4655d45f55c7bc 12-Sep-2014 Dmitriy Ivanov <dimitry@google.com> Add IFUNC support for arm64 and IRELATIVE reloc

There are number of changes in the way IFUNC related relocations are done:
1. IRELATIVE relocations are now supported for x86/x86_64 and arm64.
2. IFUNC relocations are now relying on static linker to generate
them in correct order - this removes necessety of additional
relocation pass for ifuncs.
3. Related to 2: rela?.dyn relocations are preformed before .plt ones.
4. Ifunc are resolved on symbol lookup this approach allowed to avoid
mprotect(PROT_WRITE) call on r-x program segments.

Bug: 17399706
Bug: 17177284
Change-Id: I414dd3e82bd47cc03442c5dfc7c279949aec51ed
d9ff7226613014056c9edd79a68dc5af939107a0 09-Sep-2014 Dmitriy Ivanov <dimitry@google.com> Refactoring: C++11 style DISABLE_ bionic marcos

Enable the -std=gnu++11 flag for libstdc++ static and
dynamic libs.

ScopeGuard uses DISABLE_ macros instead of '= delete';

Change-Id: I07e21b306f95fffd49345f7fa136cfdac61e0225
14669a939d113214a4a20b9318fca0992d5453f0 06-Sep-2014 Dmitriy Ivanov <dimitry@google.com> Load libraries in breadth-first order

This patch fixes the problem with symbol search order
for dlsym(RTLD_DEFAULT/RTLD_NEXT, .) by loading libraries
and ld_preloads in correct order.

Bug: https://code.google.com/p/android/issues/detail?id=74255
Change-Id: If1ba5c807322409faa914e27ecb675e2c4541f0d
Attempt: 2
498eb18b82a425f9f30132e4832f327b2ee0e545 05-Sep-2014 Dmitriy Ivanov <dimitry@google.com> Revert "Load libraries in breadth-first order"

This reverts commit a3ad450a2e3fb6b3fe359683b247eba20896f646.

Change-Id: Ia2b838ad2159c643b80c514849582f4b4f4f40e5
b2a30ee8d209154efc367db11b4167a5d6db605f 05-Sep-2014 Dmitriy Ivanov <dimitry@google.com> Fix order of soinfo links (repairs libcxx tests).

Change-Id: Iee9de09657351cd6a7512784ca797e4b84cdd98b
a3ad450a2e3fb6b3fe359683b247eba20896f646 29-Jul-2014 Dmitriy Ivanov <dimitry@google.com> Load libraries in breadth-first order

This patch fixes the problem with symbol search order
for dlsym(RTLD_DEFAULT/RTLD_NEXT, .) by loading libraries
and ld_preloads in correct order.

Bug: https://code.google.com/p/android/issues/detail?id=74255
Change-Id: I4cf84c70dbaabe99310230dfda12385ae5401859
29bbc9dd4c606de9187e46d8899a2a744715c967 02-Sep-2014 Dmitriy Ivanov <dimitry@google.com> Encapsulate soinfo_link_image and soinfo_relocate

Also get rid of needed[] array for these functions

Change-Id: I8d12887dbec0724309bb171e6bbd9b9ceb32cc70
0cd83ebb0e9784827d9ec0a8028a710e73a28b2b 02-Sep-2014 Dmitriy Ivanov <dimitry@google.com> Introduce size-based r/w allocators

Change-Id: I75165fc392e5380124039e6db49b0f559c8a518e
c2048944ff8d9f2993264b45dfabf18d9036e379 29-Aug-2014 Dmitriy Ivanov <dimitry@google.com> Look into ld_preloads before current library

Change lookup order during relocation so that
ld_preloads always precede caller (unless caller
is main executable).

Asan needs this change in order to intercept libc->libc
calls.

Bug: 15432753
(cherry picked from commit 05e190c093ad5b04691ed87100a711ef91f380b0)

Change-Id: I5bfb58e18015b1ec5b77842dbb37fb122fa1fd1a
4bea498544bb1377f610520d7f58856382a6e5fc 29-Aug-2014 Dmitriy Ivanov <dimitry@google.com> Erase elements in LinkedList::remove_if

Change-Id: I5119a78c73ffe780a81c53ab5ff0266d5c82d319
851135bf9941b3813adb9b4f43d76e040c4ba157 29-Aug-2014 Dmitriy Ivanov <dimitry@google.com> Replace NULL with nullptr

Change-Id: Iad50be617d318ca98883b843229c960ad5b9afa9
05e190c093ad5b04691ed87100a711ef91f380b0 29-Aug-2014 Dmitriy Ivanov <dimitry@google.com> Look into ld_preloads before current library

Change lookup order during relocation so that
ld_preloads always precede caller (unless caller
is main executable).

Asan needs this change in order to intercept libc->libc
calls.

Bug: 15432753
Change-Id: If69aa16efe59aa35bb30e96feb83d08f1efbec86
052fa3a34c07b9b361c30565f029dd543da14e30 27-Aug-2014 Christopher Ferris <cferris@google.com> Replace snprintf calls in linker.

When enabling debug malloc, the snprintf calls in the linker fails to
update the buffer.

The problem is that snprintf makes a call to pthread_getspecific that
returns a valid pointer, but the data it points to is zero. This should
never happen and causes the snprintf to stop and do nothing.

Temporarily replace snprintf with a different implementation to work
around this issue.

Bug: 16874447
Bug: 17302493

(cherry pick from commit 172955a4e30b88ce8239a7ef426b4e8903e9923c)

Change-Id: Idca9d417978403d61debfd0434aaa82fd770f33b
172955a4e30b88ce8239a7ef426b4e8903e9923c 27-Aug-2014 Christopher Ferris <cferris@google.com> Replace snprintf calls in linker.

When enabling debug malloc, the snprintf calls in the linker fails to
update the buffer.

The problem is that snprintf makes a call to pthread_getspecific that
returns a valid pointer, but the data it points to is zero. This should
never happen and causes the snprintf to stop and do nothing.

Temporarily replace snprintf with a different implementation to work
around this issue.

Bug: 16874447
Bug: 17302493
Change-Id: I7a500f28adf153150cf2812fae745ff41f1c48d3
608217e1674d8fd8b334fe18c753b6c4638ed783 27-Aug-2014 Dmitriy Ivanov <dimitry@google.com> Remove unnecessary calls to LinkedList::clear()

Change-Id: I981d2700cb17322c634b751715543fd33ee49b7c
14241402de0faa4b244b1bd6b1f0799ce169b880 26-Aug-2014 Dmitriy Ivanov <dimitry@google.com> Enable __cxa_atexit && __cxa_finalize for linker

This allows adding destructors to classes used
for global variables.

Change-Id: I5e1cd63fe3bf8f66de88cc4f7437cafb350f49b5
0d15094287fe0f288d9c258953143fc1998b6b5a 22-Aug-2014 Dmitriy Ivanov <dimitry@google.com> Bump soinfo version

This includes:
1. Placing has_ifunc after fields with version = 0
2. Switch to has_min_version(v) function.
3. Minor soinfo initialization refactoring (placement new + ctor)

Change-Id: I1bf5fde4d930914012ce5f3ad5acb48217da9b2d
9598b8c415e2fa9f240508185fe8c964b83f538d 21-Aug-2014 Dmitriy Ivanov <dimitry@google.com> Run constructors before resolving ifunc functions

Bug: 17177284
Change-Id: I5714b9bc2d1ca8f8711806bfb68da3d524213e99
02aa70589d22fa9b65da43de705d6de2715870c6 19-Aug-2014 Dmitriy Ivanov <dimitry@google.com> Revert "Add support for protected local symbol lookup."

This reverts commit d97e9f546ea195686a78e539315b273393609b9e.

Bug: 17107521
(cherry picked from commit 9419420919ea846bbad5510850c7aaec95021648)

Change-Id: I1a6df946ac8075699e77d68ffa6ac4a21b88e4bf
9419420919ea846bbad5510850c7aaec95021648 19-Aug-2014 Dmitriy Ivanov <dimitry@google.com> Revert "Add support for protected local symbol lookup."

This reverts commit d97e9f546ea195686a78e539315b273393609b9e.

Bug: 17107521
Change-Id: I2b81ce2b5a4a2d166133a2626e49d81b6aef3672
8a84d383fb74135e928d341baa180c55854f2f42 13-Aug-2014 Dmitriy Ivanov <dimitry@google.com> Optimize symbol lookup

Do not run symbol lookup on already visited soinfos
Not taking into account already visited libraries
dramatically slows down dlsym in cases when there
are multiple occurrences of a large library in
dependency tree.

Bug: 16977077

(cherry picked from commit 042426ba6375f5c145379e598486ec6d675533c9)

Change-Id: I69d59e395e8112f119343e8a4d72fe31cd449f31
042426ba6375f5c145379e598486ec6d675533c9 13-Aug-2014 Dmitriy Ivanov <dimitry@google.com> Optimize symbol lookup

Do not run symbol lookup on already visited soinfos
Not taking into account already visited libraries
dramatically slows down dlsym in cases when there
are multiple occurrences of a large library in
dependency tree.

Bug: 16977077
Change-Id: I1379f30ed8b06758dd1cc76b80833ac8589afa50
c5a13efa9bc4264be0a9a9e37c00633af01584ed 23-Jul-2014 Brigid Smith <brigidsmith@google.com> Added test for ifunc support in dynamic linker.

ifuncs now work in i386 and x86_64 when called in the same library as
well as in a different library.

Bug:6657325
Change-Id: Ic0c48b1b0a76cb90f36c20c79f68294cc3fd44a1
db7a17d4ff56a05af01ee2fee1f3c55245bfc630 05-Aug-2014 Dmitriy Ivanov <dimitry@google.com> Revert "Revert "Fix dlsym(3) to do breadth first search.""

This reverts commit 1b1966d9448e979d1503a3d8843708bfa8880dc6.

Change-Id: I05d6d3481aaf8f3e260d2e5e950248519a1d347f
1b1966d9448e979d1503a3d8843708bfa8880dc6 04-Aug-2014 Dmitriy Ivanov <dimitry@google.com> Revert "Fix dlsym(3) to do breadth first search."

This reverts commit 422106a24d620af4be58e8d92a2e9b7b6167b72d.

Change-Id: I9e26a6933d10eb30438b521450f2010997ca5aee
422106a24d620af4be58e8d92a2e9b7b6167b72d 29-Jul-2014 Dmitriy Ivanov <dimitry@google.com> Fix dlsym(3) to do breadth first search.

dlsym(3) with handle != RTLD_DEFAULT|RTLD_NEXT performs
breadth first search through the dependency tree.

Bug: 16653281

(cherry picked from commit aa0f2bdbc22d4b7aec5d3f8f5f01eaeaa13414c2)

Change-Id: I0ba8c2034ab341f8a279cdb4e2e7e47f1aef7897
aa0f2bdbc22d4b7aec5d3f8f5f01eaeaa13414c2 29-Jul-2014 Dmitriy Ivanov <dimitry@google.com> Fix dlsym(3) to do breadth first search.

dlsym(3) with handle != RTLD_DEFAULT|RTLD_NEXT performs
breadth first search through the dependency tree.

Bug: 16653281
Change-Id: I017a6975d1a62abb0218a7eb59ae4deba458e324
5febb0da6f6d7106c403e6809917d89d6ee081ad 29-Jul-2014 Dmitriy Ivanov <dimitry@google.com> Fix 'adb shell /system/bin/linker' crash

Bug: https://code.google.com/p/android/issues/detail?id=63174

(cherry picked from commit efe13832dccf2cec2898b89ca4418a6aac29d3eb)

Change-Id: I43629e4a14870f67abc2dd5ff2e3040c47b2168d
65549969488bbce7f5d1b57714ba32c466943470 25-Jul-2014 Dmitriy Ivanov <dimitry@google.com> Fix global variable initialization for linker

Linker now calls init functions for itself.

(cherry picked from commit 4151ea73b75e274d1ff80b42d9d457a783208516)

Change-Id: I3300fe22de8ad8466a5b1c2d551429769a42852d
4151ea73b75e274d1ff80b42d9d457a783208516 25-Jul-2014 Dmitriy Ivanov <dimitry@google.com> Fix global variable initialization for linker

Linker now calls init functions for itself.

Change-Id: Ibd099812493041ac70f591e3f379ee742b4683b8
efe13832dccf2cec2898b89ca4418a6aac29d3eb 29-Jul-2014 Dmitriy Ivanov <dimitry@google.com> Fix 'adb shell /system/bin/linker' crash

Bug: https://code.google.com/p/android/issues/detail?id=63174
Change-Id: I072290ea11109c07f277ad3dec7f44fcb7bf6aa6
3a8646fc5d9f1a9304251a1d1c8ff9e523d81b40 08-Jul-2014 Dmitriy Ivanov <dimitry@google.com> Change android_dlextinfo flags to uint64_t

Change-Id: Id27e8f8e58dbcf6ae79644f2ad3af3dd0aef9ae7
d38306694179962f2d784fd1828afd4af1d8a4ec 03-Jul-2014 Dmitriy Ivanov <dimitry@google.com> Build fix

Change-Id: Ib43e0f055e3c5f07b50393bfcab9738454835ac3
76e289c026f11126fc88841b3019fd5bb419bb67 03-Jul-2014 Nick Kralevich <nnk@google.com> Revert "Reenable support for non-PIE executables"

/system/bin/tf_daemon on Nakasi has been updated so it's
a PIE executable. We can now drop non-PIE support.

This reverts commit d81b3b275dff99561cbe5905ca63a1c72fa54a17.

Bug: 15086752
Bug: 15732002
Bug: 14566672
Change-Id: I832c4de01a8fa050754ea64da317d1639990265e
04dc91ae763adc403a14c88b4c46f77b3d2d71a3 01-Jul-2014 Dmitriy Ivanov <dimitry@google.com> Load library using file handle.

* This patch enables dlopen by file descriptor
instead of path/name.

Bug: 15984217
Change-Id: Ib39051e00567fb97070bf96d8ce63993877c0a01
12bf3bcdeeaa0dcdc7a4f4e4d11bc2fc3bf6bd7a 01-Jul-2014 Dmitriy Ivanov <dimitry@google.com> Write message to stderr on __libc_fatal()

Change-Id: Ia8d6e256768fa51786d0139d3f3b6e9e4bebe027
d97e9f546ea195686a78e539315b273393609b9e 29-Jun-2014 Dmitriy Ivanov <dimitry@google.com> Add support for protected local symbol lookup.

Bug: http://code.google.com/p/android/issues/detail?id=66048
Change-Id: Ib334223df27adad9477fb241ab099c5e26df4a7d
e43c4a7a665032a29cb5ec15d4adbf81ea199220 29-Jun-2014 Dmitriy Ivanov <dimitry@google.com> Disallow dlopen("egl/blah.so") on LP64

Bug: 7465467
Change-Id: Ibd3a4f1a6095f4397bde4f656e3c11b67f7edd47
aa836f731016f7f1099d6a6ce47a35f1ec17dd4e 30-Jun-2014 Elliott Hughes <enh@google.com> Reinstate the x86 dynamic linker warning for text relocations.

Bug: 11358761
Change-Id: I4fc56ce7d76c9703a307ddd4d371d5e98bc6f51d
d81b3b275dff99561cbe5905ca63a1c72fa54a17 19-Jun-2014 Nick Kralevich <nnk@google.com> Reenable support for non-PIE executables

On Nakasi builds, /system/bin/tf_daemon is a pre-compiled
vendor supplied binary. When support for non-PIE executables
was removed, that daemon failed to start, which induced
a number of bugs.

* keystore is broken
* CTS runs will hang after a certain period of time

Temporarily reenable non-PIE support for 32-bit platforms
until Nakasi is fixed.

This rolls back the following commits:

Cleanup: updated comments
* 6275f2083415d22a6ce0de55645079cd47e0cc80
Cleanup: remove AARCH/ARM_COPY relocation support
* b906e13c55c9fe9b4157ba548534a0230434882b

And restricts the following patch to 64 bit only:

Remove support for non-PIE executables
* 2aebf5429bb1241a3298b5b642d38f73124c2026

Bug: 14566672
Bug: 15086752
Bug: 15732002
Change-Id: Ia2501aa14bd30feb4a6ce66bdb7c9f066dba0b5f
1a586293400d0e1d73e6eb82f7dfe9d2d9ed3c4b 04-Jun-2014 Elliott Hughes <enh@google.com> Remove an unused parameter from the dlopen implementation.

Change-Id: I9297913a743bb570b48ebbe594ff711a481e89e0
d286796fce1e6fff407b719a53eb2afbeb96c327 04-Jun-2014 Elliott Hughes <enh@google.com> Turn on -Wunused and fix the mistakes it uncovers.

Change-Id: I023d2d8b547fbc21d4124bb7510d42b06a0dc501
3c005d60194aadd92584258118c06782c9deab11 23-May-2014 Bjorn Andersson <bjorn.andersson@sonymobile.com> Do not add arcs to the soinfo graph on dlopen

While introducing RTLD_NOLOAD in b648a8a5 a change in how soinfo structs are
connected was also introduced. When calling dlopen the library that is loaded
is added as a child to the soinfo from which the caller comes - i.e. building a
dependency graph.

Unfortunately this shows issues upon unloading, such as blowing the stack if
there are loops in the graph.

This change reverts that part of b648a8a5, keeping everything as a child of the
root soinfo.

Change-Id: I604ee9210613b19f693a568158e69707620a95db
Signed-off-by: Bjorn Andersson <bjorn.andersson@sonymobile.com>
2ea60ff0b415ad5b135f498a38c4b56ea75215aa 22-May-2014 Elliott Hughes <enh@google.com> Remove unnecessary #includes of <sys/atomics.h>.

Bug: 14903517
Change-Id: I7b5bcebe58774a441da986cc02376dd88e00ea0e
b648a8a57ee42533a5bf127225a252f73ca2cbbc 20-May-2014 Dmitriy Ivanov <dimitry@google.com> Add RTLD_NOLOAD support and some related changes.

* Aligned RTLD_ values with glibc for lp64
* dlopen supports RTLD_NOLOAD flag
* soinfo_unload calls find_library(.., RTLD_NOLOAD)
instead of naive find_loaded_library_by_name()
* dlopen changed to add child to caller soinfo instead
of somain.

Bug: https://code.google.com/p/android/issues/detail?id=64069
Change-Id: I1a65f2c34f3e0edc6d2c41a2e408b58195feb640
bb5bb2046fa0759d94995cbfb4f41137cd0b2a91 16-May-2014 Pavel Chupin <pavel.v.chupin@intel.com> Add R_X86_64_64 to the list of possible weak relocs

Change-Id: I768a5948d89701a1719734954a3524d3c7187e6a
Signed-off-by: Pavel Chupin <pavel.v.chupin@intel.com>
489e498434f53269c44e3c13039eb630e86e1fd9 20-May-2014 Dmitriy Ivanov <dimitry@google.com> Fix lookup-by-base-name for lp64

Bug:https://code.google.com/p/android/issues/detail?id=6670
Change-Id: I5b70e7cde7f40799148aca0a91fb2bb08e0f2b54
d59e50063ad708509f3ad83350be33f5612c4f54 09-May-2014 Dmitriy Ivanov <dimitry@google.com> Improve detection of already loaded libraries

Linker is now able to resolve symlinked libraries correctly.

soinfo is extended to save the graph of dependencies during
load/unload. Dependencies are used only in CallConstructor.

Bug: 9741592
Change-Id: Id9c48a74c46aa89bcdf3d54ec2f8ba3d398130b1
1728b2396591853345507a063ed6075dfd251706 14-May-2014 Elliott Hughes <enh@google.com> Switch to g_ for globals.

That's what the Google style guide recommends, and we're starting
to get a mix.

Change-Id: Ib0c53a890bb5deed5c679e887541a715faea91fc
d597d263bc32422402d4810ce4ec070f0227c2f7 06-May-2014 Dmitriy Ivanov <dimitry@google.com> Refactor linker allocator

Makes it reusable for different fixed sized and not very
big structures (<PAGE_SIZE).

Change-Id: Id5ec13fc6541b1935ef7fe3671c22b98685abbae
6275f2083415d22a6ce0de55645079cd47e0cc80 12-May-2014 Dmitriy Ivanov <dimitry@google.com> Cleanup: updated comments

Bug: 14566672
Change-Id: I49ad28e3914b7d559db1e98542fee919db768f49
b906e13c55c9fe9b4157ba548534a0230434882b 12-May-2014 Dmitriy Ivanov <dimitry@google.com> Cleanup: remove AARCH/ARM_COPY relocation support

They are only legal for ET_EXEC binaries and these are no
longer supported.

Bug: 14566672
Change-Id: I99e0ff47e8c572db474bc5e52df870a72269abb3
2aebf5429bb1241a3298b5b642d38f73124c2026 07-May-2014 Nick Kralevich <nnk@google.com> Remove support for non-PIE executables

Don't support the dynamic linker loading ET_EXEC executables. Only
support ET_DYN executables.

Bug: 14566672
Change-Id: Ia1f2bfffe7ea867c1cd62e67d7fd637c60c0728d
5ca7ed9005ea16733d7c87d7154473b7a500be0c 03-May-2014 Dmitriy Ivanov <dimitry@google.com> Disallow dlopen("egl/blah.so") on LP64

Change-Id: I9a563a9dada6522129b1890bc1292667230e80a5
0dcf06f976670b5d05286b184d150f61b71c1184 22-Apr-2014 Torne (Richard Coles) <torne@google.com> Fix arm64/x86 build.

Add missing second param to soinfo_link_image in a section that's not
compiled on ARM.

Bug: 13005501
Change-Id: Id0ede8e03da4e05b25c0aeb24a840f868031d4e8
865119efd47ae3cae5a0c09c6a9cc184a10614c1 18-Apr-2014 Du Chenyang <chenyang.du@intel.com> Temporarily disable text relocation warnings for x86 libraries

Too many such warnings will cause CTS failed. This issue still exists
in some x86 version libraries: libdvm.so/libart.so.

$scanelf -qT out/target/product/generic_x86/system/lib/libdvm.so
libdvm.so: (memory/data?) [0x2BAC7] in (optimized out: previous dvmAsmInstructionStartCode) [0x2B2F8]
libdvm.so: (memory/data?) [0x2BB98] in (optimized out: previous dvmAsmInstructionStartCode) [0x2B2F8]
libdvm.so: (memory/data?) [0x2EB28] in (optimized out: previous dvmAsmInstructionStartCode) [0x2B2F8]
libdvm.so: (memory/data?) [0x2EF87] in (optimized out: previous dvmAsmInstructionEndCode) [0x2EF63]
libdvm.so: (memory/data?) [0x2EFAF] in (optimized out: previous dvmAsmInstructionEndCode) [0x2EF63]
libdvm.so: (memory/data?) [0x2EFD7] in (optimized out: previous dvmAsmInstructionEndCode) [0x2EF63]
libdvm.so: (memory/data?) [0x2EFFF] in (optimized out: previous dvmAsmInstructionEndCode) [0x2EF63]
libdvm.so: (memory/data?) [0x2F027] in (optimized out: previous dvmAsmInstructionEndCode) [0x2EF63]

Bug: https://code.google.com/p/android/issues/detail?id=68431
Change-Id: I11ecac282f1163e49a82156fce2a76cc2d619960
183ad9df536ab04ef35a397a1f4724e4e401d11f 27-Feb-2014 Torne (Richard Coles) <torne@google.com> Allow sharing the RELRO section via a file.

Add flags and a file descriptor to android_dlopen_ext() to allow writing
the RELRO section of the loaded library to a file after relocation
processing, and to allow mapping identical pages from the file over the
top of relocated memory in another process. Explicitly comparing the
pages is required in case a page contains a reference to a symbol
defined in another library loaded at a random base address.

Bug: 13005501
Change-Id: Ibb5b2d384edfaa5acf3e97a5f8b6115c10497a1e
12bbb9164578b6512b8b07a3fb093858244b7c7b 06-Feb-2014 Torne (Richard Coles) <torne@google.com> Support loading libraries to a reserved address.

Add flags and parameters to android_dlopen_ext() to allow loading a
library at an already-reserved fixed address. If the library to be
loaded will not fit within the space reserved, then the linker will
either fail, or allocate its own address space as usual, according to
which flag has been specified. This behaviour only applies to the
specific library requested; any other libraries loaded as dependencies
will be loaded in the normal fashion.

There is a new gtest included to cover the functionality added.

Bug: 13005501
Change-Id: I5d1810375b20fc51ba6a9b3191a25f9792c687f1
012cb4583a5f8564059142bb1900ea3a31e7cfa9 06-Feb-2014 Torne (Richard Coles) <torne@google.com> Add android_dlopen_ext() interface to linker.

Add a function "android_dlopen_ext()", defined in <android/dlext.h>.
This is an extended version of dlopen() which takes a struct for passing
additional parameters for Android-specific functionality. This will be
used to support RELRO section sharing between separate processes.

Bug: 13005501
Change-Id: I9c99b2f2a02ee329dedaeba09ef3a1113b17b2d6
812fd4263a005b88f3b4222baa910114f938d594 25-Mar-2014 Kito Cheng <kito@0xlab.org> Use __unused instead of UNUSED in linker.cpp

- sys/cdefs.h already define __unused, just use it
instead of define a local one.

Change-Id: Iacf3da9193e65e1f34b12760b28bcb64b67cb790
006f9ad8910c945cd50e54f6c34d8c27b11c1193 19-Feb-2014 Benjamin Adolphi <b.adolphi@gmail.com> Linker writes to wrong memory location when processing DT_MIPS_RLD_MAP

When bionic's dynamic linker processes the .dynamic section of a MIPS ELF binary and encounters the DT_MIPS_RLD_MAP dynamic array tag, it calculates the address of where to write a pointer to the _r_debug structure. The current implementation simply reads the value given in the d_ptr field and writes the pointer address to that location. However, this value has to be adjusted to reflect the real load address of the binary. Otherwise the linker will write to a faulty location possibly resulting in a crash when linking a MIPS binary that includes DT_MIPS_RLD_MAP. This change corrects that problem.

Change-Id: I1a91874f7ab47289001fe72d9016660c14c70362
Signed-off-by: Benjamin Adolphi <b.adolphi@gmail.com>
c62b8a4d3f73b070099d9aa594a261b5250d6cc9 13-Feb-2014 Elliott Hughes <enh@google.com> Remove unused variables not spotted by GCC.

Change-Id: I49a16096bc0f41f3ad0007249161e8bdfcf3438c
faf05bacd45719291b371f24b1b89543881b37f6 12-Feb-2014 Elliott Hughes <enh@google.com> Clean up all the lint cpplint can find in the dynamic linker.

Change-Id: Ic9ee7153817c22a252cc4b309283e355b623cab9
9918665a45095ad135576f005c0e5307feb366a1 07-Feb-2014 Chris Dearman <chris.dearman@imgtec.com> [MIPS64] Dynamic linker

Change-Id: I937c7c776cae3d66e214798d5217a922cd106bfc
Signed-off-by: Chris Dearman <chris.dearman@imgtec.com>
Signed-off-by: Duane Sand <duane.sand@imgtec.com>
0266ae5f884d72da58f33a072e865ba131234a5e 11-Feb-2014 Elliott Hughes <enh@google.com> Switch <elf.h> over to linux uapi under the covers.

Remove the linker's reliance on BSD cruft and use the glibc-style
ElfW macro. (Other code too, but the linker contains the majority
of the code that needs to work for Elf32 and Elf64.)

All platforms need dl_iterate_phdr_static, so it doesn't make sense
to have that part of the per-architecture configuration.

Bug: 12476126
Change-Id: I1d7f918f1303a392794a6cd8b3512ff56bd6e487
3a9c5d66dc8d41272f51482b713717af7049697e 10-Feb-2014 Elliott Hughes <enh@google.com> Fix <link.h>.

Also move some of the stuff that should be in <link.h> out of the
private "linker.h", to make it clearer that these are public API
known to gdb that we can't change.

Bug: 12554197
Change-Id: I830e1260d3d8b833ed99bc1518f1c6b6102be8af
5ceb889ac9a36e74e4e00c34c57cbb58d73e228c 03-Dec-2013 Weiwu Chen <weiwu.chen@intel.com> bionic: Change the type of soinfo's size to size_t

Some system functions like munmap expect soinfo's size to be size_t, but currently
it is unsigned. Change it to size_t to fit 64bit's portability.

Change-Id: I0bf6d522b38b0cd9bf1db05b004b5326217412a2
Signed-off-by: Weiwu Chen <weiwu.chen@intel.com>
Signed-off-by: Qiming Shi <qiming.shi@intel.com>
a4aafd156068ee174012f28cd894dbecf0e4ab90 14-Jan-2014 Elliott Hughes <enh@google.com> Make it possible for code to query the dynamic linker's default search path.

We're not going to have init(1) set LD_LIBRARY_PATH globally on 64-bit.
This patch makes it possible for libnativehelper to set LD_LIBRARY_PATH
in each Java VM (to support System.loadLibrary) without also hard-coding
the default search path there.

Change-Id: If13961fae976e06dd80d5ef522f31e8b7eb01154
b93702a0463fa0b87bf25d7ae9bdb09a35ea6a50 22-Dec-2013 Elliott Hughes <enh@google.com> Improve dynamic linker diagnostics for internal errors.

If the linker can't resolve its own internal references to symbols,
we currently exit silently (albeit with EXIT_FAILURE). Not very helpful.

Change-Id: I1614fc970dee4560b38832ede1987b65a8e53a1e
e365f9d6543bc6607864ef61257505239dde15d1 10-Oct-2013 Marcus Oakland <marcus.oakland@arm.com> AArch64: Linker64 support for AArch64

Addition of support for AArch64 in the linker64 target.

Change-Id: I8dfd9711278f6706063e91f626b6007ea7a3dd6e
Signed-off-by: Marcus Oakland <marcus.oakland@arm.com>
5407eed84b98056a5af7d95007d8d511ebad60e4 09-Dec-2013 Pavel Chupin <pavel.v.chupin@intel.com> Fix debugging issues in vdso handling

Under valgrind ehdr_vdso is null and causing segfault.
Adding debug info for vdso producing plenty of issues on debugging
through gdbserver, removing it. It doesn't seem it should be here.

Unwinding through vdso test still works.

Change-Id: I1a7e233c493f2268d725fa8d7279822d07decc49
Signed-off-by: Pavel Chupin <pavel.v.chupin@intel.com>
ebd506c69e12b6dcaf5be94cc8ed1b53af299f9f 31-Oct-2013 Sergey Melnikov <sergey.melnikov@intel.com> Fix linker crashes during unknown symbol lookup

Integration of kernel VDSO into internal bionic data structures using
common functions.
Fix for dl_iterate_phdr function: the function provides incorrect
address of object in case of nonzero virtual and base addresses.
Location in address space of a particular program header should be
calculated using the formula: addr = base_addr + virtual_addr.

Signed-off-by: Sergey Melnikov <sergey.melnikov@intel.com>
Change-Id: Ie2ab4257fd456242aab8afed0bd5bd6b29e81d6d
e4d792adb8d6f9228b9ac9dc1ad7f43b271f085f 28-Oct-2013 Elliott Hughes <enh@google.com> Don't allow text relocations on 64-bit.

I've also updated our <sys/exec_elf.h> to match upstream.

Change-Id: I52f9fce3167541811208d273ff23ceaa112f7135
4eeb1f12a8b63afc0d0ad4d466b16fbffb21cd5a 26-Oct-2013 Elliott Hughes <enh@google.com> Clean up linker architecture macros.

We don't need our own architecture macros; the standard ones will do.

This patch also fixes some __x86_64__ tests to be USE_RELA tests instead,
because they're not actually x86_64-specific.

I've cleaned up architecture-specific code slightly so where possible
all the code corresponding to a particular architecture is together.

This patch also fixes a bug in LP64 DT_PLTGOT handling, which should be
an error rather than falling through into DT_DEBUG! There was another #ifdef
bug where we'd only report unexpected DT_ entries on MIPS.

Change-Id: Id1d04e372611f641c1aa278a18e379f28af9eaf5
b8b0b6b412267e514c99a6d3636aefa3c7715673 25-Oct-2013 Elliott Hughes <enh@google.com> Revert "Don't warn about x86 text relocations. They're too prevalent."

This reverts commit 5be2c5998c996ff9d5efb94c127d9b832a295822.

Change-Id: I3fc8ca530cdbd74c834fb9cfabe812c9386419fc
5be2c5998c996ff9d5efb94c127d9b832a295822 23-Oct-2013 Elliott Hughes <enh@google.com> Don't warn about x86 text relocations. They're too prevalent.

We should fix this (and disallow it for x86_64), but for now let's get CTS
running again.

libdvm.so and libcutils.so are the main problems.

$ scanelf -qT out/target/product/generic_x86/symbols/system/lib/libcutils.so
libcutils.so: (memory/data?) [0x4125] in (optimized out: previous android_memset16) [0x4100]
libcutils.so: (memory/data?) [0x424F] in (optimized out: previous android_memset16) [0x4100]
libcutils.so: (memory/data?) [0x42F8] in (optimized out: previous android_memset16) [0x4100]
libcutils.so: (memory/data?) [0x4349] in (optimized out: previous android_memset16) [0x4100]
libcutils.so: (memory/data?) [0x4406] in (optimized out: previous android_memset16) [0x4100]
libcutils.so: (memory/data?) [0x45AC] in (optimized out: previous android_memset32) [0x4590]
libcutils.so: (memory/data?) [0x4650] in (optimized out: previous android_memset32) [0x4590]
libcutils.so: (memory/data?) [0x46F9] in (optimized out: previous android_memset32) [0x4590]
libcutils.so: (memory/data?) [0x474A] in (optimized out: previous android_memset32) [0x4590]
libcutils.so: (memory/data?) [0x4807] in (optimized out: previous android_memset32) [0x4590]

Bug: 11353056
Change-Id: Id4a76b310be7fe858a8a60d0d260b09913b66be9
3d4470c14a57b0b9ae74060370be53469e95d6a1 22-Oct-2013 Nick Kralevich <nnk@google.com> change wording on text relocation message.

The current message is too alarmist.

Change-Id: I53e8eadca239f867b4e6b9c193eba96e267950c3
c075c18537d18ccb6760ba1f5727ce2c0890285a 16-Oct-2013 Pavel Chupin <pavel.v.chupin@intel.com> x86_64: Add R_X86_64_64 relocation handling

Change-Id: I86ffc56fa6a9053bed44e92a579530c2beb8eb2c
Signed-off-by: Pavel Chupin <pavel.v.chupin@intel.com>
1a57f9f75c5752d990a2749b000ec4ceace94b54 06-Feb-2013 Pavel Chupin <pavel.v.chupin@intel.com> x86_64: Rename 64-bit linker to linker64

That's for having both on the same system.

Change-Id: Ic2bc2c015e6486e8b6a7576f7b28d2d027534368
Signed-off-by: Pavel Chupin <pavel.v.chupin@intel.com>
eb847bc8666842a3cfc9c06e8458ad1abebebaf0 10-Oct-2013 Elliott Hughes <enh@google.com> Fix x86_64 build, clean up intermediate libraries.

The x86_64 build was failing because clone.S had a call to __thread_entry which
was being added to a different intermediate .a on the way to making libc.so,
and the linker couldn't guarantee statically that such a relocation would be
possible.

ld: error: out/target/product/generic_x86_64/obj/STATIC_LIBRARIES/libc_common_intermediates/libc_common.a(clone.o): requires dynamic R_X86_64_PC32 reloc against '__thread_entry' which may overflow at runtime; recompile with -fPIC

This patch addresses that by ensuring that the caller and callee end up in the
same intermediate .a. While I'm here, I've tried to clean up some of the mess
that led to this situation too. In particular, this removes libc/private/ from
the default include path (except for the DNS code), and splits out the DNS
code into its own library (since it's a weird special case of upstream NetBSD
code that's diverged so heavily it's unlikely ever to get back in sync).

There's more cleanup of the DNS situation possible, but this is definitely a
step in the right direction, and it's more than enough to get x86_64 building
cleanly.

Change-Id: I00425a7245b7a2573df16cc38798187d0729e7c4
011bc0ba45a8b7766a205cb21269dbafb32294b6 08-Oct-2013 Elliott Hughes <enh@google.com> Use /system/lib64 and /vendor/lib64 for 64-bit libraries.

Change-Id: I4886aeb3070bf97b4cfe8053388ecb1bda288017
c00f2cb587630d5e954c7f548749f1e3170b3cb1 05-Oct-2013 Elliott Hughes <enh@google.com> x86_64 linker.

Based on I8dc3e2cb596f75dc58ae82e4dc58f8c177dd3323 by
Pavel Chupin <pavel.v.chupin@intel.com>.

Change-Id: Icd582d277cbe273477b450f2848343d72c86ec9f
c620059479c47a78d57086d73726c9adc2f337ad 01-Oct-2013 Elliott Hughes <enh@google.com> Remove 32-bit assumptions from the ELF code.

Change-Id: I2c1f3d34c33685799aade8866eec44479ff9f963
24053a461e7a20f34002262c1bb122023134989d 20-Aug-2013 Christopher Ferris <cferris@google.com> Add the dl_iterate_phdr function to libdl for arm.

Bug: 8410085

Merge from internal master.

(cherry-picked from cb491bc66dc0abc145930b09086eb9189a30f6c2)

Change-Id: I94ed51bc5d4c626df7552c0e85c31ccee2d6568f
cb491bc66dc0abc145930b09086eb9189a30f6c2 20-Aug-2013 Christopher Ferris <cferris@google.com> Add the dl_iterate_phdr function to libdl for arm.

Bug: 8410085
Change-Id: I94ed51bc5d4c626df7552c0e85c31ccee2d6568f
9ef1fbb644bf85fa211588853316efa4848547c6 21-Aug-2013 Brian Carlstrom <bdc@google.com> Make mips_relocate_got tolerate a missing got

Bug: 10094803

(cherry picked from commit 7ee26878065abb494600595349ce58b2b2db3709)

Change-Id: I9fbb65d20011f2f625fde3b15ac8c6887dd03ae4
87c358524e479235aa6241736d2ce325f89daafc 21-Aug-2013 Brian Carlstrom <bdc@google.com> Make mips_relocate_got tolerate a missing got

Bug: 10094803

(cherry picked from commit 7ee26878065abb494600595349ce58b2b2db3709)

Change-Id: Ib15bccecaee421dc463d46a3956b054051708759
c45087bffa528c0809f0df2e0a3708eba7018b33 25-Jan-2013 Sergey Melnikov <sergey.melnikov@intel.com> Kernel dso support for 'dl_iterate_phdr' function

Kernel provides virtual DSO for stack unwinding/exception handlind info for
signal usage case. Stack unwinding routines use 'dl_iterate_phdr' function
for additional DWARF info gathering from DSOs. Patch enables virtual DSO
enumeration via dl_iterate_phdr function.

Signed-off-by: Sergey Melnikov <sergey.melnikov@intel.com>
Change-Id: Ic2882b28f40b456a088bc1e63c50cbfda7e4a102
c9084427aa15259c8bfb9b13b979597a4abd1805 21-Jun-2013 Nick Kralevich <nnk@google.com> linker: Emit a warning on text relocations

Text relocations unnecessarily mark pages as dirty, preventing them
from being swapped out, wasting memory. Also, text relocations
prevent the code from running on certain hardened systems.

Print a message in logcat and stderr when we see a text relocation,
to encourage developers to fix their code.

Change-Id: I6051a7463911e090ae5727a355397d539669d5b9
7e5a8cc5230dcc027686813e51a1b001cee4c602 18-Jun-2013 Elliott Hughes <enh@google.com> Make LD_PRELOAD failures just warnings.

This matches glibc and makes life easier for developers who want to
sometimes preload a library from init (which has no conditionals); they
can simply move/remove the library to disable.

Change-Id: I579b8633f958235af6e46bb53b378b9e363afb1f
6bec5b792a5f034089a942cb28cab26d36408235 04-Jun-2013 Christopher Ferris <cferris@google.com> Small cleanup of soinfo_elf_lookup.

- Remove unnecessary line.
- Move declarations to first use.

Change-Id: I1d8398d6c13f7cb86bffe0b68af849e35a4b234d
738370d9387396922c10910edb61272e585be107 09-May-2013 Elliott Hughes <enh@google.com> Don't fail to run DT_INIT and DT_INIT_ARRAY constructors if a shared library has DT_PREINIT_ARRAY constructors.

The GNU dynamic linker silently ignores a DT_PREINIT_ARRAY section
in a shared library. We had ineffectual code that tried to report
an error, which I tried to fix but got wrong --- my version still
wouldn't report the error to the caller, but would prevent us from
continuing to call constructors.

Bug: 8825226

(cherry picked from commit 8147d3c284932896ab6095232b355979b9eb33d3)

Change-Id: Iad8e7e3743d1a5e6bd1d44ef40b1ab3499cb64f2
8147d3c284932896ab6095232b355979b9eb33d3 09-May-2013 Elliott Hughes <enh@google.com> Don't fail to run DT_INIT and DT_INIT_ARRAY constructors if a shared library has DT_PREINIT_ARRAY constructors.

The GNU dynamic linker silently ignores a DT_PREINIT_ARRAY section
in a shared library. We had ineffectual code that tried to report
an error, which I tried to fix but got wrong --- my version still
wouldn't report the error to the caller, but would prevent us from
continuing to call constructors.

Bug: 8825226
Change-Id: I4fd8450ecc44d8767a1cb808aeecfbfbfc77c070
8d3e91d4f842911366155845afb3cfbdad0b4cad 25-Apr-2013 Nick Kralevich <nnk@google.com> linker: only re-open std* for setuid programs.

get_AT_SECURE() was getting called before linker_env_init() had
been called, and returning the default value ("true"). This was
causing us to reopen closed stdin, stdout, and stderr for ALL
processes, not just privileged (setuid) processes.

Calling path:
- __linker_init
- soinfo_link_image
- get_AT_SECURE
- __linker_init_post_relocation
- linker_env_init

This change restores the intended behavior of only re-opening
stdin, stdout, and stderr for privileged processes.

Change-Id: I8b085ea6597710ac4c1a3c93f1bf8b81eecb08c0
7b4d77e400d321ccc7cdadd1cd225ebb1a69d358 04-Apr-2013 Elliott Hughes <enh@google.com> Make abort messages available to debuggerd.

This adds __libc_fatal, cleans up the internal logging code a bit more,
and switches suitable callers over to __libc_fatal. In addition to logging,
__libc_fatal stashes the message somewhere that the debuggerd signal handler
can find it before calling abort.

In the debuggerd signal handler, we pass this address to debuggerd so that
it can come back with ptrace to read the message and present it to the user.

Bug: 8531731

(cherry picked from commit 0d787c1fa18c6a1f29ef9840e28a68cf077be1de)

Change-Id: I5daeeaa36c1fc23f7f437d73a19808d9d558dd4d
0d787c1fa18c6a1f29ef9840e28a68cf077be1de 04-Apr-2013 Elliott Hughes <enh@google.com> Make abort messages available to debuggerd.

This adds __libc_fatal, cleans up the internal logging code a bit more,
and switches suitable callers over to __libc_fatal. In addition to logging,
__libc_fatal stashes the message somewhere that the debuggerd signal handler
can find it before calling abort.

In the debuggerd signal handler, we pass this address to debuggerd so that
it can come back with ptrace to read the message and present it to the user.

Bug: 8531731
Change-Id: I416ec1da38a8a1b0d0a582ccd7c8aaa681ed4a29
8f7120bbacb0bb7a8aca1102f76f64a462f40231 22-Mar-2013 Kito Cheng <kito@0xlab.org> Drop unnecessary execution permission for .cpp/.c/.h

Change-Id: I9ac2b9d8f6bdb4fab8962210c5ec8f9c3e8c0ebf
8f2a5a0b40fc82126c691d5c30131d908772aab7 15-Mar-2013 Elliott Hughes <enh@google.com> Clean up internal libc logging.

We only need one logging API, and I prefer the one that does no
allocation and is thus safe to use in any context.

Also use O_CLOEXEC when opening the /dev/log files.

Move everything logging-related into one header file.

Change-Id: Ic1e3ea8e9b910dc29df351bff6c0aa4db26fbb58
ca0c11bd823f37f03cc8067cb182876827d5275a 12-Mar-2013 Elliott Hughes <enh@google.com> Use more types than just 'unsigned' in the linker.

Still chipping away at the situation where every variable in the
linker was of type 'unsigned'. This patch switches counts over to
being size_t and adds an explicit type for init/fini function pointers
and arrays of function pointers.

Also improve logging from CallArray.

Also remove trailing "\n"s from log messages.

Change-Id: Ie036d2622caac50f4d29f0570888bb527661d77e
fa8c05dc00bb41ae8fe5cb5e4f82816e30f7f7b2 12-Mar-2013 Kito Cheng <kito@0xlab.org> Use Elf32_Addr instead of unsigned in linker

Change-Id: I52dcbb4b0ff0a4052e0ad7a9bbeb2df65c9d2f66
2d4b9b7cff78b9a378d7fc0f28c702dc43002020 07-Mar-2013 Brian Carlstrom <bdc@google.com> Fix typo of DT_NEEDED for DT_NULL

(cherry-pick of 138b205ea9efc117fe522c2d7191378023a6e2cd)

Change-Id: Ia895cb3018df55554627f1f61dcdfdada4a961ce
5e2492eb89b778ee71e37e7406fe290d986ece70 06-Mar-2013 Kito Cheng <kito@0xlab.org> Fix TIMING/STATS/COUNT_PAGES dynamic linker build

Change-Id: I6432ac378816da253b83d1c7fb1d3fb64647b89e
43cc7f795b48e9c13a54e15af829369805f11652 06-Mar-2013 Brian Carlstrom <bdc@google.com> Fix MIPS linker build

(cherry-picked from 8c7d8c2057e303985f78eab96da747ddaa013c78)

Change-Id: Idcf62ab95f8fccbc2d7c3e771a4cfbe768a1555e
650be4e584eeab3591b9e273bfd6d169eea60853 06-Mar-2013 Elliott Hughes <enh@google.com> More linker cleanup.

Change-Id: I9fb3c7c0d4b4ffef0eeaf092d4e30ffe63a08671
d4ee82dfa3ba01baa10e3ca48fcb31a27b8a4e81 01-Mar-2013 Brian Carlstrom <bdc@google.com> Minor linker cleanup, primarily to use Elf32_Dyn

Change-Id: Ifa9408e9859c6f79444715bed4808b7c13fdced5
d3920b3a996b358e48232f417aa0a1e44a60f155 08-Feb-2013 Elliott Hughes <enh@google.com> Switch to using AT_RANDOM for the stack guards.

Bug: 7959813
Change-Id: I8db4b8912ba649bfe668c6f22aa44690ddd401a2
42b2c6a5eed5e4ef35315b8cd32d1355f12a69b6 07-Feb-2013 Elliott Hughes <enh@google.com> Clean up the argc/argv/envp/auxv handling.

There's now only one place where we deal with this stuff, it only needs to
be parsed once by the dynamic linker (rather than by each recipient), and it's
now easier for us to get hold of auxv data early on.

Change-Id: I6314224257c736547aac2e2a650e66f2ea53bef5
d2b1a7311f023a1c532b5b418fc4bc7bd835be34 06-Feb-2013 Elliott Hughes <enh@google.com> Remove partial implementation of MIPS non-PIC support.

Change-Id: I3c287e52aae10559508174e73113367aea40e5c2
1e980b6bc8315d00a07312b25486531247abd98c 18-Jan-2013 Elliott Hughes <enh@google.com> Fix the duplication in the debugging code.

We had two copies of the backtrace code, and two copies of the
libcorkscrew /proc/pid/maps code. This patch gets us down to one.

We also had hacks so we could log in the malloc debugging code.
This patch pulls the non-allocating "printf" code out of the
dynamic linker so everyone can share.

This patch also makes the leak diagnostics easier to read, and
makes it possible to paste them directly into the 'stack' tool (by
using relative PCs).

This patch also fixes the stdio standard stream leak that was
causing a leak warning every time tf_daemon ran.

Bug: 7291287
Change-Id: I66e4083ac2c5606c8d2737cb45c8ac8a32c7cfe8
36bd371e26c716cbc18e11801b13eff0352d91b0 16-Jan-2013 Nick Kralevich <nnk@google.com> Revert "stack protector: use AT_RANDOM"

The AT_RANDOM changes broke setuid / setgid executables
such as "ping". When the linker executes a setuid program,
it cleans the environment, removing any invalid environment
entries, and adding "NULL"s to the end of the environment
array for each removed variable. Later on, we try to determine
the location of the aux environment variable, and get tripped
up by these extra NULLs.

Reverting this patch will get setuid executables working again,
but getauxval() is still broken for setuid programs because of
this bug.

This reverts commit e3a49a8661125f24aec8a1453e54b3b78005e21e.

Change-Id: I05c58a896b1fe32cfb5d95d43b096045cda0aa4a
e3a49a8661125f24aec8a1453e54b3b78005e21e 14-Jan-2013 Nick Kralevich <nnk@google.com> stack protector: use AT_RANDOM

Populate the stack canaries from the kernel supplied
AT_RANDOM value, which doesn't involve any system calls.
This is slightly faster (6 fewer syscalls) and avoids
unnecessarily reading /dev/urandom, which depletes entropy.

Bug: 7959813

Change-Id: If2b43100a2a9929666df3de56b6139fed969e0f1
99c32055cb50443f722c55914869c1f6bb941959 14-Jan-2013 Elliott Hughes <enh@google.com> Fix my git mistake.

This was the formatting change that was supposed to be in
cf23905a4bcc7bfdd109be5b6d69ad06877aa217.

Change-Id: Ib79fa031b68f6f541f532507eb589afeaedb831f
cf23905a4bcc7bfdd109be5b6d69ad06877aa217 12-Jan-2013 Chris Dearman <chris@mips.com> [MIPS] Set DT_DEBUG dyntab entry if it is writable

This is primarily for MIPS exutables that do not have a
DT_MIPS_RLD_MAP entry.

Change-Id: I4c221d92debcfed961eeee2515123f3fb21ec8e6
Signed-off-by: Chris Dearman <chris@mips.com>
db492b3ca753c4ef688d0daf648294de0c89145e 04-Jan-2013 Elliott Hughes <enh@google.com> Fix debug malloc.

...which has been broken since the linker data structures went read-only.

Bug: 7941716
Change-Id: If28f6bac0fcb13e371e4d85b064544f561c8d692
cade4c36e7c9c62db3f476a0f9cfc329bac9acb7 20-Dec-2012 Elliott Hughes <enh@google.com> Support System.loadLibrary for libraries with transitive dependencies.

Also fix the FLAG_ERROR annoyance --- it's not helpful to cache failures.

Bug: 7896159
Bug: http://code.google.com/p/android/issues/detail?id=34416
Bug: http://code.google.com/p/android/issues/detail?id=22143
Change-Id: I60f235edb4ea4756e1f7ce56f7739f18e8a50789
e66190d2a97a713ae4b4786e60ca3d67ab8aa192 19-Dec-2012 Elliott Hughes <enh@google.com> Check for unknown flags passed to dlopen(3).

Change-Id: I56f4aab0e5a1487bc32d2c4d231e8bd15c4ac8da
20a24403bc333cd92996cd43cef2e6a79c72d055 31-Oct-2012 Chris Dearman <chris@mips.com> Do not include '\0' when writing error messages to stderr

Change-Id: I6adc806c3920e5a4ae61ca55c40613fcf338b18c
Signed-off-by: Chris Dearman <chris@mips.com>
c5db969aa4a24a76fc0964f2ff89533e832b47a6 15-Nov-2012 Chao-Ying Fu <fu@mips.com> We should use load_bias. This patch fixes MIPS NDK device exception test failures.

Change-Id: I4b718c36666e66062c1f13e4deea1ec7a7951c54
9c94fc9fbefe55836c1e1b949850f7726e64c118 05-Nov-2012 Elliott Hughes <enh@google.com> Tone down some of the overly-verbose linker logging.

We don't need to see every dlopen(3)/dlsym(3) failure unless LD_DEBUG is on.

Change-Id: I1edfe8b72f32ff54dd30e1acf32e20d470d5e9f7
61a9ccb41eba8c35cae6e21318aca7160a402c5b 02-Nov-2012 Elliott Hughes <enh@google.com> Make dynamic linker debugging always available.

If you need to build your own linker to get debugging, the debugging
is never available when you need it.

Change-Id: I5ff7e55753459d49a2990f25d9aa155e0b8602e0
c77c434149959e135ba21d1dd8a78a408fef2489 31-Oct-2012 Pavel Chupin <pavel.v.chupin@intel.com> Adjust symbol lookup for DT_SYMBOLIC case

According ELF spec re. DT_SYMBOLIC:
This element's presence in a shared object library alters the dynamic
linker's symbol resolution algorithm for references within the library.
Instead of starting a symbol search with the executable file, the
dynamic linker starts from the shared object itself. If the shared
object fails to supply the referenced symbol, the dynamic linker then
searches the executable file and other shared objects as usual.

This change implements the last part.

Change-Id: Iae95d53d455313a4306f11733941bcd3596ac85f
Signed-off-by: Pavel Chupin <pavel.v.chupin@intel.com>
6971fe4ca52ebdaa85ba676a044412b01d2ef1bf 02-Nov-2012 Elliott Hughes <enh@google.com> Allow dlopen("egl/blah.so").

NVIDIA binary blobs construct strings to pass to dlopen(3) that
contain '/' but require that we fall back to LD_LIBRARY_PATH.

Change-Id: Iad831899986baace6962f4b335eeb288250a1e22
d23736e4f228e46304b7cbc674a1d0094d73e0f5 01-Nov-2012 Elliott Hughes <enh@google.com> Keep the dynamic linker's soinfo pools mostly read-only.

We'll need a lot more refactoring of this code before we can reduce
the granularity, but this is a step forward.

Change-Id: I07061720e734b571a8399c1d5b4f2f35cd681307
1a6961650c82168864afe040dbdc05977db701df 01-Nov-2012 Elliott Hughes <enh@google.com> Stop defining our own PAGE_SIZE and PAGE_MASK, and test dlclose(3) too.

Also remove an unnecessary #include and a now-obsolete TODO.

Change-Id: I36d923721e349a286934b9534090a67ce0786e7b
ba98d9237b0eabc1d8caf2600fd787b988645249 12-Sep-2012 Magnus Malmborn <magnus.malmborn@sonymobile.com> Dynamically allocate soinfo-structs in linker

Request memory from the system when needed instead of having a fixed
array for soinfo structs. Note that malloc() et al can't be used in
linker, so use mmap() instead.

Change-Id: I4b495995931d7752b0e8c944e64d1fe41b9f7144
124fae9eabd7a25d80dfa8c3b56bed0f0fba16f1 31-Oct-2012 Elliott Hughes <enh@google.com> Reject .so files with no sysv hash table.

Also ensure that dlopen(3) errors always include the name of the library we
failed to open.

Also fix a bug where we'd fall back to searching LD_LIBRARY_PATH and the
built-in paths for names that include slashes.

Bug: http://code.google.com/p/android/issues/detail?id=38479
Change-Id: Ib2c009ed083344a7a012749d58f8679db2f26c78
5ae44f302b7d1d19f25c4c6f125e32dc369961d9 30-Aug-2012 Ard Biesheuvel <ard.biesheuvel@gmail.com> linker: handle R_ARM_COPY relocations in a proper way

If an executable contain copy relocations, other references
to the symbol it points to should be preempted and made to
point to the copy instead.

Also, the linker should make sure the target area has
sufficient space to contain the copy. It also checks
whether the library that supplies the symbol is built
with -Bsymbolic, and errors out if this is the case.

Change-Id: If135c83590092741cfd8f82f54816f363a4a4a3b
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@gmail.com>
18a206c81d9743481e364384affd43306911283d 30-Oct-2012 Elliott Hughes <enh@google.com> More dynamic linker cleanup.

I still want to break linker_format out into its own library so we can reuse
it for malloc debugging and so forth. (There are many similar pieces of code
in bionic, but the linker's one seems to be the most complete/functional.)

Change-Id: If3721853d28937c8e821ca1d23cf200e228a409a
5419b9474753d25dff947c7740532f86d130c0be 17-Oct-2012 Elliott Hughes <enh@google.com> Make dlerror(3) thread-safe.

I gave up trying to use the usual thread-local buffer idiom; calls to
calloc(3) and free(3) from any of the "dl" functions -- which live in
the dynamic linker -- end up resolving to the dynamic linker's stubs.
I tried to work around that, but was just making things more complicated.
This alternative costs us a well-known TLS slot (instead of the
dynamically-allocated TLS slot we'd have used otherwise, so no difference
there), plus an extra buffer inside every pthread_internal_t.

Bug: 5404023
Change-Id: Ie9614edd05b6d1eeaf7bf9172792d616c6361767
3b297c40794b23d50cb5240f9b03f6ef25fd98db 12-Oct-2012 Elliott Hughes <enh@google.com> Fix dlerror(3).

Add unit tests for dlerror(3) in various situations. I think We're at least
as good as glibc now.

Also factor out the ScopedPthreadMutexLock and use it here too.

Bug: http://code.google.com/p/android/issues/detail?id=38398
Change-Id: I040938b4366ab836e3df46d1d8055b92f4ea6ed8
9c3449ecd9d5e9cdb1e995e35e53334a4a288a5e 13-Sep-2012 Xiaokang Qin <xiaokang.qin@intel.com> bionic: linker: Need update the map->l_addr for execution.

Currently, linker doesn't update the map->l_addr for execution.
Which could break the Unwind_Backtrace with PT_GNU_EH_FRAME enabled
in new toolchain.

Change-Id: Ifbd853134da64a962f7e4c4105e56a3f20def1b2
Author: Fengwei Yin <fengwei.yin@intel.com>
Signed-off-by: Jack Ren <jack.ren@intel.com>
Author-tracking-BZ: 57077
e9b6fc6f82276188404a2839e31a2f4c19f6c336 29-Aug-2012 Elliott Hughes <enh@google.com> Improve the dynamic linker diagnostics.

Lose the pid, only show the name of the function (not its whole signature),
and include the name of the library we failed to load. (I hadn't noticed
that the library name was missing before because in Java we add that into
the UnsatisfiedLinkError detail message.)

The new output looks like this:

Cannot load library: soinfo_relocate(linker.cpp:968): cannot locate symbol "__libc_malloc_default_dispatch" referenced by "libc_malloc_debug_leak.so"...

Change-Id: I3bb5c9780d9aaf3a9e4418ea55bc98122a81f80f
d39c3abd5ad8600fb1d79a0b95a58197197087e0 24-Aug-2012 Nick Kralevich <nnk@google.com> linker: Fix ARM_R_COPY relocations

Per http://infocenter.arm.com/help/topic/com.arm.doc.ihi0044d/IHI0044D_aaelf.pdf
Section 4.7.1.10, ARM_R_COPY relocations are only suppose to reference shared
libraries, not the executable itself. When resolving an R_ARM_COPY symbol,
ensure we don't look in our own symbol.

This partially addresses
http://code.google.com/p/android/issues/detail?id=28598 . After this
patch, the printfs generated by the test program are:

global = 0x42 (0x401c7000)
global = 0x42 (0x11000)

before, the output was:

global = 0x42 (0x40071000)
global = 0x0 (0x11000)

I'm still not very happy with this patch, but I think it's an improvement
over where we were at before.

This change was modeled after https://android-review.googlesource.com/38871

Change-Id: Id7ad921e58395e76a36875bcc742ec5eeba53f08
bedfe38b8ba512dd6236c00e8b4a9b01c2bd1281 14-Aug-2012 Elliott Hughes <enh@google.com> More cleanup.

Make more stuff static, remove some dead code, and fix a few typos.

Change-Id: I010b0eadeaf61e2899c37014ad1e7082c70bd510
12c78bbded8ec03f821dfa09174464c04836e4ea 14-Aug-2012 Ard Biesheuvel <ard.biesheuvel@gmail.com> linker: avoid clobbering the .dynamic section of shared libs

This patch removes the DT_NEEDED hack which stores pointers
to soinfo structs in the .dynamic section of the library
being loaded.

Instead, it caches the soinfo struct pointers on the stack
during relocation time. After relocation time, i.e. when
calling constructors and destructors of the shared library
and its dependencies, uncached access is used instead,
doing lookups using the string table entries pointed to by
the DT_NEEDED entries.

By removing this hack, it is no longer needed to undo the
PT_GNURELRO protection, i.e., all non-writable mappings
can remain non-writable during their entire lifespan.

Even though, strictly speaking, the algorithmic complexity
has increased somewhat, the real-world adverse effect
is negligible on the systems I have tested.

Change-Id: I2361502560b96b5878f7f94a8e8a215350d70d64
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@gmail.com>
9181a5dcfe69199415c7aebf93524cc3dd6f8a6f 13-Aug-2012 Evgeniy Stepanov <eugenis@google.com> Fix module constructor order.

.preinit_array goes before the constructors of LD_PRELOAD-ed libraries.

Change-Id: I1af32ce29eaf3ca4351ae8a0f7f5da5165853216
5135b3ae6ebc460418f7917bd36b368340e48d5a 11-Aug-2012 Nick Kralevich <nnk@google.com> linker: don't perform unnecessary mprotects

The linker only needs to mark the text segment as
writable iff the file has text relocations. Unnecessarily
calling mprotect when it isn't necessary is slow, and some
security enhanced kernels don't like it. Pages which are
simultaneously writable and executable are considered a no-no.

The vast majority of executables / shared libraries on Android
do NOT have text relocations.

Change-Id: Ic38ce30a99b7e33ecf21efd9c108547a58eafa35
06f0e74a2b957db93fed3fdd49fe939ab2fe1595 11-Aug-2012 Ben Cheng <bccheng@google.com> Set the dynamic field in the link map for the linker itself.

Otherwise gdb will print a spurious warning each time gdb is used:

warning: .dynamic section for "/system/bin/linker" is not at the expected
address (wrong library or version mismatch?)

BUG:6946614
Change-Id: Ib21b8db0615751189c1601140deb43bc089289b6
4688279db5dcc4004941e7f133c4a1c3617d842c 04-Aug-2012 Elliott Hughes <enh@google.com> Clean up the linker a bit, remove prelinking support.

Also make the errors more readable, since none of us seemed to know
what they actually meant. The new style is still as verbose as the
old, but that's probably necessary in the absence of chained exceptions
in C. Here's what you'd see if you try to boot after removing
libsurfaceflinger.so:

32267 32267 E AndroidRuntime: java.lang.UnsatisfiedLinkError: Cannot load library: (linker.c:1629, pid 32259) soinfo_link_image: could not load library "libsystem_server.so" needed by "libandroid_servers.so"; caused by (linker.c:1629, pid 32259) soinfo_link_image: could not load library "libsurfaceflinger.so" needed by "libsystem_server.so"; caused by (linker.c:709, pid 32259) load_library: library "libsurfaceflinger.so" not found

This patch also fixes almost all of the compiler warnings.

Change-Id: I64bb59aed6d4e039c15ea45be2367f319ef879f8