commit: c86cbf1fadb88931f20cc781d1ef30e6a246e0f7 Author: Sam James <sam <AT> gentoo <DOT> org> AuthorDate: Sun May 25 05:29:30 2025 +0000 Commit: Sam James <sam <AT> gentoo <DOT> org> CommitDate: Sun May 25 05:29:30 2025 +0000 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=c86cbf1f
sys-devel/mold: backport systemd crash fix Bug: https://github.com/rui314/mold/issues/1463 Closes: https://bugs.gentoo.org/955406 Signed-off-by: Sam James <sam <AT> gentoo.org> .../mold/files/mold-2.39.1-systemd-crash.patch | 85 +++++++++++++++ sys-devel/mold/mold-2.39.1-r1.ebuild | 121 +++++++++++++++++++++ 2 files changed, 206 insertions(+) diff --git a/sys-devel/mold/files/mold-2.39.1-systemd-crash.patch b/sys-devel/mold/files/mold-2.39.1-systemd-crash.patch new file mode 100644 index 000000000000..714983178fc6 --- /dev/null +++ b/sys-devel/mold/files/mold-2.39.1-systemd-crash.patch @@ -0,0 +1,85 @@ +https://bugs.gentoo.org/955406 +https://github.com/rui314/mold/issues/1463#issuecomment-2907548327 +https://github.com/rui314/mold/commit/53c175850350ba24e264ffc3ac7979892b22bf4c + +From 53c175850350ba24e264ffc3ac7979892b22bf4c Mon Sep 17 00:00:00 2001 +From: Rui Ueyama <[email protected]> +Date: Fri, 16 May 2025 10:45:29 +0900 +Subject: [PATCH] Align TLS segment correctly + +This effectively reverts 5249edc57f8cfbf5c9a3821f82c71c9713f47cdf. +--- + src/passes.cc | 21 ++++++++++++++++++++- + test/tls-large-alignment.sh | 6 +++--- + 2 files changed, 23 insertions(+), 4 deletions(-) + +diff --git a/src/passes.cc b/src/passes.cc +index 6c41a2abbd..b916f88fab 100644 +--- a/src/passes.cc ++++ b/src/passes.cc +@@ -2411,6 +2411,15 @@ void sort_output_sections(Context<E> &ctx) { + sort_output_sections_by_order(ctx); + } + ++template <typename E> ++static i64 get_tls_segment_alignment(Context<E> &ctx) { ++ i64 val = 1; ++ for (Chunk<E> *chunk : ctx.chunks) ++ if (chunk->shdr.sh_flags & SHF_TLS) ++ val = std::max<i64>(val, chunk->shdr.sh_addralign); ++ return val; ++} ++ + // This function assigns virtual addresses to output sections. Assigning + // addresses is a bit tricky because we want to pack sections as tightly + // as possible while not violating the constraints imposed by the hardware +@@ -2455,8 +2464,12 @@ static void set_virtual_addresses_regular(Context<E> &ctx) { + std::vector<Chunk<E> *> &chunks = ctx.chunks; + u64 addr = ctx.arg.image_base; + ++ auto is_tls = [](Chunk<E> *chunk) { ++ return chunk->shdr.sh_flags & SHF_TLS; ++ }; ++ + auto is_tbss = [](Chunk<E> *chunk) { +- return (chunk->shdr.sh_type == SHT_NOBITS) && (chunk->shdr.sh_flags & SHF_TLS); ++ return (chunk->shdr.sh_flags & SHF_TLS) && (chunk->shdr.sh_type == SHT_NOBITS); + }; + + for (i64 i = 0; i < chunks.size(); i++) { +@@ -2513,6 +2526,12 @@ static void set_virtual_addresses_regular(Context<E> &ctx) { + } + } + ++ // TLS sections are included only in PT_LOAD but also in PT_TLS. ++ // We align the first TLS section so that the PT_TLS segment starts ++ // at an address that meets the segment's alignment requirement. ++ if (is_tls(chunks[i]) && (i == 0 || !is_tls(chunks[i - 1]))) ++ addr = align_to(addr, get_tls_segment_alignment(ctx)); ++ + // TLS BSS sections are laid out so that they overlap with the + // subsequent non-tbss sections. Overlapping is fine because a STT_TLS + // segment contains an initialization image for newly-created threads, +diff --git a/test/tls-large-alignment.sh b/test/tls-large-alignment.sh +index a88ac32da1..afbd777e2f 100755 +--- a/test/tls-large-alignment.sh ++++ b/test/tls-large-alignment.sh +@@ -18,14 +18,14 @@ extern _Thread_local int x; + extern _Thread_local int y[]; + + int main() { +- printf("%d %d %d %d\n", x, y[0], y[1], y[2]); ++ printf("%lu %d %d %d %d\n", (unsigned long)&x % 256, x, y[0], y[1], y[2]); + } + EOF + + $CC -B. -shared -o $t/d.so $t/a.o $t/b.o + + $CC -B. -o $t/exe1 $t/a.o $t/b.o $t/c.o +-$QEMU $t/exe1 | grep '^42 1 2 3$' ++$QEMU $t/exe1 | grep '^0 42 1 2 3$' + + $CC -B. -o $t/exe2 $t/c.o $t/d.so +-$QEMU $t/exe2 | grep '^42 1 2 3$' ++$QEMU $t/exe2 | grep '^0 42 1 2 3$' + diff --git a/sys-devel/mold/mold-2.39.1-r1.ebuild b/sys-devel/mold/mold-2.39.1-r1.ebuild new file mode 100644 index 000000000000..61b69150bfe4 --- /dev/null +++ b/sys-devel/mold/mold-2.39.1-r1.ebuild @@ -0,0 +1,121 @@ +# Copyright 2021-2025 Gentoo Authors +# Distributed under the terms of the GNU General Public License v2 + +EAPI=8 + +inherit cmake flag-o-matic toolchain-funcs + +DESCRIPTION="A Modern Linker" +HOMEPAGE="https://github.com/rui314/mold" +if [[ ${PV} == 9999 ]] ; then + EGIT_REPO_URI="https://github.com/rui314/mold.git" + inherit git-r3 +else + SRC_URI="https://github.com/rui314/mold/archive/refs/tags/v${PV}.tar.gz -> ${P}.tar.gz" + # -alpha: https://github.com/rui314/mold/commit/3711ddb95e23c12991f6b8c7bfeba4f1421d19d4 + KEYWORDS="-alpha ~amd64 ~arm ~arm64 ~loong ~ppc ~riscv ~sparc ~x86" +fi + +# mold (MIT) +# - xxhash (BSD-2) +# - siphash ( MIT CC0-1.0 ) +LICENSE="MIT BSD-2 CC0-1.0" +SLOT="0" +IUSE="debug test" +RESTRICT="!test? ( test )" + +RDEPEND=" + app-arch/zstd:= + >=dev-cpp/tbb-2021.7.0-r1:= + dev-libs/blake3:= + sys-libs/zlib + !kernel_Darwin? ( + >=dev-libs/mimalloc-2:= + ) +" +DEPEND="${RDEPEND}" + +PATCHES=( + "${FILESDIR}"/${PN}-2.39.1-systemd-crash.patch +) + +pkg_pretend() { + # Requires a c++20 compiler, see #831473 + if [[ ${MERGE_TYPE} != binary ]]; then + if tc-is-gcc && [[ $(gcc-major-version) -lt 10 ]]; then + die "${PN} needs at least gcc 10" + elif tc-is-clang && [[ $(clang-major-version) -lt 12 ]]; then + die "${PN} needs at least clang 12" + fi + fi +} + +src_prepare() { + cmake_src_prepare + + # Needs unpackaged dwarfdump + rm test/{{dead,compress}-debug-sections,compressed-debug-info}.sh || die + + # Heavy tests, need qemu + rm test/gdb-index-{compress-output,dwarf{2,3,4,5}}.sh || die + rm test/lto-{archive,dso,gcc,llvm,version-script}.sh || die + + # Sandbox sadness + rm test/run.sh || die + sed -i 's|`pwd`/mold-wrapper.so|"& ${LD_PRELOAD}"|' \ + test/mold-wrapper{,2}.sh || die + + # Fails if binutils errors out on textrels by default + rm test/textrel.sh test/textrel2.sh || die + + # Fails with (sometimes, maybe dependent on sys-devel/clang default + # linker): + # "/usr/bin/x86_64-pc-linux-gnu-ld.bfd: unrecognised emulation mode: llvm" + rm test/lto-llvm2.sh || die + + # static-pie tests require glibc built with static-pie support + if ! has_version -d 'sys-libs/glibc[static-pie(+)]'; then + rm test/{,ifunc-}static-pie.sh || die + fi +} + +src_configure() { + use debug || append-cppflags "-DNDEBUG" + + local mycmakeargs=( + -DBUILD_TESTING=$(usex test) + -DMOLD_LTO=OFF # Should be up to the user to decide this with CXXFLAGS. + -DMOLD_USE_MIMALLOC=$(usex !kernel_Darwin) + -DMOLD_USE_SYSTEM_MIMALLOC=ON + -DMOLD_USE_SYSTEM_TBB=ON + ) + + if use test ; then + mycmakeargs+=( + -DMOLD_ENABLE_QEMU_TESTS=OFF + ) + fi + + cmake_src_configure +} + +src_test() { + export TEST_CC="$(tc-getCC)" TEST_GCC="$(tc-getCC)" \ + TEST_CXX="$(tc-getCXX)" TEST_GXX="$(tc-getCXX)" + cmake_src_test +} + +src_install() { + dobin "${BUILD_DIR}"/${PN} + + # https://bugs.gentoo.org/872773 + insinto /usr/$(get_libdir)/mold + doins "${BUILD_DIR}"/${PN}-wrapper.so + + dodoc docs/{design,execstack}.md + doman docs/${PN}.1 + + dosym ${PN} /usr/bin/ld.${PN} + dosym ${PN} /usr/bin/ld64.${PN} + dosym -r /usr/bin/${PN} /usr/libexec/${PN}/ld +}
