Commit graph

315 commits

Author SHA1 Message Date
Peter Collingbourne
7eb851c7da Disable sanitization of crt objects.
The accompanying soong change causes sanitize attributes to be allowed on
cc_object targets and propagates sanitize attributes into dependencies. This
is problematic for the crt objects in sanitizer builds because everything
depends on them including the sanitizer runtime, so a circular dependency
would otherwise be created. Furthermore, some of the code in these objects
runs before sanitizer initialization so it is unlikely that sanitizing them
would work anyway. Therefore, disable sanitization on these objects.

Change-Id: I25380dfc8eed5db34b034ba127a9d6b5674032fa
2019-09-26 12:16:06 -07:00
Elliott Hughes
ae03b12925 Remove global seccomp list.
Never used, and incompatible with having bionic in a mainline module.

Test: builds
Change-Id: If377f66cc105fd3a1ec4d9c92330fa6a2d2c145c
2019-09-17 16:37:05 -07:00
Christopher Ferris
2b0638ef29 Make bionic_malloc.h a platform header.
Instead of having platform directories directly include the
private header, create a platform header directory and export it.

Bug: 130763340

Test: Builds.
Change-Id: Ie0f092b3fe077a3de8b90266c0b28bfbc20d0dfa
Merged-In: Ie0f092b3fe077a3de8b90266c0b28bfbc20d0dfa
(cherry picked from commit 8f582ef2f8)
2019-09-16 12:27:33 -07:00
Elliott Hughes
261bd745ee Support statvfs on API levels before 19.
Split statfs and statvfs. The former has been available forever, and the
latter is implemented in terms of the former. The implementation has
been moved into headers so that it can be used at low API levels.

There's no reason for any Android or Linux code to use statvfs rather
than statfs, but code that needs to build on Darwin too will want to use
statvfs because Darwin's statfs is very spartan.

Bug: https://github.com/android-ndk/ndk/issues/609
Test: treehugger
Change-Id: Icf3d5723a260099fddb2d9f902e3047b0f041647
2019-08-29 21:57:58 -07:00
Vic Yang
03ff4365ec Use the new sort_bss_symbols_by_size option for libc
Instead of maintaining a symbol ordering file, using the new
sort_bss_symbols_by_size property allows for symbol sorting at build
time.

Bug: 135754984
Test: Build and check the resulting libc.so has its bss symbols sorted.
Change-Id: I4a1cd6774dfe61b73f454bdf95b535db1f9fb1ac
2019-07-29 13:26:33 -07:00
Paul Duffin
6b5cb034e3 Add bionic_libc_private_headers for use by art
This avoids art having a direct reference to bionic directories which
would prevent the bionic module from being unbundled from the runtime
module.

Bug: 134379140
Test: m droid
Change-Id: I9545767b76341fd01166b675bdd156f620d4f262
2019-07-18 14:48:44 +01:00
Elliott Hughes
3975431aba Merge "Add avx2 version of wmemset in binoic" 2019-07-16 23:00:24 +00:00
Shalini Salomi Bodapati
4ed2f475d8 Add avx2 version of wmemset in binoic
Test: ./tests/run-on-host.sh 64
Change-Id: Id2f696cc60a10c01846ca3fe0d3a5d513020afe3
Signed-off-by: Shalini Salomi Bodapati <shalini.salomi.bodapati@intel.com>
2019-07-16 18:06:57 +05:30
Elliott Hughes
5c6a3f9fbc libnetd_client: support hooking sendto/sendmsg/sendmmsg too.
Samsung has asked for this for KNOX.

Test: treehugger
Change-Id: Iffaace9f8cb265ce8c911472989c9829cbf91a42
2019-06-20 08:32:24 -07:00
Yi Kong
6cfd9a1071 Merge "Clean up no_libgcc" 2019-06-05 00:58:35 +00:00
Elliott Hughes
1b61d78fc1 Build 32-bit ARM assembler with -mno-restrict-it.
We're not going to change this code, ARM's not going to break it.
Silence the warnings.

Bug: http://b/114120867
Test: treehugger
Change-Id: Ie25ef44706c952efc5d54012391bee19af095818
2019-06-04 10:38:34 -07:00
Yi Kong
cd3155dd17 Clean up no_libgcc
This property is getting removed.

Test: build
Change-Id: Ib7b8cb189b21b55da6305f6644b0b029b41e8e4b
2019-06-03 16:04:01 -07:00
Mitch Phillips
dfde0eeee1 Change SANITIZE_TARGET refs from 'coverage' to 'fuzzer'.
Cleanup of references to 'coverage' in build files. Part of a larger
cleanup to make fuzzing work again in the Android build tree.

Also fixed a test issue with emulated TLS with the new changes, and
removed libc.so fuzzer support until a linked bug is fixed
(b/132640749).

Bug: 121042685
Test: With all patches in the bug merged: mmma bionic
Change-Id: I592352fe9210ff811a2660a88cbbfe48d70a1e57
Merged-In: I592352fe9210ff811a2660a88cbbfe48d70a1e57
2019-05-30 16:49:13 +00:00
Pirama Arumuga Nainar
17e7c75265 Disable native_coverage for scudo-related libraries
Bug: http://b/133379274
Bug: http://b/133322197

Test: coverage-enabled mediaextractor, which uses scudo, no longer
crashes during llvm_gcov_init.

Change-Id: I85a0cc91a2fbd8433823769c3032ec2591424e55
2019-05-22 22:18:37 -07:00
Christopher Ferris
0c0f6fb293 Keep .debug_frame on arm 32.
The arm exidx unwind information can be sparse and clang is producing
functions that cannot be properly represented. The .debug_frame includes
extra unwind information that covers the cases that are not complete, so
do not remove it. For example, the __strchr_chk function has a push
in the middle of the function, so any crash before that instruction will
not unwind properly.

This does increase the size of libc.so, but only by about 80,000 bytes.

Bug: 132992102

Test: Verified the .debug_frame exists in libc.so only for arm32.
Test: Used the unwind_reg_info to verify that __str_chk gets proper
Test: unwind info. Also use unwind_reg_info on some assembler functions
Test: to make sure that there is no overlapping information.
Change-Id: If9a6de15b3adf08a93c4563da8c89846e4dd059b
2019-05-17 17:52:51 -07:00
Jake Weinstein
bff53b2617 libc: import ARM strcmp from newlib
* Current version is also based on newlib, but an older revision

* The Krait and A9 specific changes no longer seem relevant, so
  let's use A15 directly.

Tested on OnePlus 3 (MSM8996):

Before (Krait strcmp):
                                       iterations      ns/op
BM_string_strcmp/8                          1000k         24    0.322 GiB/s
BM_string_strcmp/64                           20M        123    0.519 GiB/s
BM_string_strcmp/512                           2M        920    0.556 GiB/s
BM_string_strcmp/1024                       1000k       1818    0.563 GiB/s
BM_string_strcmp/8Ki                         200k      14405    0.569 GiB/s
BM_string_strcmp/16Ki                        100k      28762    0.570 GiB/s
BM_string_strcmp/32Ki                         50k      57526    0.570 GiB/s
BM_string_strcmp/64Ki                         10k     114959    0.570 GiB/s

After:
                                       iterations      ns/op
BM_string_strcmp/8                          1000k         28    0.284 GiB/s
BM_string_strcmp/64                           20M        107    0.596 GiB/s
BM_string_strcmp/512                           2M        800    0.639 GiB/s
BM_string_strcmp/1024                       1000k       1579    0.649 GiB/s
BM_string_strcmp/8Ki                         200k      12469    0.657 GiB/s
BM_string_strcmp/16Ki                        100k      24931    0.657 GiB/s
BM_string_strcmp/32Ki                         50k      49843    0.657 GiB/s
BM_string_strcmp/64Ki                         20k      99635    0.658 GiB/s

Test: bionic-benchmarks BM_string_memcmp
Change-Id: Icb3bfb0a381bcc1e10885ca5e9547842c3f620d7
2019-05-16 04:37:26 +00:00
dimitry
7f04880820 Enable native_bridge_support
Enable native bridge support for bionic libraries.
Makes it possible to use them in binaries for translated
architectures.

Bug: http://b/77159578
Test: make
Change-Id: Iccd4ad7aecfa5260cc15f09ca975d2e18987278a
2019-05-06 17:13:51 +02:00
Neil Fuller
f5eaea32b6 Merge "Move /system dependency on tz_version to bionic" 2019-04-29 12:59:32 +00:00
Neil Fuller
a7db90f32d Move /system dependency on tz_version to bionic
Move /system dependency on tz_version to bionic from core-libart.

The file is not used by code but is useful on device to identify
the format / version / origin of the tzdata file. The
tz_version file identifies the Android release (e.g. 3.1 == Q), which
implies the version of zic used to generate tzdata, and any Android
revision of the tzdata (e.g. 2019a v2) that may have taken place. The
file was previously used by by the tzdatacheck binary but it has since
switched to using the copy in the runtime module.

The bionic README.md is also updated here to reflect latest locations of
scripts.

Bug: 131239046
Test: make installclean / make droid / inspect /system
Change-Id: Ib142f98aa30c8c9d5eda33df55d4191478570ced
2019-04-25 09:35:58 +01:00
Elliott Hughes
8c3140a612 Merge "threads.h: Add C11 thread support." 2019-04-24 20:33:08 +00:00
Elliott Hughes
4206711352 threads.h: Add C11 thread support.
FreeBSD, glibc, and musl have all implemented C11 threads at this
point. POSIX is looking at how to align with it. Probably time to jump
on the bandwagon ourselves...

Implemented in the same style as <termios.h> so we can provide this
functionality even on older API levels. This does mean that this is
strictly more expensive than calling pthread functions directly.

Although this isn't in POSIX yet, assume that it's going to be basically
the same as C11 and add the header test anyway. We should revisit this
when POSIX actually adds <threads.h>.

Test: new tests
Change-Id: I8602d67ce71ca7f8ed1529daa0a8ea1feb083dd6
2019-04-24 09:12:29 -07:00
Yi Kong
7f3527fb5c Merge "Implement __gnu_[u]ldivmod_helper methods in libc" 2019-04-23 05:54:33 +00:00
Yi Kong
b410d0e69e Implement __gnu_[u]ldivmod_helper methods in libc
These symbols were previously provided by Android's out-dated libgcc,
but they're removed/deprecated in upstream libgcc, and also won't be
available in libclang_rt.builtins. We need to provide these methods in
libc itself for compatiblity.

Test: build with these symbols stripped in libgcc
Bug: 29275768
Change-Id: I04a05258c6c06b5a22ead41e148b02792ffbc941
2019-04-22 18:12:55 -07:00
Elliott Hughes
1311545bb2 Merge "Reland ifuncs for strcmp and strlen." 2019-04-22 23:32:33 +00:00
Elliott Hughes
927fe99692 Reland ifuncs for strcmp and strlen.
This reverts commit e4788d4c7e,
which undid this change during the Q betas.

Bug: http://b/120989619
Change-Id: Iea589fd0e56426971adf9f7c19c2aedf0d7a7a60
2019-04-22 18:57:21 +00:00
Elliott Hughes
782c485880 Generate assembler system call stubs via genrule.
There's no need to check in generated code.

Test: builds & boots
Change-Id: Ife368bca4349d4adeb0666db590356196b4fbd63
2019-04-16 12:31:00 -07:00
Elliott Hughes
d67b03734d libc: generate syscall stubs in one big file...
...all the better to switch to a genrule rather than checking in
generated source.

This also removes all the code in the script to deal with git,
rather than fix it. We won't need that where we're going.

Test: boots
Change-Id: I468ce019d4232a7ef27e5cb5cfd89f4c2fe4ecbd
2019-04-16 00:54:11 +00:00
Jiyong Park
3ff116a68c Load libc_malloc_* libraries from the runtime APEX
/system/lib/libc.so is a symlink to libc.so in the runtime APEX.
libc_malloc_* libraries are bundled with libc.so because they share
implementation details.

However, since libc.so is loaded in the default namespace where the
runtime APEX path (/apex/com.android.runtime/lib) is not accessible,
libc.so has been using libc_malloc_* from /system/lib. This is
wrong because libc.so (from the runtime APEX) and libc_malloc_* (from
the platform) may not be in-sync.

libc.so now uses android_dlopen_ext to load libc_malloc_* libraries
correctly from the "runtime" linker namespace.

Bug: 122566199
Test: bionic-unit-tests

Merged-In: I46980fbe89e93ea79a7760c9b8eb007af0ada8d8
Change-Id: I46980fbe89e93ea79a7760c9b8eb007af0ada8d8
(cherry picked from commit 4e46ac69c2)
2019-04-11 21:36:16 +09:00
Christopher Ferris
fc26d71af1 Create a lib that uses scudo instead of jemalloc.
The media processes already use scudo as their allocator. However, it
doesn't really correctly replace the normal allocation functions, so create
a set of wrappers that allow us to use scudo closer to how jemalloc is used.

This is only a temporary change, and should be removed for the next
release of Android. In that version, we will be using standalone
scudo which won't require this wrapper code.

Bug: 123689570

Test: Ran new bionic unit tests. There are failures, but only with
Test: extensions that scudo does not support.

Change-Id: I0516c23d654a9b6c69b157c5501245d2e0b3d264
2019-04-01 13:02:49 -07:00
Yi Kong
efd25a0fd7 Move x86 and x86_64 libc to use libcrt
With __cpu_model visibility issue fixed in libcrt, we can move x86 and
x86_64 libc to use libcrt as well.

Test: emulator boots
Bug: 122993569
Change-Id: If71c324180010a57e3e9598d758a4d6ab1a3c369
2019-03-27 16:54:28 +00:00
Christopher Ferris
1fc5ccfe76 Add a platform API for setting an allocation limit.
Introduce an M_SET_ALLOCATION_LIMIT enumerator for android_mallopt(),
which can be used to set an upper bound on the total size of all
allocations made using the memory allocation APIs.

This is useful for programs such as audioextractor and mediaserver
which need to set such a limit as a security mitigation. Currently
these programs are using setrlimit(RLIMIT_AS) which isn't exactly
what these programs want to control. RLIMIT_AS is also problematic
under sanitizers which allocate large amounts of address space as
shadow memory, and is especially problematic under shadow call stack,
which requires 16MB of address space per thread.

Add new unit tests for bionic.

Add new unit tests for malloc debug that verify that when the limit
is enabled, malloc debug still functions for nearly every allocation
function.

Bug: 118642754
Test: Ran bionic-unit-tests/bionic-unit-tests-static.
Test: Ran malloc debug tests and perfetto integration tests.
Change-Id: I735403c4d2c87f00fb2cdef81d00af0af446b2bb
2019-03-15 10:54:55 -07:00
Jiyong Park
036e09c36e Don't install *.mountpoint targets
The *.mountpoint targets that installs /bionic/lib/lib*.so and
/bionic/bin/linker* are no longer needed.

Now, /system/lib/lib*.so and /system/bin/linker* are simply symlinks to
the corresponding files in the runtime apex. For example,

/system/lib/libc.so -> /apex/com.android.runtime/lib/bionic/libc.so

This is made possible because we now activate APEXes even before the
data partition is mounted. Before the data partition mounting, the
APEXes from the system partition are ativated. After the data partition
is mounted, updated APEXes in the partition (if any) are activated. As a
result, the symlink always points to the valid path regardless of
whether /data is mounted or not.

Bug: 125549215
Test: device boots
Change-Id: Ie7d83686abe00b3c436f9f9db75d4244200a0fc9
2019-03-14 07:35:52 +09:00
Christopher Ferris
6c619a0da3 Refactor the malloc_info code.
malloc_info needs to be per native allocator, but the code treated it
like a global function that doesn't depend on the native memory allocator.

Update malloc debug to dump the actual pointers that it has been tracking.

Test: bionic-unit-tests pass.
Test: malloc debug tests pass.
Test: malloc hook tests pass.
Change-Id: I3b0d4d748489dd84c16d16933479dc8b8d79013e
Merged-In: I3b0d4d748489dd84c16d16933479dc8b8d79013e
(cherry picked from commit a3656a98b1)
2019-03-07 08:39:55 -08:00
Yi Kong
e3d90de50b Switch libm to libcrt.builtins
After switching libm from libgcc to libcrt.builtins, some of the symbols
are no longer getting included in libm, causing the compiler to complain
about missing symbols from the version script. Explicitly export them in
libc (since libm depends on libc).

Bug: 122993571
Test: m checkbuild
Test: bionic-unit-tests
Change-Id: Ie91765874d20df605f557b1a8c4236619553c549
2019-02-22 13:33:15 -08:00
Jeffrey Vander Stoep
dced8138d8 Revert "Revert "Turn on XOM for libc""
This reverts commit d119269c1c.

Reason for revert: b/124792601 fixed

Change-Id: I8603231042b0e70772fc174f5493db4ef0587323
Test: bionic-unit-tests
Bug: 122993569
Bug: 123241361
2019-02-21 23:13:52 +00:00
Yi Kong
d119269c1c Revert "Turn on XOM for libc"
This reverts commit 51b8255cf5.

Breaks app compat.

Bug: 124792601
Change-Id: I99690d0092066fdfd76dc68aa3ed0fe0df873892
2019-02-20 10:27:38 +00:00
Yi Kong
51b8255cf5 Turn on XOM for libc
Test: bionic-unit-tests
Bug: 122993569
Bug: 123241361
Change-Id: Ibce7bd9dc45c39a27fee33fd0566483dd8427cce
2019-02-15 12:48:26 -08:00
Yi Kong
165b1cf57b Switch libc to libcrt.builtins
With the switch to libcrt.builtins, some symbols no longer becomes
exported. Add dummy references to them to force them to be exported.
This is to maintain backwards binary compatibility with ancient Android
versions.

x86 and x86_64 crashes with libcrt, keep using libgcc for now.

Test: bionic-unit-tests
Bug: 29275768
Bug: 122993569
Change-Id: Ieab5af354e3924af4a03d888b28c6e75090cb613
2019-02-15 12:46:19 -08:00
Treehugger Robot
0197b0a92f Merge "Use no_libcrt property instead of hard coding projects to exclude" 2019-02-13 21:53:26 +00:00
Christopher Ferris
e4cdbc4754 Refactor malloc common into distinct pieces.
The pieces:
- The malloc common shared by static and dynamic code (malloc_common.cpp).
- The code for shared libraries that includes any dlopen'ing
  (malloc_common_dynamic.cpp).
- The implementation of perfetto's heapprofd (malloc_heapprofd.cpp).

This makes it easier to see what's going on in the many different areas.
It should also make it easier to add the allocation capping option.

Other related changes:
- Update the unit tests for android_mallopt. All of the current options
  don't work on static binaries, so make sure that is reflected in the test.
- A few names changes to make sure that all code is consistent.

Test: Ran tests (malloc hooks/malloc debug/perfetto/bionic unit tests).
Change-Id: I0893bfbc0f83d82506fac5d1f37cf92fbdef6f59
2019-02-12 14:19:07 -08:00
Yi Kong
16f947281f Use no_libcrt property instead of hard coding projects to exclude
Test: m checkbuild
Change-Id: If34c72d37dc4077ca3e83135391256bc53d295b5
2019-02-12 09:49:23 -08:00
Elliott Hughes
01809e1fd1 Switch to OpenBSD div/ldiv/lldiv.
Test: ran tests
Change-Id: I6ecf5878162d7cee81af40edd4b44406196f49be
2019-02-05 16:48:22 -08:00
Elliott Hughes
fbac97a54c Move NetBSD string routines to OpenBSD.
NetBSD seems to be the least well maintained of our three BSD upstreams,
and it's already the one we use the least. Let's push a little further
in that direction...

Test: new smoke tests
Change-Id: Idfebd11794445fe14cbfa07177a7392a7b36a5e4
2019-02-05 12:15:27 -08:00
Jiyong Park
a5f914aef1 Add bionic mount points under /bionic
This change adds following files and symlinks:

Files:
/bionic/lib[64]/lib{c|dl|m}.so
/bionic/bin/linker[64]

Symlinks:
/system/lib[64]/lib{c|dl|m}.so -> /bionic/lib[64]/lib{c|dl|m}.so
/system/bin/linker[64] -> /bionic/bin/linker[64]
/system/bin/linker_asan[64] -> /bionic/bin/linker[64]

The files serve as mount points for either the bootstrap Bionic or the
default Bionic from the runtime APEX. init does the bind-mounting during
booting.

The symlinks are there to not change the ordinary paths to the bionic
files; there are many places that the paths are implied or hard-coded,
e.g., dlopen("/system/lib/libc.so") or DT_INTERP pointing to
/system/bin/linker in the vendor prebuilts.

Bug: 120266448
Test: m blueline, cf_x86, aosp_arm
The aforementioned files and symlinks are found

Change-Id: I97e38c29409ac0610dde285db8df6e94a7930094
2019-01-31 13:44:20 +09:00
Ryan Prichard
083d850b30 Move the linker allocator into libc
Rename LinkerMemoryAllocator -> BionicAllocator
Rename LinkerSmallObjectAllocator -> BionicSmallObjectAllocator

libc and the linker need to share an instance of the allocator for
allocating and freeing dynamic ELF TLS memory (DTVs and segments). The
linker also continues to use this allocator.

Bug: http://b/78026329
Test: /data/nativetest/bionic-unit-tests-static
Test: /data/nativetest64/bionic-unit-tests-static
Test: /data/nativetest/linker-unit-tests/linker-unit-tests32
Test: /data/nativetest64/linker-unit-tests/linker-unit-tests64
Change-Id: I2da037006ddf8041a75f3eba2071a8fcdcc223ce
2019-01-25 15:31:35 -08:00
Martijn Coenen
011523f4df Merge changes If330efda,I34864837,I8bc5c1cb
* changes:
  Add support for seccomp filter that limits setresuid/setresgid.
  Create APP_ZYGOTE seccomp policy.
  genfunctosyscallnrs: maps bionic functions to syscall numbers.
2019-01-22 22:22:42 +00:00
Martijn Coenen
d269d9b9e9 Add support for seccomp filter that limits setresuid/setresgid.
Add a new function that installs a seccomp filter that checks
all setresuid/setresgid syscalls to fall within the passed in
uid/gid range. It allows all other syscalls through. Therefore,
this filter is meant to be used in addition to one of the
regular whitelist syscall filters. (If multiple seccomp filters
are installed a in process, all filters are run, and the most
restrictive result is used).

Since the regular app and app_zygote seccomp filters block all
other calls to change uid/gid (setuid, setgid, setgroups,
setreuid, setregid, setfsuid), combining these filters prevents
the process from using any other uid/gid than the one passed as
arguments to the new function.

Bug: 111434506
Test: atest CtsSeccompHostTestCases
Change-Id: If330efdafbedd8e7d38ca81896a4dbb0bc49f431
2019-01-19 09:09:30 +01:00
Martijn Coenen
c3752be837 Create APP_ZYGOTE seccomp policy.
The APP_ZYGOTE seccomp policy is identical to the APP seccomp policy,
with the exception of allowing setresgid(32), which the app zygote
needs to be able to do (within a certain range).

Bug: 111434506
Test: manual
Change-Id: I34864837c981d201225e3e2e5501c0415a9a7dc8
2019-01-19 09:09:30 +01:00
Martijn Coenen
0c6de75a45 genfunctosyscallnrs: maps bionic functions to syscall numbers.
Bionic maps typical C functions like setresuid() to a syscall,
depending on the architecture used. This tool generates a .h
file that maps all bionic functions in SYSCALLS.txt to the
syscall number used on a particular architecture. It can then
be used to generate correct seccomp policy at runtime.

Example output in func_to_syscall_nrs.h:

Bug: 111434506
Test: manually inspect func_to_syscall_nrs.h
Change-Id: I8bc5c1cb17a2e7b5c534b2e0496411f2d419ad86
2019-01-19 09:09:30 +01:00
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