Commit graph

10066 commits

Author SHA1 Message Date
Hans Boehm
9ac60bf82b Make stdatomic.h work with gcc4.6 host compiler
This is needed to make L work correctly, and bionic tests pass
again, after applying the equivalent of
commit 00aaea3645 there.

It makes the preexisting code that uses __sync implementations
much more useful, although we should no longer be exercising that
code in AOSP.

Specifically fixes:

We were invoking __has_extension and __has_builtin for GCC compilations.
They're clang specific. Restructured the tests.

The __sync implementation was not defining the LOCK_FREE macros.

ATOMIC_VAR_INIT was using named field initializations.  These are a
C, not C++, feature, that is not supported by g++ 4.6.

The stdatomic bionic test still failed with 4.6 and glibc with our
questionable LOCK_FREE macro implementation.  Don't run that piece
with 4.6.

In L, this is a prerequisite for fixing:

    Bug:16880454
    Bug:16513433

Change-Id: I9b61e42307f96a114dce7552b6ead4ad1c544eab
(cherry picked from commit 32429606bf)
2014-09-02 11:37:02 -07:00
Hans Boehm
2b10e2f122 Undefine _Atomic before redefining
Stdatomic.h was potentially redefining _Atomic, in spite of a
prior definition by <atomic>.  This could cause g++ builds that
included <stdatomic.h> with an available <atomic> header to break.

A functional stdatomic.h is a prerequisite for fixing the
following bugs.  This is the middle of 3 AOSP updates to
bionics stdatomic.h that are needded to get there.

Bug:16880454
Bug:16513433

Change-Id: I562c7115118c0587d594d4d5b62d25101e47bfd8
(cherry picked from commit 3e4a0099a1)
2014-09-02 10:32:34 -07:00
Hans Boehm
c8cf3513ec Fix, generalize stdatomic.h; improve test.
We seem to use this stdatomic.h sometimes, and slightly different prebuilts
at other times, making them all difficult to test, and making it unclear
which one we're testing.  This generalizes the bionic header so that it
can be used directly as the prebuilt header as well.  So long as they
don't diverge again, that should somewhat improve test coverage.

Use the correct builtin for atomic_is_lock_free.

Fix atomic_flag_init.

Turn on atomic tests even with __GLIBC__, since they now appear to pass.

Include uchar.h in stdatomic.h where needed.

Add a basic memory ordering test.

Fix bit-rotted comments in bionic tests makefile.

Prerequisite for fixing b/16880454 and

Bug:16513433

Change-Id: If6a14c1075b379395ba5d93357d56025c0ffab68
(cherry picked from commit 00aaea3645)
2014-09-02 10:32:33 -07:00
Dmitriy Ivanov
c191a8adee Merge "Look into ld_preloads before current library" into lmp-dev 2014-09-01 21:08:55 +00:00
Elliott Hughes
b2eb09a9ed Use __GNUC_PREREQ rather than __GNUC_PREREQ__ to match glibc.
Bug: 16874785

(cherry picked from commit e0c56efddf)

Change-Id: I9c922ba019f648766fc399d1c4e35e789e25acd4
2014-08-29 16:10:57 -07:00
Dmitriy Ivanov
05e190c093 Look into ld_preloads before current library
Change lookup order during relocation so that
 ld_preloads always precede caller (unless caller
 is main executable).

 Asan needs this change in order to intercept libc->libc
 calls.

Bug: 15432753
Change-Id: If69aa16efe59aa35bb30e96feb83d08f1efbec86
2014-08-29 11:46:06 -07:00
Elliott Hughes
67f1f3b171 Have pthread_attr_getstack for the main thread report RLIMIT_STACK...
...rather than just what's already mapped in. This seems somewhat
contrary to POSIX's "All pages within the stack described by stackaddr
and stacksize shall be both readable and writable by the thread", but
it's what glibc does.

Bug: 17111575

(cherry picked from commit 9e4ffa7032)

Change-Id: I73f219a569917b2e4546c09436d7ef5231facc07
2014-08-27 16:50:53 -07:00
Elliott Hughes
a0eeb0b69f Merge "Fix pthread_getattr_np for the main thread." into lmp-dev 2014-08-27 23:49:56 +00:00
Christopher Ferris
598d25bf78 Merge "Replace snprintf calls in linker." into lmp-dev 2014-08-27 22:42:11 +00:00
Christopher Ferris
172955a4e3 Replace snprintf calls in linker.
When enabling debug malloc, the snprintf calls in the linker fails to
update the buffer.

The problem is that snprintf makes a call to pthread_getspecific that
returns a valid pointer, but the data it points to is zero. This should
never happen and causes the snprintf to stop and do nothing.

Temporarily replace snprintf with a different implementation to work
around this issue.

Bug: 16874447
Bug: 17302493
Change-Id: I7a500f28adf153150cf2812fae745ff41f1c48d3
2014-08-27 15:30:43 -07:00
Elliott Hughes
6cc4e3b6ce Merge "call uselocale() before freelocale() to make sure that g_local_key has a valid locale." into lmp-dev 2014-08-27 17:25:23 +00:00
Wally Yau
8a46cf0fcf call uselocale() before freelocale() to make sure that g_local_key has a valid locale.
For tests that call uselocale(), the locale is stored in the
g_userlocale_key thread-specific key. If freelocale() is called later,
then g_uselocal_key points to a deleted pointer. CTS eventually calls
vfprintf to print the result, which calls MB_CUR_MAX and MB_CUR_MAX
accesses the deleted locale stored in g_uselocale_key, causing unpredictable
errors.

Fixed the tests by calling uselocale() with the old locale before
calling freelocale.

Bug: 17299565
Change-Id: I87efa2a9b16999a11d587f68d3aeedcbe6ac8a2c
2014-08-27 17:22:29 +00:00
Christopher Ferris
3f7635f490 Use the default unwind code.
This speeds up the debug malloc code by using the original unwinding code.
The only catch is that it has to link in the libc++ arm unwind code or
there will be crashes when attempting to unwind through libc++ compiled
code.

Bug: 16874447
Change-Id: Ifdbbcbd4137d668b25cf3c2bd59535e06ebfa5a7
2014-08-26 16:02:51 -07:00
Elliott Hughes
6421823410 Fix pthread_getattr_np for the main thread.
On most architectures the kernel subtracts a random offset to the stack
pointer in create_elf_tables by calling arch_align_stack before writing
the auxval table and so on. On all but x86 this doesn't cause a problem
because the random offset is less than a page, but on x86 it's up to two
pages. This means that our old technique of rounding the stack pointer
doesn't work. (Our old implementation of that technique was wrong too.)

It's also incorrect to assume that the main thread's stack base and size
are constant. Likewise to assume that the main thread has a guard page.
The main thread is not like other threads.

This patch switches to reading /proc/self/maps (and checking RLIMIT_STACK)
whenever we're asked.

Bug: 17111575
Signed-off-by: Fengwei Yin <fengwei.yin@intel.com>

(cherry picked from commit 57b7a6110e)

Change-Id: I87e679ee1c0db8092f2d1221c8e7c1461545c5a4
2014-08-26 12:55:01 -07:00
Elliott Hughes
84d0683a82 Fix unistd.getpid_caching_and_clone.
This test only works if you're root (strictly: if you have permission to
CLONE_NEWNS), so it's useful to us when we're doing ad hoc testing (since
that's usually done as root), but it's not useful as part of CTS or when
running the tests on the host.

Bug: 16705621
Bug: 17170200
Change-Id: Ia92c871b15f7e45fc174bb59bc95540fd00ae745
2014-08-21 19:23:53 -07:00
Elliott Hughes
2d80400a9e Fix some 32-bit-isms in <stdio.h>.
Bug: 17157793
Change-Id: I8290e240b92e5617f4c12c0eacad6e622e677b6a
2014-08-20 12:14:21 -07:00
Dan Albert
1506fc178e Expose android_set_abort_message().
Removes the leading underscores from __android_set_abort_message() and
moves its declaration into a public header file.

Bug: 17059126
Change-Id: I470c79db47ec783ea7a54b800f8b78ecbe7479ab
(cherry picked from commit ce6b1abbb1)
(cherry picked from commit 3a25ab952b)
2014-08-19 18:46:45 +00:00
Dmitriy Ivanov
e3ad34b3bc Merge "Revert "Add support for protected local symbol lookup."" into lmp-dev 2014-08-18 21:31:41 +00:00
Dmitriy Ivanov
9419420919 Revert "Add support for protected local symbol lookup."
This reverts commit d97e9f546e.

Bug: 17107521
Change-Id: I2b81ce2b5a4a2d166133a2626e49d81b6aef3672
2014-08-18 15:11:50 -07:00
Dan Albert
6df7b60998 Hide C++ stuff in libc. Put it back in libstdc++.
Bug: 17062445
Change-Id: I027b186719654c2865b08c3fa83f90fa00c1e838
(cherry picked from commit fd5ee9aebc)
2014-08-18 13:56:07 -07:00
Christopher Ferris
9e56ce4cd3 Merge "Fix leak_realloc, copy entire allocation." into lmp-dev 2014-08-16 04:01:11 +00:00
Christopher Ferris
5df0839cea Fix leak_realloc, copy entire allocation.
Bug: 16874447
Change-Id: Ie54a73fd75529961195fa5173d9116d0ae897b03
2014-08-15 18:55:53 -07:00
Dmitriy Ivanov
d8e007695c Merge "Keep symbols for linker" into lmp-dev 2014-08-15 21:23:40 +00:00
Dmitriy Ivanov
be4348e7c7 Keep symbols for linker
Bug: 17011146

(cherry picked from commit ad5e8b5073)

Change-Id: Ib1d3f8d6d38af98586658e01ed1ec79d2c5b4d42
2014-08-15 14:18:26 -07:00
Hans Boehm
f0f66c0264 Have stdatomic.h punt to C++ atomic when possible
This is an alternate, somewhat simpler, fix that makes it safe to
include both <atomic> and <stdatomic.h> from C++ code in either order.
It means that C code consistently uses one implementation of atomics
and C++ another.  We still have to make sure that those two
implementations interoperate correctly at runtime; in particular,
any flavor of atomic object needs to be represented exactly like the
underlying type, with the proper alignment constraint.

Bug:17007799
Change-Id: Iffcfc5220d8fa150f89dd083a121b24d23f268fc
(cherry picked from commit 019d395811)
2014-08-15 11:42:36 -07:00
Dan Albert
e2050ae1aa Merge "Change name of MB_CUR_MAX implementation function." into lmp-dev 2014-08-14 19:49:28 +00:00
Dan Albert
bafee43161 Change name of MB_CUR_MAX implementation function.
Glibc calls theirs __ctype_get_mb_cur_max. Make ours match to cut down
on differences between bionic and glibc.

Bug: 11156955
Change-Id: Ib7231f01aa9676dff30aea0af25d597bfe07bc73
2014-08-14 14:01:44 -07:00
Dan Albert
553c0ea52b Merge "Move mtctxres.c to libc_dns.a." into lmp-dev 2014-08-14 16:46:52 +00:00
Dan Albert
9f533972ae Move mtctxres.c to libc_dns.a.
Has the effect of making ___mtctxres hidden.

Bug: 11156955
Change-Id: I5aa5f49344ad5ecb33f48737430561b329bcbb0d
(cherry picked from commit 891ec7a6e4)
2014-08-14 16:46:22 -07:00
Christopher Ferris
0533195e16 Merge "malloc_usable_size returns the original size." into lmp-dev 2014-08-14 16:46:52 +00:00
Christopher Ferris
59c1ee44d0 malloc_usable_size returns the original size.
Bug: 16874447
Change-Id: Ie3ce683fd1f58b837b8ea91dc798e561b8593356
2014-08-14 12:48:04 -07:00
Dmitriy Ivanov
4bea4c631f Label pages mapped by linker_allocator
(cherry picked from commit 51a22a12ab)

Bug: 17013324
Change-Id: I345c9d0fecc29d3626c5be01cc3c0ed1583ac361
2014-08-13 18:15:29 -07:00
Dmitriy Ivanov
8a84d383fb Optimize symbol lookup
Do not run symbol lookup on already visited soinfos
 Not taking into account already visited libraries
 dramatically slows down dlsym in cases when there
 are multiple occurrences of a large library in
 dependency tree.

Bug: 16977077

(cherry picked from commit 042426ba63)

Change-Id: I69d59e395e8112f119343e8a4d72fe31cd449f31
2014-08-13 09:30:52 -07:00
Dan Albert
d332bc6878 Hide __libc_malloc_dispatch.
Now that -Bsymbolic is fixed, we can hide __libc_malloc_dispatch without
breaking ASAN.

Bug: 11156955
Change-Id: Ia2fc9b046a74e666b33aa6c6c5435f70a63b8021
2014-08-12 16:54:24 -07:00
Elliott Hughes
72d7e667c7 Fix our x86 PIC_PROLOGUE.
The old definition only worked for functions that didn't use numbered
local labels. Upstream uses '666' not only as some kind of BSD in-joke,
but also because there's little likelihood of any function having
labels that high.

There's a wider question about whether we actually want to go via the
PLT at all in this code, but that's a question for another day.

Bug: 16906712
Change-Id: I3cd8ecc448b33f942bb6e783931808ef39091489
2014-08-09 18:45:55 -07:00
Dan Albert
f4d21fba06 Merge "Make __set_errno hidden in asm." into lmp-dev 2014-08-09 00:45:27 +00:00
Dan Albert
e35fd48a83 Make __set_errno hidden in asm.
This fixes the build after the -Bsymbolic change.

Bug: 16853291
Change-Id: I989c9fec3c32e0289ea257a3bd2b7fd2709b6ce2
(cherry picked from commit bc9f9f25bf)
2014-08-08 15:37:50 -07:00
Christopher Ferris
49de01a5be Add a way to disable backtracing in malloc debug.
The property libc.debug.malloc.nobacktrace set to non-zero disables
getting backtracing when using mode 1 or mode 10.

Bug: 16874447

Change-Id: I7650ba9f4385b5110b743cab01e877fc69545b3c
2014-08-08 00:16:29 -07:00
Elliott Hughes
43227c0b40 Android is all-PIC/PIE.
Clean up the x86/x86_64 assembler. The motivator (other than reducing
confusion) was that asm.h incorrectly checked PIC rather than __PIC__.

Bug: 16823325

(cherry picked from commit 6b6364a7fc)

Change-Id: I89ca57fa0eb34a36de6cb11ea85f71054fce709d
2014-08-07 11:28:34 -07:00
Christopher Ferris
3e7b8e2a8b Merge "Do a second key cleanup in pthread_exit." into lmp-dev 2014-08-06 23:54:36 +00:00
Christopher Ferris
18d93f2793 Do a second key cleanup in pthread_exit.
During pthread_exit, the keys are cleaned. Unfortunately, a call to
free occurs after the cleanup and the memory for some of the keys
is recreated when using jemalloc. The solution is to do the key
cleanup twice.

Also, modify the pthread_detach__leak test to be less flaky
when run on a jemalloc system.

Bug: 16513133
Change-Id: Ic17e8344bdc1ba053c4f5b6d827a4c19c57860c1
2014-08-06 17:12:30 -07:00
Elliott Hughes
501eb513ae Merge "Upgrade bionic to tzdata2014f." into lmp-dev 2014-08-06 23:54:36 +00:00
Elliott Hughes
6edf8985c1 Merge "Fix the tzdata update tools." into lmp-dev 2014-08-06 23:49:20 +00:00
Elliott Hughes
90cb5ffb85 Fix the tzdata update tools.
The recent libcore ZoneInfo changes mean that we can no longer
compile libcore's ZoneInfo against the RI. Luckily, the field in
our data file that we needed ZoneInfo for isn't actually used.
This change removes our dependence on libcore.

I've left the field in to avoid a file format change. We can remove
the field if/when we next have a real need to bump the file format.

Bug: 16168653
Change-Id: Iedad2252c2b49f4d8bb2c7d9078b39b622444ca7
2014-08-06 15:29:10 -07:00
Elliott Hughes
0dc2c1db6f Upgrade bionic to tzdata2014f.
From the release notes:

  Changes affecting future time stamps

    Russia will subtract an hour from most of its time zones on
    2014-10-26 at 02:00 local time.  (Thanks to Alexander Krivenyshev.)
    There are a few exceptions: Magadan Oblast (Asia/Magadan) and
    Zabaykalsky Krai are subtracting two hours; conversely, Chukotka
    Autonomous Okrug (Asia/Anadyr), Kamchatka Krai (Asia/Kamchatka),
    Kemerovo Oblast (Asia/Novokuznetsk), and the Samara Oblast and the
    Udmurt Republic (Europe/Samara) are not changing their clocks.  The
    changed zones are Europe/Kaliningrad, Europe/Moscow,
    Europe/Simferopol, Europe/Volgograd, Asia/Yekaterinburg, Asia/Omsk,
    Asia/Novosibirsk, Asia/Krasnoyarsk, Asia/Irkutsk, Asia/Yakutsk,
    Asia/Vladivostok, Asia/Khandyga, Asia/Sakhalin, and Asia/Ust-Nera;
    Asia/Magadan will have two hours subtracted; and Asia/Novokuznetsk's
    time zone abbreviation is affected, but not its UTC offset.  Two
    zones are added: Asia/Chita (split from Asia/Yakutsk, and also with
    two hours subtracted) and Asia/Srednekolymsk (split from
    Asia/Magadan, but with only one hour subtracted).  (Thanks to Tim
    Parenti for much of the above.)

  Changes affecting past time stamps

    China's five zones have been simplified to two, since the post-1970
    differences in the other three seem to have been imaginary.  The
    zones Asia/Harbin, Asia/Chongqing, and Asia/Kashgar have been
    removed; backwards-compatibility links still work, albeit with
    different behaviors for time stamps before May 1980.  Asia/Urumqi's
    1980 transition to UTC+8 has been removed, so that it is now at
    UTC+6 and not UTC+8.  (Thanks to Luther Ma and to Alois Treindl;
    Treindl sent helpful translations of two papers by Guo Qingsheng.)

    Some zones have been turned into links, when they differed from
    existing zones only for older UTC offsets where the data were likely
    invented.  These changes affect UTC offsets in pre-1970 time stamps
    only.  This is similar to the change in release 2013e, except this
    time for western Africa.  The affected zones are: Africa/Bamako,
    Africa/Banjul, Africa/Conakry, Africa/Dakar, Africa/Freetown,
    Africa/Lome, Africa/Nouakchott, Africa/Ouagadougou, Africa/Sao_Tome,
    and Atlantic/St_Helena.  This also affects the
    backwards-compatibility link Africa/Timbuktu.  (Thanks to Alan
    Barrett, Stephen Colebourne, Tim Parenti, and David Patte for
    reporting problems in earlier versions of this change.)

    Asia/Shanghai's pre-standard-time UT offset has been changed from
    8:05:57 to 8:05:43, the location of Xujiahui Observatory.  Its
    transition to standard time has been changed from 1928 to 1901.

    Asia/Taipei switched to JWST on 1896-01-01, then to JST on
    1937-10-01, then to CST on 1945-09-21 at 01:00, and did not observe
    DST in 1945.  In 1946 it observed DST from 05-15 through 09-30; in
    1947 from 04-15 through 10-31; and in 1979 from 07-01 through 09-30.
    (Thanks to Yu-Cheng Chuang.)

    Asia/Riyadh's transition to standard time is now 1947-03-14, not
    1950.

    Europe/Helsinki's 1942 fall-back transition was 10-04 at 01:00, not
    10-03 at 00:00.  (Thanks to Konstantin Hyppönen.)

    Pacific/Pago_Pago has been changed from UTC-11:30 to UTC-11 for the
    period from 1911 to 1950.

    Pacific/Chatham has been changed to New Zealand standard time plus
    45 minutes for the period before 1957, reflecting a 1956 remark in
    the New Zealand parliament.

    Europe/Budapest has several pre-1946 corrections: in 1918 the
    transition out of DST was on 09-16, not 09-29; in 1919 it was on
    11-24, not 09-15; in 1945 it was on 11-01, not 11-03; in 1941 the
    transition to DST was 04-08 not 04-06 at 02:00; and there was no DST
    in 1920.

    Africa/Accra is now assumed to have observed DST from 1920 through
    1935.

    Time in Russia before 1927 or so has been corrected by a few seconds
    in the following zones: Europe/Moscow, Asia/Irkutsk, Asia/Tbilisi,
    Asia/Tashkent, Asia/Vladivostok, Asia/Yekaterinburg,
    Europe/Helsinki, and Europe/Riga.  Also, Moscow's location has been
    changed to its Kilometer 0 point.  (Thanks to Vladimir Karpinsky for
    the Moscow changes.)

Bug: 16168653
Change-Id: I23827254bcf50dd07a2192ed34b02224d73e07a0
2014-08-06 15:26:13 -07:00
Dan Albert
bc0d65c114 Merge "Proper MB_CUR_MAX." into lmp-dev 2014-08-06 17:14:55 +00:00
Dan Albert
6035e6cc83 Proper MB_CUR_MAX.
Previously this was hard coded to 4. This is only the case for UTF-8
locales.

As a side effect, this properly reports C.UTF-8 as the default locale
instead of C.

Change-Id: I7c73cc8fe6ffac61d211cd5f75287e36de06f4fc
(cherry picked from commit 1aec7c1a35)
2014-08-06 13:17:43 -07:00
Dan Albert
5b39a44575 Merge "Fix mbsrtowcs(3) src param for finished string." into lmp-dev 2014-08-06 17:19:40 +00:00
Dan Albert
938a8008a6 Fix mbsrtowcs(3) src param for finished string.
A mistake I made while cleaning this up the first time through.
mbstrtowcs(3) sets the src param to null if it finishes the string.

Change-Id: I6263646e25d9537043b7025fd1dd6ae195f365e2
(cherry picked from commit b6cc8e00cd)
2014-08-06 13:00:54 -07:00
Dan Albert
40079b0031 Fixes build.
This change somehow went missing from the vfork change.

Change-Id: I807a2072080eac20601c694e85ba5723220289d8
(cherry picked from commit 9eae8405e8)
2014-08-06 12:32:28 -07:00