Commit graph

27499 commits

Author SHA1 Message Date
Elliott Hughes
0159b64aa5 Allow more leeway to fix sys_time.gettimeofday flakiness.
Bug: http://b/121156651
Test: ran tests
Change-Id: Ieb8ee481ea3572533823e6cb0eab4ec089a38e44
2019-01-18 08:20:55 -08:00
Ryan Prichard
314c0f7989 Merge "Fix soinfo_tls::module dangling reference" 2019-01-18 04:15:07 +00:00
Ryan Prichard
bf427f4225 Fix soinfo_tls::module dangling reference
The field was pointing into an element of an std::vector, but the address
of a vector element is invalidated when the vector is resized.

This bug was caught by the new elftls.shared_ie and
elftls_dl.dlopen_shared_var_ie tests.

Bug: http://b/78026329
Test: bionic unit tests
Change-Id: I7232f6d703a9e339fe8966a95b7a68bae2c9c420
2019-01-17 17:13:53 -08:00
Josh Gao
190626872a Merge "linker: only generate log messages when logging is enabled" 2019-01-18 00:50:23 +00:00
Ryan Prichard
9a238653c1 Merge changes Ia08e1b5c,I60e589dd,Ib7edb665,Ibf1bf5ec,Ibd623857
* changes:
  Handle R_GENERIC_TLS_TPREL relocations
  Avoid a dlopen abort on an invalid TLS alignment
  Initialize static TLS memory using module list
  Record TLS modules and layout static TLS memory
  StaticTlsLayout: add exe/tcb and solib layout
2019-01-17 23:10:51 +00:00
Tim Murray
a022034da2 linker: only generate log messages when logging is enabled
Avoids some unnecessary work during dlopen/dlclose/dlsym for most
cases.

Bug: 122471935
Test: fewer page faults during app startup
Change-Id: Ie886e1e671066af3c6f3a895f9a8126f209d6660
2019-01-17 14:24:14 -08:00
Treehugger Robot
1f6adf5863 Merge "Allow more leeway to fix time.clock_gettime flakiness." 2019-01-17 22:15:33 +00:00
Martijn Coenen
de70b72b4f Merge "Update getpwnam() tests to correctly handle new app zygote uids." 2019-01-17 20:49:19 +00:00
Elliott Hughes
8dff0bb66b Allow more leeway to fix time.clock_gettime flakiness.
Bug: http://b/121156651
Test: ran tests
Change-Id: Ic949763e56c46f05ed2565ca4465a15c7ecf768c
2019-01-17 12:32:32 -08:00
Martijn Coenen
f9d2299ee2 Update getpwnam() tests to correctly handle new app zygote uids.
The UID range [90000..98999] is used for isolated processes that are
spawned from an application zygote. Otherwise they are identical to
regular isolated processes in the [99000..99999] range. Fix the tests to
match the new range.

Bug: 111434506
Test: atest bionic-unit-tests-static
Change-Id: Id0352f2cf0d21edb04d95f01ea2548e95b62317a
2019-01-17 13:36:47 +01:00
Logan Chien
d4f8f4e20b Merge "Add __attribute__((unused)) to __BIONIC_ERROR_FUNCTION_VISIBILITY" 2019-01-17 12:31:57 +00: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
Ryan Prichard
1988350d1c Avoid a dlopen abort on an invalid TLS alignment
If the alignment of a TLS segment in a shared object is invalid, return
an error through dlerror() rather than aborting the process.

Bug: http://b/78026329
Test: bionic unit tests
Change-Id: I60e589ddd8ca897f485d55af089f08bd3ff5b1fa
2019-01-16 23:19:40 -08:00
Treehugger Robot
5bccde719f Merge "Fix fd leak in android_dlopen_ext." 2019-01-17 04:16:43 +00:00
Ryan Prichard
361c1b4a3b Initialize static TLS memory using module list
This implementation simply iterates over each static TLS module and
copies its initialization image into a new thread's static TLS block.

Bug: http://b/78026329
Test: bionic unit tests
Change-Id: Ib7edb665271a07010bc68e306feb5df422f2f9e6
2019-01-16 16:52:47 -08:00
Ryan Prichard
e5e69e0912 Record TLS modules and layout static TLS memory
Bug: http://b/78026329
Test: bionic unit tests
Change-Id: Ibf1bf5ec864c7830e4cd1cb882842b644e6182ae
2019-01-16 16:52:47 -08:00
Martin Stjernholm
de853ffa7f Fix fd leak in android_dlopen_ext.
It can happen e.g. if android_dlopen_ext is called with an absolute path to
a file that is not accessible in the current namespace. The first
load_library call in find_library_internal will then open the file and
assign its fd to the task and return false. Then linked namespaces are
searched, and load_library gets called again and opens the same file and
overwrites the fd in the task without closing it first. (In one of the later
calls the namespace config might very well allow the file to be loaded and
the android_dlopen_ext call eventually returns successfully, and the process
continues with the leaked fd.)

The code could perhaps be changed to avoid opening the file repeatedly in
these cases, but the LoadTask class should arguably keep its state clean
anyway.

Bug: 113373927
Test: Flash and boot device with (and without) http://r.android.com/812674,
  which moves libart.so to the runtime namespace and thus makes it load
  /system/framework/*/boot*.oat files across the namespace boundary from
  runtime to default.
Change-Id: Iae91b7c743c5f3f973506153ba52898ae72e6fee
2019-01-17 00:48:18 +00:00
Ryan Prichard
977e47d018 StaticTlsLayout: add exe/tcb and solib layout
Replace reserve_tcb with reserve_exe_segment_and_tcb, which lays out both
the TCB and the executable's TLS segment, accounting for the difference in
layout between variant 1 and variant 2 targets.

The function isn't actually called with a non-null TlsSegment* yet.

Bug: http://b/78026329
Test: bionic unit tests
Change-Id: Ibd6238577423a7d0451f36da7e64912046959796
2019-01-16 15:54:52 -08:00
Treehugger Robot
05ca47512c Merge "Revert "Expose more symbols temporarily"" 2019-01-16 23:46:31 +00:00
Treehugger Robot
aef4a49a3f Merge changes I221b1342,I1d1276da,I89b128df,Icb348a11,Ifb3b2d8d
* changes:
  Add a __bionic_get_tls_segment function
  Factor out ScopedRWLock into its own header
  Build the linker with -D_USING_LIBCXX
  Provide a stub aeabi.read_tp on other archs
  Remove TLS_SLOT_TSAN(8)
2019-01-16 23:23:25 +00:00
Ryan Prichard
21709b785d Merge "Use TLS_SLOT_THREAD_ID macro in vfork.S" 2019-01-16 22:36:53 +00:00
Jiyong Park
606191fd61 Revert "Expose more symbols temporarily"
This reverts commit 220f51e566.

The internal modules that were using extra symbols are all fixed.

Bug: 120266448
Test: m ndk_translation_all in cf_x86_phone
Change-Id: I561b16de1c320d2624e7cf8e6211e0c70edc823d
2019-01-17 04:04:42 +09:00
Florian Mayer
37a7f711eb Merge "Do not run heapprofd_initialize twice concurrently." 2019-01-16 18:48:41 +00:00
Treehugger Robot
702c325933 Merge "libc: Sort symbols by size to reduce dirty pages" 2019-01-16 17:52:48 +00:00
Ryan Prichard
4809755c0f Add a __bionic_get_tls_segment function
The function searches for a TLS segment in a ElfXX_Phdr table.

Bug: http://b/78026329
Test: bionic unit tests
Change-Id: I221b13420d1a2da33fc2174b7dd256589f6ecfdb
2019-01-16 01:11:26 -08:00
Ryan Prichard
82aea78136 Use TLS_SLOT_THREAD_ID macro in vfork.S
No functional change intended.

Bug: none
Test: bionic unit tests
Change-Id: I7ee0a2b3f0e3807abe88bfa34ef3cd56c150a8f6
2019-01-16 01:11:26 -08:00
Ryan Prichard
c86576c1fb Factor out ScopedRWLock into its own header
Bug: http://b/78026329
Test: bionic unit tests
Change-Id: I1d1276da835bc8ecac7a7abb714d639a1ee58007
2019-01-16 01:11:26 -08:00
Ryan Prichard
9ee8069046 Build the linker with -D_USING_LIBCXX
This macro is necessary for using stdatomic.h and <atomic> in the same
libc++-based program. <atomic> is used implicitly by other STL headers,
and stdatomic.h is used (or will be used) in headers shared with libc.
libc only has access to stdatomic.h because it can't use an STL.

Bug: http://b/78026329
Test: bionic unit tests
Change-Id: I89b128df08b478287ef4e2867319e74dbcc30d4e
2019-01-16 01:11:26 -08:00
Ryan Prichard
073fffde09 Provide a stub aeabi.read_tp on other archs
Using "#if defined(...)" inside the test body seems to be the convention.

Bug: none
Test: bionic-unit-tests
Change-Id: Icb348a1184e630c5e199129bbe2090fd1e490fa5
2019-01-16 01:11:26 -08:00
Ryan Prichard
2e724175ac Remove TLS_SLOT_TSAN(8)
As of the switch to clang-r346389c, it has been replaced with
TLS_SLOT_SANITIZER(6). lld reserves 8 words beyond the TP on arm/arm64, so
Bionic can't use anything beyond 7.

The DTV and bionic_tls slots on x86 haven't been part of a release yet,
and they should be strictly internal to Bionic anyway, so shift them down.

Bug: http://b/78026329
Test: bionic unit tests
Change-Id: Ifb3b2d8d85efe1417ee9a10b657b665ec6f2fd3d
2019-01-16 01:11:26 -08:00
Logan Chien
ae4d10bf4a Add __attribute__((unused)) to __BIONIC_ERROR_FUNCTION_VISIBILITY
This commit adds `__attribute__((unused))` to
`__BIONIC_ERROR_FUNCTION_VISIBILITY`, so that `open()`, `openat()`,
`snprintf()`, and `sprintf()` don't raise `-Werror,-Wunused-function`
when `_FORTIFY_SOURCE` is enabled.

These errors were hidden because the include directories were passed
with `-isystem` (instead of `-I`) and clang did not report
`-Wunused-function` from `-isystem`.

Bug: 119086738
Test: make checkbuild
Change-Id: I0de71efdbacd90c5c6a419fc0368c92e8efdfd63
2019-01-16 15:41:33 +08:00
Christopher Ferris
b21fc16a22 Merge "Update to v4.20.1 kernel headers." 2019-01-15 20:09:07 +00:00
Christopher Ferris
86a4837a8e Update to v4.20.1 kernel headers.
This includes one manual change:

In the file bionic/libc/kernel/uapi/linux/in.h, the macro IN_BADCLASS
was not definied correctly. Change the macro from:

  #define IN_BADCLASS(a) ((((long int) (a)) == 0xffffffff)

to:

  #define IN_BADCLASS(a) (((long int) (a)) == (long int)0xffffffff)

This change is being pushed to the upstream kernels.

Test: Builds and boots.
Change-Id: Ia304773a9dc6789b34d9769d73742384d6afb571
Merged-In: Ia304773a9dc6789b34d9769d73742384d6afb571
(cherry picked from commit 967fb01cce)
2019-01-15 07:33:14 -08:00
Vic Yang
6903fb81e1 libc: Sort symbols by size to reduce dirty pages
By sorting symbols by size, small symbols are grouped together and we
usually have less dirty pages at runtime.  On cuttlefish, this results
in 20KB less dirty pages just after libc is loaded.

Bug: 112073665
Test: Build libc and check symbol ordering.
Test: Compare runtime private dirty memory usage on cuttlefish.
Change-Id: Ic8fa996f81adb5a8cbc4b97817d2b94ef0697a2a
2019-01-14 11:43:41 -08:00
Neil Fuller
ca305a39e5 Merge "Track movement of ICU .dat file" 2019-01-13 16:22:59 +00:00
Ryan Prichard
2242cca714 Merge changes I65430637,Ib75d9dab
* changes:
  Reorganize static TLS memory for ELF TLS
  pthread_key.cpp: factor out get_thread_key_data
2019-01-12 00:57:12 +00:00
Ryan Prichard
45d1349c63 Reorganize static TLS memory for ELF TLS
For ELF TLS "local-exec" accesses, the static linker assumes that an
executable's TLS segment is located at a statically-known offset from the
thread pointer (i.e. "variant 1" for ARM and "variant 2" for x86).
Because these layouts are incompatible, Bionic generally needs to allocate
its TLS slots differently between different architectures.

To allow per-architecture TLS slots:
 - Replace the TLS_SLOT_xxx enumerators with macros. New ARM slots are
   generally negative, while new x86 slots are generally positive.
 - Define a bionic_tcb struct that provides two things:
    - a void* raw_slots_storage[BIONIC_TLS_SLOTS] field
    - an inline accessor function: void*& tls_slot(size_t tpindex);

For ELF TLS, it's necessary to allocate a temporary TCB (i.e. TLS slots),
because the runtime linker doesn't know how large the static TLS area is
until after it has loaded all of the initial solibs.

To accommodate Golang, it's necessary to allocate the pthread keys at a
fixed, small, positive offset from the thread pointer.

This CL moves the pthread keys into bionic_tls, then allocates a single
mapping per thread that looks like so:
 - stack guard
 - stack [omitted for main thread and with pthread_attr_setstack]
 - static TLS:
    - bionic_tcb [exec TLS will either precede or succeed the TCB]
    - bionic_tls [prefixed by the pthread keys]
    - [solib TLS segments will be placed here]
 - guard page

As before, if the new mapping includes a stack, the pthread_internal_t
is allocated on it.

At startup, Bionic allocates a temporary bionic_tcb object on the stack,
then allocates a temporary bionic_tls object using mmap. This mmap is
delayed because the linker can't currently call async_safe_fatal() before
relocating itself.

Later, Bionic allocates a stack-less thread mapping for the main thread,
and copies slots from the temporary TCB to the new TCB.
(See *::copy_from_bootstrap methods.)

Bug: http://b/78026329
Test: bionic unit tests
Test: verify that a Golang app still works
Test: verify that a Golang app crashes if bionic_{tls,tcb} are swapped
Merged-In: I6543063752f4ec8ef6dc9c7f2a06ce2a18fc5af3
Change-Id: I6543063752f4ec8ef6dc9c7f2a06ce2a18fc5af3
(cherry picked from commit 1e660b70da)
2019-01-11 15:34:22 -08:00
Ryan Prichard
27d59338b9 pthread_key.cpp: factor out get_thread_key_data
This change makes it easier to move the location of the pthread keys
(e.g. into the bionic_tls struct).

Bug: http://b/78026329
Test: bionic unit tests
Test: disassembly of libc.so doesn't change
Merged-In: Ib75d9dab8726de96856af91ec3daa2c5cdbc2178
Change-Id: Ib75d9dab8726de96856af91ec3daa2c5cdbc2178
(cherry picked from commit ecad24fad9)
2019-01-11 15:33:57 -08:00
Treehugger Robot
98564b8c74 Merge changes from topic "move_bionic_to_apex"
* changes:
  Expose more symbols temporarily
  Add stubs variants for bionic libs
2019-01-11 16:59:15 +00:00
Christopher Ferris
688028d7a5 Merge "Update kernel headers with new parser." 2019-01-11 06:03:19 +00:00
Christopher Ferris
48fe0aef16 Update kernel headers with new parser.
Test: Builds.
Change-Id: I3f0714d53ac893ccc3e66f7a92d0ea7a6737f1c3
2019-01-10 17:33:56 -08:00
Christopher Ferris
19f2ed2d1d Merge "Fix notice file." 2019-01-11 01:31:58 +00:00
Christopher Ferris
4282833dfc Fix notice file.
The only 2019 android copyright is coming from a test file, which is
not included in our normal notice.

Test: Can upload.
Change-Id: Ie22332f927b99c28eb71c1daf5615adfef8c5d11
2019-01-10 16:07:44 -08:00
Christopher Ferris
9dd7d2e640 Merge "Rewrite removeVarsAndFuncs." 2019-01-10 23:48:36 +00:00
Christopher Ferris
658b16fd90 Rewrite removeVarsAndFuncs.
The current version has these bugs:
- Adding a semicolon after a function results in the removal of structures
  following the function.
- Function like macros get removed on accident rather than on purpose.
- It removes extern "C" { completely, which might not be a bug, but doesn't
  seem right.

I couldn't easily fix any of these problems because the code depends heavily
on the header being correct.

New unit tests added for the function to cover all of these cases.

A follow-on CL will include the updated headers.

Bug: 112290385

Test: Passes all new unit tests.
Test: When run on the current kernel headers, the generated headers are
Test: nearly the same, missing data is being added.
Change-Id: Ib22a5f2e78873544e8a9d54e385af1156b2a72bb
2019-01-10 15:15:15 -08:00
Neil Fuller
62d8d9fc8f Track movement of ICU .dat file
Track movement of ICU .dat file into the runtime module

This reverts commit b9e7b699a2.
This is a reapply of commit 68c6bd8b43

Bug: 120853401
Bug: 119293618
Test: build / boot
Change-Id: I69e0dde2756da64ac0b17f1726145dccacf5961f
2019-01-09 15:27:02 +00:00
Tim Murray
43889f5e2c Merge "Remove some PR_SET_VMAs during pthread_create" 2019-01-09 03:20:43 +00:00
Tim Murray
466e0ecb88 Remove some PR_SET_VMAs during pthread_create
PR_SET_VMA takes mmap_sem, which can cause contention and reduce
performance any time many threads are created at the same time,
like app startup.

Test: camera launch performance
Bug: 122471935
Change-Id: If7fa7ad99654c01d503f694976fd92bfd30d2afd
2019-01-08 13:27:41 -08:00
Ryan Prichard
c14d46f086 Merge "Add ARM EABI function __aeabi_read_tp" 2019-01-08 21:19:01 +00:00
Neil Fuller
5d89fbd207 Merge "Update the "host" bionic code tzdata lookup logic" 2019-01-08 10:06:54 +00:00