Commit graph

42600 commits

Author SHA1 Message Date
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
Treehugger Robot
4107b95c9a Merge "Ignore bionic versioning in vendor modules" into main am: f3a8ae87fd
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2994436

Change-Id: I04d4d40917387c0cf50389cb178bb203b959065b
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2024-03-14 03:59:16 +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
3c1d1517eb Merge "Fix orthography of GetTestLibRoot()." into main am: 8af71663c0
Original change: https://android-review.googlesource.com/c/platform/bionic/+/3001796

Change-Id: Ie423455893647903452a5ab9e8d177cc7108f623
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2024-03-14 00:34:24 +00: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
6bc86d4212 Merge "Move memtag_stack out of libc_globals" into main am: 60573deb72
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2994684

Change-Id: I0d4d4b05aeaba9e717a60e67e989be517f1b7c27
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2024-03-13 18:29:28 +00:00