Commit graph

42786 commits

Author SHA1 Message Date
Elliott Hughes
3bfb6eeb14 sysconf()/getpagesize() documentation.
Plus a little bit of cleanup of the sysconf() implementation...

Change-Id: I017d50e537e4721c9a4c4a62e9dea771ee920fb8
2024-03-27 21:23:42 +00:00
Treehugger Robot
2910ce1ed5 Merge "Update status.md." into main 2024-03-27 02:59:47 +00:00
Treehugger Robot
a00ed8a895 Merge "linker: Process RELR relocations before ANDROID_REL[A]." into main 2024-03-27 02:53:08 +00:00
Elliott Hughes
a459c0b066 Update status.md.
We were still using "Android O" in developer-facing documentation, we'd forgotten to document the destroyed pthread_mutex_t behavior change, and we'd forgotten to document the existence of _Fork() and <android/crash_detail.h>.

Change-Id: Ie2c94a1956b7252472116cacc90f38fa4e2dd229
2024-03-27 02:16:49 +00:00
Peter Collingbourne
e0ebca8fa3 linker: Process RELR relocations before ANDROID_REL[A].
ANDROID_REL[A] need to be processed after RELR in case it contains
an IRELATIVE relocation with a resolver that accesses data relocated
by RELR.

Bug: 331466607
Change-Id: I50865e67fc1492d75324ef3cb9defef3f8b88421
2024-03-26 18:38:32 -07:00
Elliott Hughes
5a42460cc6 Merge "elf.h: add EF_RISCV_FLOAT_ABI." into main 2024-03-26 23:08:53 +00:00
Treehugger Robot
fb95ed5df7 Merge "Improve our dlsym()/dlvsym() docs a bit more." into main 2024-03-26 22:33:48 +00:00
Elliott Hughes
386e64df7d Merge "Use ifuncs for memset and memrchr." into main 2024-03-26 21:03:19 +00:00
Elliott Hughes
b90d6b35a6 elf.h: add EF_RISCV_FLOAT_ABI.
See code comments for details. I think everything we could reasonably
upstream from this file is now an upstream pull request. If they get in,
I'll try my luck with the arm32 TLS constant (which is a bit more
interesting because there's a probably obsolete conflict upstream, but
someone who knows about FreeBSD/arm32 would want to look at that).

Test: treehugger
Change-Id: I5bf197045940d25efb2a520716499d924c362b57
2024-03-26 19:15:42 +00:00
Elliott Hughes
cb47a4f671 Use ifuncs for memset and memrchr.
Not useful right now, but Qualcomm has an Oryon memset they'd like to
use, and there's no reason to treat memrchr as a weird special case.

Bug: https://issuetracker.google.com/330105715
Test: treehugger
Change-Id: Id879479bf4f45433debcb3fe08cfa96bb1eb3b93
2024-03-26 18:58:50 +00:00
Elliott Hughes
edc73c5492 Improve our dlsym()/dlvsym() docs a bit more.
RTLD_DEFAULT/RTLD_NEXT already linked to the functions, but the functions should link to the constants too.

Change-Id: I854b632092f077d71918e99b3caec874e1df1ef3
2024-03-26 16:46:29 +00:00
Treehugger Robot
0339184afc Merge "Remove duplicate ELF_ST_TYPE() macro." into main 2024-03-22 22:21:00 +00:00
Elliott Hughes
6bf133dc5f Remove duplicate ELF_ST_TYPE() macro.
The Linux uapi header fixed their definition in 5.19 to not have the cast that we were working around here. (See https://lkml.kernel.org/r/Ymv7G1BeX4kt3obz@localhost.localdomain for the upstream patch.)

Change-Id: Ied3368551ebb82f44f411684fe3666d06efbd22e
2024-03-22 20:46:52 +00:00
Elliott Hughes
2a70ee680c Merge "Update FreeBSD elf_common.h." into main 2024-03-22 20:40:42 +00:00
Treehugger Robot
ef9504be7d Merge "Change doc about crash_detail name" into main 2024-03-21 22:09:00 +00:00
Ryan Prichard
a35df79cd8 Merge "Fix StaticTlsLayout for atypical alignment values" into main 2024-03-21 21:38:59 +00:00
Florian Mayer
a5d6778356 Change doc about crash_detail name
Test: none, doc change
Bug: 326097280
Change-Id: I5a79b8ac7448e564a9d72ad1c9323cea35d82227
2024-03-21 13:50:44 -07:00
Elliott Hughes
6cd03eff43 Update FreeBSD elf_common.h.
Looks like I'd been bad here, and added new stuff to this file rather
than <elf.h> directly. I've also done nothing to upstream any of this.
This patch at least addresses the former problem, moving our stuff out
into <elf.h>.

Rather than *delete* anything that conflicts with Linux in elf_common.h,
I've disable it with // or #if, and marked those as Android changes to
make it less likely that the next update accidentally drops them (which
isn't super likely, since most of them should actually cause build
failures when they conflict with uapi).

Test: treehugger
Change-Id: Id0deccc7305c60b0f708b55e2eed0dedc0bca41d
2024-03-21 20:13:36 +00:00
Ryan Prichard
439639268d Fix StaticTlsLayout for atypical alignment values
arm32/arm64: Previously, the loader miscalculated a negative value for
offset_bionic_tcb_ when the executable's alignment was greater than
(8 * sizeof(void*)). The process then tended to crash.

riscv: Previously, the loader didn't propagate the p_align field of the
PT_TLS segment into StaticTlsLayout::alignment_, so high alignment
values were ignored.

__bionic_check_tls_alignment: Stop capping alignment at page_size().
There is no need to cap it, and the uncapped value is necessary for
correctly positioning the TLS segment relative to the thread pointer
(TP) for ARM and x86. The uncapped value is now used for computing
static TLS layout, but only a page of alignment is actually provided:
 * static TLS: __allocate_thread_mapping uses mmap, which provides only
   a page's worth of alignment
 * dynamic TLS: BionicAllocator::memalign caps align to page_size()
 * There were no callers to StaticTlsLayout::alignment(), so remove it.

Allow PT_TLS.p_align to be 0: quietly convert it to 1.

For static TLS, ensure that the address of a TLS block is congruent to
p_vaddr, modulo p_align. That is, ensure this formula holds:

    (&tls_block % p_align) == (p_vaddr % p_align)

For dynamic TLS, a TLS block is still allocated congruent to 0 modulo
p_align. Fixing dynamic TLS congruence is mostly a separate problem
from fixing static TLS congruence, and requires changing the dynamic
TLS allocator and/or DTV structure, so it should be fixed in a
later follow-up commit.

Typically (p_vaddr % p_align) is zero, but it's currently possible to
get a non-zero value with LLD: when .tbss has greater than page
alignment, but .tdata does not, LLD can produce a TLS segment where
(p_vaddr % p_align) is non-zero. LLD calculates TP offsets assuming
the loader will align the segment using (p_vaddr % p_align).
Previously, Bionic and LLD disagreed on the offsets from the TP to
the executable's TLS variables.

Add unit tests for StaticTlsLayout in bionic-unit-tests-static.

See also:
 * https://github.com/llvm/llvm-project/issues/40872
 * https://sourceware.org/bugzilla/show_bug.cgi?id=24606
 * https://reviews.llvm.org/D61824
 * https://reviews.freebsd.org/D31538

Bug: http://b/133354825
Bug: http://b/328844725
Bug: http://b/328844839
Test: bionic-unit-tests bionic-unit-tests-static
Change-Id: I8850c32ff742a45d3450d8fc39075c10a1e11000
2024-03-20 17:01:35 -07:00
Treehugger Robot
294ed38a4b Merge "Remove an unused header file." into main 2024-03-19 21:34:29 +00:00
Elliott Hughes
383349cf06 Remove an unused header file.
This was our only remaining BSD 4-clause file.

Test: N/A
Change-Id: I3a4042a92f1ff6ab7d3e1a0cd043952f98f0861e
2024-03-19 19:37:41 +00:00
Treehugger Robot
029f1cf479 Merge "Include the SPDX identifiers in NOTICE files." into main 2024-03-19 19:04:38 +00:00
Elliott Hughes
526bd985c8 Include the SPDX identifiers in NOTICE files.
We're starting to see projects _only_ use the SPDX identifiers (and
they're more readable "at a glance" anyway), so it's probably time to
include these...

Test: N/A
Change-Id: I5c76d77dcd392a8db1166108e410389d349a42c3
2024-03-19 15:56:30 +00:00
Treehugger Robot
f14e4c15b3 Merge "Update the --hash-style= documentation." into main 2024-03-19 04:16:15 +00:00
Elliott Hughes
91219ec81e Update the --hash-style= documentation.
danalbert made clang just do the right thing years ago, so update the docs to reflect that.

Change-Id: I08dd4bf4f2fc37fcaabba331f129221d8abf7498
2024-03-19 00:51:08 +00:00
Elliott Hughes
a8b8cd7be9 Merge "Remove workaround for a fixed bug." into main 2024-03-18 16:04:06 +00:00
Elliott Hughes
7b95053aa0 Remove workaround for a fixed bug.
We're still copy & pasting this workaround about, but the bug was supposedly fixed years ago!

Bug: http://b/34945607
Bug: http://b/33942619
Bug: http://b/34195559
Change-Id: Icf3d184d2ddb447dff7dacccea1dc903da816505
2024-03-16 00:22:00 +00:00
Treehugger Robot
5067ef29d4 Merge "Flush all the streams if CHECK() fails." into main 2024-03-15 21:04:53 +00:00
Elliott Hughes
dc0510ec17 Flush all the streams if CHECK() fails.
It's usually more helpful to see all the output so far.

If we're worried about fflush() failing because of the state we're in, we shouldn't be using stdio at all!

If this _does_ become a problem, we should probably switch to using the internal functions: `__assert2` for bionic, `__assert_fail` for musl/glibc, and `__assert_rtn` for macOS.

Unfortunately although `__assert2` and `__assert_fail` take the same arguments, they're in a different order, so we can't simply add a symbol alias to make that difference go away, and it's not clear that there's enough value to adding an otherwise unused symbol.

Change-Id: I653183737ab6368890bbd9d0e2f37fc5cb2e1dec
2024-03-15 15:23:12 +00:00
Ryan Prichard
3abc30d6a6 Merge "Make tests/libs/CHECK.h work on the host" into main 2024-03-14 23:15:19 +00:00
Ryan Prichard
68eb690f86 Merge changes Idb061b98,I93c17ca6 into main
* changes:
  ldd: skip relocation processing, TLS modules, CFI
  Guard against linker[64] having a PT_TLS segment
2024-03-14 22:58:51 +00:00
Ryan Prichard
32bb3673c1 ldd: skip relocation processing, TLS modules, CFI
This avoids a diagnostic on arm32/arm64 when running ldd on a shared
library with a PT_TLS segment:

executable's TLS segment is underaligned: alignment is 8, needs to be at least 64 for ARM64 Bionic

Bug: http://b/328822319
Test: ldd /system/lib64/libc.so
Change-Id: Idb061b980333ba3b5b3f44b52becf041d76ea0b7
2024-03-14 14:01:04 -07:00
Ryan Prichard
b4937462f5 Guard against linker[64] having a PT_TLS segment
The loader doesn't currently support using TLS within itself.
Previously, if a TLS segment was accidentally linked into the loader,
then the loader's `soinfo_tls* tls_` field would be initialized with a
valid TlsSegment, but the loader soinfo wouldn't be registered with
linker_tls.cpp, so the module ID would be 0. (The first valid module ID
is 1.)

The result was architecture-dependent. On x86, everything worked until
the first TLS access, which segfaulted. On arm64, relocating TLSDESC
hit a CHECK() failure on the invalid module ID.

Make the loader more robust:
 * Abort in the loader if it detects that it has a TLS segment.
 * For R_GENERIC_TLS_DTPMOD, verify that a module ID is valid before
   writing it.

Bug: none
Test: manually add a thread_local variable to the loader
Test: bionic-unit-tests
Change-Id: I93c17ca65df4af2d46288957a0e483b0e2b13862
2024-03-14 13:25:16 -07:00
Kalesh Singh
4fbcbbd522 Merge changes Ib76b022f,I98882edd,I575d626b into main
* changes:
  bionic: loader: Only zero the last partial page in RW segments
  Reapply "RELAND: bionic: loader: Extend GNU_RELRO protection"
  Reapply "RELAND: bionic: loader: Extend LOAD segment VMAs"
2024-03-14 20:22:26 +00:00
Elliott Hughes
63df96b7fb Merge "crt*.o cleanup." into main 2024-03-14 18:37:18 +00:00
Christopher Ferris
41cc7be55a Merge "Minor benchmark fixes." into main 2024-03-14 03:38:20 +00:00
Treehugger Robot
f3a8ae87fd Merge "Ignore bionic versioning in vendor modules" into main 2024-03-14 03:35:13 +00:00
Ryan Prichard
e4912ac995 Make tests/libs/CHECK.h work on the host
The `__assert2` function is not provided by glibc, in particular.

Bug: none
Test: manual
Change-Id: I72c428fd0794aceec2bfaf37638be0ff6a02f289
2024-03-13 18:31:15 -07:00
Elliott Hughes
8af71663c0 Merge "Fix orthography of GetTestLibRoot()." into main 2024-03-14 00:11:05 +00:00
Christopher Ferris
b2bb21da8d Minor benchmark fixes.
Change the AT_All_XXX to AT_ALL_XXX.

Change the name of the from_prot and to_prot parameters to be more
descriptive.

Add a few extra large page sizes. Without this, it jumps from a
relatively small size to an extreme large size and nothing in
between.

Clang-format modified the args_shorthand initialization.

Test: Ran benchmarks on device.
Change-Id: I5105788cbf05793fcb4d86c26037ec435635631e
2024-03-13 16:59:44 -07:00
Elliott Hughes
6a30b71b07 crt*.o cleanup.
Say .S instead of .c in a comment, and don't add an include directory we don't need.

Change-Id: I4cfc39904a4ad67a2aadb6691c527f7e38d9c4c7
2024-03-13 23:41:32 +00:00
Kalesh Singh
1d3ba112ab bionic: loader: Only zero the last partial page in RW segments
Only zero the partial page at the end of the segment. There may be
entire pages beyond first page boundary after the segment -- due to
segment padding (VMA extension); but these are not expected to be
touched (faulted).

Do not attempt to zero the extended region past the first partial page,
since doing so may:
  1) Result in a SIGBUS, as the region is not backed by the underlying
     file.
  2) Break the COW backing, faulting in new anon pages for a region
     that will not be used.

Bug: 327600007
Bug: 328797737
Test: Dexcom G7 app
Test: atest -c linker-unit-tests
Test: bootup/idle/system-processes-memory-direct
Change-Id: Ib76b022f94bfc4a4b7eaca2c155af81478741b91
Signed-off-by: Kalesh Singh <kaleshsingh@google.com>
2024-03-13 13:40:28 -07:00
Kalesh Singh
702d9b0bad Reapply "RELAND: bionic: loader: Extend GNU_RELRO protection"
This reverts commit 26de64896c.

Bug: 328797737
Test: Dexcom G7 app
Change-Id: I98882edd17f0ea5432ab254482ab9508bfaf4f56
Signed-off-by: Kalesh Singh <kaleshsingh@google.com>
2024-03-13 13:38:44 -07:00
Kalesh Singh
4084b555b2 Reapply "RELAND: bionic: loader: Extend LOAD segment VMAs"
This reverts commit 7a04fedc78.

Test: Dexcom G7 app
Bug: 328797737
Change-Id: I575d626b1313d1c66bf25f29c43a9a101024a4f8
Signed-off-by: Kalesh Singh <kaleshsingh@google.com>
2024-03-13 13:37:30 -07:00
Florian Mayer
60573deb72 Merge "Move memtag_stack out of libc_globals" into main 2024-03-13 17:54:37 +00:00
Elliott Hughes
eb75833834 Merge "Add missing documentation to <dlfcn.h>." into main 2024-03-13 14:48:50 +00:00
Justin Yun
ced630225a Ignore bionic versioning in vendor modules
Vendor modules do not follow bionic versioning but define their own
versioning for LLNDK. Ignore the __INTRODUCED_IN annotation for
vendor modules.

Bug: 302113279
Test: build trunk-staging and next configurations
Change-Id: I04646b524d17f7ae47f0f96cb98f221f3e821629
2024-03-13 21:02:58 +09:00
Elliott Hughes
eb4cf41766 Add missing documentation to <dlfcn.h>.
All the dude wanted was to mention that dlclose() can cause problems with thread locals...

Change-Id: Iea23c49b6b2d6d93b85b2aa0ab1183e68cf39695
2024-03-12 23:45:00 +00:00
Elliott Hughes
8d8138aad1 Fix orthography of GetTestLibRoot().
Change-Id: Ib052329b3ebced12a7e2d75b3628b33c7043e0d8
2024-03-12 22:37:13 +00:00
Florian Mayer
73750dc38e Move memtag_stack out of libc_globals
We cannot use a WriteProtected because we are accessing it in a
multithreaded context.

Test: atest memtag_stack_dlopen_test w/ MTE
Test: atest bionic-unit-tests w/ MTE
Test: atest bionic-unit-tests on _fullmte
Bug: 328256432
Change-Id: I39faa75f97fd5b3fb755a46e88346c17c0e9a8e2
2024-03-12 12:42:23 -07:00