Commit graph

27485 commits

Author SHA1 Message Date
Logan Chien
17af91b588 Add libc_headers header lib
This commit extracts `libc_headers` for `libasync_safe` and
`libpropertyinfoparser` (in the `system/core` repository).

Before this change, `libasync_safe` expects that `libc` is automatically
added to `system_shared_libs` of the libasync_safe vendor variant even
if `libc_defaults` explicitly declines any `system_shared_libs`.

This commit defines `libc_headers` for `libasync_safe` and
`libpropertyinfoparser` so that they can find the headers from libc
without causing circular dependencies.

Bug: 123006819
Test: make checkbuild
Change-Id: I2435ab61d36ff79ca2b4ef70bd898b795159c725
2019-01-19 07:18:38 +08:00
Logan Chien
d4f8f4e20b Merge "Add __attribute__((unused)) to __BIONIC_ERROR_FUNCTION_VISIBILITY" 2019-01-17 12:31:57 +00:00
Treehugger Robot
5bccde719f Merge "Fix fd leak in android_dlopen_ext." 2019-01-17 04:16:43 +00: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
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
Ryan Prichard
45024fefe7 Add ARM EABI function __aeabi_read_tp
By default, Clang uses this arm32 function to read the thread pointer,
either for ELF TLS or via __builtin_thread_pointer(). It's probably better
to inline the cp15 access using -mtp=cp15, but that's not the default yet.

See https://reviews.llvm.org/D34878?id=114573.

Bug: http://b/78026329
Test: bionic unit tests
Change-Id: I93b8926075f0b2cea8df9ef518d54f2820a8ff5b
2019-01-07 20:30:35 -08:00
Neil Fuller
2e967fcbab Update the "host" bionic code tzdata lookup logic
The "if defined(__ANDROID__)" else branch is there to support
bionic when running on host environments.

The code now checks the
${ANDROID_RUNTIME_ROOT}/etc/tz/tzdata path as well.

This is similar to the current on-device expectations.

Eventually, we may remove the /system / ANDROID_ROOT cases.

Bug: 119293618
Test: build only
Change-Id: I8310f7b5a1c14567a648673970c636c7c84ff818
2019-01-07 21:08:37 +00:00
Treehugger Robot
e7964158ce Merge "dir.${section}: downgrade "can't resolve" diag" 2019-01-07 01:08:36 +00:00
Ryan Prichard
6b55cc36d3 dir.${section}: downgrade "can't resolve" diag
When parsing a dir.${section} line in ld.config.txt, the linker uses
realpath() to resolve each directory path. If realpath() fails, the linker
uses the non-resolved path instead. Previously, it issued a warning to
stderr and logcat, but realpath() is expected to fail on /postinstall when
running a binary in /data/local/tmp, so downgrade the warning to an INFO()
notice.

Bug: http://b/120996057
Test: copy ping to /data/local/tmp, run it, verify no errors
Test: bionic unit tests
Change-Id: I2104084e12ea18840230997408559299bf3bddac
2019-01-04 15:05:44 -08:00
Jiyong Park
220f51e566 Expose more symbols temporarily
Following additional symbols are temporarily exposed from the runtime APEX
to satisfy the dependencies from other non-AOSP modules. This will be
reverted when the modules are built with the boostrap bionic libraries.

Bug: 120266448
Test: m
Change-Id: I39ac40a40545723ea2aeb185b9cd293d511f802f
2019-01-04 22:29:36 +09:00
Jiyong Park
c45fe9f7bd Add stubs variants for bionic libs
Bionic libs are part of the runtime APEX (com.android.runtime). In order
to be able to update the runtime APEX independetly from the platform, we
have to prevent things outside of the APEX from using bionic symbols
that are not guaranteed to be stable. Otherwise, platform could break
when a symbol is removed from the libs via the APEX update.

To achive this goal, this change adds stubs variant to the bionic libs.
With this, things outside of the runtime APEX (i.e. other APEXes and the
platform) are built with the stubs variants that provide only the
symbols that are guaranteed to be stable.

The set of symbols are basically the same as the symbols available to
NDK clients. However, there are a few additional symbols that are not
available for NDK but should be made available for platform components.
They are marked with "# apex" tag. Symbols with that tag are not exposed
to apps (via NDK stubs) or vendors (via LLNDK stubs).

Note that the stubs is a build-time only artifact. It is used just to
break the build when private symbols are used outside of the runtime
APEX. At runtime, the real library in the APEX is used.

Bug: 120266448
Test: m
Test: m bionic-unit-tests
Change-Id: I7b8d75830c81d7d7d54e2fca21a85b3417531b47
2019-01-04 22:29:36 +09:00
Ryan Prichard
c975355066 Merge "libc_shared_globals: add a constexpr ctor" 2019-01-04 03:56:40 +00:00
Ryan Prichard
0b0ee0c634 libc_shared_globals: add a constexpr ctor
Having a constexpr constructor should guarantee that the static
`globals` variable in __libc_shared_globals is initialized statically
(as opposed to dynamically), which is important because
__libc_shared_globals is called very early (before the linker has
relocated itself). With the constructor, though, the fields can safely
have in-line default initializers.

Bug: none
Test: bionic unit tests
Change-Id: Icde821557369625734a4d85d7ff55428bad5c247
2019-01-03 17:11:27 -08:00
Treehugger Robot
d14d83032c Merge "Check return value of scandir in icu.cpp" 2019-01-03 00:55:06 +00:00
Treehugger Robot
82d4bae5d4 Merge "Add generic TLS linker reloc macros" 2019-01-03 00:18:10 +00:00
Alex Light
ecb95b8a15 Check return value of scandir in icu.cpp
We could cause illegal memory access due to not checking the scanddir
return value.

Test: run linux-bionic dex2oat to build boot.oat
Bug: 119332362
Change-Id: Ic5824e0373b9b99d8f892b4fcf22e742c6f792da
2019-01-02 15:30:50 -08:00
Ryan Prichard
2ccb2f04e0 Add generic TLS linker reloc macros
Bug: http://b/78026329
Test: build bionic
Change-Id: I7f9d3a250f27c31d0b8d9a3a306468fdf723f9c8
2019-01-02 14:36:26 -08:00
Chih-hung Hsieh
07468a811e Merge "Fix/suppress bionic google-explicit-constructor warnings" 2019-01-02 22:29:13 +00:00
Treehugger Robot
49c631a746 Merge "Fix modify_stack_protector flake" 2019-01-02 22:27:41 +00:00