Commit graph

108 commits

Author SHA1 Message Date
Evgenii Stepanov
6bbb75aa77 Revert "Linker support for MTE globals."
Revert submission 2709995

Reason for revert: linker crash in soinfo::apply_relr_reloc

Reverted changes: /q/submissionid:2709995

Bug: 314038442
Change-Id: I2c6ad7f46fb1174f009253602ad08ceb36aa7d71
2023-12-06 19:01:46 +00:00
Mitch Phillips
e8139f585a Linker support for MTE globals.
This patch adds the necessary bionic code for the linker to protect
global data using MTE.

The implementation is described in the MemtagABI addendum to the
AArch64 ELF ABI:
https://github.com/ARM-software/abi-aa/blob/main/memtagabielf64/memtagabielf64.rst

In summary, this patch includes:

1. When MTE globals is requested, the linker maps writable SHF_ALLOC
   sections as anonymous pages with PROT_MTE (copying the file contents
   into the anonymous mapping), rather than using a file-backed private
   mapping. This is required as file-based mappings are not necessarily
   backed by the kernel with tag-capable memory. For sections already
   mapped by the kernel when the linker is invoked via. PT_INTERP, we
   unmap the contents, remap a PROT_MTE+anonymous mapping in its place,
   and re-load the file contents from disk.

2. When MTE globals is requested, the linker tags areas of global memory
   (as defined in SHT_AARCH64_MEMTAG_GLOBALS_DYNAMIC) with random tags,
   but ensuring that adjacent globals are never tagged using the same
   memory tag (to provide detemrinistic overflow detection).

3. Changes to RELATIVE, ABS64, and GLOB_DAT relocations to load and
   store tags in the right places. This ensures that the address tags are
   materialized into the GOT entries as well. These changes are a
   functional no-op to existing binaries and/or non-MTE capable hardware.

Bug: N/A
Test: atest bionic-unit-tests CtsBionicTestCases --test-filter=*Memtag*

Change-Id: Id7b1a925339b14949d5a8f607dd86928624bda0e
2023-11-20 15:53:06 +01:00
Ryan Prichard
9a027c7236 Hold the loader mutex in linker_main once constructors are running
A constructor could spawn a thread, which could call into the loader,
so the global loader mutex must be held.

Bug: http://b/290318196
Test: treehugger
Change-Id: I7a5249898a11fbc62d1ecdb85b24017a42a4b179
2023-07-21 23:14:46 -07:00
Mitch Phillips
a493fe4153 Add the recoverable GWP-ASan feature.
GWP-ASan's recoverable mode was landed upstream in
https://reviews.llvm.org/D140173.

This mode allows for a use-after-free or a buffer-overflow bug to be
detected by GWP-ASan, a crash report dumped, but then GWP-ASan (through
the preCrashReport() and postCrashReportRecoverableOnly() hooks) will
patch up the memory so that the process can continue, in spite of the
memory safety bug.

This is desirable, as it allows us to consider migrating non-system apps
from opt-in GWP-ASan to opt-out GWP-ASan. The major concern was "if we
make it opt-out, then bad apps will start crashing". If we don't crash,
problem solved :). Obviously, we'll need to do this with an amount of
process sampling to mitigate against the 70KiB memory overhead.

The biggest problem is that the debuggerd signal handler isn't the first
signal handler for apps, it's the sigchain handler inside of libart.
Clearly, the sigchain handler needs to ask us whether the crash is
GWP-ASan's fault, and if so, please patch up the allocator. Because of
linker namespace restrictions, libart can't directly ask the linker
(which is where debuggerd lies), so we provide a proxy function in libc.

Test: Build the platform, run sanitizer-status and various test apps
with recoverable gwp-asan. Assert that it doesn't crash, and we get a
debuggerd report.
Bug: 247012630

Change-Id: I86d5e27a9ca5531c8942e62647fd377c3cd36dfd
2023-02-02 15:35:25 -08:00
Ryan Prichard
bb1e37358f Delay setting linker soname until post-reloc and post-ctor
Setting the linker's soname ("ld-android.so") can allocate heap memory
now that the name uses an std::string, and it's probably a good idea to
defer doing this until after the linker has relocated itself (and after
it has called C++ constructors for global variables.)

Bug: none
Test: bionic unit tests
Test: verify that dlopen("ld-android.so", RTLD_NOLOAD) works
Change-Id: I6b9bd7552c3ae9b77e3ee9e2a98b069b8eef25ca
2021-01-13 17:48:05 -08:00
Elliott Hughes
f9dd1a760a Store soname as a std::string.
Once upon a time (and, indeed, to this very day if you're on LP32) the
soinfo struct used a fixed-length buffer for the soname. This caused
some issues, mainly with app developers who accidentally included a full
Windows "C:\My Computer\...\libfoo.so" style path. To avoid all this we
switched to just pointing into the ELF file itself, where the DT_SONAME
is already stored as a NUL-terminated string. And all was well for many
years.

Now though, we've seen a bunch of slow startup traces from dogfood where
`dlopen("libnativebridge.so")` in a cold start takes 125-200ms on a recent
device, despite no IO contention. Even though libnativebridge.so is only
20KiB.

Measurement showed that every library whose soname we check required
pulling in a whole page just for the (usually) very short string. Worse,
there's readahead. In one trace we saw 18 pages of libhwui.so pulled
in just for `"libhwui.so\0"`. In fact, there were 3306 pages (~13MiB)
added to the page cache during `dlopen("libnativebridge.so")`. 13MiB for
a 20KiB shared library!

This is the obvious change to use a std::string to copy the sonames
instead. This will dirty slightly more memory, but massively improve
locality.

Testing with the same pathological setup took `dlopen("libnativebridge.so")`
down from 192ms to 819us.

Bug: http://b/177102905
Test: tested with a pathologically modified kernel
Change-Id: I33837f4706adc25f93c6fa6013e8ba970911dfb9
2021-01-11 09:57:46 -08:00
Ryan Prichard
172611f5ce __loader_cfi_fail: acquire g_dl_mutex
CfiFail calls find_containing_library, which searches the linker's
internal soinfo list, which could be modified by another thread.

Bug: http://b/150372650
Test: bionic-unit-tests
Change-Id: I59024a0a47913caa75702f15ec058b0a360727b5
2020-04-20 18:14:51 -07:00
Ryan Prichard
c2a93792fc android_get_exported_namespace: acquire g_dl_mutex
android_get_exported_namespace searches g_exported_namespaces, which
isn't modified after process initialization, but it does the search
using a new std::string object, and the linker's malloc/free functions
aren't thread-safe. (They're protected by the same lock (g_dl_mutex) as
the rest of the linker's state.)

Bug: http://b/150372650
Test: bionic-unit-tests
Change-Id: Iafd12e5ab36ae61f0642aad59939f528d31bda16
2020-04-20 17:59:43 -07:00
Ryan Prichard
d9a4115273 Cleanup linker unwinder integration
The linker shouldn't throw exceptions, but because it links with
libc++_static.a, there are code paths that could throw an exception. On
those code paths, the unwinder needs to lookup EH information for the
linker binary, and the linker had two inconsistent ways of doing this:

 * dl_iterate_phdr (for libgcc): dlfcn.cpp defined a linker-internal
   version of this API that forwarded to __loader_dl_iterate_phdr

 * __gnu_Unwind_Find_exidx (for arm32 libgcc): linker_exidx_static.c was
   an old, broken copy of exidx_static.c that used
   __exidx_start/__exidx_end symbols. (The file should have used the
   addresses of the symbols rather than their contents.)

The linker's data structures might be in an inconsistent state at a point
where exceptions are thrown, so it seems better to limit its unwinder to
just the linker binary's EH info. Rather than forward the dl* EH APIs,
link in the static-binary versions from libc_unwind_static.a. That library
is already part of libc_nomalloc.a, but include it directly with
whole_static_libs so that __gnu_Unwind_Find_exidx is defined when we're
using libgcc on arm32.

Try to link in libunwind_llvm.a into the arm32 linker binary so we're
using the same unwinder as normal arm32 binaries. I'm not sure the library
will appear in the right order, but maybe it doesn't matter given LLD's
unconventional archive linking semantics.

Test: bionic unit tests
Test: "readelf --dyn-syms linker" reports no UNDEF symbols
Test: "readelf -r linker" reports only relative relocations
Bug: none
Change-Id: I5982ec830ba0f15d066536de24f6cd7e9503498b
Merged-In: I5982ec830ba0f15d066536de24f6cd7e9503498b
2019-10-16 04:20:23 +00:00
Ryan Prichard
cf9ed12d10 Use PT_INTERP as the linker's l_name path
Ordinary executables have a PT_INTERP path of /system/bin/linker[64], but:
 - executables using bootstrap Bionic use /system/bin/bootstrap/linker[64]
 - ASAN executables use /system/bin/linker_asan[64]

gdb appears to use the PT_INTERP path for debugging the dynamic linker
before the linker has initialized the r_debug module list. If the linker's
l_name differs from PT_INTERP, then gdb assumes that the linker has been
unloaded and searches for a new solib using the linker's l_name path.

gdb may print a warning like:

warning: Temporarily disabling breakpoints for unloaded shared library "$OUT/symbols/system/bin/linker64"

If I'm currently debugging the linker when this happens, gdb apparently
doesn't load debug symbols for the linker. This can be worked around with
gdb's "sharedlibrary" command, but it's better to avoid it.

Previously, when PT_INTERP was the bootstrap linker, but l_name was
"/system/bin/linker[64]", gdb would find the default non-bootstrap linker
binary and (presumably) get confused about symbol addresses.

(Also, remove the "static std::string exe_path" variable because the
soinfo::realpath_ field is a std::string that already lasts until exit. We
already use it for link_map_head.l_name in notify_gdb_of_load.)

Bug: http://b/134183407
Test: manual
Change-Id: I9a95425a3a5e9fd01e9dd272273c6ed3667dbb9a
2019-06-05 18:02:40 -07:00
Elliott Hughes
34583c1089 Move dlerror out of a TLS slot and into a pthread_internal_t member.
Bug: N/A
Test: boots, tests pass.
Change-Id: Idf25d2ee457a5d26d0bdd6281cee72c345c8b755
2018-12-06 05:19:57 +00:00
Ryan Prichard
abf736a780 Expose libc_shared_globals to libc.so with symbol
Previously, the address of the global variable was communicated from the
dynamic linker to libc.so using a field of KernelArgumentBlock, which is
communicated using the TLS_SLOT_BIONIC_PREINIT slot.

As long as this function isn't called during relocations (i.e. while
executing an ifunc), it always return a non-NULL value. If it's called
before its PLT entry is relocated, I expect a crash.

I removed the __libc_init_shared_globals function. It's currently empty,
and I don't think there's one point in libc's initialization where
shared globals should be initialized.

Bug: http://b/25751302
Test: bionic unit tests
Change-Id: I614d25e7ef5e0d2ccc40d5c821dee10f1ec61c2e
2018-11-28 14:26:14 -08:00
Elliott Hughes
ff1428a48e Move API levels from uint32_t to int.
(cherrypick of a6c71a09670ca636cca5cfea9d74b03a951e2b5e.)

Bug: N/A
Test: builds
Change-Id: I9c414e30e3c4fe2a4e16a2fe4ce18eae85fe4844
2018-11-13 21:25:07 -08:00
Ryan Prichard
0489645e00 Fix linker's _r_debug (gdb) info
* Initialize the exe's l_ld correctly, and initialize its l_addr field
   earlier.

 * Copy the phdr/phnum fields from the linker's temporary soinfo to its
   final soinfo. This change ensures that dl_iterate_phdr shows the phdr
   table for the linker.

 * Change init_linker_info_for_gdb a little: use an soinfo's fields to
   init the soinfo::link_map_head field, then reuse the new
   init_link_map_head function to handle the linker and the executable.

Test: manual
Test: bionic-unit-tests
Bug: https://issuetracker.google.com/112627083
Bug: http://b/110967431
Change-Id: I40fad2c4d48f409347aaa1ccb98d96db89da1dfe
2018-08-21 17:20:07 -07:00
Logan Chien
9ee4591cb4 linker: Allow link namespaces without name filters
This commit allows users to create a link without soname filters between
two linker namespaces.

The motivation is to establish one-way shared library isolation.  For
example, assume that there are two linker namespaces `default` and
`vndk`.  We would like to limit the shared libraries that can be used by
the `default` namespace.  In the meanwhile, we would like to allow the
`vndk` namespace to use shared libs from the `default` namespace if the
soname cannot be find in the search path or loaded sonames of the `vndk`
namespace.

          shared_libs  = %VNDK_CORE_LIBRARIES%
          shared_libs += %VNDK_SAMEPROCESS_LIBRARIES%
    vndk <-------------------------------------------- default
       \_______________________________________________/^
                allow_all_shared_libs = true

android_link_namespaces_all_libs() is added to libdl, but it is
versioned as LIBC_PRIVATE.  android_link_namespaces_all_libs() is only
for unit tests.

Bug: 69824336

Test: adb shell /data/nativetest/linker-unit-tests/linker-unit-tests32
Test: adb shell /data/nativetest64/linker-unit-tests/linker-unit-tests64

Test: adb shell /data/nativetest/bionic-unit-tests/bionic-unit-tests
Test: adb shell /data/nativetest64/bionic-unit-tests/bionic-unit-tests

Test: Update /system/etc/ld.config*.txt and check whether the vndk
linker namespace of the vendor process can access the shared libs from
the default linker namespace.

Change-Id: I2879f0c5f5af60c7e56f8f743ebd2872e552286b
2018-01-25 14:45:29 +08:00
dimitry
06016f226e Fix dlclose for libraries with thread_local dtors
Introduce new flag to mark soinfo as TLS_NODELETE when
there are thread_local dtors associated with dso_handle
belonging to it.

Test: bionic-unit-tests --gtest_filter=dl*
Test: bionic-unit-tests-glibc --gtest_filter=dl*
Bug: https://github.com/android-ndk/ndk/issues/360
Change-Id: I724ef89fc899788f95c47e6372c38b3313f18fed
2018-01-10 10:24:06 +01:00
dimitry
8e8c2c0013 Unhardcode linker soname
Set and use DT_SONAME instead.

Test: bionic-unit-tests
Change-Id: I38a246c8a43664792424e8fef96ae2ff5f743ba6
2018-01-09 11:11:46 +01:00
dimitry
7abea57ba5 Replace artificial symbol table with proper one
This change also replaces elf-hash with gnu-hash.

Test: make
Test: bionic-unit-tests --gtest_filter=dl*:Dl*
Change-Id: Ibc4026f7abc7e8002f69c33eebaf6a193f1d22eb
2017-08-29 18:18:28 +02:00
Dimitry Ivanov
cd510cbed9 Make dl_iterate_phdr return correct name for first entry
Test: bionic-unit-tests --gtest_filter=link*
Change-Id: Ib3f1e0fbc76fed9a5f27ffdd9bbf847a3e8d3665
2017-05-31 23:45:15 +00:00
Jiyong Park
01de74e76d linker: add android_get_exported_namespace
Depending on how ld.config.txt is configured, there can be multiple
built-in namespaces created by the linker from the beginning of a
process. android_get_exported_namespace is a platform only API for
getting a handle (android_namespace_t*) to one of the built-in namespaces
with given name. The returned namespace can then be given to
android_dlopen_ext in order to explicitly specify the target namespace
where the library is searched and loaded from.

Note that this function only returns 'exported' namespaces created via
ld.config.txt file. In order to export a namespace, the visible property
should be set to true:

namespace.<name>.visible = true

Namespaces are hidden by default. Hidden namespaces and namespaces
that are created programmatically, notably 'classloader-namespace',
aren't returned by this function.

Bug: 36851137
Test: confirmed that namespaces created with ld.config.txt is retrieved.
Test: linker-unit-tests passes
Merged-in: I714b510fa24f77e42c3dfc4c827b3befa8bb2951
Change-Id: I0d05fa7e0e116009edf8ea362ab46774bc617cbf
(cherry picked from commit d7c4832e6a)
2017-04-28 10:14:28 +09:00
Elliott Hughes
295082b3af Avoid "D linker : (null)" with debug.ld.all for dlerror.
We only want to know when dlerror is actually set. The previous change
to this logic moved it so that we only show actual updates to dlerror,
not every string that might end up in dlerror's output. This change
ignores cases where we're _clearing_ dlerror (which happens on every
call to dlerror).

Bug: http://b/37287938
Test: ran tests
Change-Id: I0c30ee199dc76d9aea165c1d90f694ead488518b
2017-04-15 09:11:15 -07:00
Dimitry Ivanov
11968b80af linker: log only real dlerrors
Currently linker reports all potential dlerrors
for example if library was not found in 'this'
namespace - it initializes linker error buffer
with not found message but when consequent
search in linked namespace succeeds this message
is droped because dlopen was successful.

This commit avoids logging false positive error
messages when debug.ld.* set to dlerror.

Test: manual
Change-Id: I480694a1b1bbacd6bd1d8505cd2ee491710964cc
2017-03-28 11:15:47 -07:00
Josh Gao
5e2285d3cc Allocate thread local buffers in __init_tls.
Thread local buffers were using pthread_setspecific for storage with
lazy initialization. pthread_setspecific shares TLS slots between the
linker and libc.so, so thread local buffers being initialized in a
different order between libc.so and the linker meant that bad things
would happen (manifesting as snprintf not working because the
locale was mangled)

Bug: http://b/20464031
Test: /data/nativetest64/bionic-unit-tests/bionic-unit-tests
      everything passes
Test: /data/nativetest/bionic-unit-tests/bionic-unit-tests
      thread_local tests are failing both before and after (KUSER_HELPERS?)
Test: /data/nativetest64/bionic-unit-tests-static/bionic-unit-tests-static
      no additional failures
Change-Id: I9f445a77c6e86979f3fa49c4a5feecf6ec2b0c3f
2017-02-22 16:05:03 -08:00
Dimitry Ivanov
bcc4da9b75 Unify linker files under one license (BSD)
Historically we had part of the linker licensed under BSD and
another part under Apache 2 license. This commit makes all the
linker code licensed under BSD license.

Test: m
Change-Id: I11b8163ae75966b5768d3fe992679de376106515
2017-02-15 15:35:33 -08:00
Dimitry Ivanov
7a34b9d57a Replace public library list with shared lib sonames (part 2/2)
This commit updates interface of libdl.c.

1. android_init_namespaces is replaces with android_init_anonymous_namespace
2. added 2 arguments to android_create_namespace to specify linked namespace
   and the list of shared libraries sonames.
3. symbol lookup does not get past boundary libraries (added check and test for it).

Bug: http://b/26833548
Bug: http://b/21879602
Test: bionic-unit-tests --gtest_filter=dl*:Dl*
Change-Id: I32921da487a02e5bd0d2fc528904d1228394bfb9
2017-02-09 23:26:44 -08:00
Evgenii Stepanov
0a3637d3eb Runtime support for CFI
Control Flow Integrity support in bionic.

General design:
http://clang.llvm.org/docs/ControlFlowIntegrityDesign.html#shared-library-support

This CL implements subsections "CFI Shadow" and "CFI_SlowPath" in the above document.

Bug: 22033465
Test: bionic device tests
Change-Id: I14dfea630de468eb5620e7f55f92b1397ba06217
2017-01-18 13:13:52 -08:00
Dimitry Ivanov
a6588e5d6f Fix android_dlwarning lookup
Bug: http://b/33530622
Test: mm
Change-Id: I3eefca58e91b7bbc41f6add9b8c756f1474a7f93
2016-12-12 13:12:59 -08:00
Dimitry Ivanov
d9e427cf41 Bionic loader is no longer hijacking libdl.so
Do not hijack libdl.so methods but make libdl proxy calls to
loader instead. This will be replaces by calls to libc.so
once loader functionality is migrated.

Also add a lock to dl_unwind_find_exidx function call.

Test: bionic-unit-tests --gtest_filter=dl*:Dl*
Bug: http://b/27106625
Change-Id: Ic33a7109a86f4262798d63a35f4c61d15b0068bb
2016-12-09 14:53:59 -08:00
Andreas Gampe
dcb846cb49 Revert "Bionic loader is no longer hijacking libdl.so"
This reverts commit c12acef96b.

Breaks the Mips build.

Bug: 27106625
Change-Id: I27edb7114065c36e1b618e387530d58189cdb184
2016-12-06 02:10:13 +00:00
Dimitry Ivanov
c12acef96b Bionic loader is no longer hijacking libdl.so
Do not hijack libdl.so methods but make libdl proxy calls to
loader instead. This will be replaces by calls to libc.so
once loader functionality is migrated.

Also add a lock to dl_unwind_find_exidx function call.

Test: bionic-unit-tests --gtest_filter=dl*:Dl*
Bug: http://b/27106625
Change-Id: I9e666e771e4bbca52151cfa7fc4c8677e1480818
2016-12-05 11:19:19 -08:00
Elliott Hughes
5e071a18ce dlerror returns char*, not const char*.
http://pubs.opengroup.org/onlinepubs/9699919799/functions/dlerror.html:

    char *dlerror(void);
    ...
    The application shall not modify the string returned.

Change-Id: I5e684bfd3930c39a2a30ea6fd005a5d5d3e5b181
2016-08-11 15:02:45 -07:00
Dimitry Ivanov
48ec288d40 Extract soinfo and globals to separate files.
Move soinfo and globals out of linker.cpp to
separate files.

Breaking up huge linker.cpp into smaller peaces
in order to make it easier to extract part of the
code that belongs to libdl.so and remove parts of
the code that do not belong to linker

(refactoring part 2 of many)

Change-Id: I868417f4b8d2b84d0e8265e354bc7977161497e2
2016-08-08 16:12:53 -07:00
Dimitry Ivanov
769b33fadf Sync linker with internal branch
This change includes dlwarning implementation and
the compatibility greylist for apps targeting pre-N.

Change-Id: Ibf02a07cc58cbbb1a5aef4ac34558c5d43e4305f
Test: Run bionic-unit-tests --gtest_filter=dl*:Dl*
2016-08-01 19:47:27 +00: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
Chih-Hung Hsieh
1a5fd9c155 Fix misc-macro-parentheses warnings in bionic.
Add parentheses around macro arguments used beside operators,
or use constexpr for simple constants.
Bug: 28705665

Change-Id: I378c8aad92d3ec8e8c4b0440b5c2c99dfe01ce79
2016-06-10 15:25:49 -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
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
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
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
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
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
Dmitriy Ivanov
42d5fcb9f4 Introducing linker namespaces
Bug: http://b/22548808
Change-Id: Ia3af3c0a167f1d16447a3d83bb045d143319b1e1
2015-11-15 12:09:16 -08:00
Mike Frysinger
747d30ebf3 dlfcn: update ifdef around old_name_
Commit 9185e04f72 changed the ifdef around
old_name_ from __arm__ to __work_around_b_###__, but missed one place in
dlfcn.cpp.  So if you do a build w/out that workaround for arm, you end
up with a build failure:
bionic/linker/dlfcn.cpp:275:27: error: no member named 'old_name_' in 'soinfo'
    strlcpy(__libdl_info->old_name_, __libdl_info->soname_, sizeof(__libdl_info->old_name_));
            ~~~~~~~~~~~~  ^
bionic/linker/dlfcn.cpp:275:82: error: no member named 'old_name_' in 'soinfo'
    strlcpy(__libdl_info->old_name_, __libdl_info->soname_, sizeof(__libdl_info->old_name_));
                                                                   ~~~~~~~~~~~~  ^

Bug: 24425865
Change-Id: Idbe1cc1c28083afeee6d90203c221f30f661c69c
2015-10-20 14:06:25 -04:00
Dmitriy Ivanov
e5cfafe344 Fix potential race condition on dlopen
Call to find_containing_library should be guarded.

Change-Id: I985a903da48b83bcd35e957a979158eb9b80e70b
2015-07-17 10:36:10 -07:00
Evgenii Stepanov
0cdef7e7f3 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
2015-07-07 10:56:06 -07:00
Dmitriy Ivanov
7271caf93d 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 f7d5bf334d)
2015-06-29 15:14:28 -07:00
Dmitriy Ivanov
1913352c6b 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 04f7e3e955)
2015-06-02 18:09:23 -07:00
Dmitriy Ivanov
d974e88046 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
2015-05-28 14:56:42 -07:00
Dmitriy Ivanov
79fd668bb4 Add functions to provide target sdk version
Bug: http://b/21364029
Change-Id: I8648d1bff6c8fd6e7cd12da7f128e048b9f2829a
2015-05-27 14:31:36 -07:00