Commit graph

29119 commits

Author SHA1 Message Date
Ryan Prichard
8dc7da51b5 Merge "__cxa_finalize: skip fflush call on dlclose" into qt-dev 2019-04-30 19:43:17 +00:00
Ryan Prichard
1f2ea32463 __cxa_finalize: skip fflush call on dlclose
In __cxa_finalize, only call fflush(NULL) when the program is exiting, not
when a library is unloaded with dlclose. This change restores behavior
from 2015.

Flushing output is needed when the program exits, but flushing everything
is hazardous at other times because it can block -- fflush(NULL) locks
every file, so it also blocks on read operations.

Bug: http://b/130655235
Test: manual
Change-Id: I2f5ecffa6724bfd98a93d145ab5313c793c01ae6
(cherry picked from commit c5d8c6c6e4)
2019-04-26 14:52:18 -07:00
dimitry
62b214dc87 Make pthread_get/setschedparam weak for native bridge
Bug: http://b/130825973
Test: run affected app on cuttlefish
Change-Id: I776f26f5eaebdfdb1256ff621bd05ef5a90b852a
(cherry picked from commit c7b81108b4)
2019-04-26 10:27:00 +02:00
Yi Kong
b7944a3b2d Merge "Implement __gnu_[u]ldivmod_helper methods in libc" into qt-dev 2019-04-24 04:40:40 +00:00
Ryan Prichard
53080db75a Merge "PIMutexUnlock: load owner_tid in non-common case" into qt-dev 2019-04-23 20:55:52 +00:00
TreeHugger Robot
768eb27f0d Merge "Only write main library's RELRO by default." into qt-dev 2019-04-23 17:41:43 +00:00
Torne (Richard Coles)
ebfebd057a Only write main library's RELRO by default.
ANDROID_DLEXT_WRITE_RELRO was inadvertently writing out the RELRO
section of all libraries loaded during a given dlopen() call instead of
only the main library; since the other libraries are loaded at
unpredictable addresses this additional data is rarely useful.

Fix this to only happen when the
ANDROID_DLEXT_RESERVED_ADDRESS_RECURSIVE flag is being used.

Bug: 128623590
Test: DlExtRelroSharingTest.CheckRelroSizes
Change-Id: I05e8651d06ce2de77b8c85fe2b6238f9c09691ad
(cherry picked from commit 5d10374947)
2019-04-23 12:21:56 -04:00
Yi Kong
570ab497ae 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: Ie1ccdb711872bf3fc317cb908fed67c9a8955e42
Merged-In: I04a05258c6c06b5a22ead41e148b02792ffbc941
(cherry picked from commit b410d0e69e)
2019-04-23 08:11:52 +00:00
Ryan Prichard
ea722a0779 PIMutexUnlock: load owner_tid in non-common case
For a recursive or errorcheck PI mutex, the old_owner variable wasn't
being initialized. As a result, unlocking a doubly-locked recursive
mutex owned by another thread decremented the mutex counter. Instead, the
unlock call should fail with EPERM.

Bug: http://b/130841532
Test: bionic-unit-tests
Test: bionic-unit-tests-glibc --gtest_filter='pthread.pthread_mutex_lock*'
Change-Id: I37adb094cb2ce8d51df7b4f48e8d6bc144436418
(cherry picked from commit 4b6c0f5dce)
2019-04-23 00:19:30 -07:00
Elliott Hughes
84cb324786 Reland ifuncs for strcmp and strlen.
This reverts commit e4788d4c7e,
which undid this change during the Q betas.

Bug: http://b/120989619

(cherry picked from commit 927fe99692)

Change-Id: Ie8fc0fc0965055f312c2c0cc0f64adb7594ffdb4
2019-04-22 16:33:38 -07:00
Elliott Hughes
5bab966ca8 Workaround ASan not knowing about reallocarray.
Ensure we call realloc@plt rather than (as was previously happening)
inlining realloc into reallocarray, which makes the allocation invisible
to ASan.

Bug: http://b/129989984
Test: objdump

(cherry picked from commit 390be50067)

Change-Id: I0676b70cb9a7d7323252eabfff055c0e806915ef
2019-04-22 07:51:39 -07:00
Christopher Ferris
2601d43459 Move all leak info functions to android_mallopt.
Bug: 130028357

Test: malloc_hooks unit tests.
Test: Enable backtrace for mediaserver, run dumpsys media.player -m
Test: Enable backtrace for calendar, run am dumpheap -n <PID> <FILE>
Change-Id: I6774e28ccd9b3f2310127a5b39ccd15fe696a787
Merged-In: I6774e28ccd9b3f2310127a5b39ccd15fe696a787
(cherry picked from commit 3aadc5e80a)
2019-04-19 11:16:17 -07:00
Christopher Ferris
21f5850627 Merge "Remove gMallocLeakZygoteChild." into qt-dev 2019-04-17 17:30:22 +00:00
Daniel Mentz
bc3e37ca23 clean_header: Run outside of $ANDROID_BUILD_TOP
Enable the use case where we run clean_header.py from outside of
$ANDROID_BUILD_TOP. Previously, this script required the current working
directory to be under $ANDROID_BUILD_TOP. Running it from a different
directory resulted in the following error message:

 clean_header.py: error: Not in android tree pointed at by ANDROID_BUILD_TOP (....)

(cherry picked from commit d12d6f67bc)

Bug: 128420573
Change-Id: If07b0345401f5dd35b41876a3838209595bf8ab1
Merged-In: I48210ea1a0033228a9aaa4124d28247b07cee6d4
2019-04-16 14:26:20 -07:00
Daniel Mentz
5ca5d4aa1d clean_header: Fix error handling for no-such-file case
The function cleanupFile should always return a single value (as opposed
to a tuple or list). In addition, if it encounters an error, it is
expected to return a value that evaluates to False. As it stands,
however, it returns (None, None) in certain error cases. Change this
function to return None, in those cases.

We previously saw the following error message, when we tried to run
clean_header.py on a non-existent file.

Traceback (most recent call last):
  File "clean_header.py", line 208, in <module>
    b.updateGitFiles()
  File "utils.py", line 164, in updateGitFiles
    self._writeFile(dst)
  File "utils.py", line 136, in _writeFile
    f.write(self.new_data[dst])
TypeError: expected a string or other character buffer object

(cherry picked from commit 6d6b4cedd1)

Bug: 128420573
Change-Id: Id1dfab71e7efdee14950520df69f2e35219ee353
Merged-In: I5f717dd1a4388f598f0fd4bfd5e6129017de9095
2019-04-16 14:26:02 -07:00
Christopher Ferris
ab1c43dd6d Remove gMallocLeakZygoteChild.
Remove this global variable and change the setting of it to non-zero
to a call to android_mallopt.

In addition, change the initialize function to use pass a bool* instead of
int*.

Bug: 130028357

Test: Ran malloc_debug/malloc_hooks/perfetto tests.
Change-Id: I20d382bdeaaf38aac6b9dcabea5b3dfab3c945f6
Merged-In: I20d382bdeaaf38aac6b9dcabea5b3dfab3c945f6
(cherry picked from commit 5225b342f0)
2019-04-16 10:59:36 -07:00
Christopher Ferris
c8c4babc33 Add malloc benchmarks.
Adding some benchmarks that keep a certain number of allocation
around. This benchmark should not be used as an absolute for determining
what is a good/bad native allocator. However, it should be used to make
sure that numbers are not completely changed between allocator versions.

Also update the malloc sql benchmark to match the same style as these
new benchmarks.

Bug: 129743239

Test: Ran these benchmarks.
Change-Id: I1995d98fd269b61d9c96efed6eff3ed278e24c97
Merged-In: I1995d98fd269b61d9c96efed6eff3ed278e24c97
(cherry picked from commit 7ec2c8a9b6)
2019-04-09 13:26:50 -07:00
Jiyong Park
ff94a13d2d Don't load libc_malloc_* libs from runtime ns for libc_scudo
malloc_common_dynamic.cpp is compiled into both libc.so and
libc_scudo.so. When compiled for libc_scudo.so, it doesn't try to load
libc_malloc_* libs from the runtime linker namespace. This is because,
unlike libc.so which is shared from the runtime APEX, libc_scudo.so is
copied to any APEX that it needs. Furthermore, libdl_android which
provides android_get_exported_namespace is not available for vendors. So
the vendor variant of libc_scudo.so can't anyway locate the runtime
namespace.

Bug: 130213757
Bug: 122566199
Test: `m libc_scudo libc_scudo` is successful
Test: inspect the built library to see if it has reference to
android_get_exported_namespace

Change-Id: I4c41de361fdb3fa34b95218923f4ce4e9c010f9e
2019-04-10 02:29:25 +09:00
TreeHugger Robot
478f7f12b3 Merge "Load libc_malloc_* libraries from the runtime APEX" into qt-dev 2019-04-09 03:51:45 +00:00
Ryan Prichard
05c2966b2e Merge "Fix dlsym and dladdr for TLS symbols" into qt-dev 2019-04-05 20:03:19 +00:00
Jiyong Park
4e46ac69c2 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

Change-Id: I46980fbe89e93ea79a7760c9b8eb007af0ada8d8
(cherry picked from commit aea5c34423)
2019-04-06 00:19:37 +09:00
Ryan Prichard
3f05d3e971 Fix dlsym and dladdr for TLS symbols
* dlsym: call __tls_get_addr for TLS symbols

 * dladdr: skip TLS symbols

Bug: b/123772574
Test: bionic unit tests
Change-Id: I59a8bc4a7d455e1018b0d577b027b6417c8487cd
(cherry picked from commit e4d620bc80)
2019-04-04 16:46:59 -07:00
Adrian-CJ Hung
62bb17a890 Workaround potential access to unmapped stack
Issue:
Process is crashed near the end (startup_handshake_lock.unlock()) in
pthread_create().

The newly created child thread passes this handshake_lock unexpectedly
=> its stack is unmapped & its associated pthread_internal_t data
structure can’t be accessed.

Analysis:
The created child thread should be blocked by startup_handshake_lock.lock()
and enter __futex_wait_ex()

But if the parent thread is in the middle of startup_handshake_lock.unlock():

  void unlock() {
    if (atomic_exchange_explicit(&state, Unlocked, memory_order_seq_cst) == LockedWithWaiter) {  // => the state is modified to Unlocked

    // (a) if the child thread is back to running and pass the while() check in Lock::lock()
    // (b) the child thread executes its start_routine and then pthread_exit
    // (c) the stack of the child thread (where its pthread_internal_t (so the startup_handshake_lock) is located) will be unmapped

     __futex_wake_ex(&state, process_shared, 1);   // => when the parent thread is back to running
                                                   // the “state” & “process_shared” of startup_handshake_lock can’t be accessed (unmapped)
                                                   // so the process will be crashed
    }
  }

Bug: 129744706
Test: Monkey

(cherry picked from commit 8c1a14d4f3)

Change-Id: I88f3e1f205f802ece751aacd63fe7d3cc56f2a5f
2019-04-04 12:49:33 -07:00
Bill Rassieur
20a0001e05 Merge master@5406228 into git_qt-dev-plus-aosp.
am: 5da3333d1b

Change-Id: I25c9f2606c7d692fb1b7d40d8205122b27f74dda
2019-04-03 16:10:52 -07:00
Torne (Richard Coles)
07603294cd Merge "Fix DLEXT_WRITE_RELRO when loading multiple libs." am: 865866ee2b am: c950489599
am: ce62c05753

Change-Id: I234ee6e837fe2609918cee82121aa3994afbd4d8
2019-04-03 09:12:36 -07:00
Torne (Richard Coles)
ce62c05753 Merge "Fix DLEXT_WRITE_RELRO when loading multiple libs." am: 865866ee2b
am: c950489599

Change-Id: Iea5e24a6a46094cf87d77852ccc8b124c4bdb075
2019-04-03 08:36:06 -07:00
Torne (Richard Coles)
c950489599 Merge "Fix DLEXT_WRITE_RELRO when loading multiple libs."
am: 865866ee2b

Change-Id: I96ec82554fbb96b983d09db9c998274dda9e1a1a
2019-04-03 08:27:54 -07:00
Treehugger Robot
865866ee2b Merge "Fix DLEXT_WRITE_RELRO when loading multiple libs." 2019-04-03 15:19:57 +00:00
Pirama Arumuga Nainar
74ce129f90 Merge "Move bionic-unit-tests-static to libclang_rt.builtins" am: 96c21e43b4 am: b993b94d41
am: 55615c7b2c

Change-Id: I40b8dc97589c0a48fed037d3a35be6e25ef1b48a
2019-04-03 08:19:53 -07:00
Pirama Arumuga Nainar
55615c7b2c Merge "Move bionic-unit-tests-static to libclang_rt.builtins" am: 96c21e43b4
am: b993b94d41

Change-Id: Ifea68caa592bd22d36ab392ca8e3016c5b46e9b7
2019-04-03 08:11:26 -07:00
Pirama Arumuga Nainar
b993b94d41 Merge "Move bionic-unit-tests-static to libclang_rt.builtins"
am: 96c21e43b4

Change-Id: I79c2c06cd179d6cb1fa63e69735ae4bff0559145
2019-04-03 08:06:09 -07:00
Treehugger Robot
96c21e43b4 Merge "Move bionic-unit-tests-static to libclang_rt.builtins" 2019-04-03 14:45:47 +00:00
Pirama Arumuga Nainar
0d16a31664 Move bionic-unit-tests-static to libclang_rt.builtins
Bug: http://b/129728267
Bug: http://b/117167374

This test is now built with XOM (because libm now uses XOM) but it
should also use libclang_rt.builtins since libgcc is not built with XOM.

Test: bionic-unit-tests-static passes (but used to segfault with XOM
exceptions without this change).

Change-Id: I0b1dfe52e48db5f5e9386c7722ecd91e155be56f
2019-04-02 22:45:29 -07:00
Torne (Richard Coles)
fa9f7f28d4 Fix DLEXT_WRITE_RELRO when loading multiple libs.
ANDROID_DLEXT_WRITE_RELRO was causing the GNU RELRO sections of
libraries to become corrupted if more than one library was being loaded
at once (i.e. if the root library has DT_NEEDED entries for libraries
that weren't already loaded). The file offset was not being correctly
propagated between calls, so after writing out the (correct) RELRO data
to the file, it was mapping the data at file offset 0 for all libraries,
which corrupted the data for all but one of the libraries.

Fix this by passing file_offset as a pointer the same way that
phdr_table_map_gnu_relro does.

Bug: 128623590
Test: tbd
Change-Id: I196cd336bd5a67454e89fd85487356b1c7856871
2019-04-02 18:06:12 -04:00
Christopher Ferris
2fb7b814b0 Merge "Disable info messages by default for malloc debug." am: e6fd53b751 am: f2905f4ce3
am: 8e1ffaf89f

Change-Id: I64fd19ded1111960c8080f7c7f9eea84ca99651c
2019-04-02 14:24:47 -07:00
Christopher Ferris
8e1ffaf89f Merge "Disable info messages by default for malloc debug." am: e6fd53b751
am: f2905f4ce3

Change-Id: Iddb4900532ef816f8bf061a142cd0ec74b45a850
2019-04-02 13:40:11 -07:00
Christopher Ferris
f2905f4ce3 Merge "Disable info messages by default for malloc debug."
am: e6fd53b751

Change-Id: I088f92572a5b0af474a311f6bf73b48924b2960a
2019-04-02 13:06:53 -07:00
Christopher Ferris
e6fd53b751 Merge "Disable info messages by default for malloc debug." 2019-04-02 19:46:29 +00:00
Christopher Ferris
c328e4465d Disable info messages by default for malloc debug.
Add a new option verbose for malloc debug that is not enabled by default.
This disables all of the info log messages. It turns out these log
messages can add a measurable amount of time and can change the boot up.

Bug: 129239269

Test: Adjusted unit tests pass.
Test: Verified no messages unless verbose option used.
Change-Id: I805cb7c8ecb44de88119574e59d784877cacc383
2019-04-02 10:55:21 -07:00
Vic Yang
7e2220eed3 Merge "libc: Update symbol_ordering file" am: 4fbe126643 am: b325aaa0d1
am: 652a5974e6

Change-Id: I508666c8c3957ad4c5438006ace6643649f5f9f0
2019-04-01 21:19:02 -07:00
Vic Yang
652a5974e6 Merge "libc: Update symbol_ordering file" am: 4fbe126643
am: b325aaa0d1

Change-Id: I25992bd0c478750165924c1dfde59b719dcd85fe
2019-04-01 21:14:56 -07:00
Vic Yang
b325aaa0d1 Merge "libc: Update symbol_ordering file"
am: 4fbe126643

Change-Id: I65533c8e42cbc630d14fa3f62a70a4af9a652875
2019-04-01 21:10:50 -07:00
Treehugger Robot
4fbe126643 Merge "libc: Update symbol_ordering file" 2019-04-02 03:51:51 +00:00
Christopher Ferris
667457767e Merge "Create a lib that uses scudo instead of jemalloc." am: d486e024c6 am: b525ee4a11
am: f3edfb5773

Change-Id: Ie30808227d135bd9b60f0ae8c6c408523e7c6ea7
2019-04-01 19:13:34 -07:00
Christopher Ferris
f3edfb5773 Merge "Create a lib that uses scudo instead of jemalloc." am: d486e024c6
am: b525ee4a11

Change-Id: I5013c5efe11cd587d51f1766855eaa62d53b116e
2019-04-01 19:04:26 -07:00
Christopher Ferris
b525ee4a11 Merge "Create a lib that uses scudo instead of jemalloc."
am: d486e024c6

Change-Id: I181015004ab7c1f74112048395173d0067ba1753
2019-04-01 18:54:22 -07:00
Christopher Ferris
d486e024c6 Merge "Create a lib that uses scudo instead of jemalloc." 2019-04-02 01:37:07 +00: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
Vic Yang
90cca40111 libc: Update symbol_ordering file
There have been several changes since the file was created.  Update the
file with latest build.  We also sort the symbols by names when they
have the same size so that future updates are easier to review.

Bug: 124521408
Test: Build and inspect symbol ordering
Change-Id: Iedd885b9a87d882ae278a1f117f40b20d064c384
2019-04-01 12:08:50 -07:00
Yi Kong
d116f8d23b Merge "Modernise code to use override specifier" am: 4699cf6174 am: 2e3a19d5b4
am: d3a825fe61

Change-Id: Ia5e05fd2fdf4d6a003fe6960bca1bd41487ecc05
2019-03-29 19:42:35 -07:00