Commit graph

121 commits

Author SHA1 Message Date
Peter Collingbourne
ea11be0cc8 Add bootstrap directory to bootstrap linker's search path.
A proposed set of changes:
https://android-review.googlesource.com/q/topic:"no-dup-hwasans"

will cause the HWASAN runtime to be moved from /system/lib64 to
/system/lib64/bootstrap. This causes a problem in the case where libc is built
with HWASAN but init is not built with HWASAN. In this case, libc.so will have
a DT_NEEDED dependency on the HWASAN runtime but init will not. Currently,
init and other bootstrap executables arrange to load bootstrap libraries by
setting rpath, but rpath only has an effect on libraries directly depended
on by the main executable, not libraries indirectly depended on by it. This
means that the loading of the HWASAN runtime will fail.

Instead of relying on rpath to find the bootstrap libraries, modify the
bootstrap linker so that it searches the bootstrap library directory after
searching the rpath.

Change-Id: I297be32e04ecd316ee12b8e694588e1249e2bb89
2019-05-16 16:10:41 -07:00
Dmytro Chystiakov
e712cd185f Fix Bionic dlfcn.dladdr_libc test case for 64bit binary translations
64bit libraries should be located in /system/lib64 directory
instead of /system/lib for platforms with emulated arhitecture.

This patch updated ALTERNATE_PATH_TO_SYSTEM_LIB for 64bit values

Test: run cts -m CtsBionicTestCases -t dlfcn.dladdr_libc

Change-Id: I29d6d36d15d7e61818c7ed1cfd0786745d9ae6a2
Signed-off-by: Dmytro Chystiakov <dmytro.chystiakov@intel.com>
2019-03-29 13:49:12 -07:00
Elliott Hughes
e08288465e Merge "bionic tests: use GTEST_SKIP." 2019-03-27 02:05:57 +00:00
Elliott Hughes
bcaa454d32 bionic tests: use GTEST_SKIP.
Also be a bit more to the point in our messages, focusing on "why" not
"what".

Test: ran tests
Change-Id: I297806c7a102bd52602dcd2fcf7a2cd34aba3a11
2019-03-12 10:26:39 -07:00
Peter Collingbourne
b39cb3c31d linker: Handle libraries with disjoint mappings correctly.
It's possible and sometimes beneficial for a library to have disjoint mappings
and for other libraries to be mapped into the gap between the mappings using
ANDROID_DLEXT_RESERVED_ADDRESS. See for example the proposal for partitioning
in lld [1].

Because the find_containing_library and do_dl_unwind_find_exidx functions use
a simple bounds check to figure out whether a pointer belongs to a library
they will, given a pointer into a library mapped into the gap of a library
with disjoint mappings, return a pointer to the soinfo for the outer library
instead of the inner one, because the outer library will appear before the
inner one in the solist.

From a user perspective this means that we won't be able to unwind the inner
library's frames on 32-bit ARM with libgcc, dladdr() will return information
for the outer library given a pointer to the inner one and dlopen() et al will
use the linker namespace of the outer library when called from the inner one
(although they will usually be the same).

To make this work correctly, make it so that once find_containing_library
sees a match for the bounds check, it examines the library's PT_LOADs to
make sure that there is a mapping for the given address. This is similar
to how libgcc and libunwind_llvm already handle finding the PT_GNU_EH_FRAME
on non-ARM32 platforms [2,3]. do_dl_unwind_find_exidx is reimplemented in
terms of find_containing_library.

[1] http://lists.llvm.org/pipermail/llvm-dev/2019-February/130583.html
[2] e739ac0e25/libunwind/src/AddressSpace.hpp (L523)
[3] https://android.googlesource.com/toolchain/gcc/+/master/gcc-4.9/libgcc/unwind-dw2-fde-dip.c#294

Test: /data/nativetest{,64}/bionic-unit-tests/bionic-unit-tests on walleye-userdebug
Change-Id: I368fe6ad3c470b3dff80f7d9b04253566d63a7d2
2019-03-08 18:34:34 -08:00
Ryan Prichard
06d2d790ad Add tests for dynamic ELF TLS
Bug: http://b/78026329
Test: bionic unit tests
Merged-In: I508fa38b331eeec7dae53039b4b1ec6cedea3034
Change-Id: I508fa38b331eeec7dae53039b4b1ec6cedea3034
2019-01-29 08:35:10 +00:00
Ryan Prichard
5f5a1929e8 Disable the dlfcn.dlopen_library_with_ELF_TLS test
This test is verifying that an ELF TLS solib can't be loaded, but once
ELF TLS is implemented, it *can* be loaded. Removing the test requires
coordinated changes with internal test suites.

I could modify the test to verify that the solib was successfully loaded,
but support for dynamic ELF TLS appears across a few different CLs.

Bug: http://b/78026329
Test: bionic unit tests
Change-Id: If8cd798f456568a5c76310b754cea48ca8edaa82
2019-01-25 17:53:01 -08:00
Ryan Prichard
fb8730d495 Handle R_GENERIC_TLS_TPREL relocations
This relocation is used for static TLS's initial-exec (IE) accesses.

A TLS symbol's value is its offset from the start of the ELF module's
TLS segment. It doesn't make sense to add the load_bias to this value,
so skip the call to soinfo::resolve_symbol_address.

Allow TLS relocations to refer to an unresolved weak symbol. In that case,
sym will be non-zero, but lsi will be nullptr. The dynamic linker resolves
the TPREL relocation to 0, making &missing_weak_symbol equal the thread
pointer.

Recognize Gold-style relocations to STB_LOCAL TLS symbols/sections and
issue an error.

Remove the "case R_AARCH64_TLS_TPREL64", because the R_GENERIC_TLS_TPREL
case handles it.

Remove the no-op R_AARCH64_TLSDESC handler. It's better to issue an error.
dlopen_library_with_ELF_TLS now fails with a consistent error about an
unimplemented dynamic TLS relocation.

Bug: http://b/78026329
Test: bionic unit tests (elftls tests are added in a later CL)
Change-Id: Ia08e1b5c8098117e12143d3b4ebb4dfaa5ca46ec
2019-01-17 00:45:55 -08:00
Christopher Ferris
6d2c0bdf6e Move isolated test runner out of bionic.
Use a global gtest isolation runner rather than the custom one in
bionic.

Test: Ran all unit tests and verified same behavior before and after.

Change-Id: I24a7cf17cf8e018d0f51969c64b53ce9059cc779
2018-09-27 22:22:17 -07:00
dimitry
55547db434 Add secondary counter in place of tls_nodelete flag
The tls_nodelete state should apply to load_group not
isolated soinfo. This actually also means that multiple
soinfos may have tls_counter on their dso_handles.

This change replaces TLS_NODELETE flag with secondary counter.
Note that access to the secondary counter (located inside soinfo)
is pretty expensive because it requires soinfo lookup by dso_handle
whereas dso_handle counter is much faster. This is why it is updated
only when dso_handle counter starts or hits 0.

Bug: http://b/80278285
Test: bionic-unit-tests --gtest_filter=dl*
Change-Id: I535583f6714e45fa2a7eaf7bb3126da20ee7cba9
2018-05-30 10:56:59 +02:00
Ryan Prichard
6814028920 Define DT_ANDROID_REL[A] correctly for a test
DT_ANDROID_REL is 0x6000000f, but this code defined it as 0x60000002.
DT_ANDROID_RELA is 0x60000011, but this code defined it as 0x60000004.

compat_elf_hash_and_relocation_tables tests that certain shared libraries
are linked with ordinary relocations and not with packed relocations. A
shared library will only have one kind of relocation table, so the test
mostly still worked by requiring DT_REL[A].

Previously, this test would have allowed libdl.so to have packed
relocations.

Test: /data/nativetest/bionic-unit-tests/bionic-unit-tests \
  --gtest_filter=dlext.compat_elf_hash_and_relocation_tables
Test: manual
Bug: none
Change-Id: Ic8aa919a68fb6ed01a7994b69c0c7dd3798d6b67
2018-05-23 14:40:40 -07:00
Ryan Prichard
470b66644b Break libdl.so and ld-android.so's dependency on libc.so.
* Specify "nocrt: true" to avoid calling __cxa_finalize.

 * Define a dummy __aeabi_unwind_cpp_pr0 for arm32.

Bug: b/62815515
Bug: b/73873002
Test: boot AOSP hikey960-userdebug
Test: run ndk_cxa_example in special /system/bin/debug namespace
Test: run Bionic unit tests
Change-Id: I59bcb100a2753286b59c51a47d7a183507219a07
2018-03-30 13:56:03 -07:00
Elliott Hughes
9724e93c19 Reject .so files using ELF TLS.
Bug: http://b/74361956
Test: ran tests
Change-Id: I53e71252eb08c607c2c436dcba433374c8c53887
2018-03-23 18:46:07 -07:00
Elliott Hughes
9076b0c4e7 Be clearer about linker warnings.
Explicitly say "warning" for warnings, explicitly say what action
we're going to take (such as "(ignoring)"), always provide a link to
our documentation when there is one, explicitly say what API level the
behavior changes at, and explicitly say why we're allowing the misbehavior
for now.

Bug: http://b/71852862
Test: ran tests, looked at logcat
Change-Id: I1795a5af45deb904332b866d7d666690dae4340b
2018-02-28 12:37:28 -08:00
dimitry
153168c855 Fix RTLD_NEXT/DEFAULT lookup
RTLD_NEXT/DEFAULT lookup should not skip handle lookup
in the case when the load group is RTLD_GLOBAL.

Note that there is a difference between load group is local group.
The local group includes externally referenced libraries where
the load group does not. The external reference in this context is a
DT_NEEDED library that belongs to a previously loaded group.

Bug: http://b/72237367
Test: bionic-unit-tests --gtest_filter=dl*
Change-Id: I8997cc961c13a5396f1756161798b45ed1cab16c
2018-02-20 17:10:00 +01:00
Elliott Hughes
da1bb11340 The VDSO soname varies by architecture.
From http://man7.org/linux/man-pages/man7/vdso.7.html:

       user ABI   vDSO name
       ─────────────────────────────
       aarch64    linux-vdso.so.1
       arm        linux-vdso.so.1
       ia64       linux-gate.so.1
       mips       linux-vdso.so.1
       ppc/32     linux-vdso32.so.1
       ppc/64     linux-vdso64.so.1
       s390       linux-vdso32.so.1
       s390x      linux-vdso64.so.1
       sh         linux-gate.so.1
*      i386       linux-gate.so.1
*      x86-64     linux-vdso.so.1
       x86/x32    linux-vdso.so.1

Note that Android "x86" is Linux's "i386", which is the odd one out
amongst Android's supported architectures.

Bug: http://b/72831787
Test: ran tests
Change-Id: I0a28127af042e2fd7673f24bbb30f8a50556cf96
2018-02-16 10:05:08 -08:00
Ian Pedowitz
b6310c2aa7 Fixing app compat issue b/72143978
This is a squash revert of a4a4854 and 1b0f2b4

  Revert "Remove a test for backwards compatibility we no longer support."

  This reverts commit a4a485454a.

  # This is the commit message #2:

  Revert "Remove obsolete workaround."

  This reverts commit 1b0f2b49d5.

Bug: 72143978
Bug: 24465209
Test: Tested failing case on sailfish, reverted back all CL's since
Test: 3471433 for b/24465209 and apps open
2018-01-18 16:26:45 -08:00
Elliott Hughes
a4a485454a Remove a test for backwards compatibility we no longer support.
Bug: http://b/24465209
Test: ran tests
Change-Id: I80bb86379f108d88a6f4abb031450d13ac87c7b9
2018-01-12 15:27:48 -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
109040c868 Add test checking library unload on dlclose
Bug: http://b/68262627
Test: Run bionic-unit-tests --gtest_filter=dl*:Dl*
Change-Id: Ied85bc4ab37524cfcdbc33fd6c6e69b8d87ee08a
2017-11-07 10:51:59 +01:00
Raj Mamadgi
527229cb72 Fix for dlfcn.rtld_next_from_library.
Using fclose to get the same address for the test assertion because
Samsung already uses LD_PRELOAD to intercept `close`.

Bug: http://b/67978141
Bug: http://b/68855476
Test: ran tests
Change-Id: I2da463e8b27e0db5cb1ba370d30f0402d7531396
Signed-off-by: Raj Mamadgi <r.mamadgi@samsung.com>
2017-11-03 15:00:09 -07:00
Jiyong Park
01162f2469 Fix: linker segfault on dlopen of a DF_1_GLOBAL so
Added the missing null check routine.

Bug: 67755729
Test: dlfcn.dlopen_df_1_global added and it passes
Change-Id: Ibe8db18b0b5a481e2e9937041abef6d6b179dd87
2017-10-19 15:13:54 +09:00
dimitry
b9555a9251 Fix dlopen_vdso test
arm32 is still missing vdso (at least on some kernels).
This commit adds explicit check for it and skip the test
if AT_SYSINFO_EHDR is not set.

Test: run 32bit bionic-unit-tests --gtest_filter=dlfcn.dlopen_vdso on angler
Change-Id: I7fae78c6a4f819601a4ac9e8e1da53ff07c833ff
2017-10-11 18:04:05 +02:00
dimitry
c18de1bd47 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
2017-09-26 14:34:18 +02:00
Dimitry Ivanov
db6ab3d5ec Enable dlfcn.dt_runpath_absolute_path in glibc tests
dlfcn.dt_runpath_absolute_path no longer fails when
running bionic-unit-tests on glibc

Bug: http://b/25320359
Test: bionic-unit-tests-glibc --gtest_filter=dlfcn.dt*
Change-Id: Ia0ecf43293cb0fed28516fd8cb87e7f5f2d6e648
2017-06-27 11:02:51 -07:00
Elliott Hughes
8ad4093659 Add #defines for some key enums.
Building ruby actually trips over both of these:

* if the RTLD_ constants aren't #defined, it uses its own incorrect values.

* if the REG_ constants aren't #defined, it confuses x86 with x86-64.

In all other places where we have enums in our headers, we already match
existing glibc practice.

Bug: http://b/62531921
Test: builds
Change-Id: I5b3aab25a1a24611bdc58f2eda4104a78e9f841c
2017-06-15 15:12:29 -07:00
Dimitry Ivanov
c42b4bb097 Remove known failures from arm ifunc tests
Since clang does not produce IRELATIVE relocations
this test started passing when we switched away from gcc
This is still a problem because it now leads to
situation where static ifuncs become globally visible
but this is a different problem.

Test: bionic-unit-tests --gtest_filer=dl*
Change-Id: Id27ba5093b88519c00acbc43ab8a991a671a9f51
2017-05-03 11:01:00 -07:00
Dimitry Ivanov
21975b2861 Add ifunc for variable test-case
Also move ifunc tests to clang and c++.

Test: bionic-unit-tests --gtest_filter=dlfcn.ifunc*
Change-Id: I008c4fc01470c8e4d314003c03a2b63ff9bf7fd8
2017-05-02 16:35:20 -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
Dimitry Ivanov
fc32dcb128 Disable compat_elf_hash_and_relocation_tables test for x86
Bug: http://b/36571076
Test: run bionic-unit-tests on fugu
Change-Id: I2f901bc99e55f15b06fe6a5b0d7a125d1b8241a8
2017-03-24 10:58:23 -07: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
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
ea8f396c59 Add test checking init/fini call order
This test is checking that loader complies with the order described in
http://www.sco.com/developers/gabi/latest/ch5.dynamic.html#init_fini

Bug: http://b/35201832
Test: bionic-unit-tests --gtest_filter=dl*:Dl*
Test: bionic-unit-tests-glibc --gtest_filter=dl*
Change-Id: I4cdf878c043112442c191e82aa9f5d5077e4d8c4
2017-02-09 14:07:05 -08:00
Victor Khimenko
14b9d7199c Fix bionic-unit-tests in arch with binary translator
If binary translator is involved then libc is not place in /system/lib
or /system/lib64.  It's placed into /syste/lib/arm, /system/lib/arm64,
etc.  FUGU is an example of such an architecture.

Support both cases by picking right path at runtime.

Test: run bionic-unit-tests --gtest_filter=dlfcn.dladdr_libc
Change-Id: I8345c0f6c19376ebe5106f9670fd2addeb9b9080
2017-01-25 20:57:48 +01:00
Dimitry Ivanov
01c888c857 Mark ifunc tests failing on arm as known failures
Bug: http://b/27930475
Test: run bionic-unit-tests on arm and arm64
Change-Id: I5084b6a5ef4b56ca9985da63a5e6896f771810f0
2017-01-23 14:52:07 -08:00
Dimitry Ivanov
59dd61573f Merge "Add test for elf-hash and packed relocations" 2016-12-15 18:27:22 +00:00
Dimitry Ivanov
d5b578ac15 Add test for empty symbol lookup
Check that dlsym(handle, "") fails.

Bug: http://b/33530622
Test: bionic-unit-tests --gtest_filter=dlfcn*
Test: bionic-unit-tests-glibc --gtest_filter=dlfcn*
Change-Id: Iae572bd1d9b798be619c5018de2a5450bf37977e
2016-12-14 15:16:56 -08:00
Dimitry Ivanov
ac4bd2f793 Add test for elf-hash and packed relocations
This adds CTS test for system libraries to support
workaround for http://b/24465209: some apps require
a subset of system libs to have elf-hash and not to
use packed relocations.

Bug: http://b/32917341
Bug: http://b/24465209
Test: bionic-unit-tests --gtest_filter=Dl*:dl*
Change-Id: Ia0bc28506b1f1f97d4cf902d73b0769e2815fed3
2016-12-14 11:16:21 -08:00
Dimitry Ivanov
d0b5c3ad65 Fix bionic-unit-tests-glibc
Also add another test for dlsym(RTLD_NEXT, ..)

Bug: http://b/33106624
Test: run bionic-unit-tests-glibc and bionic-unit-tests
Change-Id: I340165d66bf2360b0e3273d3561a08cb5e7bd025
2016-11-28 13:09:19 -08:00
Dimitry Ivanov
c7365eb2fa Improve dlerror_concurrent test
Add a test to check if result is thread-local, not only buffer.

Test: run bionic-unit-tests
Change-Id: Ia95f88c0d76aa86f7f439836393abd67a57dd396
2016-11-17 14:23:24 -08:00
Dimitry Ivanov
816676e70d Add test for libraries with textrels
Make sure android fails to load them.

Bug: http://b/30795430
Test: bionic-unit-tests --gtest_filter=dlfcn.dlopen_invalid*
Test: cts-tradefed run singleCommand cts --skip-preconditions -m CtsBionicTestCases
Change-Id: Id0ebdf336b2f297007479ceb1bbccf778a7ca3f2
2016-10-19 14:21:42 -07:00
Dimitry Ivanov
927877c7d3 bionic-unit-tests: remove dependency on ANDROID_DATA
Replace references to ANDROID_DATA enviroment variable with references
to g_testlib_root.

Bug: http://b/22182538
Test: build and run bionic-unit-tests --gtest_filter=dl*:Dl*
Test: make cts && cts-tradefed run singleCommand cts --skip-preconditions -m CtsBionicTestCases
Change-Id: I5667e991551cec55b9b664f2f0063039671ff34b
2016-10-10 13:56:20 -07:00
Dimitry Ivanov
708589f5e8 bionic-unit-tests: Create symlinks in runtime
Instead of creating symlinks in build time and then relying
on usage of adb sync (adb push follows symlinks) - create
them in test run time.

Test: mm && run bionic-unit-tests --gtest_filter=dl*:Dl*
Bug: http://b/22182538
Change-Id: I9d2a873e3ba303533c14ba5e3b779e4a67925462
2016-10-10 04:41:56 -07:00
Dimitry Ivanov
a36e59bb99 Move test libraries under /data/nativetests
Move libraries used in bionic-unit-tests out of system partition to
/data/nativetests../bionic-loader-test-libs

Bug: http://b/22182538
Test: build bionic and run bionic-unit-tests
Change-Id: I170177bef782839d0b4970ae4418bf54d0a77836
2016-09-02 14:27:47 -07:00
Nikola Veljkovic
44a654446e [mips] Add missing linker shdr tests
Test: bionic-unit-tests for mips, mips64.
Change-Id: I8ed5f03df8d129e74fa04be2b203bd113a381888
2016-08-16 18:52:06 +00:00
Treehugger Robot
3b2d331e77 Merge "linker: add test for zeroed out shdr_table_" 2016-08-15 23:23:26 +00:00
Treehugger Robot
4154b77285 Merge "linker: add test for zero shdr offset" 2016-08-15 22:01:30 +00:00
Dimitry Ivanov
559583469c linker: add test for zeroed out shdr_table_
Bug: http://b/30795430
Change-Id: I86b658d01b64670d3e702ddb1d3f9db4f75d784f
Test: bionic-unit-tests --gtest_filter=dlfcn.dlopen_invalid*
2016-08-15 14:06:04 -07:00
Treehugger Robot
63ccb1bdac Merge "[MIPS] Fix bionic test build" 2016-08-15 21:00:47 +00:00
Dimitry Ivanov
4623044517 linker: add test for zero shdr offset
Bug: http://b/30795430
Change-Id: I03853257c4b632ad9daaf1e90f9620678397cff0
Test: bionic-unit-tests --gtest_filter=dlfcn.dlopen_invalid*
2016-08-15 13:42:47 -07:00