439639268d
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 |
||
---|---|---|
.. | ||
arch | ||
testdata | ||
Android.bp | ||
dlfcn.cpp | ||
ld.config.format.md | ||
ld_android.cpp | ||
ldd.sh | ||
linked_list.h | ||
linked_list_test.cpp | ||
linker.arm.map | ||
linker.cpp | ||
linker.generic.map | ||
linker.h | ||
linker_auxv.cpp | ||
linker_auxv.h | ||
linker_block_allocator.cpp | ||
linker_block_allocator.h | ||
linker_block_allocator_test.cpp | ||
linker_cfi.cpp | ||
linker_cfi.h | ||
linker_common_types.h | ||
linker_config.cpp | ||
linker_config.h | ||
linker_config_test.cpp | ||
linker_crt_pad_segment_test.cpp | ||
linker_debug.cpp | ||
linker_debug.h | ||
linker_debuggerd.h | ||
linker_debuggerd_android.cpp | ||
linker_debuggerd_stub.cpp | ||
linker_dlwarning.cpp | ||
linker_dlwarning.h | ||
linker_gdb_support.cpp | ||
linker_gdb_support.h | ||
linker_globals.cpp | ||
linker_globals.h | ||
linker_gnu_hash.h | ||
linker_gnu_hash_benchmark.cpp | ||
linker_gnu_hash_test.cpp | ||
linker_libc_support.c | ||
linker_libcxx_support.cpp | ||
linker_logger.cpp | ||
linker_logger.h | ||
linker_main.cpp | ||
linker_main.h | ||
linker_mapped_file_fragment.cpp | ||
linker_mapped_file_fragment.h | ||
linker_memory.cpp | ||
linker_namespaces.cpp | ||
linker_namespaces.h | ||
linker_note_gnu_property.cpp | ||
linker_note_gnu_property.h | ||
linker_note_gnu_property_test.cpp | ||
linker_phdr.cpp | ||
linker_phdr.h | ||
linker_reloc_iterators.h | ||
linker_relocate.cpp | ||
linker_relocate.h | ||
linker_relocs.h | ||
linker_sdk_versions.cpp | ||
linker_sleb128.h | ||
linker_sleb128_test.cpp | ||
linker_soinfo.cpp | ||
linker_soinfo.h | ||
linker_test_globals.cpp | ||
linker_tls.cpp | ||
linker_tls.h | ||
linker_translate_path.cpp | ||
linker_translate_path.h | ||
linker_transparent_hugepage_support.cpp | ||
linker_utils.cpp | ||
linker_utils.h | ||
linker_utils_test.cpp | ||
linker_wrapper.cpp | ||
MODULE_LICENSE_BSD | ||
NOTICE | ||
rt.cpp |