History log of /bionic/linker/linker_main.cpp
Revision Date Author Comments
69c68c46ac18a440bf1c0447d8343a6dbad595f1 09-May-2018 dimitry <dimitry@google.com> vdso should be available in all namespaces

vdso should be available in all namespaces when present. This
bug went undetected because the way libc currently uses vdso (it
does all the lookups itself). This makes it available for the
programs that want to take advantage by dlopening it.

Bug: http://b/73105445
Bug: http://b/79561555
Test: adb shell /data/nativetest/arm/bionic-unit-tests/bionic-unit-tests --gtest_filter=dl.exec_with_ld_config_file
Test: adb shell /data/nativetest/bionic-unit-tests/bionic-unit-tests --gtest_filter=dl*
Change-Id: I8eae0c9848f256190d1c9ec85d10dc6ce383a8bc
965d06da1ed957c349dbdfcc7831b462b757bf85 28-Nov-2017 dimitry <dimitry@google.com> Fix logic in loading dependencies crossing namespace boundaries

This change addresses multiple problems introduced by
02586a2a34e6acfccf359b94db840f422b6c0231

1. In the case of unsuccessful dlopen the failure guard is triggered
for two namespaces which leads to double unload.

2. In the case where load_tasks includes libraries from 3 and more
namespaces it results in incorrect linking of libraries shared between
second and third/forth and so on namespaces.

The root cause of these problems was recursive call to find_libraries.
It does not do what it is expected to do. It does not form new load_tasks
list and immediately jumps to linking local_group. Not only this skips
reference counting it also will include unlinked but accessible library
from third (and fourth and fifth) namespaces in invalid local group. The
best case scenario here is that for 3 or more namesapces this will
fail to link. The worse case scenario it will link the library
incorrectly with will lead to very hard to catch bugs.

This change removes recursive call and replaces it with explicit list of
local_groups which should be linked. It also revisits the way we do
reference counting - with this change the reference counts are updated after
after libraries are successfully loaded.

Also update soinfo_free to abort in case when linker tries to free same
soinfo for the second time - this makes linker behavior less undefined.

Test: bionic-unit-tests
Bug: http://b/69787209
Change-Id: Iea25ced181a98c6503cce6e2b832c91d697342d5
27242c642eac64d4d47a1899af341170c9456d79 21-Oct-2017 Josh Gao <jmgao@google.com> Actually correctly call vector::erase after remove_if.

vector::erase(iterator) erases the element that that iterator points
to, vector::erase(iterator a, iterator b) erases the range [a, b), with
a == b being a no-op.

Test: LD_PRELOAD=libc.so sh
Change-Id: I6a85c1cfaa8eb67756cb75d421f332d5c9a43a33
44f6e189d97fa3e07e2a95605d4ecd76bc73b103 19-Oct-2017 Josh Gao <jmgao@google.com> Correctly call vector::erase after std::remove_if.

std::remove_if moves removed elements to the end, without actually
resizing the collection. To do so, you have to call erase on its
returned iterator.

Test: mma
Change-Id: Iae7f2f194166408f2b101d0c1cfc95202d8bbe63
04f7a798cff26c1809138d329e0a5717efc2b3c5 29-Sep-2017 dimitry <dimitry@google.com> Replace abort with exit(1) in __linker_cannot_link

Bug: http://b/67038409
Test: bionic-unit-tests
Change-Id: I7d39b44f2da8c5111ac8a9faf3416f19d5a35c05
c18de1bd47a558c9a24c6a4645df27df2c4738b4 26-Sep-2017 dimitry <dimitry@google.com> Link vdso before linking the main executable

Also set linked flag after it is linked and
call constructors. Set RTLD_NODELETE flag to
prevent accidental unloads.

Test: bionic-unit-tests --gtest_filter=dl*:Dl*
Test: bionic-unit-tests-glibc --gtest_filter=dl*
Change-Id: Ib2178849b918cbefd6f8fcfe6d1f78889fe0bf76
7b0af7ad82fcf88e800d1a553d81fda29dc064bd 16-Sep-2017 Elliott Hughes <enh@google.com> Always log errno when aborting.

(Where errno is relevant.)

Also consistently use -1 as the fd for anonymous mmaps. (It doesn't matter,
but it's more common, and potentially more intention-revealing.)

Bug: http://b/65608572
Test: ran tests
Change-Id: Ie9a207632d8242f42086ba3ca862519014c3c102
7abea57ba599b9b114031ae33699b5d7fba8cc97 29-Aug-2017 dimitry <dimitry@google.com> 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
34a4acd801fbd401fcc3c62928effac7b161b1d8 19-May-2017 Jiyong Park <jiyong@google.com> linker: the global group is added to all built-in namespaces

With ld.config.txt, we now have multiple built-in namespaces other than
the default namespace. Libs (and their dependents) listed in LD_PRELOAD
must be visible to those additional namespaces as well.

This also adds a debugging only feature: path to the linker config file
can be customized via LD_CONFIG_FILE environment variable. This works
only for debuggable builds.

Bug: 38114603
Bug: 62815515
Test: 1. ./external/compiler-rt/lib/asan/scripts/asan_device_setup --lib
prebuilts/clang/host/linux-x86/clang-stable/lib64/clang/5.0/lib/linux
2. enable talkback shortcut
3. in the home screen, hold vol-up/down together
4. device does not reboots and talkback shortcut is toggled
Test: bionic-unit-tests and linker-unit-tests successful

Merged-In: I9a03591053f4a9caea82f0dcb23e7a3d324bb9bd
Change-Id: I9a03591053f4a9caea82f0dcb23e7a3d324bb9bd
(cherry picked from commit 02586a2a34e6acfccf359b94db840f422b6c0231)
02586a2a34e6acfccf359b94db840f422b6c0231 19-May-2017 Jiyong Park <jiyong@google.com> linker: the global group is added to all built-in namespaces

With ld.config.txt, we now have multiple built-in namespaces other than
the default namespace. Libs (and their dependents) listed in LD_PRELOAD
must be visible to those additional namespaces as well.

This also adds a debugging only feature: path to the linker config file
can be customized via LD_CONFIG_FILE environment variable. This works
only for debuggable builds.

Bug: 38114603
Bug: 62815515
Test: 1. ./external/compiler-rt/lib/asan/scripts/asan_device_setup --lib
prebuilts/clang/host/linux-x86/clang-stable/lib64/clang/5.0/lib/linux
2. enable talkback shortcut
3. in the home screen, hold vol-up/down together
4. device does not reboots and talkback shortcut is toggled
Test: bionic-unit-tests and linker-unit-tests successful

Change-Id: I9a03591053f4a9caea82f0dcb23e7a3d324bb9bd
ad2d0380a69db3066d49c5a67b85d6858236012f 31-Jul-2017 Elliott Hughes <enh@google.com> Clean up linker fatals slightly.

Use __linker_cannot_link more consistently, and fix a comment.

Bug: http://b/22798163
Test: ran tests
Change-Id: Id6d868f459997eaa67b8cbbf85b0b0f2749bf43d
f9abbf69838bd8649d51fe3b8b6550fc14462757 06-Jul-2017 dimitry <dimitry@google.com> The ifdef check for AT_SYSINFO_EHDR is no longer needed

AT_SYSINFO_EHDR is present in all architectures

Test: make
Change-Id: I0f4c115bb48e47ea156e7fca936960f5f10c618e
705910094d07ddfc5a3b7a4baab58b0a94bcc691 28-Jun-2017 George Burgess IV <gbiv@google.com> bionic: fix assorted static analyzer warnings

Warnings:

bionic/libc/bionic/fts.c:722:5: warning: Null passed to a callee that
requires a non-null 1st parameter

bionic/libc/bionic/sched_cpualloc.c:34:25: warning: Result of 'malloc'
is converted to a pointer of type 'cpu_set_t', which is incompatible
with sizeof operand type 'unsigned long'

bionic/linker/linker_main.cpp:315:7: warning: Access to field 'e_type'
results in a dereference of a null pointer (loaded from variable
'elf_hdr')

bionic/linker/linker_main.cpp:493:66: warning: Access to field 'e_phoff'
results in a dereference of a null pointer (loaded from variable
'elf_hdr')

bionic/linker/linker_main.cpp:90:14: warning: Access to field 'next'
results in a dereference of a null pointer (loaded from variable 'prev')

Bug: None
Test: mma; analyzer warnings are gone. CtsBionicTestCases pass.
Change-Id: I699a60c2c6f64c50b9ea06848a680c98a8abb44a
cd510cbed9dc1e1b65b9d34676fdf6d85101f22c 01-Jun-2017 Dimitry Ivanov <dimitry@google.com> Make dl_iterate_phdr return correct name for first entry

Test: bionic-unit-tests --gtest_filter=link*
Change-Id: Ib3f1e0fbc76fed9a5f27ffdd9bbf847a3e8d3665
7a3681e5b6c39bc2b3b62031ca5941dbf7bc4e63 25-Apr-2017 Christopher Ferris <cferris@google.com> 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
4cabfaad340c957ff691cfbc420b29da805c5dd8 07-Mar-2017 Dimitry Ivanov <dimitry@google.com> 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
9b1cc4bb9cd84c2a52b8183a418e9dbb41f59959 24-Mar-2017 Dimitry Ivanov <dimitry@google.com> 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
2a6955e040f24b31a2dfe829f47e35ac91733489 23-Feb-2017 Dimitry Ivanov <dimitry@google.com> 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
7d429d3c480166e1013bcdf68f4be479209aa509 02-Feb-2017 Dimitry Ivanov <dimitry@google.com> 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
95e2e6f6204ea02de9e0dad9bd274e3c5d51a88c 01-Feb-2017 Dan Albert <danalbert@google.com> 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
0a3637d3eb2424d8e825ad1825f843450a888406 06-Jul-2016 Evgenii Stepanov <eugenis@google.com> 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
2a3b4fa6ec9ab3d4604860b0bdd3766c9f5c44f4 27-Oct-2016 Josh Gao <jmgao@google.com> Rename libdebuggerd_client to libdebuggerd_handler.

Bug: http://b/30705528
Test: debuggerd_test
Change-Id: I625a9a2e7304d172873ba9344b74efa57ad7bdad
607d307b1f4562219393dea3cbc6ea47b46f1650 09-Jan-2017 Elliott Hughes <enh@google.com> 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
3bdb31b51b353d12e482d28d6ffe115944f8819e 07-Jan-2017 Elliott Hughes <enh@google.com> 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
d9e427cf41893377dcdd0650ba20ff7cf7d72209 23-Nov-2016 Dimitry Ivanov <dimitry@google.com> 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
dcb846cb4978130d5db6b795e22e08b65e73f3cd 06-Dec-2016 Andreas Gampe <agampe@google.com> Revert "Bionic loader is no longer hijacking libdl.so"

This reverts commit c12acef96bd80c419654e159e1dc24a69513a86d.

Breaks the Mips build.

Bug: 27106625
Change-Id: I27edb7114065c36e1b618e387530d58189cdb184
c12acef96bd80c419654e159e1dc24a69513a86d 23-Nov-2016 Dimitry Ivanov <dimitry@google.com> 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
7ec52b12efc1c4ed9cd83ba8c95fab5bbf39aaf4 29-Nov-2016 Dan Willemsen <dwillemsen@google.com> Enable libc/libdl/libm/linker for host bionic

Disables debuggerd integration unless building for android.

Bug: 31559095
Test: Diff out/soong/build.ninja before/after, only change is moving
linker's libdebuggerd_client static lib to the beginning of the
list.
Test: lunch aosp_arm64-eng; mmma -j bionic
Change-Id: I62e725f7a9b98b7fe31637d0a835fd5846b0aff0
3f6605754464c0856862c4d66ed03227a60a6f4d 09-Sep-2016 Dimitry Ivanov <dimitry@google.com> linker: Refactoring step 3 of many

Extract linker executable specific code to linker_main.cpp;
this part of code does not have a place in libdl.a/so.

Bug: http://b/14998480
Bug: http://b/30706810
Test: mm && run bionic-unit-tests
Change-Id: I90f7475e93a919b0f9525da22928089ad35b8f6c