Investigation revealed that the vector instructions in the assembly
implementation of memcmp seem to be putting QEMU into a bad state. This
code sometimes results in a SIGILL.
Temporarily disable the vector instructions for just this function.
Bug: 306514350
Test: Verified boot on AOSP CF image.
Change-Id: I184762354092b4b500c78a29a10db18cef0dab90
Rather than do the work to fix the ODR violations while preserving non-V,
let's just remove the non-V code. Android will require V anyway, and
anyone trying to work on a non-V system in the meantime already needs
a bunch of patches to the build system and ART, so one more shouldn't
hurt too much.
Test: treehugger
Change-Id: Iab43d8a80d99a4d045b0008dbea4e7e8696d1167
These are the same function for machines with binary floats (that is:
all machines), but ldexp() is in libc rather than libm, so we can't just
use an alias.
We were using this duplicate copy of the code, but upstream FreeBSD has
removed it, and I'd prefer to do the same.
Longer term, we should just move all of libm into libc (but keep an
empty libm for compatibility), but this is probably easier for now.
Test: treehugger
Change-Id: I1a1d6d4f1771316f791ad59c714a3a65aedefc81
This gives us C11 Annex K's qsort_s(), which -- despite being Annex K --
is potentially useful in that it resolves the long-standing argument
about what the signature of qsort_r() is supposed to be. I'll import
it here first, and worry about actually using it separately (given that
glibc/musl and macOS/iOS don't have it; only Windows and [now] FreeBSD,
but not even the other BSDs).
For now, though, this change is a no-op.
Bug: http://b/17203231
Bug: http://b/31807750
Test: treehugger
Change-Id: Id8d2916b608ba8251df8643694da542e9b11eaae
* Rationale
The question often comes up of how to use multiple time zones in C code.
If you're single-threaded, you can just use setenv() to manipulate $TZ.
toybox does this, for example. But that's not thread-safe in two
distinct ways: firstly, getenv() is not thread-safe with respect to
modifications to the environment (and between the way putenv() is
specified and the existence of environ, it's not obvious how to fully
fix that), and secondly the _caller_ needs to ensure that no other
threads are using tzset() or any function that behaves "as if" tzset()
was called (which is neither easy to determine nor easy to ensure).
This isn't a bigger problem because most of the time the right answer
is to stop pretending that libc is at all suitable for any i18n, and
switch to icu4c instead. (The NDK icu4c headers do not include ucal_*,
so this is not a realistic option for most applications.)
But what if you're somewhere in between? Like the rust chrono library,
for example? What then?
Currently their "least worst" option is to reinvent the entire wheel and
read our tzdata files. Which isn't a great solution for anyone, for
obvious maintainability reasons.
So it's probably time we broke the catch-22 here and joined NetBSD in
offering a less broken API than standard C has for the last 40 years.
Sure, any would-be caller will have to have a separate "is this
Android?" and even "is this API level >= 35?" path, but that will fix
itself sometime in the 2030s when developers can just assume "yes, it
is", whereas if we keep putting off exposing anything, this problem
never gets solved.
(No-one's bothered to try to implement the std::chrono::time_zone
functionality in libc++ yet, but they'll face a similar problem if/when
they do.)
* Implementation
The good news is that tzcode already implements these functions, so
there's relatively little here.
I've chosen not to expose `struct state` because `struct __timezone_t`
makes for clearer error messages, given that compiler diagnostics will
show the underlying type name (`struct __timezone_t*`) rather than the
typedef name (`timezone_t`) that's used in calling code.
I've moved us over to FreeBSD's wcsftime() rather than keep the OpenBSD
one building --- I've long wanted to only have one implementation here,
and FreeBSD is already doing the "convert back and forth, calling the
non-wide function in the middle" dance that I'd hoped to get round to
doing myself someday. This should mean that our strftime() and
wcsftime() behaviors can't easily diverge in future, plus macOS/iOS are
mostly FreeBSD, so any bugs will likely be interoperable with the other
major mobile operating system, so there's something nice for everyone
there!
The FreeBSD wcsftime() implementation includes a wcsftime_l()
implementation, so that's one stub we can remove. The flip side of that
is that it uses mbsrtowcs_l() and wcsrtombs_l() which we didn't
previously have. So expose those as aliases of mbsrtowcs() and
wcsrtombs().
Bug: https://github.com/chronotope/chrono/issues/499
Test: treehugger
Change-Id: Iee1b9d763ead15eef3d2c33666b3403b68940c3c
Pull the portable C string functions from FreeBSD, and do fairly literal
translations of our existing .S files for the bionic-specific stuff.
Test: treehugger
Change-Id: Id42e5b8a51ed73155be020d74edd7011a2103574
Even with formatting off, clang still tries to rearrange the include
files or the using statements, so disable that too.
Test: Verified that the include directories are not rearranged.
Change-Id: I991a1b2bfa94a8202c5a486664658d654f1c7811
Use the .clang-format-2 found in system/core instead of this which is
not actually being used.
Also, enable clang-format running by default.
All upstream directories are marked as ignoring formatting so that
their source files are not modified.
Test: NA
Change-Id: Icee6030f373fa5f072df162f97e6f34320e3d89a
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
r334928 | kib | 2018-06-10 10:54:44 -0700 (Sun, 10 Jun 2018) | 16 lines
libc qsort(3): stop aliasing.
Qsort swap code aliases the sorted array elements to ints and longs in
order to do swap by machine words. Unfortunately this breaks with the
full code optimization, e.g. LTO.
See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83201 which seems to
reference code directly copied from libc/stdlib/qsort.c.
PR: 228780
Reported by: mliska@suse.cz
Reviewed by: brooks
Sponsored by: The FreeBSD Foundation
MFC after: 2 weeks
Differential revision: https://reviews.freebsd.org/D15714
Test: treehugger
Change-Id: Iac608b13bbf8a2dcb48c935a7871c0d2f05bff79
r293856 | brooks | 2016-01-13 13:50:08 -0800 (Wed, 13 Jan 2016) | 10 lines
Avoid reading pass the end of the source buffer when it is not NUL
terminated.
If this buffer is adjacent to an unmapped page or a version of C with
bounds checked is used this may result in a crash.
PR: 206178
Submitted by: Alexander Cherepanov <cherepan@mccme.ru>
MFC after: 1 week
and
r293855 | brooks | 2016-01-13 13:49:01 -0800 (Wed, 13 Jan 2016) | 10 lines
Avoid reading pass the end of the source buffer when it is not NUL
terminated.
If this buffer is adjacent to an unmapped page or a version of C with
bounds checked is used this may result in a crash.
PR: 206177
Submitted by: Alexander Cherepanov <cherepan@mccme.ru>
MFC after: 1 week
Test: treehugger
Change-Id: I3f7b9e6d0648574d2836f7721dfe47c1bae146de
r342757 | kevans | 2019-01-03 19:13:24 -0800 (Thu, 03 Jan 2019) | 19 lines
getopt_long(3): fix case of malformed long opt
When presented with an arg string like '-l-', getopt_long will successfully
parse out the 'l' short option, then proceed to match '--' against the first
longopts entry as it later does a strncmp with len=0. This latter bit is
arguably another bug in itself, but presumably not a practical issue as all
callers of parse_long_options are already doing the right thing (except this
one pointed out).
An opt string like '-l-' should be considered malformed and throw a bad
argument rather than behaving as if '--' were passed. It cannot possibly do
what the invoker expects, and it's probably the result of a typo (ls -l- a)
rather than any intent.
Reported by: Tony Overfield <toverfield@yahoo.com>
Reviewed by: imp
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D18616
Test: treehugger
Change-Id: I593713bc35d70eb1975c9d7587528f2b3f9731af
r325389 | kib | 2017-11-04 03:52:58 -0700 (Sat, 04 Nov 2017) | 7 lines
C++17 requires quick_exit(3) to be async-signal safe.
Make it safe, and update man page with the useful information.
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Test: treehugger
Change-Id: Idf84b1f1e360c031b0e39d5f6e80d17308db1940
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
Originally a BSD extension, now in glibc too. We've used it internally
for a while.
(cherry-pick of e4b13f7e3ca68edfcc5faedc5e7d4e13c4e8edb9.)
Bug: http://b/112163459
Test: ran tests
Change-Id: I813c3a62b13ddb91ba41e32a5a853d09207ea6bc
Merged-In: I813c3a62b13ddb91ba41e32a5a853d09207ea6bc
This is the FreeBSD implementation, plus some tests. The FreeBSD
implementation includes the GNU extensions and seems to be what
iOS is using too, which should provide bug compatibility for app
developers.
The code unfortunately uses a lot of stack, and uses FreeBSD locale
implementation that we don't have, but it does seem better maintained
than the other BSDs.
Bug: http://b/29251134
Test: ran tests
Change-Id: Ie477b45e42a6df1319b25712098519d2b33adf67
I'm unable to find a bug, but we've had requests for this internally
once or twice (though I pointed those folks at the STL), and there's
code we build for the host or in our bootloaders that would use this,
and there's reasonable-looking FreeBSD implementation ready and waiting.
Bug: N/A
Test: ran tests
Change-Id: I6ddee4b71bea4c22ed015debd31d3eaac4fcdd35
Since realpath no longer needs to be overloaded, we can restore the
upstream source to purity. We'll be able to do this with most of the
other functions when we pull a newer clang in.
Bug: 12231437
Test: m checkbuild on bionic internal master; CtsBionicTestCases show
no new failures.
Change-Id: I484221bba0b291273fece23d2be2f5f9fd713d2c
Almost all of our w* functions come from FreeBSD already. The one downside is
that we can't take all our w* functions from FreeBSD because FreeBSD handles
locales very differently from us.
Bug: N/A
Test: ran tests
Change-Id: I177b4332499992babd5d5afe5b3f469f8c4345a5
r279663: enhance to handle 32-bit aligned data on 64-bit systems
r279666: qsort(3): small style(9) cleanups.
r288030: Use ANSI C prototypes. Eliminates -Wold-style-definition
warnings.
r318514: Use size_t.
r318515: Reduce the possible recursion level to log2(N) by always
recursing on the smaller partition instead.
Bug: 38450217
Test: builds, ./tests/run-on-host.sh 64
Change-Id: Ieb622e6f54f8f6d6f62e1bdb491d3b5c8e2f9965
This patch adds clang-style FORTIFY to Bionic. For more information on
FORTIFY, please see https://goo.gl/8HS2dW . This implementation works
for versions of clang that don't support diagnose_if, so please see the
"without diagnose_if" sections. We plan to swap to a diagnose_if-based
FORTIFY later this year (since it doesn't really add any features; it
just simplifies the implementation a lot, and it gives us much prettier
diagnostics)
Bug: 32073964
Test: Builds on angler, bullhead, marlin, sailfish. Bionic CTS tests
pass on Angler and Bullhead.
Change-Id: I607aecbeee81529709b1eee7bef5b0836151eb2b
Interestingly, this mostly involves cleaning up our implementation of
various <string.h> functions.
Change-Id: Ifaef49b5cb997134f7bc0cc31bdac844bdb9e089
This means all our stdio implementation is now the OpenBSD implementation.
The only thing we lose is the STDIO_THREAD_LOCK calls but they were no-ops
anyway.
We should probably talk to upstream about this. Either fix the locking or,
preferably, encourage them to move away from this pooling (especially since
there's no eviction policy).
Bug: 17154680
Change-Id: Ie2523e444a7d0965b8d141d57e3e11f6432d5b9a
Almost all of our stdio is actually OpenBSD, so although this isn't
really a core part of stdio (it doesn't touch struct FILE, for example)
it probably makes sense for it to come from the same upstream. My
actual motivation though is that it's the only FreeBSD file we have
compiler warnings from.
This patch moves us over to -Werror by default, with only the DNS code
having -Wno-error.
Change-Id: Id244a5b445cba41b0a1ca30298ca7b1ed177810c
* Register cleanup function with atexit
instead of calling it explicitly on
exit()
* abort() no longer calls _cleanup:
Flushing stdio buffers on abort is no
longer required by POSIX.
* dlmalloc no longer need to reset cleanup
(see above)
* Upstream findfp.c makebuf.c setvbuf.cexit.c
to openbsd versions.
Bug: 14415367
Change-Id: I277058852485a9d3dbb13e5c232db5f9948d78ac