Commit graph

35705 commits

Author SHA1 Message Date
Colin Cross
daa6b82edf Fix bionic benchmarks and header tests for musl
Fix references to symbols that don't exist in musl in the bionic
benchmarks, and disable the header tests for musl.

Bug: 190084016
Test: m USE_HOST_MUSL=true host-native
Change-Id: I6b1964afa4a7b6e6a4812e9f2605fcfc2fae9691
2022-02-02 12:36:39 -08:00
Florian Mayer
8266380c77 Merge "Fix HWASan crashes in heapprofd initialization." 2022-02-01 20:30:25 +00:00
Florian Mayer
6c1c3422a2 Fix HWASan crashes in heapprofd initialization.
Test: atest perfetto_integrationtests on HWASan build

Bug: 210588740
Change-Id: Iddaa4a7d0dedee541f97bbf0a13958de023bdf59
2022-02-01 17:10:32 +00:00
Treehugger Robot
650233457a Merge "Silence -Wnon-power-of-two-alignment for a test" 2022-01-29 01:04:50 +00:00
Pirama Arumuga Nainar
44dd9facb2 Silence -Wnon-power-of-two-alignment for a test
Bug: http://b/214080353

The wrong alignment to aligned_alloc() is deliberate.  Silence the
warning around the test.

Test: build with clang-r445002
Change-Id: I73bad7775423c908c2bbe1c550e8ce5aeede129d
2022-01-28 13:27:07 -08:00
Daniele Di Proietto
f7e721cdc9 Merge "Fix recursive deadlock inside bionic_systrace" 2022-01-26 23:12:27 +00:00
Daniele Di Proietto
f5f04b19fe Fix recursive deadlock inside bionic_systrace
The first time should_trace() returns true, bionic_trace_begin() calls
open() on trace_marker.

The problem is that open() can call bionic_trace_begin(). We've observed
this happening, for example when:

* fdtrack is enabled. dlopen("libfdtrack.so") can be used to enable
  fdtrack on a process.
* ThreadA is busy unwinding inside fdtrack and is holding an fdtrack
  internal mutex.
* ThreadB calls bionic_trace_begin() for the first time since the
  property "debug.atrace.tags.enableflags" contains ATRACE_TAG_BIONIC.
* ThreadB calls open("/sys/kernel/tracing/trace_marker"). Since fdtrack
  is enabled, ThreadB tries to do unwinding as well.
* ThreadB, inside fdtrack's unwinding tries to grab the same mutex that
  ThreadA is holding.
* Mutex contention is reported using bionic_systrace, therefore
  bionic_trace_begin() is called again on ThreadB.
* ThreadB tries to grab g_lock in bionin_systrace.cpp, but that's
  already held by ThreadB itself, earlier on the stack. Therefore
  ThreadB is stuck.

I managed to reproduce the above scenario by manually pausing ThreadA
inside unwinding with a debugger and letting ThreadB hitting
bionic_trace_begin() for the first time.

We could avoid using g_lock while calling open() (either by releasing
g_lock and reacquiring it later, or by using atomics), but
bionic_trace_begin() would try to call open() again. In my tests, open()
does not call bionic_trace_begin() a third time, because fdtrack has
reentrancy protection, but there might be another code path inside open
that calls bionic_trace_begin again (it could be racy or only happen in
certain configurations).

This commit fixes the problem by implementing reentrancy protection in
bionic_systrace.

Sample callstack from ThreadA deadlocked before the fix:
```
  * frame #0: 0x0000007436db077c libc.so`syscall at syscall.S:41
    frame #1: 0x0000007436db0ba0 libc.so`bionic_trace_begin(char const*) [inlined] __futex(ftx=0x000000743737a548, op=<unavailable>, value=2, timeout=0x0000000000000000, bitset=-1) at bionic_futex.h:45:16
    frame #2: 0x0000007436db0b8c libc.so`bionic_trace_begin(char const*) [inlined] __futex_wait_ex(ftx=0x000000743737a548, value=2) at bionic_futex.h:66:10
    frame #3: 0x0000007436db0b78 libc.so`bionic_trace_begin(char const*) [inlined] Lock::lock(this=0x000000743737a548) at bionic_lock.h:67:7
    frame #4: 0x0000007436db0b74 libc.so`bionic_trace_begin(char const*) [inlined] should_trace() at bionic_systrace.cpp:38:10
    frame #5: 0x0000007436db0b74 libc.so`bionic_trace_begin(message="Contending for pthread mutex") at bionic_systrace.cpp:59:8
    frame #6: 0x0000007436e193e4 libc.so`NonPI::MutexLockWithTimeout(pthread_mutex_internal_t*, bool, timespec const*) [inlined] NonPI::NormalMutexLock(mutex=0x0000007296cae9f0, shared=0, use_realtime_clock=false, abs_timeout_or_null=0x0000000000000000) at pthread_mutex.cpp:592:17
    frame #7: 0x0000007436e193c8 libc.so`NonPI::MutexLockWithTimeout(mutex=0x0000007296cae9f0, use_realtime_clock=false, abs_timeout_or_null=0x0000000000000000) at pthread_mutex.cpp:719:16
    frame #8: 0x0000007436e1912c libc.so`::pthread_mutex_lock(mutex_interface=<unavailable>) at pthread_mutex.cpp:839:12 [artificial]
    frame #9: 0x00000071a4e5b290 libfdtrack.so`std::__1::mutex::lock() [inlined] std::__1::__libcpp_mutex_lock(__m=<unavailable>) at __threading_support:256:10
    frame #10: 0x00000071a4e5b28c libfdtrack.so`std::__1::mutex::lock(this=<unavailable>) at mutex.cpp:31:14
    frame #11: 0x00000071a4e32634 libfdtrack.so`unwindstack::Elf::Step(unsigned long, unwindstack::Regs*, unwindstack::Memory*, bool*, bool*) [inlined] std::__1::lock_guard<std::__1::mutex>::lock_guard(__m=0x0000007296cae9f0) at __mutex_base:104:27
    frame #12: 0x00000071a4e32618 libfdtrack.so`unwindstack::Elf::Step(this=0x0000007296cae9c0, rel_pc=66116, regs=0x0000007266ca0470, process_memory=0x0000007246caa130, finished=0x0000007ff910efb4, is_signal_frame=0x0000007ff910efb0) at Elf.cpp:206:31
    frame #13: 0x00000071a4e2b3b0 libfdtrack.so`unwindstack::LocalUnwinder::Unwind(this=0x00000071a4ea1528, frame_info=<unavailable>, max_frames=34) at LocalUnwinder.cpp:102:22
    frame #14: 0x00000071a4e2a3ec libfdtrack.so`fd_hook(event=<unavailable>) at fdtrack.cpp:119:18
    frame #15: 0x0000007436dbf684 libc.so`::__open_2(pathname=<unavailable>, flags=<unavailable>) at open.cpp:72:10
    frame #16: 0x0000007436db0a04 libc.so`bionic_trace_begin(char const*) [inlined] open(pathname=<unavailable>, flags=524289) at fcntl.h:63:12
    frame #17: 0x0000007436db09f0 libc.so`bionic_trace_begin(char const*) [inlined] get_trace_marker_fd() at bionic_systrace.cpp:49:25
    frame #18: 0x0000007436db09c0 libc.so`bionic_trace_begin(message="pthread_create") at bionic_systrace.cpp:63:25
```

Bug: 213642769
Change-Id: I10d331859045cb4a8609b007f5c6cf2577ff44df
2022-01-25 20:50:12 +00:00
Evgenii Stepanov
97ec0e312b Merge "Fix MemtagNoteTest and make it runnable on non-MTE devices." 2022-01-25 18:27:16 +00:00
Yi Kong
fb946fd873 Merge "Move linker from sampling PGO to AFDO pipeline" 2022-01-25 17:50:09 +00:00
Peter Collingbourne
ccae7efeed Merge "Disable pointer authentication in app processes." 2022-01-24 21:17:30 +00:00
Yi Kong
e20a1d9060 Move linker from sampling PGO to AFDO pipeline
Sampling PGO is being replaced by AFDO.

Test: presubmit
Change-Id: I23e4dace5f2c2d1f2499daba99a28b2a1bc0f22d
2022-01-25 03:19:58 +08:00
Evgenii Stepanov
e37ca53157 Fix MemtagNoteTest and make it runnable on non-MTE devices.
Update the path to the helper binary, and run the test on non-MTE
hardware with the expectation that the bug is not detected.

Test: bionic-unit-tests
Bug: none
Change-Id: I34eb4dc46d0bacd83824d307398f7891d4806686
2022-01-21 19:55:54 +00:00
Peter Collingbourne
bf52e88596 Disable pointer authentication in app processes.
Unfortunately we have discovered that some applications in the wild
are using PAC instructions incorrectly. To keep those applications
working on PAC enabled devices, disable PAC in application processes
for now.

Bug: 212660282
Change-Id: I3030c47be9d02a27505bd4775c1982a20755758c
2022-01-19 13:35:54 -08:00
Elliott Hughes
b838fbda2a Merge "libm: sync with upstream." 2022-01-18 22:21:25 +00:00
Treehugger Robot
095509f80a Merge "Update the status for S and T." 2022-01-16 04:49:18 +00:00
Elliott Hughes
57f17dea20 Update the status for S and T.
Test: treehugger
Change-Id: I21c4374d7e55dbbb2294cef5cc7bf50b7fe1b549
2022-01-14 16:26:25 -08:00
Elliott Hughes
e62be7eea5 Merge "Don't use LLVM when readelf(1) will do." 2022-01-14 19:45:54 +00:00
Elliott Hughes
1ff7be0713 Don't use LLVM when readelf(1) will do.
This was probably the least worst choice at the time, but we have toybox
readelf now, which is a much lighter-weight dependency (that we already
have for some other tests).

This is also one less use of the *renderscript* LLVM, which we'll be
wanting to finally delete soon.

Test: treehugger
Change-Id: I0e05b8f139ec6e6a425b575368f3d514b8b1cc64
2022-01-13 15:46:13 -08:00
Treehugger Robot
4a85b045fd Merge "Don't use llvm-defaults to build some tests." 2022-01-13 03:55:16 +00:00
Elliott Hughes
99ef447d0f libm: sync with upstream.
There's potential here to maybe lose some/all of builtins.cpp, but I'll
look at that separately later.

Test: treehugger
Change-Id: I2c2bc1d0753affdd214daeb09fa1ac7cd73db347
2022-01-12 17:52:15 -08:00
Treehugger Robot
5396787062 Merge "Fix copy pasta in guard macro for weak symbols." 2022-01-12 22:19:11 +00:00
Elliott Hughes
db358e6ae1 Don't use llvm-defaults to build some tests.
It's not clear this was ever needed, it doesn't seem to make any
difference now, and these are the defaults for the obsolete renderscript
LLVM anyway, so... yeah.

This was noticed because it was causing some of our tests to be built as
C++11 rather than [the current default of] C++17.

Test: treehugger
Change-Id: I7d72b3fd58e9cf9a02048b0298eee845d19307f7
2022-01-12 09:15:46 -08:00
Christopher Ferris
c79b02088b Merge "Update to v5.16 kernel headers." 2022-01-11 21:39:53 +00:00
Christopher Ferris
a479261feb Update to v5.16 kernel headers.
Kernel headers coming from:

Git: https://android.googlesource.com/kernel/common/
Branch: android-mainline
Tag: android-mainline-5.16

Test: Builds and bionic unit tests pass.
Change-Id: I2522c4f2a0efb9f8a193e1f2d65868e478217502
2022-01-10 13:51:15 -08:00
Treehugger Robot
f62c8f99cb Merge "Remove availability definitions for mbs APIs." 2022-01-10 21:04:37 +00:00
Dan Albert
e4106253e7 Fix copy pasta in guard macro for weak symbols.
This was pretty broken. I think anything using this was being given
always-available annotations for everything but 32-bit x86? Treehugger
should complain loudly if this was actually impacting anything though.
I suspect not since the only user of this mode is mainline which
doesn't target far back enough to have arch-specific introduction
guards.

Test: treehugger
Bug: None
Change-Id: I64e96a89d83e64512e661e88915c48a091198992
2022-01-07 16:06:54 -08:00
Dan Albert
952da92670 Remove availability definitions for mbs APIs.
Definitions for these are provided in libandroid_support for API
levels that do not expose this in the stubs. For the rare cases where
libandroid_support is not being used this will result in a lower
quality diagnostic (undefined reference instead of "not available
until API 21"), but other fixes would also have that behavior because
the libandroid_support headers are *always* available, even if
libandroid_support won't be linked.

Test: Reverted xfailed tests for #1108 and reran tests with this
Bug: https://github.com/android/ndk/issues/1108
Change-Id: I371f5b9d7caeef8dc7c80f2f6d11280ecba119c9
2022-01-07 14:38:29 -08:00
Elliott Hughes
e2c784f159 Merge "c32rtomb/mbrtoc32: remove dead code." 2021-12-16 23:52:55 +00:00
Elliott Hughes
c73c19acdb Merge "sched.h: add doc comments." 2021-12-16 23:47:13 +00:00
Elliott Hughes
31fbc1469f sched.h: add doc comments.
Test: treehugger
Change-Id: I9a6dd40bb26a5966dd32dbdf573cddc874bcb508
2021-12-15 13:56:39 -08:00
Elliott Hughes
ad1658ecfe c32rtomb/mbrtoc32: remove dead code.
When we added the fast path for the common case of ASCII, we forgot to
remove the now-dead code that handled the 1-byte case later in these
functions. This was obvious from the code coverage data.

Note that the 16-bit variants are unaffected because they're implemented
as calls to the 32-bit variants with extra range checks/surrogate
handling surrounding the call.

Test: treehugger
Change-Id: Ibd40f823519acb9aae8037bdeb3f9c5e36b9d9a6
2021-12-15 13:41:20 -08:00
Christopher Ferris
084d60a027 Merge "Mark variables as unused." 2021-12-15 18:36:43 +00:00
Christopher Ferris
724efbb57c Mark variables as unused.
clang is smart enough to notice a variable is set but not used,
but these variable are used for testing purposes. Mark one as
unused, and convert the other to a DoNotOptimize.

Bug: 197240255

Test: Compiles without warnings.
Test: Ran unit tests on coral hwasan build.
Change-Id: Ibc873e477355a702579e5a680780c77db0c58046
2021-12-14 23:02:53 +00:00
Christopher Ferris
f190be84f5 Merge "Add mallinfo2 call." 2021-12-14 05:55:16 +00:00
Elliott Hughes
1d88b551bc Merge "Add some documentation about EINTR." am: a73179fe30
Original change: https://android-review.googlesource.com/c/platform/bionic/+/1918454

Change-Id: Ia553ea3a8a3e9f966cdddf024611b3a634aafe59
2021-12-14 00:43:12 +00:00
Elliott Hughes
a73179fe30 Merge "Add some documentation about EINTR." 2021-12-14 00:25:54 +00:00
Christopher Ferris
8248e62fa9 Add mallinfo2 call.
Bug: 208293616

Test: New unit tests pass.
Change-Id: I619219b7322e2dd1c82b9c8a171dfbfe7eac6706
2021-12-13 14:26:17 -08:00
Elliott Hughes
38be11e88c Add some documentation about EINTR.
It's a common cause of confusion, and even a brief explanation can be
quite involved, so it's worth having something we can point to (and
something that interested parties might just find via a web search).

Bug: http://b/207248554
Test: treehugger
Change-Id: I4a6d8917baf99a8f7abef05ce852a31ebe048d68
2021-12-13 10:16:57 -08:00
Treehugger Robot
b2ff5e9dc2 Merge "Clarify that fdsan wasn't "enforcing" in its first release." am: 6769ccbe88
Original change: https://android-review.googlesource.com/c/platform/bionic/+/1917499

Change-Id: Id7740149851f161ddbf113257a1d9109a7843740
2021-12-10 21:47:37 +00:00
Treehugger Robot
6769ccbe88 Merge "Clarify that fdsan wasn't "enforcing" in its first release." 2021-12-10 21:23:33 +00:00
Elliott Hughes
32a72522e0 Clarify that fdsan wasn't "enforcing" in its first release.
Change-Id: I02c4ff49446995b5ea33f4fa9ca30cf204307ae8
2021-12-10 01:42:31 +00:00
Elliott Hughes
83abd83c34 Merge "strftime: format small positive integers ourselves." am: ad12582726
Original change: https://android-review.googlesource.com/c/platform/bionic/+/1897133

Change-Id: I3dab64aa9f5f94b17399b4a08d81ae847473a43a
2021-12-07 20:49:02 +00:00
Elliott Hughes
ad12582726 Merge "strftime: format small positive integers ourselves." 2021-12-07 20:30:53 +00:00
Elliott Hughes
e4d5efe231 strftime: format small positive integers ourselves.
A decent chunk of the logcat profile is spent formatting the timestamps
for each line, and most of that time was going to snprintf(3). We should
find all the places that could benefit from a lighter-weight "format an
integer" and share something between them, but this is easy for now.

Before:

-----------------------------------------------------------
Benchmark                 Time             CPU   Iterations
-----------------------------------------------------------
BM_time_strftime        781 ns          775 ns       893102

After:

-----------------------------------------------------------
Benchmark                 Time             CPU   Iterations
-----------------------------------------------------------
BM_time_strftime        149 ns          147 ns      4750782

Much of the remaining time is in tzset() which seems unfortunate.

Test: treehugger
Change-Id: Ie0f7ee462ff1b1abea6f87d4a9a996d768e51056
2021-12-06 14:55:00 -08:00
Elliott Hughes
670acdbb1e Merge "Use -fno-builtin for libc and libm." am: bb802661af
Original change: https://android-review.googlesource.com/c/platform/bionic/+/1909404

Change-Id: I15db9d94403480899a29b37e58b2d06bb63770b3
2021-12-03 16:11:08 +00:00
Elliott Hughes
bb802661af Merge "Use -fno-builtin for libc and libm." 2021-12-03 15:55:35 +00:00
Peter Collingbourne
3860403271 Merge "Fix a race condition in the bionic pthread tests." am: a43e7a87b3
Original change: https://android-review.googlesource.com/c/platform/bionic/+/1909043

Change-Id: If8069be6bbe928637233cd910fad31b2e5bbc206
2021-12-03 01:13:42 +00:00
Peter Collingbourne
a43e7a87b3 Merge "Fix a race condition in the bionic pthread tests." 2021-12-03 00:55:43 +00:00
Elliott Hughes
a13d0660fe Use -fno-builtin for libc and libm.
clang was getting in the way of a strftime(3) optimization, and smaller
hammers weren't working, and this seems like the right choice for libc
anyway? If we have code that can usefully be optimized, we should do it
in the source. In general, though, no libc/libm author should be
ignorant of memset(3) or memcpy(3), and would have used it themselves if
it made sense. (And the compiler isn't using profiling data or anything;
it's just always assuming it should use the functions, and doesn't
consider whether the cost of the calls can be amortized or not.)

Test: treehugger
Change-Id: Ia7e22623e47bfbfcfe46c1af0d95ef7e8669c0f6
2021-12-02 14:42:16 -08:00
Peter Collingbourne
c5b81844b6 Fix a race condition in the bionic pthread tests.
It's possible for the main thread to leave the RunTimedTest
function before the waiting thread has had a chance to call e.g.
pthread_cond_timedwait(). In this case, pthread_cond_timedwait()
will access the local variable ts after its lifetime has ended. Fix
the bug by making ts a field of pthread_CondWakeupTest instead. The
lifetime of pthread_CondWakeupTest is tied to that of the waiting
thread via the pthread_join() call.

Found with HWASan + uaccess logging.

Change-Id: Iefe8deb30a367dc518013d741c425b041596b0d3
2021-12-02 12:45:54 -08:00