Commit graph

39180 commits

Author SHA1 Message Date
Elliott Hughes
fce8a155df __riscv_hwprobe: don't try to set errno.
When used in an ifunc resolver, errno@plt won't be available. This is
the API the rivos folks contributing to glibc are leaning towards, for
the same reason. Hit by the berberis folks because they don't implement
the syscall so they were trying to set errno to ENOSYS.

Tested by looking at the generated assembler, and also disabling the
vdso (since on actual systems, this will go via the vdso).

Test: treehugger
Change-Id: Ie2779110f141f20efe97cb892fbdefd808b5339b
2023-08-29 15:41:36 -07:00
Elliott Hughes
b130e6dae0 Merge "<termios.h>: add two new POSIX functions." into main 2023-08-29 21:48:37 +00:00
Elliott Hughes
647472db9b <termios.h>: add two new POSIX functions.
musl already added tcgetwinsize() and tcsetwinsize(), but I didn't
notice.

Trivial single-line inlines added to a header that's already written
that way.

Test: treehugger
Change-Id: Iac95ea6a89f3872025c512f7e61987b81d0aafa7
2023-08-29 09:33:04 -07:00
Kalesh Singh
97a0587f20 Merge "bionic: CFIShadow: Remove use of PAGE_SIZE macro." into main 2023-08-28 20:04:57 +00:00
Kalesh Singh
de83440636 Merge "bionic: libdl_cfi: Remove PAGE_SIZE usage" into main 2023-08-28 17:13:01 +00:00
Elliott Hughes
a71a15fe34 Merge "sysconf(): implement cache queries." into main 2023-08-28 14:48:20 +00:00
Elliott Hughes
02df7388f1 sysconf(): implement cache queries.
This is a bit disappointing. I'd not implemented this in the past
because it wasn't available on all platforms, and -- although the
riscv64 implementation was just a cool optimization -- I thought that
the /sys stuff was actually portable, until I ran it on arm64 hardware.
So here we have getauxval() for riscv64, /sys for x86-64, and our best
guess based on ctr_el0 for arm64.

Bug: http://b/294034962
Test: ran tests on the host, an arm64 device, and riscv64 host and qemu
Change-Id: I420b69b976d30668d4d2ac548c4229e2a4eafb20
2023-08-28 14:48:12 +00:00
Kalesh Singh
461c64db9e bionic: libdl_cfi: Remove PAGE_SIZE usage
Use max_page_size() for build time variable alignments instead
of PAGE_SIZE.

In the 4k targets there is no functional difference since
max_page_size() == page_size() == 4096.

On a 16kb device max_page_size() == 65536 and page_size() == 16384.
However, aligning up does not incur any memory regressions
since the .bss/.data sections are still be backed in PAGE_SIZE'ed
chunks. See: go/16k-page-aligned-variables

Bug: 296275298
Test: mma
Change-Id: Ic944235d8a5742a51a8fb0f2a0b75e532f404110
Signed-off-by: Kalesh Singh <kaleshsingh@google.com>
2023-08-24 23:36:33 -07:00
Elliott Hughes
bf4d3a95c1 Merge "Add %b/%B to async-safe logging." into main 2023-08-24 14:34:45 +00:00
Elliott Hughes
f5b4e3ce58 Add %b/%B to async-safe logging.
Missed this when we added the new C23 binary output to the printf()
family.

Also fix %X to use "0X" instead of "0x" and add missing tests.

Test: used by new LD_SHOW_AUXV functionality
Change-Id: I6623b92acec7daf534536697de0f87352a2653ad
2023-08-23 14:08:40 -07:00
Kalesh Singh
00f5906754 bionic: CFIShadow: Remove use of PAGE_SIZE macro.
The alignment of kShadowSize to a page sized multiple is
not explicitly needed, since mmap() will return a page-sized
multiple mapping.

kCfiCheckAlign remains 4k as this is chosen by the clang
compiler. [1] [2]

[1] 3568976375/clang/lib/CodeGen/CGExpr.cpp (L3433)

[2] https://clang.llvm.org/docs/ControlFlowIntegrityDesign.html#cfi-shadow

Bug: 296275298
Test: Boot 16kb device, check no cfi failures.
Test: atest -c bionic-unit-tests
Change-Id: Iac0c129c413afe01389f529f5c64051c4ffff2df
Signed-off-by: Kalesh Singh <kaleshsingh@google.com>
2023-08-23 13:59:57 -07:00
Treehugger Robot
0398f8ab3a Merge "linker: add LD_SHOW_AUXV support." into main 2023-08-23 14:46:29 +00:00
Juan Yescas
fe690875d5 Merge "bionic: Set PTHREAD_STACK_MIN for page agnostic targets" into main 2023-08-23 02:44:58 +00:00
Kalesh Singh
8cd1ddcbf0 Merge "bionic: libc_init_static: Use page_size()" into main 2023-08-23 00:16:26 +00:00
Elliott Hughes
838dbacbfd linker: add LD_SHOW_AUXV support.
Yes, `od -t d8 /proc/self/auxv` is clever:
```
$ adb shell od -t d8 /proc/self/auxv
0000000                      33            488593047552
0000020                      51                    4720
0000040                      16                 1155071
0000060                       6                    4096
0000100                      17                     100
0000120                       3            375971917888
0000140                       4                      56
0000160                       5                      12
0000200                       7            488593051648
0000220                       8                       0
0000240                       9            375972184064
0000260                      11                       0
0000300                      12                       0
0000320                      13                       0
0000340                      14                       0
0000360                      23                       0
0000400                      25            549220780840
0000420                      26                       0
0000440                      31            549220786153
0000460                      15            549220780856
0000500                       0                       0
0000520
$
```
But this is a lot easier to read:
```
$ adb shell LD_SHOW_AUXV=1 date
AT_SYSINFO_EHDR      0x7065010000
AT_MINSIGSTKSZ       4720
AT_HWCAP             0b100011001111111111111
AT_PAGESZ            4096
AT_CLKTCK            100
AT_PHDR              0x5c79d60040
AT_PHENT             56
AT_PHNUM             12
AT_BASE              0x7065011000
AT_FLAGS             0
AT_ENTRY             0x5c79da1000
AT_UID               0
AT_EUID              0
AT_GID               0
AT_EGID              0
AT_SECURE            0
AT_RANDOM            0x7ff814eb98
AT_HWCAP2            0
AT_EXECFN            "/system/bin/date"
AT_PLATFORM          "aarch64"
Tue Aug 22 20:43:22 GMT 2023
```

Test: adb shell LD_SHOW_AUXV=1 date
Change-Id: I51c4e8cbb799eb1dc360c9417cc6f82bebdcda73
2023-08-22 14:25:01 -07:00
Juan Yescas
8d3866bacb bionic: Set PTHREAD_STACK_MIN for page agnostic targets
Page size agnostic targets will have a pthread stack equals
to 65536. Page size agnostic targets will only support ARM64 arch.

For not agnostic builds, PTHREAD_STACK_MIN will remain the same.

Bug: 296907948
Test: source build/envsetup.sh
      lunch aosp_cf_arm64_phone_pgagnostic
      m

      source build/envsetup.sh
      aosp_cf_x86_64_phone-userdebug
      m

Change-Id: Ifcc04a9d924501f686cdfec34428d3f29154fdf0
2023-08-22 20:04:13 +00:00
Treehugger Robot
9fd0f4b90d Merge "<sys/user.h>: factor PAGE_SIZE out into <bits/page_size.h>." into main 2023-08-22 18:21:22 +00:00
Elliott Hughes
1245abf7e3 <sys/user.h>: factor PAGE_SIZE out into <bits/page_size.h>.
If we're going to need PAGE_SIZE in other places, we don't want the
namespace pollution of pulling in all of <sys/user.h>. (The experimental
support for non-4KiB pages found an existing place -- <pthread.h> --
where we were assuming PAGE_SIZE is already available, as if
<sys/user.h> has already been included, so that was actually an existing
bug.)

Test: treehugger
Change-Id: Icd90ffbca1f2cf3645fadb2e432f6f45a4d63eb6
2023-08-22 15:31:51 +00:00
Treehugger Robot
d4c9419441 Merge "riscv64: increase jmp_buf size." into main 2023-08-22 15:23:43 +00:00
Juan Yescas
ac587f827c Merge "bionic: Use max_page_size() instead of PAGE_SIZE" into main 2023-08-22 15:22:44 +00:00
Elliott Hughes
d53ad05e38 Merge "riscv64: fix ifuncs, improve the ifunc tests." into main 2023-08-22 14:55:28 +00:00
Juan Yescas
3649db34a1 bionic: Use max_page_size() instead of PAGE_SIZE
Android V will support page size agnostic targets. The bionic macro
PAGE_SIZE won't be defined for the agnostic targets.

The PAGE_SIZE macro will be replaced by max_page_size() instead.

- For not agnostic builds, max_page_size() will be replaced by 4096.
- For agnostic builds, it will  be replaced by 16384

Bug: 296907948
Test: source build/envsetup.sh
      lunch aosp_cf_arm64_phone_pgagnostic
      m

      source build/envsetup.sh
      aosp_cf_x86_64_phone-userdebug
      m

Change-Id: I81731a2ec59decd19ab9fd714d4f2ac20df873b7
2023-08-22 05:34:55 +00:00
Kalesh Singh
183f58bb2a bionic: libc_init_static: Use page_size()
Use the real page size from getauxval() for memtag stack
MTE protection.

Bug: 296275298
Test: atest -c bionic-unit-tests
Change-Id: I1711291b918b09e5464f1d15358dd1ff7fa2f371
Signed-off-by: Kalesh Singh <kaleshsingh@google.com>
2023-08-21 16:55:41 -07:00
Elliott Hughes
620a72252e riscv64: fix ifuncs, improve the ifunc tests.
Talking futher to the person doing the glibc risc-v ifunc work, they
clarified that glibc _is_ passing hwcap as the first argument, and the
null pointer is actually the second argument.

https://sourceware.org/pipermail/libc-alpha/2023-August/150967.html

So since our whole purpose here was source compatibility, let's do what
they're actually doing, and let's add some tests. I've also added a test
that __riscv_hwprobe() works from an ifunc resolver because that's one
place where it might well be used. That said, one other thing that came
out of the discussion is that I actually went away and looked at a
sample of top apps to see how many are using ifuncs currently. The
result? Zero. So although this _might_ be interesting long term
(especially if clang gets riscv64 FMV), I think we've done more than we
need to with riscv64 ifuncs for now!

Test: ran locally, both dynamic and static tests
Change-Id: Ie2044d9f4e47c32c00ad381f045c537f4df38b08
2023-08-21 16:17:35 -07:00
Ryan Prichard
e722c756a5 Merge "linker_main: acquire loader lock earlier and release it later" into main 2023-08-21 21:06:39 +00:00
Elliott Hughes
7c6c1f8b59 riscv64: increase jmp_buf size.
Today's risc-v psABI meeting brought up the topic of CFI-related ABI
changes, and FreeBSD wasn't worried about jmp_buf because they already
had twice the space we do (OpenBSD matches us, presumably because they
too just picked "the next power of two" over what they actually
required), and glibc wasn't worried because they have a hilariously
large sigset_t that they can steal space from (and apparently already
did to support the x86-64 CET shadow stack).

So rather than continue to assume that our minimal amount of free space
will suffice, let's just double it while our ABI isn't yet fixed, and
know we won't have to worry about it in a couple of years time when we
actually have riscv64 hardware shadow stack.

Test: treehugger
Change-Id: I2d4cb2f5db2ac8085a2c9e9ad4f910d0d4792005
2023-08-21 20:50:14 +00:00
Treehugger Robot
d8708ba8b6 Merge "sys_hwprobe_test.cpp: compare vdso to syscall." into main 2023-08-21 20:47:52 +00:00
Mitch Phillips
e219a4179f Merge "Move bionic test libraries to a default, for easy consumption in cts." into main 2023-08-21 16:32:11 +00:00
Mitch Phillips
f5c9a65046 Move bionic test libraries to a default, for easy consumption in cts.
This list has diverged between cts/ and bionic/. Instead of having to
maintain the list, let's just make cts/ inherit the one from bionic.

Bug: 296832150
Test: atest bionic-unit-tests CtsBionicTestCases
Change-Id: I271668e83aed239107b9129dfb707f03bae47cfa
2023-08-21 13:55:10 +02:00
Juan Yescas
8ff3886ff7 Merge "bionic: Fix typo in the argument passed to getauxval()" into main 2023-08-20 17:05:31 +00:00
Juan Yescas
4c562594d9 Merge changes from topic "bionic_max_pgsize" into main
* changes:
  bionic: libc: WriteProtected use max_page_size()
  bionic: Introduce max_page_size()
2023-08-20 17:05:07 +00:00
Treehugger Robot
0c56cbad11 Merge "Add some new risc-v ELF relocations." into main 2023-08-20 08:20:14 +00:00
Kalesh Singh
2bdf22e992 bionic: libc: WriteProtected use max_page_size()
In the 4k targets there is no fucntional difference since
max_page_size() == page_size() == 4096.

On a 16kb device max_page_size() == 65536 and page_size() == 16384.
However, aligning up does not incur any memory regressions
since the .bss section is still be backes in page-sizeed chunks.

See: go/16k-page-aligned-variables

Bug: 296275298
Test: mma
Change-Id: I41c3e410f3b84c24eeb969c9aeca4b33a8d6170a
Signed-off-by: Kalesh Singh <kaleshsingh@google.com>
2023-08-19 00:05:12 +00:00
Kalesh Singh
307bae7afe bionic: Introduce max_page_size()
This can be used to "page-align" variables at build time -
__attribute__((aligned(max_pge_size()))), so it is a
preprocessor macro instead of an inline function.

There is no functional change to the 4kB-only build targets
(!defined(__BIONIC_NO_PAGE_SIZE_MACRO))

Bug: 296275298
Test: mma
Change-Id: I462e9f971a176b6b59e32e449a2e11f95c3f1b45
Signed-off-by: Kalesh Singh <kaleshsingh@google.com>
2023-08-19 00:04:53 +00:00
Ryan Prichard
67e8f22cf5 linker_main: acquire loader lock earlier and release it later
__linker_init calls soinfo::~soinfo after __linker_init_post_relocation
has returned, and ~soinfo modifies global loader state
(g_soinfo_handles_map), so the loader lock must be held.

Use a variable with a destructor (~DlMutexUnlocker) to release the
loader lock after ~soinfo returns.

It's not clear to me when the mutex should be acquired.
pthread_mutex_lock in theory can use __bionic_tls (ScopedTrace), but
that should only happen if the mutex is contended, and it won't be.
The loader constructors shouldn't be spawning a thread, and the vdso
shouldn't really have a constructor. ifunc relocations presumably don't
spawn a thread either. It probably doesn't matter much as long as it's
held before calling constructors in the executable or shared objects.

Bug: http://b/290318196
Test: treehugger
Test: bionic-unit-tests
Change-Id: I544ad65db07e5fe83315ad4489d77536d463a0a4
2023-08-18 16:23:34 -07:00
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
Juan Yescas
0bd4117f3f bionic: Fix typo in the argument passed to getauxval()
AT_PAGESZ is the correct argument for getauxval() to get the page size.

Bug: 277272383
Test: source build/envsetup.sh
      lunch aosp_cf_arm64_phone_pgagnostic
Change-Id: Ied2db77e9fda73b58f65b2f489ad7fab743c2fe7
2023-08-18 03:49:15 +00:00
Elliott Hughes
c983dbf0b2 Merge "Point to the riscv64 psABI frame pointer documentation." into main 2023-08-16 14:36:42 +00:00
Elliott Hughes
728aaf6800 sys_hwprobe_test.cpp: compare vdso to syscall.
Also fix a __has_include() that was copy & pasted without modification
from a different test.

Test: treehugger
Change-Id: Iafceb331a95ec788596ffdad60aa2202b692e589
2023-08-14 14:58:33 -07:00
Elliott Hughes
f9571ec851 Point to the riscv64 psABI frame pointer documentation.
Test: N/A
Change-Id: I6639ecfe75a4f0e3caaf7347676997e0e214f6c8
2023-08-14 19:19:39 +00:00
Juan Yescas
6e73f92f04 Merge changes from topic "bionic no page size macro" into main
* changes:
  bionic: PAGE_SIZE macro won't be used in page size agnostic targets
  bionic: Use getauxval(AT_PAGESZ) for page agnostic targets
2023-08-11 05:45:07 +00:00
Juan Yescas
7de2012422 bionic: PAGE_SIZE macro won't be used in page size agnostic targets
When the C flag -D__BIONIC_NO_PAGE_SIZE_MACRO is defined,
the PAGE_SIZE macro won't be used for page size agnostic builds.

Note: Only arm64 architectures support page size agnostic builds.

Bug: 277272383
Bug: 289419664

Test: source build/envsetup.sh
      lunch aosp_cf_arm64_phone_pgagnostic
      m

      source build/envsetup.sh
      lunch aosp_cf_x86_64_phone
      m

Change-Id: I755d5fcdd493fe6da5277a60d8e90805e9b2754d
2023-08-10 15:33:02 -07:00
Juan Yescas
49fdb0babf bionic: Use getauxval(AT_PAGESZ) for page agnostic targets
When the C flag -D__BIONIC_NO_PAGE_SIZE_MACRO is defined,
the function getauxval(AT_PAGESZ) will be called instead of
using the PAGE_SIZE macro for the arm64 architectures.

Bug: 277272383
Bug: 289419664

Test: source build/envsetup.sh
      lunch aosp_raven_pgagnostic_64-userdebug
      m

      source build/envsetup.sh
      lunch aosp_cf_x86_64_phone
      m

Change-Id: Ie904ee5601365abbcf93ee371922a351844eccff
2023-08-10 15:28:19 -07:00
Treehugger Robot
c5c913b0f5 Merge "Clarify a confusing passage in the docs." into main 2023-08-10 20:32:05 +00:00
Elliott Hughes
9b81e58ff9 Clarify a confusing passage in the docs.
Test: N/A
Change-Id: I23a89cb062982ed292bf62b4c187300b0776aa3d
2023-08-10 19:26:36 +00:00
Elliott Hughes
20ad9129e7 Merge "Rename prop_bt." into main 2023-08-08 18:40:49 +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
Kalesh Singh
b88dba9a70 Merge "linker_block_alloctor: Remove 4k page size assumption" into main 2023-08-07 23:16:30 +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