Commit graph

11314 commits

Author SHA1 Message Date
Elliott Hughes
f517b68c82 Add some new risc-v ELF relocations.
Also add the link to the canonical source.

Test: treehugger
Change-Id: I06c5d1ded5e1b372630c6963c81947450946c29a
2023-08-18 17:51:53 +00:00
Elliott Hughes
c37aa7ad3c Rename prop_bt.
Presumably "bt" was "binary tree", but "trie_node" is a bit more
specific and removes the guesswork.

Test: treehugger
Change-Id: Ib5fb2dcbcf261ce516728099d484ed9cd6c069bd
2023-08-08 14:05:01 +00:00
Treehugger Robot
8b96b46a9e Merge "Use L() in libc/arch-x86_64/bionic/*.S." into main 2023-08-07 19:20:39 +00:00
Dan Albert
1982dce568 Merge changes I1a60d6ef,Idabf0107 into main
* changes:
  Fix result for zero-length non-null conversion.
  Fix mismatched return types for surrogate pairs.
2023-08-07 17:55:09 +00:00
Elliott Hughes
072ff571d9 Use L() in libc/arch-x86_64/bionic/*.S.
I did look at a wider cleanup of libc/arch-x86_64/string/*.S but was
horrified by what I found there, with apparently-useless macros that
may actually be relevant because source files include each other. So
I'll leave the Intel-written stuff alone until/unless I actually have
reason to touch it, and just clean up our corner instead.

Test: treehugger
Change-Id: Id749f79d2fab4a2956efe9e807a067e16cd606ec
2023-08-07 09:34:06 -07:00
Treehugger Robot
6b2aa54a78 Merge "Add the L() macro for local labels to <private/bionic_asm.h>." into main 2023-08-05 00:50:09 +00:00
Christopher Ferris
636b9b9bf2 Merge "Increase time to set allocation limit." into main 2023-08-04 22:54:05 +00:00
Elliott Hughes
bc192cff55 Add the L() macro for local labels to <private/bionic_asm.h>.
This lets us remove the riscv64 "sys/asm.h" file. It turns out everyone
loves this macro --- tons of x86 and arm assembler is already using it!

I'll clean up some of the now-duplicate definitions separately, and I'll
move the assembler we wrote ourselves over to this macro (rather than
the current `.L_foo` style) too.

Test: built riscv64 _and_ arm/arm64 _and_ x86/x86-64
Change-Id: If3f93c9b71094a8bed1fd1bb81bb83ec60ce409e
2023-08-04 15:12:30 -07:00
Christopher Ferris
e9ffc52da7 Increase time to set allocation limit.
Under some circumstances, it's possible to fail the enable allocation
limit android_mallopt call. Increase the total allowed time for the
function to complete.

In addition, if the enable fails, allow another limit call to succeed
in the future.

Finally, change the limit test to use _exit instead of exit.

Bug: 291672185

Test: Ran limit test thousands of times.
Test: Forced the limit to fail and verified the second call passes.
Change-Id: I0948e6fd97231a7538b9b82b76f0a207386681b1
2023-08-04 13:10:48 -07:00
Dan Albert
16007d5204 Fix result for zero-length non-null conversion.
Bug: None
Test: deleted the xfail half of the test
Change-Id: I1a60d6ef27ebad14de79ac3bc637a6f2280334d8
2023-08-04 19:48:56 +00:00
Dan Albert
013d747dd3 Fix signature of mbstate_reset_and_return.
Bug: None
Test: None
Change-Id: Ifab9f68f542354fafa8514bf4ea73b185796bdad
2023-08-04 19:48:35 +00:00
Dan Albert
3a8fed1ac3 Fix mismatched return types for surrogate pairs.
We've had these backward all this time. The relevant quote is in a
code comment in the implementation, but the first call after
completely decoding a code point that requires a surrogate pair should
return the number of bytes decoded by the most recent call, and the
second call should return -3 (if only C had given those some named
constants that might have been more obviously wrong).

Bug: https://issuetracker.google.com/289419882
Test: Fixed the test, tests run against glibc and musl to confirm
Change-Id: Idabf01075b1cad35b604ede8d676d6f0b1dc91e6
2023-08-04 19:48:35 +00:00
Dan Albert
a9e914dd2f Make multibyte result constants public.
The magic numbers that C defines are obnoxious. We had partial
definitions for these internally. Add the missing one and move them to
a public header for anyone else that may want to use them.

Bug: None
Test: None
Change-Id: Ia6b8cff4310bcccb23078c52216528db668ac966
2023-08-04 19:48:35 +00:00
Elliott Hughes
249ae824fd Merge "riscv64: inline raise." into main 2023-08-03 14:07:49 +00:00
Elliott Hughes
0e5b89c4bf riscv64: inline raise.
Not necessary (as demonstrated by the lack of this for x86), but this
saves one stack frame in aborts, which gets you one more useful stack
frame in logs and clustering etc, which improves your chances of finding
your bug.

Test: crasher64 abort
Change-Id: Ieb214f3b46520161edc1e53c0d766353b777d8ba
2023-08-02 16:04:25 -07:00
Matthias Maennich
68cbdca6bb libm/libc: remove 'allow_untyped_symbols' flags
Those flags were used to suppress ABI tidy errors, but by now are not in
use anymore and can safely be removed.

Bug: 156513478
Change-Id: Ibc9625d139f933e48ebb4ddebe70d424f6231f3f
Signed-off-by: Matthias Maennich <maennich@google.com>
2023-08-01 17:23:49 +00:00
Elliott Hughes
2df6e5fa8f Merge "riscv64: use vdso for __riscv_hwprobe()." into main 2023-08-01 14:32:52 +00:00
Elliott Hughes
95936aec6f Merge "riscv64: pass a null argument to ifunc resolvers." into main 2023-08-01 14:32:35 +00:00
Elliott Hughes
1af07a92d6 Merge "avx2 memset: add missing vzeroupper." into main 2023-08-01 14:08:00 +00:00
Elliott Hughes
b08f79af78 riscv64: pass a null argument to ifunc resolvers.
glibc maintainer Florian Weimer pointed out that glibc passes a null first
argument to riscv64 ifunc resolvers. While not super useful right now,
that does make it much easier to switch to providing arguments in future,
such as my favorite idea of passing a default set of hwprobe key/value
pairs, along with a count of how many pairs.

Test: treehugger
Change-Id: Ibe2148dc28aa6ad230e6324b6d725fe472b7ef33
2023-07-31 19:34:38 +00:00
Elliott Hughes
9a7d048712 riscv64: use vdso for __riscv_hwprobe().
Also de-pessimize time(), where the vdso entrypoint only exists on
x86/x86-64 anyway.

Bug: https://github.com/google/android-riscv64/issues/8
Test: strace
Change-Id: I14cb2a3130b6ff88d06d43ea13d3a825a26de290
2023-07-31 12:24:31 -07:00
Elliott Hughes
f3d6b44e2b riscv64: add <sys/hwprobe.h>.
This is source compatible with the current proposal for glibc.

Bug: https://github.com/google/android-riscv64/issues/27
Test: treehugger
Change-Id: I428777e4eac1fe643d442a93a4b3ad1fdf0ffd97
2023-07-28 09:29:06 -07:00
Elliott Hughes
7c95495ead avx2 memset: add missing vzeroupper.
Also improve a few labels. This actually improves performance slightly,
and removes the weird behavior I was seeing around 512 bytes in the
"before" numbers...

Before:
```
BM_string_memset/8/0            2.12 ns         2.12 ns    332002763 bytes_per_second=3.52172G/s
BM_string_memset/16/0           2.36 ns         2.36 ns    297459840 bytes_per_second=6.31618G/s
BM_string_memset/32/0           2.36 ns         2.36 ns    296996995 bytes_per_second=12.6321G/s
BM_string_memset/64/0           2.37 ns         2.36 ns    296196644 bytes_per_second=25.2097G/s
BM_string_memset/512/0          65.9 ns         65.8 ns     10609200 bytes_per_second=7.24172G/s
BM_string_memset/1024/0         69.5 ns         69.5 ns     10079176 bytes_per_second=13.7312G/s
BM_string_memset/8192/0          123 ns          123 ns      5726682 bytes_per_second=62.2494G/s
BM_string_memset/16384/0         183 ns          183 ns      3832127 bytes_per_second=83.5219G/s
BM_string_memset/32768/0         306 ns          306 ns      2292654 bytes_per_second=99.8293G/s
BM_string_memset/65536/0         570 ns          569 ns      1224926 bytes_per_second=107.185G/s
BM_string_memset/131072/0       1067 ns         1067 ns       654098 bytes_per_second=114.395G/s
```

After:
```
BM_string_memset/8/0            2.34 ns         2.34 ns    299919615 bytes_per_second=3.18993G/s
BM_string_memset/16/0           2.58 ns         2.58 ns    271170449 bytes_per_second=5.76711G/s
BM_string_memset/32/0           2.61 ns         2.61 ns    266003840 bytes_per_second=11.4245G/s
BM_string_memset/64/0           2.62 ns         2.62 ns    269191710 bytes_per_second=22.784G/s
BM_string_memset/128/0          2.84 ns         2.84 ns    244486639 bytes_per_second=41.994G/s
BM_string_memset/256/0          4.23 ns         4.23 ns    165575532 bytes_per_second=56.4047G/s
BM_string_memset/512/0          7.12 ns         7.12 ns     99398933 bytes_per_second=67.0164G/s
BM_string_memset/1024/0         10.9 ns         10.9 ns     64108888 bytes_per_second=87.2884G/s
BM_string_memset/8192/0         63.6 ns         63.6 ns     11012138 bytes_per_second=119.989G/s
BM_string_memset/16384/0         127 ns          127 ns      5506888 bytes_per_second=120.065G/s
BM_string_memset/32768/0         252 ns          251 ns      2783524 bytes_per_second=121.346G/s
BM_string_memset/65536/0         515 ns          515 ns      1357500 bytes_per_second=118.587G/s
BM_string_memset/131072/0       1013 ns         1012 ns       691605 bytes_per_second=120.587G/s
```

Bug: http://b/292281479
Test: treehugger
Change-Id: I45bfffedbdf0ec55a1b1341ffbab0af6d240d3a3
2023-07-27 14:23:17 -07: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
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
b6dda030a8 Merge "Sync upstream FreeBSD (qsort)." into main 2023-07-20 01:48:59 +00:00
Treehugger Robot
f0d6c0a1d8 Merge "Sync with upstream FreeBSD." into main 2023-07-19 23:21:01 +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
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
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
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
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
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
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
Kelvin Zhang
fd93b6031e Check for mprotect result
Failure to mark shadow stack page as writable will result in a SEGV
fault later when a function tries to save return addresses to shadow
stack. The engineer looking at the crash report would be very confused
because the program crashes at very beginning of an innocent looking
function. For ease of debugging, check for shadow stack errors early.

Test: th
Bug: 279808236
Bug: 253652966
Change-Id: Id2da68fa984b5dfb1846ed14aa7ededee7f2508f
2023-07-11 15:42:32 -07:00
Christopher Ferris
df85637d32 Merge "Update to v6.4 kernel headers." into main 2023-07-11 21:51:16 +00:00