Commit graph

335 commits

Author SHA1 Message Date
Dimitry Ivanov
5543746934 Pass argc/argv/envp to dso constructors
The glibc implementation of the loader passes argc/argv/envp
to all elf constructors. This change makes bionic linker
behave in the same way.

Bug: http://b/30145768
Change-Id: I1c65c42aa5305a5b133c64b5748205bbde869e0e
Test: run bionic-unit-tests --gtest_filter=dl*:Dl*
2016-07-20 16:10:19 -07:00
Dimitry Ivanov
b996d60493 linker: Enable debug logging via properties
This patch lets developers tune logging of dlopen/dlerror with
setting system property.

Note that for security purposes this option is disabled on user build
for non-debuggable apps.

For starters there are 3 debug options:
 dlerror - enables logging of all dlerrors
 dlopen - traces dlopen calls

To enable system-wide logging (works only for userdebug/eng builds)
use debug.ld.all property.

To enable logging for particular app use debug.ld.app.<appname> property.

Example: Running "adb shell setprop debug.ld.all dlerror,dlopen" will log all
dlerror message as well as trace all calls to dlopen.

Bug: http://b/29458203
Change-Id: I2392c80a795509e16fe5689d0500d18b99772a64
2016-07-12 14:22:13 -07:00
Treehugger Robot
801dfc03cb Merge "Lose debuggerd client code to libdebuggerd_client." 2016-06-20 20:22:18 +00:00
Christopher Ferris
523e2a9807 Make missing public soname error message clear.
If a public library is missing, make it clear that there is no
library with that soname that is missing. This can help diagnose
problems if a library exists, but the library doesn't have the right
soname.

Bug: 29400363
(cherry picked from commit 9a84d90c75)

Change-Id: Ie2306a2e28aff779d07441dc8af078256b184f8a
2016-06-20 11:36:54 -07:00
Josh Gao
3cc387eff4 Lose debuggerd client code to libdebuggerd_client.
Bug: http://b/24414818
Change-Id: I524714e081a27df4d2046f0c8eb853a1b20592e6
2016-06-15 18:33:26 -07:00
Dimitry Ivanov
d799b2bb7e 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
2016-05-24 14:45:46 -07:00
Dimitry Ivanov
5240863ed5 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
2016-05-23 10:31:11 -07:00
Dimitry Ivanov
d2205a641c 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
(cherry picked from commit a5c1c8e820)
2016-05-19 10:47:23 -07:00
Treehugger Robot
42abf3d241 Merge "linker: Allow caller to specify parent namespace" 2016-05-17 22:43:01 +00:00
Dimitry Ivanov
2ba1cf39ae 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
2016-05-17 13:55:46 -07:00
Dimitry Ivanov
fc2da53440 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
2016-05-17 13:37:03 -07:00
Dimitry Ivanov
83fcb54208 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
2016-05-06 14:50:23 -07:00
Dimitry Ivanov
54807617dd Improve error message for empty list of public libs
Change-Id: I5a3cbc99d34e05559426b521a964d1407b67a6c4
2016-04-21 15:37:01 -07:00
Than McIntosh
1c3a5d87f2 Merge "Rename DT_MIPS_RLD_MAP2 flag to DT_MIPS_RLD_MAP_REL" 2016-04-20 14:23:10 +00:00
Dimitry Ivanov
aca299ac47 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
2016-04-14 11:52:16 -07:00
Dimitry Ivanov
3647314d89 linker: remove unnecessary reset of constructors_called flag
linker doesn't call d-tors for RTLD_NODELETE libraries. There is
no need in reseting this flag in call_destructors (which is called
from soinfo_unload).

Change-Id: I3ed03fa7207b7acf598067276fbb8874e29b5e53
2016-04-13 15:08:01 -07:00
Dimitry Ivanov
dd906d7da0 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
(cherry picked from commit 79abce4214)
2016-04-13 12:41:41 -07:00
Lazar Trsic
83b44a9e73 Rename DT_MIPS_RLD_MAP2 flag to DT_MIPS_RLD_MAP_REL
Change-Id: I2c0972f5ce3586c3f4f130034f7063f97557ab4e
2016-04-06 17:52:16 +00:00
Dimitry Ivanov
d88e1f3501 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
2016-03-28 13:15:40 -07:00
Mingwei Shi
be91052932 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.

Change-ID: Ib340c604d02c6c25714a95793737e3cfdc3fc5d7
Signed-off-by: Mingwei Shi <mingwei.shi@intel.com>
2016-03-25 14:10:05 -07:00
Yabin Cui
722072d65a CloseArchive() to free memory when OpenArchive fails.
Bug: 26962895
Change-Id: I42418eee320ddae857b42572690316c53f638e85
2016-03-22 16:43:24 -07:00
Dimitry Ivanov
e97d8ed70e Do not add linker the _r_debug.r_map on link_image
Change-Id: Idd0fb06a5d9f400c0608ae532cc4c575211810fa
2016-03-02 11:09:18 -08:00
Dimitry Ivanov
d17a377c49 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
(cherry picked from commit 350bdad61c)
2016-03-01 15:28:43 -08:00
Dimitry Ivanov
9f0a6954c6 Improvements to dynamic linker messages
Error messages now include executable name,
also linker doesn't abort if called on itself.

Change-Id: Ia17dd540919544b28062ed71751a1d79ee865206
2016-02-18 18:28:08 -08:00
Dimitry Ivanov
6b788eeff2 Move gdb support functions to a separate file
Move gdb support functions and variables to
linker_gdb_support.h/cpp

Change-Id: I96c6592a7055715b18f1137367470fe80987263f
2016-02-18 12:32:56 -08:00
Nicolas Geoffray
0fa5410b0f Revert "Move gdb support functions to a separate file"
Was reverted on internal master already.

This reverts commit f8d051c81b.

Change-Id: Ia432f83bcce91366fb23f1bb87603a093b7f074d
2016-02-18 09:31:24 +00:00
Dimitry Ivanov
f8d051c81b Move gdb support functions to a separate file
Move gdb support functions and variables to
linker_gdb_support.h/cpp

Change-Id: Id6e608617016383b68283760361c567e58e574bc
2016-02-17 16:09:35 -08:00
Dimitry Ivanov
f3064e4bc7 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

Change-Id: I0eacb3f030ea3eb16ed50ad2011d604beece2d03
2016-02-17 15:25:25 -08:00
Dimitry Ivanov
c347a10760 Merge "Update a comment for init_linker_info_for_gdb" 2016-02-17 22:20:22 +00:00
Dimitry Ivanov
6400129628 Update a comment for init_linker_info_for_gdb
Change-Id: I8e2895ecfcc6f77a180c3735342afc93be5923d3
2016-02-17 14:13:06 -08:00
Dimitry Ivanov
8d22dd53fe Initialize linker link_map for gdb directly
Remove unnecessary construction of soinfo when
initializing linker link_map for gdb.

Change-Id: Idf32cee56309aa9c9cf260efbd17a9deae9a756b
2016-02-16 14:39:15 -08:00
Dimitry Ivanov
e687d067c6 linker: remove soinfo::entry
This field is used only once and only for main executable;
no need to carry it around in soinfo structure.

Change-Id: I7f80c64e0939e28966b6fed858891f9ce2a9e26b
2016-02-16 13:25:29 -08:00
Dimitry Ivanov
88f5111123 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
2016-02-01 23:00:55 -08:00
Dimitry Ivanov
f45b0e9ede 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
2016-01-20 20:57:47 -08:00
Elliott Hughes
42d949ff9d 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
2016-01-06 20:06:08 -08:00
Elliott Hughes
116b5698d4 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
2016-01-05 11:06:50 -08:00
Dimitry Ivanov
7331fe18d7 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 e78deef364)
2015-12-19 23:38:27 -08:00
Dimitry Ivanov
9cf99cbad8 linker: add dlvsym(3)
This changes implements dlvsym - dlsym for versioned symbols.

Bug: http://b/22865643
Change-Id: Ic90a60d512104261a1416c43f9100f0d88e3b46f
2015-12-16 15:24:13 -08:00
Dimitry Ivanov
0bc3977537 Merge "Move dlsym and dladdr implementation to linker.cpp" 2015-12-11 01:26:17 +00:00
Dimitry Ivanov
4a2c5aa30c Move dlsym and dladdr implementation to linker.cpp
Bug: http://b/25716705
Bug: http://b/22865643
Change-Id: If22fc1eda219f676b5fcc06490f7901d21d1749c
2015-12-10 16:24:57 -08:00
Dimitry Ivanov
cb025e55f7 Merge "Revert "Add /odm/lib to shared lib search path"" 2015-12-10 20:17:02 +00:00
Dimitry Ivanov
39801757c3 Merge "Add permitted_when_isolated_path to linker namespaces" 2015-12-10 04:34:38 +00:00
Dimitry Ivanov
284ae3559e 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
2015-12-09 13:54:01 -08:00
Dimitry Ivanov
5a3ab3422d Merge "Revert "Ensure that readlink has access to /proc/self/fd"" 2015-12-09 21:50:54 +00:00
Dimitry Ivanov
db43526581 Revert "Ensure that readlink has access to /proc/self/fd"
This reverts commit 4e50d0247b.

Bug: http://b/24912743
Change-Id: I5d32c670f0e16aec9c74add143158e919a301673
2015-12-09 19:36:47 +00:00
Dimitry Ivanov
40728bccbc Revert "Add /odm/lib to shared lib search path"
This reverts commit f74b041cce.

Bug: 25654402
Change-Id: I77386ea3655868d7cd1a8130afbc95e70549389e
2015-12-09 19:35:02 +00:00
Dimitry Ivanov
e371ae68ac Merge "Allow dlopening public libs using absolute path" 2015-12-05 05:25:57 +00:00
Dimitry Ivanov
22840aab47 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
2015-12-04 21:21:35 -08:00
Elliott Hughes
939a7e0119 Track rename from base/ to android-base/.
Change-Id: I0a4592945400b1fa6892bf7c1fa8659fd711efa3
2015-12-04 15:27:46 -08:00
Dmitriy Ivanov
1ffec1cc4d 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
2015-11-23 16:13:10 -08:00