Commit graph

1010 commits

Author SHA1 Message Date
Dimitry Ivanov
5ef13ba0ca linker: remove link from external library on unload am: b37d10cc80 am: 3a644889b2 am: cb40eec87c am: 0399816edb
am: 85efd3b591

Change-Id: I115a7adb07feedf81064c0e740cfc617263eb689
2017-05-16 22:21:23 +00:00
Dimitry Ivanov
efbc04475e linker: remove link from external library on unload am: b37d10cc80 am: 3a644889b2 am: cb40eec87c am: 0399816edb
am: 85efd3b591

Change-Id: I0b41cdffdccab8b79a4d9c6327dc0f6f521c1acf
2017-05-16 22:21:22 +00:00
Dimitry Ivanov
cb40eec87c linker: remove link from external library on unload am: b37d10cc80
am: 3a644889b2

Change-Id: I7c022194739391c24a736a3a5deb906433fc5649
2017-05-16 22:12:22 +00:00
Dimitry Ivanov
3a644889b2 linker: remove link from external library on unload
am: b37d10cc80

Change-Id: I48901a8fbf4bc25fff1462e6086fc23b76ca2ba3
2017-05-16 22:08:52 +00:00
Dimitry Ivanov
b37d10cc80 linker: remove link from external library on unload
When unloading library make sure the soinfo_link to parent
from linked external libraries is removed as well.

Bug: 36104177
Bug: http://b/37433850
Test: manual
Change-Id: I601b54144acecac54744805b38313c46045c54cb
(cherry picked from commit ee398f820700de30941fd82e38bd917e1513cbc6)
2017-05-15 21:23:32 -07:00
Jiyong Park
37b91af0f3 greylist is no longer enabled by default.
greylist is needed only for application namepaces. Since we started using
linker-namesapces for vendors and other platform apps linker should not
enable greylist workaround by default.

Bug: http://b/37731053
Bug: https://issuetracker.google.com/38146125
Test: sailfish builds and boots
Test: bionic-unit-tests and linker-unit-tests pass
Change-Id: Iee83db6fb1ae754f5ade18491321d9bca3b5ead4
(cherry picked from commit e8ffe56a9c)
2017-05-09 17:59:00 -07:00
Jiyong Park
e8ffe56a9c greylist is no longer enabled by default.
greylist is needed only for application namepaces. Since we started using
linker-namesapces for vendors and other platform apps linker should not
enable greylist workaround by default.

Bug: http://b/37731053
Bug: https://issuetracker.google.com/38146125
Test: sailfish builds and boots
Test: bionic-unit-tests and linker-unit-tests pass
Change-Id: Iee83db6fb1ae754f5ade18491321d9bca3b5ead4
2017-05-08 23:22:16 -07:00
Christopher Ferris
5725481f1e Merge "Move libc_log code into libasync_safe." 2017-05-03 17:43:35 +00:00
Christopher Ferris
7a3681e5b6 Move libc_log code into libasync_safe.
This library is used by a number of different libraries in the system.
Make it easy for platform libraries to use this library and create
an actual exported include file.

Change the names of the functions to reflect the new name of the library.

Run clang_format on the async_safe_log.cpp file since the formatting is
all over the place.

Bug: 31919199

Test: Compiled for angler/bullhead, and booted.
Test: Ran bionic unit tests.
Test: Ran the malloc debug tests.
Change-Id: I8071bf690c17b0ea3bc8dc5749cdd5b6ad58478a
2017-05-03 08:50:43 -07:00
Dimitry Ivanov
f1cb669a9c Shared namespaces inherit parent ns properties
Make shared namespace inherit namespace links and
search/permitted paths from the parent namespace.

Bug: http://b/37854032
Test: bionic_unit_tests --gtest_filter=dl*:Dl*
Change-Id: I174661d4a1dd0cbe4a378179073719aa955f3592
(cherry picked from commit ec43dd6c36)
2017-05-02 16:42:28 -07:00
Dimitry Ivanov
ec43dd6c36 Shared namespaces inherit parent ns properties
Make shared namespace inherit namespace links and
search/permitted paths from the parent namespace.

Bug: http://b/37854032
Test: bionic_unit_tests --gtest_filter=dl*:Dl*
Change-Id: I174661d4a1dd0cbe4a378179073719aa955f3592
2017-05-02 11:40:50 -07:00
Treehugger Robot
87a47e1bb2 Merge "linker: add android_get_exported_namespace" 2017-05-02 01:37:04 +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
Dimitry Ivanov
15f1db35fa Revert "Revert "loader: enable loading libraries from tmpfs""
This reverts commit 6d59318d78.

Bug: http://b/37245203
Bug: http://b/37590327
Test: bionic-unit-tests on angler and marlin
Test: boot an angler and make sure mediacodec does not crash
2017-04-24 13:35:41 -07:00
Yin-Chia Yeh
6d59318d78 Revert "loader: enable loading libraries from tmpfs"
This reverts commit bb8b22a087.

http://b/37245203
http://b/37590327
Change-Id: I36f45697f7478b830947d641942e453ed0d5466e
2017-04-22 23:55:41 +00:00
Dimitry Ivanov
bf34ba3641 loader: enable loading libraries from tmpfs
This change adds two tests for dlopen from temporary files.
1. One Uses memfd_create() can be used to load libraries directly
from memory. This requires relaxing namespace accessibility check
in order to make this work in isolated namespaces.
2. Another checks that open with O_TMPFILE works.

Bug: http://b/37245203
Test: bionic-unit-tests --gtest_filter=dl*:Dl*
Change-Id: I3be1d7198ca17e7f1ba022a0d86c64d59a493506
(cherry picked from commit bb8b22a087)
2017-04-21 14:45:07 -07:00
Dimitry Ivanov
bb8b22a087 loader: enable loading libraries from tmpfs
This change adds two tests for dlopen from temporary files.
1. One Uses memfd_create() can be used to load libraries directly
from memory. This requires relaxing namespace accessibility check
in order to make this work in isolated namespaces.
2. Another checks that open with O_TMPFILE works.

Bug: http://b/37245203
Test: bionic-unit-tests --gtest_filter=dl*:Dl*
Change-Id: I3be1d7198ca17e7f1ba022a0d86c64d59a493506
2017-04-21 14:37:00 -07:00
Elliott Hughes
f2c6ad6338 Make the _Unwind_Ptr declaration match clang's.
Bug: https://issuetracker.google.com/37126620
Test: builds, boots angler
Change-Id: I7d4a9b998f2e5c4c7b0beed87807d7b76a564c5c
2017-04-21 19:52:21 +00:00
Elliott Hughes
72007ee68f Decode the common EM_ values.
We know what "3" and "40" are, but most folks not on our team don't.

I don't think we need to support all the weird values, because only the
supported architectures actually occur in practice.

Bug: N/A
Test: manually overwrote aarch64 libcrypto.so with an x86-64 .so and ran "date"
Test: CANNOT LINK EXECUTABLE "date": "/system/lib64/libcrypto.so" has unexpected e_machine: 62 (EM_X86_64)
Change-Id: Ic4c6325fe7968f0c96fc0bfe15a50ed922a5ba55
2017-04-19 17:49:43 -07: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
d3a07e84a7 The workaround for apps using older version of soinfos
Skip the check for accessibility in the case soinfo
does not have primary/secondary namespaces associated
with them.

Bug: http://b/37191433
Test: start an app from http://b/37191433 make sure it does not crash on lunch
Change-Id: Id4c0bdab4dfc6bc8a33fc275d71e325518e0759f
(cherry picked from commit 97b4c5f264)
2017-04-12 10:37:31 -07:00
Dimitry Ivanov
97b4c5f264 The workaround for apps using older version of soinfos
Skip the check for accessibility in the case soinfo
does not have primary/secondary namespaces associated
with them.

Bug: http://b/37191433
Test: start an app from http://b/37191433 make sure it does not crash on lunch
Change-Id: Id4c0bdab4dfc6bc8a33fc275d71e325518e0759f
2017-04-11 16:35:00 -07:00
Treehugger Robot
f17048bfb8 Merge "Send developers straight to the text relocation docs." 2017-04-11 06:07:07 +00:00
Elliott Hughes
763f6e108a Send developers straight to the text relocation docs.
It's been years since we allowed text relocations, but I had a developer
ask me how to fix them at last week's O Developer Day. They'd never seen
our docs, so let's try to fix that for anyone else who's still confused...

Bug: N/A
Test: builds
Change-Id: I9202a7b0a3f024041b646c43c87585f4fab22d09
2017-04-10 16:41:52 -07:00
Tom Cherry
c40af334c7 Merge "Move scopeguard into android::base" 2017-04-06 22:41:02 +00:00
Jiyong Park
d7c4832e6a 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
Change-Id: I0d05fa7e0e116009edf8ea362ab46774bc617cbf
2017-04-06 15:20:04 -07:00
Elliott Hughes
9e27e58faa Add support for disabling the greylist.
Useful for testing whether apps have actually stopped using greylisted
libraries even if they still have references to them in their apk to support
old Android releases but also haven't bumped their targetSdkVersion yet.

Since we already have two expensive __system_property_get calls and this
would add a third, optimize two (but leave the third since it's not
obviously amenable to optimization). None of this matters for user builds,
but I don't want userdebug/eng to have distractingly different performance.

(cherrypick of 7933bec2872aa1c3430149c7649726333c0ac9d8.)

Bug: http://b/36106661
Test: ran "can you escape 5" with and without this property
Change-Id: Id9a804695c1dca9b4be2ebd0e72f01817bb13cba
2017-04-06 10:59:24 -07:00
Tom Cherry
b8ab61804c Move scopeguard into android::base
Test: boot bullhead, bionic unit tests
Change-Id: I223249684867655ecb53713b10da41d3014f96ae
2017-04-05 16:37:07 -07:00
Elliott Hughes
7933bec287 Add support for disabling the greylist.
Useful for testing whether apps have actually stopped using greylisted
libraries even if they still have references to them in their apk to support
old Android releases but also haven't bumped their targetSdkVersion yet.

Since we already have two expensive __system_property_get calls and this
would add a third, optimize two (but leave the third since it's not
obviously amenable to optimization). None of this matters for user builds,
but I don't want userdebug/eng to have distractingly different performance.

Bug: http://b/36106661
Test: ran "can you escape 5" with and without this property
Change-Id: Id9a804695c1dca9b4be2ebd0e72f01817bb13cba
2017-04-05 15:35:04 -07:00
Josh Gao
6367f5ee55 Merge changes I826756d9,I00e2edb2
* changes:
  libc_logging: mention that they're async signal safe.
  linker: update dependencies.
2017-04-03 20:33:18 +00:00
Dimitry Ivanov
dedcf35bcc Fix lookup logic for linked namespaces
When looking for already loaded libraries include
linked namespaces to the search, but check if
the library is accessible from the main namespace.

Bug: http://b/36008422
Bug: http://b/35417197
Bug: http://b/34052337
Bug: http://b/36660652
Bug: https://issuetracker.google.com/36636090
Test: run bionic-unit-tests --gtest_filter=dl*:Dl*
Change-Id: Ic7c1d48114da3ca5dc6512ef03f595dd17b6ed17
(cherry picked from commit d3e7d08845)
2017-04-01 19:15:32 -07:00
Treehugger Robot
6a2c7f5a68 Merge "Fix lookup logic for linked namespaces" 2017-04-02 02:14:47 +00:00
Vishwath Mohan
a782f29108 Refactor sanitized library on-disk layout - bionic.
This CL changes the linker to point to the newly refactored location
of ASAN-ified libraries on disk.

This supports changes made by the following CLs -
https://android-review.googlesource.com/#/c/359087/
https://android-review.googlesource.com/#/c/359389/

Which refactor the on-disk location as follows:
/data/lib* --> /data/asan/system/lib*
/data/vendor/* --> /data/asan/vendor/*

There are a couple of advantages to this, including better isolation
from other components, and more transparent linker renaming and
SELinux policies.

(cherry picked from commit 4113def4fa)

Bug: 36574794
Bug: 36674745
Test: m -j40 && SANITIZE_TARGET="address" m -j40 and the device
boots. All sanitized libraries are correctly located in /data/asan/*.

Change-Id: Iad8b298a66c38eb0f6327f6b51027f0728aa7a40
2017-03-31 17:24:12 -07:00
Vishwath Mohan
4113def4fa Refactor sanitized library on-disk layout - bionic.
This CL changes the linker to point to the newly refactored location
of ASAN-ified libraries on disk.

This supports changes made by the following CLs -
https://android-review.googlesource.com/#/c/359087/
https://android-review.googlesource.com/#/c/359389/

Which refactor the on-disk location as follows:
/data/lib* --> /data/asan/system/lib*
/data/vendor/* --> /data/asan/vendor/*

There are a couple of advantages to this, including better isolation
from other components, and more transparent linker renaming and
SELinux policies.

Bug: 36574794
Bug: 36674745
Test: m -j40 && SANITIZE_TARGET="address" m -j40 and the device
boots. All sanitized libraries are correctly located in /data/asan/*.

Change-Id: Iad8b298a66c38eb0f6327f6b51027f0728aa7a40
2017-03-30 20:07:50 -07:00
Dimitry Ivanov
d3e7d08845 Fix lookup logic for linked namespaces
When looking for already loaded libraries include
linked namespaces to the search, but check if
the library is accessible from the main namespace.

Bug: http://b/36008422
Bug: http://b/35417197
Bug: http://b/34052337
Bug: http://b/36660652
Bug: https://issuetracker.google.com/36636090
Test: run bionic-unit-tests --gtest_filter=dl*:Dl*
Change-Id: Ic7c1d48114da3ca5dc6512ef03f595dd17b6ed17
2017-03-29 15:36:40 -07:00
Dimitry Ivanov
e7cdb2953a 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
(cherry picked from commit 11968b80af)
2017-03-28 15:03:12 -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
Dimitry Ivanov
6b0f17e588 Merge "Make anonymous namespace isoalted." 2017-03-28 00:59:09 +00:00
Dimitry Ivanov
c9dced28b6 Make anonymous namespace isoalted.
This addresses outstanding todo for anonymous namespace
and fixes an app compatibility bug.

Bug: http://b/36008422
Test: start app from http://b/36008422 and make sure it runs
Change-Id: Ie148418b944379ee1000e7274f2f6c1eca511d6c
2017-03-27 15:42:17 -07:00
Dimitry Ivanov
840ae69408 Merge "Revert "linker: add more directories to default lib paths"" 2017-03-25 07:46:22 +00:00
Treehugger Robot
deca8effd0 Merge "Load namespace configuration from ld.config.txt" 2017-03-25 05:17:32 +00:00
Dimitry Ivanov
4cabfaad34 Load namespace configuration from ld.config.txt
This change allows customization of default namespace
configuration for different executables. It also enables
target_sdk_version setup for binaries (note that this
option should explicitly be enabled in ld.config.txt).

Bug: http://b/30706810
Bug: http://b/30435785
Test: run linker-unit-tests/bionic-unit-tests, boot angler
Change-Id: Ibbe87209acf1538fc9cec04944f3d22a190c38f1
2017-03-24 15:50:45 -07:00
Treehugger Robot
ad8dcd6023 Merge "loader: stop relying on AT_BASE" 2017-03-24 02:03:58 +00:00
Dimitry Ivanov
9b1cc4bb9c loader: stop relying on AT_BASE
android loader should not rely on the fact
that AT_BASE is set because kernel currently
does not set it when linker is run standalone
(The linker does not have PT_INTERP set)

This commit replaces AT_BASE with calculated value.

Bug: http://b/30739481
Bug: http://b/35890756
Test: run bionic-unit-tests --gtest_filter=dl*
Change-Id: Ic2eb73e4452624b1f2e05f46e99e4c17df0bbc3f
2017-03-23 17:12:59 -07:00
Dimitry Ivanov
6705e8caf5 Add systrace output for dlclose/dlsym calls
Bug: http://b/27195126
Test: manual: adb shell atrace -t 5 bionic
      and run bionic-unit-tests --gtest_filter=dl*

Change-Id: I9e93a069dd440bb643890d9952913938442ac375
2017-03-21 10:38:23 -07:00
Dimitry Ivanov
5c4a58072f Add systrace output for dlopen calls
Bug: http://b/27195126
Test: manual: adb shell atrace -t 5 bionic
      and run bionic-unit-tests --gtest_filter=dl*:Dl*

Change-Id: Ib2bad794e571b89bd1f52c9e0de642c2092e5c21
2017-03-20 13:34:52 -07:00
Dimitry Ivanov
a144697500 Revert "linker: add more directories to default lib paths"
This reverts commit 1daa18e737.

To be replaced with customized linker-namespaces for different kind of binaries.

Bug: http://b/34407260
Change-Id: Ib4e480669bbdf44ee4f59bf05f07d3e082c348c9
Test: m
2017-03-17 00:08:23 +00:00
Treehugger Robot
616b2d87ea Merge "Extract format_string function." 2017-03-14 00:58:16 +00:00
Treehugger Robot
e5422d7d1f Merge "linker: add more directories to default lib paths" 2017-03-14 00:15:50 +00:00
Dimitry Ivanov
2a6d9b2543 Extract format_string function.
Extract format_string function and add a test.

Test: run linker-unit-tests
Change-Id: I794a29aaf62e184438ce1a9224b88aa0586c17b5
2017-03-13 16:25:51 -07:00
Evgenii Stepanov
5b71500301 Apply ASan linker path translation to subdirectories.
Specifically, this change would translate /system/lib/hw/foo.so to /data/lib/hw/foo.so.

Bug: 30320104
Test: in SANITIZE_TARGET=address build, /proc/$PID/maps for
  system_server show libraries from /data/lib64/hw and not from
  /system/lib64/hw.
Change-Id: Ia1fa22fa1ca088fe76e41308762efe037541fc74
2017-03-13 10:04:36 -07:00
Jiyong Park
1daa18e737 linker: add more directories to default lib paths
Due to b/33681361, libraries are now installed to different paths than
before. In order for linker to load libraries from the new paths, the
default lib paths are updated.

However, this patch is temporary; different paths must be used depending
on whether the process is executing vendor executable or framework
executable. For example, vendor executable should not be able to access
/system/lib/, which is for framework-internal libs. Similarly,
framework executables should not be able to access /vendor/lib.

We have several solutions (linker namespace and DT_RUNPATH) to support
the scenario, but haven't concluded which is better. Furthermore, if we
restrict the search path right now, it will break many parts of Android
that are not yet prepared for the restriction. So, until then, we
temporarily use the single search path for both framework/vendor
executables.

Test: build & run
Change-Id: I806e9b4379bce96653b1dd3354b9f4801abb0411
2017-03-13 08:55:23 +09:00
Josh Gao
222272ece9 linker_memory: allow fallback allocator to be turned on and off.
Let the fallback allocator be used on multiple threads (as long as only
one thread is using it at once).

Bug: http://b/35858739
Change-Id: Id3e2fc6b7c093c6e56870524ffda28946de09e29
2017-03-08 16:43:59 -08:00
Josh Gao
69a5939eae linker: update dependencies.
Remove dependencies that are now linked directly into
libdebuggerd_handler_fallback via whole_static_libraries.

Test: m
Change-Id: I00e2edb2778c2986c533f97708252aa0996d0498
2017-03-08 16:43:59 -08:00
Dimitry Ivanov
3e0821d7c2 loader: anonymous ns initialization is not required
Anonymous namesapce is zygote-specific workaround and
is not really required for other binaries.

This change allows creating namespaces without initializing
anonymous namespace.

Test: bionic-unit-tests
Change-Id: I62adc39ad69ce56b3760d36f45e3c0487c438598
2017-03-07 11:02:10 -08:00
Dimitry Ivanov
77ad64267c Remove g_default_ld_paths global variable
Test: boot, run bionic-unit-tests
Change-Id: Id05d53475cbea6d62bd5fa1ab5e457ac82bab523
2017-03-06 13:02:29 -08:00
Dimitry Ivanov
35c8e3b125 Fix greylist exception to account for linked namespaces
Do not load second copy of libraries that are supposed to
be provided by linked namespaces. Also do not print
error in the log if caller tries to open shared library
using absolute path for apps targeting N+.

Bug: http://b/35454141
Bug: http://b/26833548
Bug: http://b/35338922
Test: run bionic-unit-tests --gtest_filter=dl*
Change-Id: Icf3aeedff18d287d2ba0b3df3808b100f3ef5f7a
2017-02-27 14:16:04 -08:00
Treehugger Robot
0b87362f53 Merge "loader: set PT_INTERP to itself" 2017-02-25 02:24:28 +00:00
Dimitry Ivanov
2a6955e040 loader: set PT_INTERP to itself
Some versions of kernel set AT_BASE to 0
if dynamic loader does not have PT_INTERP
set.

Bug: http://b/30739481
Test: run /system/bin/linker64 and /system/bin/linker
Change-Id: I1b67777166fe917d3ee1a97277045ca6f5db0084
2017-02-24 16:56:38 -08:00
Dimitry Ivanov
6391e1a44d libc: __system_property_set uses writev to write atomically
__system_property_set sometimes produces broken_pipe error
when trying to write a property.

This change improves error messages and uses writev() instead
of sequence of send() calls.

Bug: http://b/35381074
Test: bionic-unit-tests --gtest_filter=prop*
Change-Id: I7a5b169c015db4e6b720370e58662de8206d1086
2017-02-24 14:00:04 -08:00
Treehugger Robot
c84e8a507c Merge "Cope with argv[0] being null in the dynamic linker." 2017-02-23 03:29:43 +00:00
Elliott Hughes
30a36273ab Cope with argv[0] being null in the dynamic linker.
Somewhat unsurprisingly, very few commands are happy to be run like this,
in particular multiplexed commands like toybox. But that's no reason for
the linker to get in the way too.

Bug: http://b/33276926
Test: new test
Change-Id: I6dd71ea0183f4da83571039c2198ebb6ed38520e
2017-02-22 17:37:52 -08: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
Treehugger Robot
bc645ef068 Merge "Fix debug.ld for apps with long names and services" 2017-02-18 00:50:47 +00:00
Dimitry Ivanov
fbe54c4fe8 Fix debug.ld for apps with long names and services
1. There is no longer limit on property names - remove
   the trimming the name of the property.
2. Make debug.ld work for processes with names ending with ":something"
   This is naming convention for services:
   https://developer.android.com/guide/components/services.html

Bug: http://b/35338922
Bug: http://b/33926793
Test: manual - set ld.debug.app property for the app
Test: from http://b/35338922 and see that it works
Test: for the service as well.
Change-Id: Ic7c6d4edce4a5a22f144496d5c0a3e458217c6e4
2017-02-17 14:57:34 -08:00
Josh Gao
4509e0ec94 Merge changes from topic 'debuggerd_inproc'
* changes:
  linker: use fallback crash handler dumping.
  linker: add android_use_fallback_allocator.
2017-02-16 23:11:52 +00:00
Josh Gao
ec0dbc3782 linker: use fallback crash handler dumping.
Bug: http://b/34684590
Test: mma
Change-Id: I0801a83768f172308339ab2118e492b5df96acd0
2017-02-15 17:00:31 -08:00
Josh Gao
9ccccc1a95 linker: add android_use_fallback_allocator.
Add a function to enable a fallback allocator to use for crash handling
in a signal handler.

Bug: http://b/34684590
Test: crasher PR_SET_NO_NEW_PRIVS
Change-Id: Ifa5de636164f34b8cb2fdec4471c20f8516b6dbe
2017-02-15 17:00:16 -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
3b236ae294 Do not use std::vector in android_namespace_t::is_accessible
Avoid constructing vector and walking all the parents of a soinfo
to check if it is accessible. The most likely scenario that the
very first check returns true.

Bug: http://b/35313368
Test: bionic-unit-tests --gtest_filter=dl*:Dl*
Change-Id: I06c65cf61ed1c30e5e454a169de4c41038863587
2017-02-13 11:25:49 -08:00
Dimitry Ivanov
2cb4dfbb8c Merge "Replace public library list with shared lib sonames (part 2/2)" 2017-02-11 19:26:49 +00:00
Dimitry Ivanov
ec90e24d33 loader: fix d-tor call order
In the case when there are multiple dependencies on
the same library in the local_group the unload may
in some situations (covered now by tests) result
calling d-tors for some libraries prematurely.

In order to have correct call order loader checks if this
is last dependency in local group before adding it to BFS
queue.

Bug: http://b/35201832
Test: bionic-unit-tests --gtest_filter=dl*:Dl*
Test: bionic-unit-tests-glibc --gtest_filter=dl*
Change-Id: I4c6955b9032acc7147a51d9f09b61d9e0818700c
2017-02-10 16:11:51 -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
Dimitry Ivanov
7d429d3c48 Replace public library list with shared lib sonames (part 1/2)
Replace public library list with shared lib sonames
which are property of a link between namespaces

This change does not touch any external interfaces
so from outside it behaves almost as it was before

One significant difference is that there is no longer
need to preload public libraries.

Bug: http://b/26833548
Test: bionic-unit-tests --gtest_filter=dl*:Dl*
Change-Id: I57e44e18a9b4f07dcd6556436346be52f52b79d7
2017-02-09 23:26:44 -08:00
Dimitry Ivanov
8cbe97de7f Remove unnecessary memsets in linker allocators
Test: linker-unit-tests
Test: bionic-unit-tests --gtest_filter=dl*:Dl*
Change-Id: I96f983dba77c9cb5698a9eb2e51b33bc128c6dd7
2017-02-09 15:53:54 -08:00
Evgenii Stepanov
9886ea3e2d Merge "Fix CFI initialization crash on x86." 2017-02-03 01:47:15 +00:00
Evgenii Stepanov
68ecec1965 Fix CFI initialization crash on x86.
Third try.

Bug: 34752378
Test: bionic tests
Change-Id: I247c127489a8ee38404e104f28d916a704e35f36
2017-02-02 14:44:46 -08:00
Dan Albert
1fedfedda8 Merge "Exit failure if trying to load non-PIE." 2017-02-01 23:38:34 +00:00
Dimitry Ivanov
68e6c03081 Check overflows in c-tor instead of doing it in d-tor
Test: bionic-unit-tests --gtest_filter=dl*:Dl*
Change-Id: Id3b17a79732155b4e469c43c764afef1dfc59057
2017-02-01 12:55:11 -08:00
Dimitry Ivanov
3bd906146b Do not load second copy of a library into same namespace
This workaround was introduced in M in order to make sure
that linker loads libraries provided in apk in case a library
with the same name was loaded by the system.

This is no longer a problem starting with Android N because
app is using different namespace and therefore does not see
libraries loaded by the system.

Test: bionic-unit-tests --gtest_filter=dl*:Dl*
Change-Id: I9995258c0f361e8df35420682b84e85a0cb924b4
2017-02-01 09:43:09 -08:00
Evgenii Stepanov
beb3eb1790 Revert "Fix CFI initialization crash on x86."
Breaks aosp-master/sdk.

This reverts commit 4ccd4317f9.
2017-01-31 17:10:03 -08:00
Dan Albert
95e2e6f620 Exit failure if trying to load non-PIE.
Amazingly this was actually breaking the NDK's ability to build
libstdc++ for x86.

Test: mma
Bug: None
Change-Id: Iafa55c31fdeb35caca7d7d7a39a3e7afa0713557
2017-01-31 16:02:43 -08:00
Evgenii Stepanov
4ccd4317f9 Fix CFI initialization crash on x86.
Second try.

Bug: 34752378
Test: bionic tests
Change-Id: I0a7453154671918b2e6e72f0bb9074c29ceb0f34
2017-01-31 13:44:55 -08:00
Alex Cheung
6fcd7a7d28 Revert "Fix CFI initialization crash on x86."
This reverts commit be46d3871c.

Reverting due to broken build:

https://android-build.googleplex.com/builds/branch-dashboard/aosp-master?build_id=3687823

Change-Id: I30968398edd9a094fce878839ba0a002ed487a77
2017-01-31 04:19:50 +00:00
Evgenii Stepanov
be46d3871c Fix CFI initialization crash on x86.
Bug: 34752378
Test: bionic tests
Change-Id: If8e33f76a1a2d83356d818fed506ea624f579860
2017-01-30 14:29:48 -08:00
Dimitry Ivanov
451909da31 Remove dependency on libc.a from the linker
Provide stub for unused but needed symbol __find_icu_symbol
which is not included to libc_nomalloc.a.

Test: mm and boot
Change-Id: I57ca09c990556d1d401e2f4a75bc49b61b4cd85d
2017-01-26 17:08:01 -08:00
Evgenii Stepanov
636a2ecfbc [cfi] Handle large libraries correctly.
Fallback to unchecked if the shadow offset overflows int16_t.
This may happen when a library's data segment is larger than 256MB.

Also updated some comments.

Bug: 22033465
Test: bionic device tests

Change-Id: I8eef42f75099f24aed566499ff1731a0bbf01ff3
2017-01-20 14:23:20 -08:00
Evgenii Stepanov
082bec5b41 Merge "Runtime support for CFI" 2017-01-18 23:39:08 +00: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
Josh Gao
2a3b4fa6ec Rename libdebuggerd_client to libdebuggerd_handler.
Bug: http://b/30705528
Test: debuggerd_test
Change-Id: I625a9a2e7304d172873ba9344b74efa57ad7bdad
2017-01-17 15:11:46 -08:00
Park Ju Hyung
ab2c5752c3 linker: convert 'mov pc' instruction to 'bx'
From Linux 3.17 6ebbf2ce437b33022d30badd49dc94d33ecfa498:

    ARMv6 and greater introduced a new instruction ("bx") which can be used
    to return from function calls.  Recent CPUs perform better when the
    "bx lr" instruction is used rather than the "mov pc, lr" instruction,
    and this sequence is strongly recommended to be used by the ARM
    architecture manual (section A.4.1.1).

Signed-off-by: Park Ju Hyung <qkrwngud825@gmail.com>

Test: No regressions detected
Test: Passes full CTS run

Change-Id: Ie268f9893e3df0f68fbfe82a13f3c7cc5c5909d8
Signed-off-by: Alex Naidis <alex.naidis@linux.com>
2017-01-14 14:40:07 +00:00
Elliott Hughes
607d307b1f Dynamic linker errors should go to stderr.
Also add the missing \n to the end of the error.

Addresses review comment.

Bug: N/A
Test: manual
Change-Id: I7c997a71e6e02381d21ac762595ba90370db9d05
2017-01-09 14:44:28 -08:00
Elliott Hughes
3bdb31b51b Exit rather than abort if asked to run a non-PIE executable.
Each release we're asked to investigate tombstones from code that hasn't
been allowed to run on Android since L. This is just wasting our time,
and clearly the "obviousness" of aborting rather than exiting hasn't ensured
that all app developers rebuild their old binaries. In some cases it seems
like they run them "just in case" and don't care if they fail.

Bug: http://b/34112178
Test: ran libsupervisor.so from com.ss.android.article.news
Change-Id: I8a3f196c4755601a3888281566fbb7b817f01dca
2017-01-07 10:38:20 -08:00
Dimitry Ivanov
e30c17fb6e Downgrade dynamic section checks to warning
For apps targeting pre-O releases print warn about
invalid dynamic section.

Bug: http://b/33842263
Test: Start an app in question and check logs for warning.
Test: Run bionic-unit-test --gtest_filter=dl*:Dl*
Change-Id: I80bd51f2133b956fc04e20a6538cccd50118c1b8
2016-12-28 16:21:49 -08:00
Dimitry Ivanov
cf00d86935 Add a way to track all dlsym calls (contd.)
The followup for 4742abdcb5

Changes in this file got lost in the process of cherry-picking
the change across repositories.

Bug: http://b/29458203
Test: flash, set debug.ld.all to dlsym and check
      if there are messages in logcat

Change-Id: I4613908e46e75c5d9ec66396767f10fc6d3e9777
2016-12-14 14:30:37 -08:00
Dimitry Ivanov
4742abdcb5 Add a way to track all dlsym calls
Add dlsym option to debug.ld.all and debug.ld.app.<appname> which
enables logging of dlsym calls.

Bug: http://b/29458203
Test: flash, set debug.ld.all to dlsym and check
      if there are messages in logcat

Change-Id: I9cb815a38b5b98aac9ebe3ac1540bcdedd2e8db0
2016-12-12 16:36:12 -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
Colin Cross
10fffb4939 Fix linker_asan64 symlink
Soong now appends the suffix to the symlink, so the multilib-specific
symlink is no longer necessary.

Test: m -j out/target/product/angler/system/bin/linker_asan64
Test: Examine LOCAL_MODULE_SYMLINKS in out/soong/Android-aosp_angler.mk
Change-Id: I913a318bb31de3e630eebd2d68041a55ce3eccaf
2016-12-08 09:57:35 -08:00
Dimitry Ivanov
fc0d48078a loader: stop linking libdl/c/m into the loader
This is to prevent situations when libgcc.a calls into incorrect
implementation of dl_iterate_phdr.

Bug: http://b/27106625
Test: build && run bionic-unit-tests --getst_filter=dl*:Dl*
Change-Id: I4cba8c4a156f91f17ba3d95c39cb80f9b70c9d8f
2016-12-06 11:15:24 -08:00