Commit graph

355 commits

Author SHA1 Message Date
Christopher Ferris
4df29ed9b4 Update to remove direct include of jemalloc_new.
In order to support scudo for non-svelte malloc and jemalloc5 for
svelte malloc, do not include jemalloc_new directly. Move that to
the export_include_dirs for libjemalloc5.

Also, change the way to enable scudo so that it only enables it
for the non-svelte config for now.

Bug: 137795072

Test: Builds
Change-Id: I3d68b443fe4d6b21729795649d0dcf66b7e95e03
2020-01-27 14:50:52 -08:00
Yifan Hong
29546b9133 Merge "Make ramdisk_available." 2020-01-24 22:39:41 +00:00
Elliott Hughes
22fb267ad6 Reimplement realpath.
Use O_PATH like musl to let the kernel do the hard work, rather than the
traditional BSD manual scheme.

Also add the most obvious missing tests from reading the man page, plus
a non-obvious test for deleted files.

Bug: http://b/131435126
Test: treehugger
Change-Id: Ie8a8986fea55f045952a81afee377ce8288a49d5
2020-01-22 18:30:50 -08:00
Yifan Hong
5a39cee1ce Make ramdisk_available.
Test: pass
Bug: 147347110
Change-Id: I142311a7558a19d209bcd63207a88e12cf6f130e
2020-01-22 12:09:33 -08:00
Christopher Ferris
c8226ec23d Merge "Revert "Enable the scudo native allocator."" 2020-01-21 21:32:32 +00:00
Peter Collingbourne
39d9156bdc Merge "Export the unwinder implementation from libc." 2020-01-21 21:28:44 +00:00
Anna Trostanetski
9981a1dac8 Revert "Enable the scudo native allocator."
This reverts commit b198958412.

Reason for revert: b/147838132. Breaks JNI calls.

Bug: 147838132

Change-Id: I657cf9fddc1e8ee60c1830a1b3f560ab51928a40
2020-01-20 20:17:10 +00:00
Ryan Savitski
b72fed164e Merge "allow for heapprofd's signal to be multiplexed" 2020-01-16 16:04:08 +00:00
Ryan Savitski
175c8867b0 allow for heapprofd's signal to be multiplexed
This patch refactors heapprofd_malloc to make it easier to reuse the
reserved signal for multiple purposes. We define a new generic signal
handler for profilers, which dispatches to more specific logic based on
the signal's payload (si_value).

The profiler signal handler is installed during libc preinit, after
malloc initialization (so races against synchronous heapprofd
initialization need not be considered). In terms of code organization, I
copied the existing approach with a loosely referenced function in
bionic_globals.h. Do tell if you'd rather a different approach here.

The profileability of a process is quite tied to the malloc
files/interfaces in bionic - in particular, it's set through
android_mallopt. I do not change that, but instead introduce a new
android_mallopt option to be able to query profileability of the
process (which is now used by the new profiler signal handler). As part
of that, gZygoteChildProfileable is moved from heapprofd_malloc to
common (alongside gZygoteChild).

I've removed the masking and reraising of the heapprofd signal when
racing against malloc_limit init. We're ok with taking a simpler
approach and dropping the heapprofd signal in such an unlikely race.

Note: this requires a corresponding change in heapprofd to use sigqueue()
instead of kill(), as the latter leaves the si_value uninitialized(?) on
the receiving side.

Bug: 144281346
Change-Id: I93bb2e82cff5870e5ca499cf86439860aca9dfa5
2020-01-15 22:55:03 +00:00
Christopher Ferris
b198958412 Enable the scudo native allocator.
This is attempt number two, all known failures and issues have
been fixed.

Bug: 137795072

Test: Built both svelte and non-svelte versions. Ran enormous numbers
Test: of performance testing.
Test: Ran scudo unit tests.
Test: Ran bionic unit tests.
Test: Ran libmemunreachable tests.
Test: Ran atest CtsRsBlasTestCases on cuttlefish instance.
Change-Id: Ib0c6ef38b63b7a1f39f4431ed8414afe3a92f9b5
2020-01-14 17:25:10 -08:00
Peter Collingbourne
6a363f7f41 Let libmemunreachable use bionic_libc_platform_headers.
Bug: 135772972
Change-Id: I2702abce849a46292dc467f9083f3b6816bfc5e6
2020-01-13 10:40:08 -08:00
Peter Collingbourne
f2b1e03606 Export the unwinder implementation from libc.
This supports the soong commit which causes most platform binaries to stop
statically linking against the unwinder implementation. The soong commit
message has more motivation for this change.

ARM32 uses LLVM libunwind, while all other platforms use libgcc as the
unwinder implementation. This matches the current choices of unwinders on
the various architectures, but means that apps which were directly linking
against the libc.so unwinder symbols on ARM32 are now using LLVM libunwind
instead of libgcc.

Set libc_headers sdk_version to 1 so that libunwind_llvm can depend on it,
and stop statically linking libunwind into libc_malloc_debug.

Bug: 144430859
Change-Id: I52c7f7893d93f500383aeb0b76086c3b6f1935a5
2020-01-10 19:07:59 -08:00
Peter Collingbourne
6dfde988e3 Merge "Add an android_mallopt for controlling the heap tagging level." 2020-01-10 15:22:24 +00:00
Peter Collingbourne
1e110fb717 Add an android_mallopt for controlling the heap tagging level.
This doesn't add any functionality for now, but there are
a couple of changes in flight that will want to add enumerators
to the mallopt, so let's give them a place to add them.

Bug: 135772972
Bug: 135754954
Change-Id: I6e810020f66070e844500c6fa99b703963365659
2020-01-09 16:39:10 -08:00
Josh Gao
5074e7d28f Move sigrtmin.h into platform headers.
Test: mma
Change-Id: Ibc97ef96fe9e32b948c245b06039b95fe4342f39
2020-01-02 14:14:15 -08:00
Ytai Ben-tsvi
5105ece816 Revert "Enable the scudo native allocator."
This reverts commit 6ffbe97859.

Reason for revert: Droidcop-triggered revert due to breakage b/146543543

Change-Id: Ie9a5b2f6ca5dbc8d3c6cafe70e34838d74e45c56
Bug: 146543543
2019-12-19 19:09:59 +00:00
Christopher Ferris
6ffbe97859 Enable the scudo native allocator.
Bug: 137795072

Test: Built both svelte and non-svelte versions. Ran enormous numbers
Test: of performance testing.
Test: Ran scudo unit tests.
Test: Ran bionic unit tests.
Change-Id: Iec6c98f2bdf6e0d5a6d18dff0c0883fac391c6d5
2019-12-18 12:27:40 -08:00
Wenhao Wang
35ee9d9a9f Merge "Add scsi directory" 2019-12-17 23:41:57 +00:00
Wenhao Wang
69537f1e2a Add scsi directory
This CL exports bionic/libc/kernel/android/scsi directory
to enable the usage of header files (e.g. sg.h) on that directory.

Test: Build AOSP 1187028
Change-Id: If580fcbc67378fab42d4f14cca1de337b603b673
2019-12-17 14:05:47 -08:00
Christopher Ferris
e1fd409fcb Add support for scudo svelte.
Bug: 137795072

Test: Built with scudo and scudo svelte.
Change-Id: Ib2afd5249b897b818012ee71547af1f4ee60201b
2019-12-16 16:22:55 -08:00
Peter Collingbourne
570de3337d Stop linking ndk_cruft*.cpp into libc.a.
We are about to introduce code into ndk_cruft that uses dlfcn.h, which isn't
available in static executables. Besides, none of the users of libc.a ought
to be depending on ndk_cruft anyway.

Bug: 144430859
Change-Id: Ic1f2e554e1fdbfee768c859acac032c1306d71fc
2019-12-11 10:01:15 -08:00
Elliott Hughes
c6b38aefa7 Sync with upstream OpenBSD strstr().
Bug: http://b/124855136
Test: treehugger
Change-Id: I6cbeb82bc0e418f50e6c171ac4e38e335c448db8
2019-11-22 11:16:23 -08:00
Peter Collingbourne
b061e77748 Link libgcc_stripped into libc.so and libm.so with --whole-archive on ARM.
This library was previously being statically linked into both libraries as a
consequence of the relocation to __aeabi_unwind_cpp_prX present in most object
files. However, after LLVM commit 1549b469, we no longer emit these relocations
on Android, so we need to link the library explicitly with --whole-archive. The
intent is to eventually stop linking libgcc into these libraries altogether,
but for now, we need to keep linking them in order to avoid breaking the build.

Change-Id: I275109527b7cbd6c4247b3fe348975d720626273
2019-11-12 14:26:23 -08:00
Nick Desaulniers
97c43095b9 bionic: libc: remove -Wimplicit-fallthrough
aosp/144287300 set it to a global cppflag.

The compiler upgrade can now check for this warning in C code.

This patch should be reverted once the BSD sources with instances of
-Wimplicit-fallthrough have been fixed.

Remove it from cflags, so that it's not re-enabled for C code until
fixed.

Bug: 139945549
Bug: 144287300
Test: mm
Change-Id: Ieca0d5b41634636477392e5209a41807f9b44bd4
Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
2019-11-11 10:49:10 -08:00
Ryan Prichard
249757bae2 Use ifuncs in the linker
Using ifuncs allows the linker to select faster versions of libc functions
like strcmp, making linking faster.

The linker continues to first initialize TLS, then call the ifunc
resolvers. There are small amounts of code in Bionic that need to avoid
calling functions selected using ifuncs (generally string.h APIs). I've
tried to compile those pieces with -ffreestanding. Maybe it's unnecessary,
but maybe it could help avoid compiler-inserted memset calls, and maybe
it will be useful later on.

The ifuncs are called in a special early pass using special
__rel[a]_iplt_start / __rel[a]_iplt_end symbols. The linker will encounter
the ifuncs again as R_*_IRELATIVE dynamic relocations, so they're skipped
on the second pass.

Break linker_main.cpp into its own liblinker_main library so it can be
compiled with -ffreestanding.

On walleye, this change fixes a recent 2.3% linker64 start-up time
regression (156.6ms -> 160.2ms), but it also helps the 32-bit time by
about 1.9% on the same benchmark. I'm measuring the run-time using a
synthetic benchmark based on loading libandroid_servers.so.

Test: bionic unit tests, manual benchmarking
Bug: none
Merged-In: Ieb9446c2df13a66fc0d377596756becad0af6995
Change-Id: Ieb9446c2df13a66fc0d377596756becad0af6995
(cherry picked from commit 772bcbb0c2)
2019-11-05 13:37:51 -08:00
Peter Collingbourne
e99912f2eb Define ANDROID_EXPERIMENTAL_MTE if the product variable experimental_mte is enabled.
This will activate code in bionic that uses the experimental MTE
userspace interface.

Bug: 135772972
Change-Id: I9ac641b9528de5376cdb920bee0e900a1b1fa9c2
2019-11-01 15:37:00 -07:00
Peter Collingbourne
36a56440e0 Pass -ffreestanding when compiling ifunc resolvers.
This flag prevents the compiler from inserting calls to libc functions in
the ifunc resolver code, which will definitely cause problems if the libc
function is itself an ifunc, but other calls that use the PLT may also be
affected, since libc may not have been fully resolved yet. As it turns out,
newer versions of clang will insert calls to memcmp in the body of the
init_cpu_variant() function in arch-arm/dynamic_function_dispatch.cpp.

Change-Id: I91f18d450835adc4b74565e9f48d5834f594a0c4
2019-10-31 17:21:17 -07:00
Peter Collingbourne
900d07d6a1 Add arm64 string.h function implementations for use with hardware supporting MTE.
As it turns out, our "generic" arm64 implementations of certain string.h
functions are not actually generic, since they will eagerly read memory
possibly outside of the bounds of an MTE granule, which may lead to a segfault
on MTE-enabled hardware. Therefore, move the implementations into a "default"
directory and use ifuncs to select between them and a new set of "mte"
implementations, conditional on whether the hardware and kernel support MTE.

The MTE implementations are currently naive implementations written in C
but will later be replaced with a set of optimized assembly implementations.

Bug: 135772972
Change-Id: Ife37c4e0e6fd60ff20a34594cc09c541af4d1dd7
2019-10-29 16:18:31 -07:00
Peter Collingbourne
609d6ec416 Merge "Adopt GNU calling convention for ifunc resolvers." 2019-10-29 17:19:33 +00:00
Elliott Hughes
ca3f8e4901 sleep/usleep: switch to trivial implementations.
Upstream keeps rearranging the deckchairs for these, so let's just
switch to the [roughly] one-liners rather than track that...

Test: treehugger
Change-Id: If655cf7a7f316657de44d41fadd43a8c55ee6f23
2019-10-28 22:25:02 -07:00
Peter Collingbourne
e949195f64 Adopt GNU calling convention for ifunc resolvers.
In order for an ifunc resolver to detect the presence of certain CPU features,
access to getauxval(AT_HWCAP) or getauxval(AT_HWCAP2) may be required. In order
for getauxval() to work, it needs to access the pointer to the auxiliary vector
stored by the linker in the libc shared globals data structure. Accessing the
shared globals requires libc to call the __libc_shared_globals() function
exported by the linker. However, in order to call this function, libc must
be fully relocated, which is not guaranteed to be the case at the point when
ifunc resolvers are called.

glibc solves this problem by passing the values of getauxval(AT_HWCAP)
(and getauxval(AT_HWCAP2) on aarch64) as arguments to the ifunc resolver.
Since this seems to be not only the most straightforward way to solve the
problem but also improves our compatibility with glibc, we adopt their
calling convention.

This change is ABI compatible with old resolvers because the arguments are
passed in registers, so the old resolvers will simply ignore the new arguments.

Bug: 135772972
Change-Id: Ie65bd6e7067f0c878df3d348c815fda61dc12de2
2019-10-28 20:20:29 -07:00
Ryan Prichard
22a6a058c7 Move dl_unwind_find_exidx from libdl.a to libc.a
arm32 has two special APIs to find exidx exception handling info,
dl_unwind_find_exidx and __gnu_Unwind_Find_exdix. The two functions have
identical behavior and function prototypes. libgcc's arm32 unwinder calls
__gnu_Unwind_Find_exdix, whereas LLVM's libunwind previously called
__gnu_Unwind_Find_exdix, but switched to dl_unwind_find_exidx as a result
of three patches (D30306, D30681, D39468).

In Bionic, for dynamic linking, __gnu_Unwind_Find_exdix in libc.so calls
dl_unwind_find_exidx in libdl.so.

For static executables, though, __gnu_Unwind_Find_exdix in libc.a used the
__exidx_* symbols, while dl_unwind_find_exidx in libdl.a(libdl_static.o)
was a return-0 no-op.

To fix the LLVM unwinder, replace the no-op dl_unwind_find_exidx in
libdl.a with a real function in libc.a(exidx_static.o), and have the GNU
function call the dl function for more consistency with dynamic linking.

dl_iterate_phdr follows a similar pattern, where the function exists in
libc.a and libdl.so (not libc.so or libdl.a).

This change makes unwinding work with an updated libunwind_llvm on arm32,
and it helps to allow unwinding in static executables without libdl.a.

Bug: https://github.com/android/ndk/issues/1094
Bug: http://b/141485154
Test: NDK tests, bionic unit tests
Change-Id: Ieeeb9b39a0e28544e21f9afe6fe51ef10d7c828c
2019-10-14 16:34:12 -07:00
Elliott Hughes
e9ff762789 Merge "Reimplement the <ctype.h> is* functions." 2019-10-09 15:09:45 +00:00
Elliott Hughes
a4959aa6f8 Reimplement the <ctype.h> is* functions.
Following on from the towlower()/towupper() changes, add benchmarks for
most of <ctype.h>, rewrite the tests to cover the entire defined range
for all of these functions, and then reimplement most of the functions.

The old table-based implementation is mostly a bad idea on modern
hardware, with only ispunct() showing a significant benefit compared to
any other way I could think of writing it, and isalnum() a marginal but
still convincingly genuine benefit.

My new benchmarks make an effort to test an example from each relevant
range of characters to avoid, say, accidentally optimizing the behavior
of `isalnum('0')` at the expense of `isalnum('z')`.

Interestingly, clang is able to generate what I believe to be the
optimal implementations from the most readable code, which is
impressive. It certainly matched or beat all my attempts to be clever!

The BSD table-based implementations made a special case of EOF despite
having a `_ctype_` table that's offset by 1 to include EOF at index 0.
I'm not sure why they didn't take advantage of that, but removing the
explicit check for EOF measurably improves the generated code on arm and
arm64, so even the two functions that still use the table benefit from
this rewrite.

Here are the benchmark results:

arm64 before:
  BM_ctype_isalnum_n                 3.73 ns         3.73 ns    183727137
  BM_ctype_isalnum_y1                3.82 ns         3.81 ns    186383058
  BM_ctype_isalnum_y2                3.73 ns         3.72 ns    187809830
  BM_ctype_isalnum_y3                3.78 ns         3.77 ns    181383055
  BM_ctype_isalpha_n                 3.75 ns         3.75 ns    189453927
  BM_ctype_isalpha_y1                3.76 ns         3.75 ns    184854043
  BM_ctype_isalpha_y2                4.32 ns         3.78 ns    186326931
  BM_ctype_isascii_n                 2.49 ns         2.48 ns    275583822
  BM_ctype_isascii_y                 2.51 ns         2.51 ns    282123915
  BM_ctype_isblank_n                 3.11 ns         3.10 ns    220472044
  BM_ctype_isblank_y1                3.20 ns         3.19 ns    226088868
  BM_ctype_isblank_y2                3.11 ns         3.11 ns    220809122
  BM_ctype_iscntrl_n                 3.79 ns         3.78 ns    188719938
  BM_ctype_iscntrl_y1                3.72 ns         3.71 ns    186209237
  BM_ctype_iscntrl_y2                3.80 ns         3.80 ns    184315749
  BM_ctype_isdigit_n                 3.76 ns         3.74 ns    188334682
  BM_ctype_isdigit_y                 3.78 ns         3.77 ns    186249335
  BM_ctype_isgraph_n                 3.99 ns         3.98 ns    177814143
  BM_ctype_isgraph_y1                3.98 ns         3.95 ns    175140090
  BM_ctype_isgraph_y2                4.01 ns         4.00 ns    178320453
  BM_ctype_isgraph_y3                3.96 ns         3.95 ns    175412814
  BM_ctype_isgraph_y4                4.01 ns         4.00 ns    175711174
  BM_ctype_islower_n                 3.75 ns         3.74 ns    188604818
  BM_ctype_islower_y                 3.79 ns         3.78 ns    154738238
  BM_ctype_isprint_n                 3.96 ns         3.95 ns    177607734
  BM_ctype_isprint_y1                3.94 ns         3.93 ns    174877244
  BM_ctype_isprint_y2                4.02 ns         4.01 ns    178206135
  BM_ctype_isprint_y3                3.94 ns         3.93 ns    175959069
  BM_ctype_isprint_y4                4.03 ns         4.02 ns    176158314
  BM_ctype_isprint_y5                3.95 ns         3.94 ns    178745462
  BM_ctype_ispunct_n                 3.78 ns         3.77 ns    184727184
  BM_ctype_ispunct_y                 3.76 ns         3.75 ns    187947503
  BM_ctype_isspace_n                 3.74 ns         3.74 ns    185300285
  BM_ctype_isspace_y1                3.77 ns         3.76 ns    187202066
  BM_ctype_isspace_y2                3.73 ns         3.73 ns    184105959
  BM_ctype_isupper_n                 3.81 ns         3.80 ns    185038761
  BM_ctype_isupper_y                 3.71 ns         3.71 ns    185885793
  BM_ctype_isxdigit_n                3.79 ns         3.79 ns    184965673
  BM_ctype_isxdigit_y1               3.76 ns         3.75 ns    188251672
  BM_ctype_isxdigit_y2               3.79 ns         3.78 ns    184187481
  BM_ctype_isxdigit_y3               3.77 ns         3.76 ns    187635540

arm64 after:
  BM_ctype_isalnum_n                 3.37 ns         3.37 ns    205613810
  BM_ctype_isalnum_y1                3.40 ns         3.39 ns    204806361
  BM_ctype_isalnum_y2                3.43 ns         3.43 ns    205066077
  BM_ctype_isalnum_y3                3.50 ns         3.50 ns    200057128
  BM_ctype_isalpha_n                 2.97 ns         2.97 ns    236084076
  BM_ctype_isalpha_y1                2.97 ns         2.97 ns    236083626
  BM_ctype_isalpha_y2                2.97 ns         2.97 ns    236084246
  BM_ctype_isascii_n                 2.55 ns         2.55 ns    272879994
  BM_ctype_isascii_y                 2.46 ns         2.45 ns    286522323
  BM_ctype_isblank_n                 3.18 ns         3.18 ns    220431175
  BM_ctype_isblank_y1                3.18 ns         3.18 ns    220345602
  BM_ctype_isblank_y2                3.18 ns         3.18 ns    220308509
  BM_ctype_iscntrl_n                 3.10 ns         3.10 ns    220344270
  BM_ctype_iscntrl_y1                3.10 ns         3.07 ns    228973615
  BM_ctype_iscntrl_y2                3.07 ns         3.07 ns    229192626
  BM_ctype_isdigit_n                 3.07 ns         3.07 ns    228925676
  BM_ctype_isdigit_y                 3.07 ns         3.07 ns    229182934
  BM_ctype_isgraph_n                 2.66 ns         2.66 ns    264268737
  BM_ctype_isgraph_y1                2.66 ns         2.66 ns    264445277
  BM_ctype_isgraph_y2                2.66 ns         2.66 ns    264327427
  BM_ctype_isgraph_y3                2.66 ns         2.66 ns    264427480
  BM_ctype_isgraph_y4                2.66 ns         2.66 ns    264155250
  BM_ctype_islower_n                 2.66 ns         2.66 ns    264421600
  BM_ctype_islower_y                 2.66 ns         2.66 ns    264341148
  BM_ctype_isprint_n                 2.66 ns         2.66 ns    264415198
  BM_ctype_isprint_y1                2.66 ns         2.66 ns    264268793
  BM_ctype_isprint_y2                2.66 ns         2.66 ns    264419205
  BM_ctype_isprint_y3                2.66 ns         2.66 ns    264205886
  BM_ctype_isprint_y4                2.66 ns         2.66 ns    264440797
  BM_ctype_isprint_y5                2.72 ns         2.72 ns    264333293
  BM_ctype_ispunct_n                 3.52 ns         3.51 ns    198956572
  BM_ctype_ispunct_y                 3.38 ns         3.38 ns    201661792
  BM_ctype_isspace_n                 3.39 ns         3.39 ns    206896620
  BM_ctype_isspace_y1                3.39 ns         3.39 ns    206569020
  BM_ctype_isspace_y2                3.39 ns         3.39 ns    206564415
  BM_ctype_isupper_n                 2.76 ns         2.75 ns    254227134
  BM_ctype_isupper_y                 2.76 ns         2.75 ns    254235314
  BM_ctype_isxdigit_n                3.60 ns         3.60 ns    194418653
  BM_ctype_isxdigit_y1               2.97 ns         2.97 ns    236082424
  BM_ctype_isxdigit_y2               3.48 ns         3.48 ns    200390011
  BM_ctype_isxdigit_y3               3.48 ns         3.48 ns    202255815

arm32 before:
  BM_ctype_isalnum_n                 4.77 ns         4.76 ns    129230464
  BM_ctype_isalnum_y1                4.88 ns         4.87 ns    147939321
  BM_ctype_isalnum_y2                4.74 ns         4.73 ns    145508054
  BM_ctype_isalnum_y3                4.81 ns         4.80 ns    144968914
  BM_ctype_isalpha_n                 4.80 ns         4.79 ns    148262579
  BM_ctype_isalpha_y1                4.74 ns         4.73 ns    145061326
  BM_ctype_isalpha_y2                4.83 ns         4.82 ns    147642546
  BM_ctype_isascii_n                 3.74 ns         3.72 ns    186711139
  BM_ctype_isascii_y                 3.79 ns         3.78 ns    183654780
  BM_ctype_isblank_n                 4.20 ns         4.19 ns    169733252
  BM_ctype_isblank_y1                4.19 ns         4.18 ns    165713363
  BM_ctype_isblank_y2                4.22 ns         4.21 ns    168776265
  BM_ctype_iscntrl_n                 4.75 ns         4.74 ns    145417484
  BM_ctype_iscntrl_y1                4.82 ns         4.81 ns    146283250
  BM_ctype_iscntrl_y2                4.79 ns         4.78 ns    148662453
  BM_ctype_isdigit_n                 4.77 ns         4.76 ns    145789210
  BM_ctype_isdigit_y                 4.84 ns         4.84 ns    146909458
  BM_ctype_isgraph_n                 4.72 ns         4.71 ns    145874663
  BM_ctype_isgraph_y1                4.86 ns         4.85 ns    142037606
  BM_ctype_isgraph_y2                4.79 ns         4.78 ns    145109612
  BM_ctype_isgraph_y3                4.75 ns         4.75 ns    144829039
  BM_ctype_isgraph_y4                4.86 ns         4.85 ns    146769899
  BM_ctype_islower_n                 4.76 ns         4.75 ns    147537637
  BM_ctype_islower_y                 4.79 ns         4.78 ns    145648017
  BM_ctype_isprint_n                 4.82 ns         4.81 ns    147154780
  BM_ctype_isprint_y1                4.76 ns         4.76 ns    145117604
  BM_ctype_isprint_y2                4.87 ns         4.86 ns    145801406
  BM_ctype_isprint_y3                4.79 ns         4.78 ns    148043446
  BM_ctype_isprint_y4                4.77 ns         4.76 ns    145157619
  BM_ctype_isprint_y5                4.91 ns         4.90 ns    147810800
  BM_ctype_ispunct_n                 4.74 ns         4.73 ns    145588611
  BM_ctype_ispunct_y                 4.82 ns         4.81 ns    144065436
  BM_ctype_isspace_n                 4.78 ns         4.77 ns    147153712
  BM_ctype_isspace_y1                4.73 ns         4.72 ns    145252863
  BM_ctype_isspace_y2                4.84 ns         4.83 ns    148615797
  BM_ctype_isupper_n                 4.75 ns         4.74 ns    148276631
  BM_ctype_isupper_y                 4.80 ns         4.79 ns    145529893
  BM_ctype_isxdigit_n                4.78 ns         4.77 ns    147271646
  BM_ctype_isxdigit_y1               4.74 ns         4.74 ns    145142209
  BM_ctype_isxdigit_y2               4.83 ns         4.82 ns    146398497
  BM_ctype_isxdigit_y3               4.78 ns         4.77 ns    147617686

arm32 after:
  BM_ctype_isalnum_n                 4.35 ns         4.35 ns    161086146
  BM_ctype_isalnum_y1                4.36 ns         4.35 ns    160961111
  BM_ctype_isalnum_y2                4.36 ns         4.36 ns    160733210
  BM_ctype_isalnum_y3                4.35 ns         4.35 ns    160897524
  BM_ctype_isalpha_n                 3.67 ns         3.67 ns    189377208
  BM_ctype_isalpha_y1                3.68 ns         3.67 ns    189438146
  BM_ctype_isalpha_y2                3.75 ns         3.69 ns    190971186
  BM_ctype_isascii_n                 3.69 ns         3.68 ns    191029191
  BM_ctype_isascii_y                 3.68 ns         3.68 ns    191011817
  BM_ctype_isblank_n                 4.09 ns         4.09 ns    171887541
  BM_ctype_isblank_y1                4.09 ns         4.09 ns    171829345
  BM_ctype_isblank_y2                4.08 ns         4.07 ns    170585590
  BM_ctype_iscntrl_n                 4.08 ns         4.07 ns    170614383
  BM_ctype_iscntrl_y1                4.13 ns         4.11 ns    171495899
  BM_ctype_iscntrl_y2                4.19 ns         4.18 ns    165255578
  BM_ctype_isdigit_n                 4.25 ns         4.24 ns    165237008
  BM_ctype_isdigit_y                 4.24 ns         4.24 ns    165256149
  BM_ctype_isgraph_n                 3.82 ns         3.81 ns    183610114
  BM_ctype_isgraph_y1                3.82 ns         3.81 ns    183614131
  BM_ctype_isgraph_y2                3.82 ns         3.81 ns    183616840
  BM_ctype_isgraph_y3                3.79 ns         3.79 ns    183620182
  BM_ctype_isgraph_y4                3.82 ns         3.81 ns    185740009
  BM_ctype_islower_n                 3.75 ns         3.74 ns    183619502
  BM_ctype_islower_y                 3.68 ns         3.68 ns    190999901
  BM_ctype_isprint_n                 3.69 ns         3.68 ns    190899544
  BM_ctype_isprint_y1                3.68 ns         3.67 ns    190192384
  BM_ctype_isprint_y2                3.67 ns         3.67 ns    189351466
  BM_ctype_isprint_y3                3.67 ns         3.67 ns    189430348
  BM_ctype_isprint_y4                3.68 ns         3.68 ns    189430161
  BM_ctype_isprint_y5                3.69 ns         3.68 ns    190962419
  BM_ctype_ispunct_n                 4.14 ns         4.14 ns    171034861
  BM_ctype_ispunct_y                 4.19 ns         4.19 ns    168308152
  BM_ctype_isspace_n                 4.50 ns         4.50 ns    156250887
  BM_ctype_isspace_y1                4.48 ns         4.48 ns    155124476
  BM_ctype_isspace_y2                4.50 ns         4.50 ns    155077504
  BM_ctype_isupper_n                 3.68 ns         3.68 ns    191020583
  BM_ctype_isupper_y                 3.68 ns         3.68 ns    191015669
  BM_ctype_isxdigit_n                4.50 ns         4.50 ns    156276745
  BM_ctype_isxdigit_y1               3.28 ns         3.27 ns    214729725
  BM_ctype_isxdigit_y2               4.48 ns         4.48 ns    155265129
  BM_ctype_isxdigit_y3               4.48 ns         4.48 ns    155216846

I've also corrected a small mistake in the documentation for isxdigit().

Test: tests and benchmarks
Change-Id: I4a77859f826c3fc8f0e327e847886882f29ec4a3
2019-10-08 12:04:09 -07:00
Jiyong Park
e87e0dcbae Restrict the availability of the bionic libs
The bionic libs are now restricted to be in the runtime APEX and the
platform (for bootstrapping). It can still be referenced from other
APEXes but can't be included there.

Bug: 139870423
Test: m
Change-Id: I7f99eef27ccf75844ca5c9a7ea866496841b738f
2019-10-07 13:52:32 +09:00
Christopher Ferris
e55e5eef8a Make it easy to switch between scudo and jemalloc.
Refactor some of the definitions to separate out all of the native
allocator pieces into one place that can be changed easily. This
should fix a few static libraries that appear to have accidentally
included jemalloc wrapper functions. For example, I verified that
libc_nomalloc.a no longer has references to any je_XXX functions.

Modify the bionic_libc_platform_headers to not include any libraries.
If this isn't updated, soong thinks there are cycles when used by
libscudo.

To enable scudo, change the libc_native_allocator_defaults defaults
from libc_jemalloc5_defaults to libc_scudo_defaults and comment out
the defaults: ["libc_scudo_wrapper_defaults"], line for the shared
library libc_scudo.

To do a final switch to scudo, it will be necessary to clean up
some code in other parts of the tree, but this allows a single cl
to enable or disable.

Bug: 137795072

Test: Builds with jemalloc or scudo with a small change.
Test: Ran bionic unit tests.
Change-Id: I07bb5432a0d2b2f405f92412e8d04fb9c9e51b31
Merged-In: I07bb5432a0d2b2f405f92412e8d04fb9c9e51b31
(cherry picked from commit ccff1b19ef)
2019-10-02 09:45:13 -07:00
Elliott Hughes
82ee3a08e2 Merge "Optimize tolower(3)/toupper(3) from <ctype.h>." 2019-09-30 18:49:51 +00:00
Christopher Ferris
d24c14d817 Merge "Make tls related header files platform accessible." 2019-09-30 16:15:33 +00:00
Elliott Hughes
1c8a2a99a7 Optimize tolower(3)/toupper(3) from <ctype.h>.
The tables in the BSD tolower/toupper are slower for ASCII than just
doing the bit twiddling.

We can't actually remove the tables on LP32, so move them into the
"cruft" we keep around for backwards compatibility (but remove them for
LP64 where they were never exposed).

I noticed that the new bit-twiddling tolower(3) was performing better
on arm64 than toupper(3). The 0xdf constant was requiring an extra MOV,
and there isn't a BIC that takes an immediate value. Since we've already
done the comparison to check that we're in the right range (where the
bit is always set), though, we can EOR 0x20 to get the same result as
the missing BIC 0x20 in just one instruction.

I've applied that same optimization to towupper(3) too.

Before:

  BM_ctype_tolower_n                 3.30 ns         3.30 ns    212353035
  BM_ctype_tolower_y                 3.31 ns         3.30 ns    211234204
  BM_ctype_toupper_n                 3.30 ns         3.29 ns    214161246
  BM_ctype_toupper_y                 3.29 ns         3.28 ns    207643473

  BM_wctype_towupper_ascii_n         3.53 ns         3.53 ns    195944444
  BM_wctype_towupper_ascii_y         3.48 ns         3.48 ns    199233248

After:

  BM_ctype_tolower_n                 2.93 ns         2.92 ns    242373703
  BM_ctype_tolower_y                 2.88 ns         2.87 ns    245365309
  BM_ctype_toupper_n                 2.93 ns         2.93 ns    243049353
  BM_ctype_toupper_y                 2.89 ns         2.89 ns    245072521

  BM_wctype_towupper_ascii_n         3.34 ns         3.33 ns    212951912
  BM_wctype_towupper_ascii_y         3.29 ns         3.29 ns    214651254

(Why do both the "y" and "n" variants speed up with the EOR
change? Because the compiler transforms the code so that we
unconditionally do the bit twiddling and then use CSEL to decide whether
or not to actually use the result.)

We also save 1028 bytes of data in the LP64 libc.so.

Test: ran the bionic benchmarks and tests
Change-Id: I7829339f8cb89a58efe539c2a01c51807413aa2d
2019-09-27 14:42:39 -07:00
Christopher Ferris
c5d3a4348a Make tls related header files platform accessible.
There are places in frameworks and art code that directly included
private bionic header files. Move these files to the new platform
include files.

This change also moves the __get_tls.h header file to tls.h and includes
the tls defines header so that there is a single header that platform
code can use to get __get_tls and the defines.

Also, simplify the visibility rules for platform includes.

Bug: 141560639

Test: Builds and bionic unit tests pass.
Change-Id: I9e5e9c33fe8a85260f69823468bc9d340ab7a1f9
Merged-In: I9e5e9c33fe8a85260f69823468bc9d340ab7a1f9
(cherry picked from commit 44631c919a)
2019-09-27 12:14:24 -07:00
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