Commit graph

39180 commits

Author SHA1 Message Date
Elliott Hughes
5684b722d9 Merge "Reuse the libm scalbn() as ldexp()." into main 2023-07-21 14:08:15 +00:00
Treehugger Robot
23f67fbb08 Merge "Disable uchar.start_state test for musl." into main 2023-07-21 00:52:17 +00:00
Dan Albert
09d3b5065d Disable uchar.start_state test for musl.
These all appear to be either musl bugs or underspecified corners of
the C standard, so rather than verify the musl behavior I've just
disabled the body of the test for musl.

Now that this is skipped, all the uchar tests are passing for bionic,
glibc, and musl.

Bug: None
Test: None
Change-Id: Icf88ef42e9b750ab45ba76bf8112967b00e72a9f
2023-07-20 22:09:30 +00:00
Elliott Hughes
c204334b06 Reuse the libm scalbn() as ldexp().
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
2023-07-20 21:05:44 +00:00
Treehugger Robot
c1c39ca5a1 Merge "Add missing setlocale calls in tests." into main 2023-07-20 20:02:33 +00:00
Dan Albert
a0d0e350a5 Add missing setlocale calls in tests.
Doesn't do anything for bionic (which is why this has gone unnoticed),
but it does change the locale for glibc and musl. After this patch,
all these tests pass on glibc. musl is still failing in
uchar.start_state, which I haven't finished investigating.

This should probably be a test fixture so it's harder to forget, but
there are a handful of tests here which don't call setlocale until
part way through the tests, and I'm not certain if that was attempting
to test some non-obvious behavior, or if that was just an accident. I
don't want to change that test behavior before understanding it
better, so this will do for now.

Bug: None
Test: ./tests/run-on-host.sh 64 --gtest_filter="uchar.*"
Test: ./tests/run-on-host.sh glibc --gtest_filter="uchar.*"
Test: ./tests/run-on-host.sh musl --gtest_filter="uchar.*"
Change-Id: Ib781a41893f021e336e67281070932f41f792318
2023-07-20 17:15:59 +00:00
Treehugger Robot
a8a9c09e0f Merge "Fix another over-long UTF-8 sequence test." into main 2023-07-20 17:03:04 +00:00
Treehugger Robot
876f3668ac Merge changes I0845fdee,I879de1e8 into main
* changes:
  Fix mbrtoc16 reserved range test for musl.
  Fix surrogate pair deocding for musl/glibc.
2023-07-20 17:03:03 +00:00
Elliott Hughes
ab9028c8ba Merge "De-pessimize SigSetConverter usage." into main 2023-07-20 16:03:27 +00:00
Treehugger Robot
87e7955d9f Merge "Sync upstream NetBSD." into main 2023-07-20 14:21:01 +00:00
Treehugger Robot
6de9b74b73 Merge "Sync upstream OpenBSD." into main 2023-07-20 14:15:45 +00:00
Treehugger Robot
8a771303b8 Merge "Sync upstream FreeBSD libm (trivial changes)." into main 2023-07-20 14:15:41 +00:00
Treehugger Robot
a1fa960388 Merge "Sync upstream FreeBSD libm (real changes)." into main 2023-07-20 14:14:20 +00:00
Treehugger Robot
b6dda030a8 Merge "Sync upstream FreeBSD (qsort)." into main 2023-07-20 01:48:59 +00:00
Treehugger Robot
52206450c4 Merge changes Iac46bc9c,I4f853107 into main
* changes:
  Invert over-long UTF-8 bool for readability.
  Add musl handling in run-on-host.sh.
2023-07-20 00:46:03 +00:00
Treehugger Robot
f0d6c0a1d8 Merge "Sync with upstream FreeBSD." into main 2023-07-19 23:21:01 +00:00
Dan Albert
f5b8c7dcf4 Fix another over-long UTF-8 sequence test.
This one forgot to set its locale, so it was passing on glibc (because
the sequence here wasn't valid in its default locale) and failing on
musl, both for the wrong reasons.

Bug: None
Test: ./tests/run-on-host.sh 64 --gtest_filter="uchar.*"
Test: ./tests/run-on-host.sh glibc --gtest_filter="uchar.*"
Test: ./tests/run-on-host.sh musl --gtest_filter="uchar.*"
Change-Id: Ic6bcd1836ba23c7010e2cde673a3beca73778021
2023-07-19 21:54:09 +00:00
Dan Albert
ef8e1581ce Fix mbrtoc16 reserved range test for musl.
Musl was treating 0xf0 as a valid character in its default locale. I
didn't dig into whether that was a musl bug or whether it was actually
translating whatever extended ASCII character that was into the
correct code point (tbh I don't know what the rule there is either).

Bug: None
Test: ./tests/run-on-host.sh 64 --gtest_filter="uchar.*"
Test: ./tests/run-on-host.sh glibc --gtest_filter="uchar.*"
Test: ./tests/run-on-host.sh musl --gtest_filter="uchar.*"
Change-Id: I0845fdee9a016ad67ccff3716129ff29f83a63d7
2023-07-19 21:54:09 +00:00
Dan Albert
78da292886 Invert over-long UTF-8 bool for readability.
Also actually assign a bool to it. I'd originally written a #define
and apparently forgot to fix the value. I'm a bit surprised that clang
didn't complain.

Bug: None
Test: ./tests/run-on-host.sh 64 --gtest_filter="uchar.*"
Test: ./tests/run-on-host.sh glibc --gtest_filter="uchar.*"
Test: ./tests/run-on-host.sh musl --gtest_filter="uchar.*"
Change-Id: Iac46bc9c48fd70853d5c447e812e25e617281d2b
2023-07-19 21:54:09 +00:00
Dan Albert
1e8e0c1f03 Fix surrogate pair deocding for musl/glibc.
Bug: https://issuetracker.google.com/289419882
Test: ./tests/run-on-host.sh 64 --gtest_filter="uchar.*"
Test: ./tests/run-on-host.sh glibc --gtest_filter="uchar.*"
Test: ./tests/run-on-host.sh musl --gtest_filter="uchar.*"
Change-Id: I879de1e88d27b28f3c4892ab1b00bd942a32383e
2023-07-19 21:54:09 +00:00
Dan Albert
b9bc50910e Add musl handling in run-on-host.sh.
Bug: None
Test: ./tests/run-on-host.sh glibc
Test: ./tests/run-on-host.sh musl
Change-Id: I4f85310750402e1187358aeb4a585f26092b97ac
2023-07-19 21:53:11 +00:00
Dan Albert
1b256de728 Merge changes Ia7dd2ded,I9e85a9ae,Id7436404 into main
* changes:
  Fix uchar.mbrtoc16_zero_len for glibc and musl.
  Fix mbrtoc32 tests for out of range code points.
  Fix mbrtoc32 test for musl and glibc.
2023-07-19 21:47:54 +00:00
Elliott Hughes
65ab63bcea Sync upstream FreeBSD (qsort).
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
2023-07-19 14:14:58 -07:00
Elliott Hughes
8810bd7585 Sync upstream FreeBSD libm (real changes).
Test: treehugger
Change-Id: Icf591ba195a3f5080203b157aa7f43d518a9cc69
2023-07-19 14:11:58 -07:00
Elliott Hughes
c1e46b62e9 Sync upstream FreeBSD libm (trivial changes).
More interesting changes to come, but there's enough of this noise I'm
separating it out...

Test: treehugger
Change-Id: I0efc0ac860a147112369df7561ee48a92a2a5e84
2023-07-19 14:08:03 -07:00
Elliott Hughes
ac496ec2ba Sync upstream OpenBSD.
A couple of minor optimizations since the last sync.

Test: treehugger
Change-Id: Ibba2cd6749f989a24b74a64d0db180bd0458fdc8
2023-07-19 13:36:44 -07:00
Elliott Hughes
60260e22e7 Sync upstream NetBSD.
Only one trivial change.

Test: treehugger
Change-Id: Ibae666f752425a74e984b202fa42e13bcd284a30
2023-07-19 13:33:13 -07:00
Elliott Hughes
523b03a2dc Sync with upstream FreeBSD.
Only trivial changes here.

Test: treehugger
Change-Id: Ie4c0c0c74482192bf53b4c1021b0183cb8f046bd
2023-07-19 12:56:55 -07:00
Elliott Hughes
215baed16f De-pessimize SigSetConverter usage.
While looking at the disassembly for the epoll stuff I noticed that this
expands to quite a lot of code that the compiler can't optimize out for
LP64 (because it doesn't know that the "copy the argument into a local
and then use the local" bit isn't important).

There are two obvious options here. Something like this:
```
  int signalfd64(int fd, const sigset64_t* mask, int flags) {
    return __signalfd4(fd, mask, sizeof(*mask), flags);
  }

  int signalfd(int fd, const sigset_t* mask, int flags) {
  #if defined(__LP64__)
    return signalfd64(fd, mask, flags);
  #else
    SigSetConverter set = {.sigset = *mask};
    return signalfd64(fd, &set.sigset64, flags);
  #endif
  }
```
Or something like this:
```
  int signalfd64(int fd, const sigset64_t* mask, int flags) {
    return __signalfd4(fd, mask, sizeof(*mask), flags);
  }

  #if defined(__LP64__)
  __strong_alias(signalfd, signalfd64);
  #else
  int signalfd(int fd, const sigset_t* mask, int flags) {
    SigSetConverter set = {};
    set.sigset = *mask;
    return signalfd64(fd, &set.sigset64, flags);
  }
  #endif
```
The former is slightly more verbose, but seems a bit more obvious, so I
initially went with that. (The former is more verbose in the generated
code too, given that the latter expands to _no_ code, just another symbol
pointing to the same code address.)

Having done that, I realized that slight changes to the interface would
let clang optimize away most/all of the overhead for LP64 with the only
preprocessor hackery being in SigSetConverter itself.

I also pulled out the legacy bsd `int` conversions since they're only
used in two (secret!) functions, so it's clearer to just have a separate
union for them. While doing so, I suppressed those functions for
riscv64, since there's no reason to keep carrying that mistake forward.

posix_spawn() is another simple case that doesn't actually benefit from
SigSetConverter, so I've given that its own anonymous union too.

Test: treehugger
Change-Id: Iaf67486da40d40fc53ec69717c3492ab7ab81ad6
2023-07-19 12:20:07 -07:00
Zijun Zhao
46f1873b1e Merge "Fix duplicate symbols error in bionic" into main 2023-07-19 18:13:11 +00:00
Dan Albert
9a9bbe5fc6 Fix uchar.mbrtoc16_zero_len for glibc and musl.
Bug: None
Test: ./tests/run-on-host.sh glibc --gtest_filter="uchar.*"
Change-Id: Ia7dd2dedd39ac287350bab42493e886939556111
2023-07-19 18:04:10 +00:00
Dan Albert
9fa76f1374 Fix mbrtoc32 tests for out of range code points.
Same as the earlier fix for mbrtoc16. Other implementations support
the older RFC, bionic supports the new one.

Bug: None
Test: ./tests/run-on-host.sh glibc --gtest_filter="uchar.*"
Change-Id: I9e85a9ae53aaaa112a76665063acd2bd856b26cf
2023-07-19 17:59:29 +00:00
Dan Albert
0b8fbdf4b3 Fix mbrtoc32 test for musl and glibc.
glibc and musl both interpreted the spec differently than we did
(better, imo) for the return value of a zero-length conversion. Fix
the test to handle that.

Also converted the test from ASSERT to EXPECT to reduce the number of
builds needed to find failures.

Bug: None
Test: ./tests/run-on-host.sh glibc --gtest_filter="uchar.*"
Change-Id: Id74364040ce3b0e21bacd78f70467053cc8a6058
2023-07-19 17:59:27 +00:00
Treehugger Robot
0b310d9e57 Merge "Remove unused _ARC4_ATFORK() macro." into main 2023-07-19 01:36:18 +00:00
Treehugger Robot
b88a23ec58 Merge "Fix the (unused) return type for readlinkat() in SYSCALLS.TXT." into main 2023-07-18 22:57:19 +00:00
Elliott Hughes
f9a9537a26 Remove unused _ARC4_ATFORK() macro.
Test: treehugger
Change-Id: Ie1ac8a5512f89da34f8d04f177bc8d4a303c42d2
2023-07-18 22:44:40 +00:00
zijunzhao
3b57730346 Fix duplicate symbols error in bionic
Symbol __rand48_seed, __rand48_mult and __rand48_add are duplicate when switch -fcommon to -fno-common, but this was already fixed upstream, so sync with upstream's version.

Bug: b/151457797
Test: mm
Change-Id: Ie673a4c58671cdac405e0ff313c5898728f7b426
2023-07-18 22:39:33 +00:00
Elliott Hughes
9634513a63 Merge "Update <sys/cachectl.h>." into main 2023-07-18 22:36:53 +00:00
Dan Albert
d0b8d3c901 Merge "Fix 5-byte mbrtoc16 test for glibc/musl." into main 2023-07-18 22:25:11 +00:00
Treehugger Robot
7ca162602b Merge "Make getentropy available from <unistd.h>" into main 2023-07-18 20:10:06 +00:00
Elliott Hughes
8d350da500 Update <sys/cachectl.h>.
NDK API review complained about missing nullability annotations (added),
not having a `__riscv` #if guard around this function (added), and not
using `__INTRODUCED_IN(35)`. I haven't done the last of these because
that seems less helpful than the traditional "nothing" meaning "always
available" (since this riscv64-only function will be available from
whatever the first riscv64 API level ends up being).

Bug: http://b/291777120
Test: treehugger
Change-Id: I501b42851bd5b1612244bd86351628d249a57b99
2023-07-18 18:58:02 +00:00
Elliott Hughes
76879c921c Fix the (unused) return type for readlinkat() in SYSCALLS.TXT.
No functional change because the syscall wrapper generator doesn't use
the return types, but having the wrong return type is distracting.

Bug: https://github.com/android/ndk/issues/1908
Test: treehugger
Change-Id: I8b1a6ca11247554d28e85cb6c26ad8328c66a2b9
2023-07-18 15:24:22 +00:00
Dan Albert
1252ab04c3 Fix 5-byte mbrtoc16 test for glibc/musl.
Also split that case out into a separate test to avoid complicating
the test for the common cases.

Bug: None
Test: ./tests/run-on-host.sh glibc --gtest_filter="uchar.mbrtoc16"
Change-Id: If7e50f659ad99ee9bab8847fc7320c7bbd629c5d
2023-07-17 23:52:02 +00:00
David Benjamin
7110157e94 Make getentropy available from <unistd.h>
getentropy is originally an OpenBSD-ism, where it was in <unistd.h> from
day one:
https://man.openbsd.org/OpenBSD-5.6/getentropy

FreeBSD's and Linux's current man pages also document it this way:
https://man7.org/linux/man-pages/man3/getentropy.3.html
https://man.freebsd.org/cgi/man.cgi?query=getentropy&sektion=3&format=html

The man7.org URL is even cited by bionic itself in the comments, though
glibc originally put it in <sys/random.h> and added to <unistd.h> very
shortly afterwards:
https://sourceware.org/bugzilla/show_bug.cgi?id=17252#c9

The cited man page (maintained separately from glibc) originally
documented <sys/random.h>...
https://git.kernel.org/pub/scm/docs/man-pages/man-pages.git/commit/man3/getentropy.3?id=b0265728162cdcafb8e7d7f1372e8de1a4c963ed

But similarly fixed it to <unistd.h> three months later:
https://git.kernel.org/pub/scm/docs/man-pages/man-pages.git/commit/man3/getentropy.3?id=9cf011f94b56e8832c5a5d8cf66d4a115d34b9cc

musl matches the BSDs in putting it in <unistd.h>, but not
<sys/random.h>.
https://git.musl-libc.org/cgit/musl/tree/include/unistd.h?id=25e6fee27f4a293728dd15b659170e7b9c7db9bc#n183

POSIX will likely place it there too:
https://www.austingroupbugs.net/view.php?id=1134

macOS and Fuchsia place it in <sys/random.h> and not <unistd.h>, though
given the rest of this precedent, they're clearly outliers. (Note iOS
does *not* have getentropy, just macOS. The system has it, but it's not
exposed as public API. See https://dev.gnupg.org/T5375 and
https://github.com/openssl/openssl/pull/15924.)

Use the more standard location in bionic and put getentropy in
<unistd.h>. This will improve portability and avoid needing workarounds
in BoringSSL. For compatibility, keep it also available in
<sys/random.h> by using a <bits/getentropy.h> header.

BYPASS_INCLUSIVE_LANGUAGE_REASON=Above URLs are not hosted by Android and reference the name of a command-line utility, short for 'manual', as in instruction manual

Bug: 290898063
Test: treehugger
Change-Id: Id2d6b6ea09d814e5ba2cb117a7af2c74861148fb
2023-07-17 21:50:53 +00:00
Elliott Hughes
a2cdb247e1 Merge "Add riscv_hwprobe to the seccomp allowlist." into main 2023-07-14 18:49:58 +00:00
Elliott Hughes
13b1d97406 Add riscv_hwprobe to the seccomp allowlist.
We're not ready to add a syscall wrapper to bionic for this (see
https://www.openwall.com/lists/libc-coord/2023/07/13/1 for more), but it's
useful for writing a CTS test ensuring that misaligned accesses are fast.

(I've also moved userfaultfd() next to membarrier() where it belongs:
the existing comment was incorrect.)

Bug: https://github.com/google/android-riscv64/issues/87
Test: treehugger
Change-Id: Ibe691e461c564caebfed295e7acda73cb9b97618
2023-07-14 14:09:32 +00:00
Elliott Hughes
a09f741c2a Merge "Add __riscv_flush_icache() to <sys/cachectl.h>." into main 2023-07-13 19:04:30 +00:00
Elliott Hughes
a4b7949aca Merge "Consistently use %m rather than strerror() in logging." into main 2023-07-13 13:36:46 +00:00
Elliott Hughes
74d9765be9 Add __riscv_flush_icache() to <sys/cachectl.h>.
The obsolete mips header rides again!

The most interesting part of this change is that I've removed the hack
that meant that all system call wrappers starting with `__` defaulted to
being hidden symbols. That's no longer useful given our linker scripts,
and it actively got in the way here because the public libc symbol
actually starts with `__` in glibc, and it would be weird and annoying
for developers if we chose a different name.

Test: strace
Change-Id: I230479787895e8e34f566ade36346a8241eea998
2023-07-12 16:30:55 -07:00
Elliott Hughes
2557f73c05 Consistently use %m rather than strerror() in logging.
When I added %m to async_safe_* too, we never followed up and cleaned up
callers.

Test: treehugger
Change-Id: If81943c4c45de49f0fb4bc29cfbd3fc53d4a47fe
2023-07-12 21:16:31 +00:00