Commit graph

27465 commits

Author SHA1 Message Date
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
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
Chih-Hung Hsieh
770032ddfa Fix/suppress bionic google-explicit-constructor warnings
* Add explicit to conversion constructors/operators

Bug: 28341362
Test: make with WITH_TIDY=1 DEFAULT_GLOBAL_TIDY_CHECKS=-*,google-explicit-constructor
Change-Id: Id1ad0327c1b8c6f094bcbb3ae599bc1f716b3f2f
2019-01-02 11:04:05 -08:00
Ryan Prichard
76e7fd4e26 Fix modify_stack_protector flake
The previous test would fail to crash if the first byte of the canary was
already NUL (1 of 256 runs assuming uniform canary distribution).

Bug: http://b/121156651
Test: bionic unit tests
2019-01-01 19:46:41 -08:00
Haibo Huang
7bd54ade8d Merge "libc: Optimize ARM memcmp by using NEON." 2018-12-22 04:54:23 +00:00
Kyle Repinski
78da73adad libc: Optimize ARM memcmp by using NEON.
Because NEON_UNALIGNED_ACCESS has never been defined, it has gone unused.
This change enables NEON optimization if __ARM_NEON__ is defined.

Test: bionic-benchmarks-32 BM_string_memcmp

On Nextbit Robin (MSM8992), here are the results

Before:
                                       iterations      ns/op
BM_string_memcmp/8                            50M         28    0.277 GiB/s
BM_string_memcmp/64                           50M         54    1.169 GiB/s
BM_string_memcmp/512                           5M        444    1.151 GiB/s
BM_string_memcmp/1024                          2M        885    1.156 GiB/s
BM_string_memcmp/8Ki                         200k       7401    1.107 GiB/s
BM_string_memcmp/16Ki                        200k      14469    1.132 GiB/s
BM_string_memcmp/32Ki                        100k      28726    1.141 GiB/s
BM_string_memcmp/64Ki                         50k      57480    1.140 GiB/s

After:
                                       iterations      ns/op
BM_string_memcmp/8                            50M         22    0.351 GiB/s
BM_string_memcmp/64                         1000k         17    3.688 GiB/s
BM_string_memcmp/512                          20M        105    4.848 GiB/s
BM_string_memcmp/1024                         10M        190    5.367 GiB/s
BM_string_memcmp/8Ki                        1000k       1496    5.475 GiB/s
BM_string_memcmp/16Ki                       1000k       2746    5.966 GiB/s
BM_string_memcmp/32Ki                        500k       5481    5.978 GiB/s
BM_string_memcmp/64Ki                        200k      10971    5.973 GiB/s

Change-Id: I3c76ce7fa2796872e0171d5502b0ebd6e2893339
2018-12-22 01:04:27 +00:00
Christopher Ferris
0ec6aa0f22 Merge "Fix handling of libs with a ro map and a rx map." 2018-12-19 18:14:15 +00:00
Christopher Ferris
b233fab925 Fix handling of libs with a ro map and a rx map.
When the linker was changed so that it put a read-only map and
read-execute map, this code incorrectly computed the relative pc and
offset. Modify to look for the actual start map in this case.

Also, change the load_base name to load_bias.

Bug: 120613266

Test: Dumped logcat while dumping backtraces.

Change-Id: I6628694c5222ea34d63217af3d138707d4900004
2018-12-18 17:45:46 -08:00
Elliott Hughes
727a6ebcfb Merge "Make stdlib.getloadavg more resiliant." 2018-12-19 01:33:36 +00:00
Elliott Hughes
3b3e09aad0 Merge "Fix sys_prctl.pr_cap_ambient." 2018-12-19 01:32:39 +00:00
Elliott Hughes
910a2a83a4 Fix sys_prctl.pr_cap_ambient.
This test didn't clear errno before testing it, so was sensitive to
whatever code had run before. Since I'd already added the code to dump
the exact kernel version before realizing the actual bug, I've left that
in too.

Bug: http://b/121156651
Test: ran tests
Change-Id: I38482036cb6f035c0c98c27eb64d17829f29b09a
2018-12-18 15:19:40 -08:00
Elliott Hughes
72a54a41a7 Make stdlib.getloadavg more resiliant.
Using rint(3) gave us a step where if one side was 1.4 and the other
was 1.5, that would be 1 and 2 respectively. So instead use a simple
difference. Also log more detail in case this doesn't fix the flakiness.

Bug: http://b/121156651
Test: ran tests
Change-Id: Ib5b2eb05d2b1eb8c4a10b182a8703510a3ef0cea
2018-12-18 14:47:25 -08:00
Elliott Hughes
0c499a69e3 Merge "Generate the per-arch .map files at build time." 2018-12-18 19:21:01 +00:00
Treehugger Robot
22549b331c Merge "Increase 2ms to 5ms to reduce flake." 2018-12-18 16:34:46 +00:00
Elliott Hughes
0dafa8a3a5 Increase 2ms to 5ms to reduce flake.
Bug: http://b/121156651
Test: ran tests
Change-Id: Ief699cacf920b144bf66821cf0ac73930fae9274
2018-12-17 16:04:45 -08:00
Elliott Hughes
d19b3c5274 Generate the per-arch .map files at build time.
We shouldn't be checking in these generated files...

Bug: N/A
Test: ran tests
Change-Id: Ib67c1ba839eacd7acebd713e1dcd4dd2c25d67f0
2018-12-17 12:26:42 -08:00
Vic Yang
9ea997a2ac Merge "Further improve of linker memory allocators" 2018-12-14 00:56:56 +00:00
Vic Yang
2bbd49be84 Merge "Reduce LinkerSmallObjectAllocator memory overhead" 2018-12-14 00:56:33 +00:00
Treehugger Robot
1e10cdc916 Merge "Suppress cert-dcl16-c clang-tidy warnings" 2018-12-13 21:38:14 +00:00
Chih-Hung Hsieh
37a2e61133 Suppress cert-dcl16-c clang-tidy warnings
Bug: 120614316
Test: make with WITH_TIDY=1 DEFAULT_GLOBAL_TIDY_CHECKS=-*,cert-dcl16-c
Change-Id: Iab21f41806d81268ebc13bb9605920b4b8e825c9
2018-12-13 11:49:34 -08:00
Haibo Huang
c87fb3ed82 Merge "No ifunc for strcmp and strlen" 2018-12-13 19:23:08 +00:00