Commit graph

324 commits

Author SHA1 Message Date
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
Hung-ying Tyan
0ebe2f07c3 Merge "Add /odm/lib to shared lib search path" 2015-11-19 16:38:51 +00:00
Junichi Uekawa
313632db57 Merge "Do not depend on host bits to get the right size to write." 2015-11-19 12:44:19 +00:00
Junichi Uekawa
ff35b1e659 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
2015-11-19 11:28:20 +09:00
Hung-ying Tyan
f74b041cce 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
2015-11-18 23:45:25 +08:00
Dmitriy Ivanov
3cc35e224c 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
2015-11-17 18:45:12 -08:00
Dmitriy Ivanov
fbfba64068 Remove the warning about empty LD_LIBRARY_PATH
Change-Id: I3eca11512d8055ab94dd0a6badcd83ce6440d675
2015-11-16 14:23:37 -08:00
Dmitriy Ivanov
d9b08a0bc0 Fix arm64 and x86 builds
Change-Id: Ic3746b2f200f42218b6ac857c1631e873c767c17
2015-11-16 13:17:27 -08:00
Dmitriy Ivanov
42d5fcb9f4 Introducing linker namespaces
Bug: http://b/22548808
Change-Id: Ia3af3c0a167f1d16447a3d83bb045d143319b1e1
2015-11-15 12:09:16 -08:00
Dmitriy Ivanov
fd7a91e692 linker: cleanup solist after unsuccessful read
Bug: http://b/25560017
Change-Id: I03c5a1d7aed34c480d341aacfb3b1afdfa037b99
2015-11-06 10:44:37 -08:00
Dmitriy Ivanov
126af757c6 Implement load at fixed address feature
Bug: http://b/24683631
Change-Id: I3a39ab526c8f9e213339b60e135e5459d0f41381
2015-10-27 11:27:34 -07:00
Dmitriy Ivanov
4f7a7ad3fe Implement Library Load Order Randomization
Bug: http://b/24047022
Change-Id: I36e05b403bfbaae8542a95147f9114a8b9c8ac0e
2015-10-22 18:26:07 -07:00