Commit graph

43186 commits

Author SHA1 Message Date
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
94ed10a372 Merge "elf.h: add EF_RISCV_FLOAT_ABI." into main am: 5a42460cc6
Original change: https://android-review.googlesource.com/c/platform/bionic/+/3014180

Change-Id: I0343fdabed035a4489f21b21c47c80e7d9c26ec9
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2024-03-26 23:26:14 +00:00
Elliott Hughes
5a42460cc6 Merge "elf.h: add EF_RISCV_FLOAT_ABI." into main 2024-03-26 23:08:53 +00:00
Treehugger Robot
d053919555 Merge "Improve our dlsym()/dlvsym() docs a bit more." into main am: fb95ed5df7
Original change: https://android-review.googlesource.com/c/platform/bionic/+/3014673

Change-Id: I97ddb763b9349a00a9285101beeda422dd46736b
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2024-03-26 22:46:41 +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
7f0d140cd0 Merge "Use ifuncs for memset and memrchr." into main am: 386e64df7d
Original change: https://android-review.googlesource.com/c/platform/bionic/+/3011735

Change-Id: I0dc49db3697fae445db9019f138af8863a08cd83
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2024-03-26 21:21:23 +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
f91bb70cc3 Merge "Remove duplicate ELF_ST_TYPE() macro." into main am: 0339184afc
Original change: https://android-review.googlesource.com/c/platform/bionic/+/3010513

Change-Id: I4d1ed712ba238e83ce7bdbf7f418e55d76740486
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2024-03-22 22:33:44 +00:00
Treehugger Robot
0339184afc Merge "Remove duplicate ELF_ST_TYPE() macro." into main 2024-03-22 22:21:00 +00:00
Elliott Hughes
ed44a83386 Merge "Update FreeBSD elf_common.h." into main am: 2a70ee680c
Original change: https://android-review.googlesource.com/c/platform/bionic/+/3008738

Change-Id: Ica0e6a2b595497d323b8c6285869f8cfa1147dae
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2024-03-22 20:58:59 +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
5b457cb0a4 Merge "Change doc about crash_detail name" into main am: ef9504be7d
Original change: https://android-review.googlesource.com/c/platform/bionic/+/3009234

Change-Id: I6187ba986288e307fab1c4724273cdc1593238b9
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2024-03-21 23:09:32 +00:00
Treehugger Robot
ef9504be7d Merge "Change doc about crash_detail name" into main 2024-03-21 22:09:00 +00:00
Ryan Prichard
97aca9c925 Merge "Fix StaticTlsLayout for atypical alignment values" into main am: a35df79cd8
Original change: https://android-review.googlesource.com/c/platform/bionic/+/3001042

Change-Id: I5755a87f537c369e438381dc2ea4f966d41f8784
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2024-03-21 21:59:04 +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
796262626c Merge "Remove an unused header file." into main am: 294ed38a4b
Original change: https://android-review.googlesource.com/c/platform/bionic/+/3006621

Change-Id: I15fa9d531ee6a62b7f460597f8b3961d1e43381c
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2024-03-19 22:21:04 +00: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
c36c345b3a Merge "Include the SPDX identifiers in NOTICE files." into main am: 029f1cf479
Original change: https://android-review.googlesource.com/c/platform/bionic/+/3006954

Change-Id: I6b65f0615f70de47db69610f871528a0e220a587
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2024-03-19 19:23:44 +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
1f390bf119 Merge "Update the --hash-style= documentation." into main am: f14e4c15b3
Original change: https://android-review.googlesource.com/c/platform/bionic/+/3004376

Change-Id: I156121420b91f1db3b940c7e748031ef819a6e8d
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2024-03-19 04:33:18 +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
eb93d1a550 Merge "Remove workaround for a fixed bug." into main am: a8b8cd7be9
Original change: https://android-review.googlesource.com/c/platform/bionic/+/3005801

Change-Id: Ifa332aff4b07b6d70759a358c66eea0bce91bf9e
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2024-03-18 16:26:11 +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
8c6a1a2868 Merge "Flush all the streams if CHECK() fails." into main am: 5067ef29d4
Original change: https://android-review.googlesource.com/c/platform/bionic/+/3002962

Change-Id: I5596c9843b6e204e46309ada8529c57b7e7c1990
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2024-03-15 21:20:58 +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
f20f72ae6f Merge "Make tests/libs/CHECK.h work on the host" into main am: 3abc30d6a6
Original change: https://android-review.googlesource.com/c/platform/bionic/+/3003534

Change-Id: I72e1d967680af3fb2adfb340f779984f99d10a9b
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2024-03-14 23:25:54 +00:00
Ryan Prichard
070f69bd76 Merge changes Idb061b98,I93c17ca6 into main am: 68eb690f86
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2995381

Change-Id: I41bfb6cadfe79ffc3b33194d58c8784ed631fbde
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2024-03-14 23:25:40 +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
Kalesh Singh
7059a29043 Merge changes Ib76b022f,I98882edd,I575d626b into main am: 4fbcbbd522
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2992659

Change-Id: Ie131d4f108656228bdf7bb2a84bd2eeec0985472
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2024-03-14 20:46:22 +00: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
e423c3231b Merge "crt*.o cleanup." into main am: 63df96b7fb
Original change: https://android-review.googlesource.com/c/platform/bionic/+/3001061

Change-Id: I4a6a085bbb008af5bebf499ac4b488881e73d9de
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2024-03-14 19:11:30 +00:00
Elliott Hughes
63df96b7fb Merge "crt*.o cleanup." into main 2024-03-14 18:37:18 +00:00
Christopher Ferris
cf54c528f3 Merge "Minor benchmark fixes." into main am: 41cc7be55a
Original change: https://android-review.googlesource.com/c/platform/bionic/+/3003517

Change-Id: I6b88fafe267becff4c2b3486f9ce58511d5f0268
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2024-03-14 03:59:28 +00:00