commit:     6f278ebfe80120e491bf4473ab56627c2075a52f
Author:     idealseal <realidealseal <AT> protonmail <DOT> com>
AuthorDate: Sat Jul  5 10:10:54 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Tue Jul  8 19:45:51 2025 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=6f278ebf

sys-devel/mold: add 2.40.1

Closes: https://bugs.gentoo.org/948507
Signed-off-by: idealseal <realidealseal <AT> protonmail.com>
Part-of: https://github.com/gentoo/gentoo/pull/42879
Signed-off-by: Sam James <sam <AT> gentoo.org>

 sys-devel/mold/Manifest                            |   1 +
 .../mold/files/mold-2.40.1-fix-clang-fd-leak.patch |  32 ++++++
 sys-devel/mold/mold-2.40.1.ebuild                  | 121 +++++++++++++++++++++
 3 files changed, 154 insertions(+)

diff --git a/sys-devel/mold/Manifest b/sys-devel/mold/Manifest
index 10b1eec790ab..0cc90845b91e 100644
--- a/sys-devel/mold/Manifest
+++ b/sys-devel/mold/Manifest
@@ -1,2 +1,3 @@
 DIST mold-2.37.1.tar.gz 10169802 BLAKE2B 
702f5678f070b66cd3e6a2df000aad73ce6248d0bb025bfbfaa5de76be71c2ea265c45c5e5086426c79354f95c9326e0c33b0e78a144881a22456fbb495e46b1
 SHA512 
641c6668ee31368409d80ea01c0d84a58eac827eedc110495ca075bfce22081c906308d027e4723750995fc0d8b6bba8be3c3472c20f765ef45d14e1c4e36cd4
 DIST mold-2.39.1.tar.gz 10224022 BLAKE2B 
417e3f4f505b62e309d59e00646ddb9a90a6c073e3ec2b507d31f2c8ca58c2d1356acfea56fd57e2769c7bbec6eb308038f1f6d28b39bb79e1f21001a370ffe8
 SHA512 
2d6d3d892d0dc6b256fbb2a1bbe7519948c2cd683549d23727da9cbccf1dad80a3af2826bf96b9d02ed56a765fa46ffc8fcd23168bb5624a1fa4b9dd21606005
+DIST mold-2.40.1.tar.gz 11033828 BLAKE2B 
016232dd9a73a697c8059db820de950de37acba6147bb4be96ec621fd0133d35994386e4ec1f37a580ce8553523e3f0ad9d2e9ae8dba975795964b8fec1ceb72
 SHA512 
2dc8c18b19df070790eb4eb8e8505f87552f8f12033d465f06415db4ce5bace4209e392b52359dc8811d96ead3567381198cd3941a038547da515d3ab47039e6

diff --git a/sys-devel/mold/files/mold-2.40.1-fix-clang-fd-leak.patch 
b/sys-devel/mold/files/mold-2.40.1-fix-clang-fd-leak.patch
new file mode 100644
index 000000000000..e16df17f6a5f
--- /dev/null
+++ b/sys-devel/mold/files/mold-2.40.1-fix-clang-fd-leak.patch
@@ -0,0 +1,32 @@
+From 1956ae6ac863116a1b7396606427e45fbdee59e0 Mon Sep 17 00:00:00 2001
+From: Rui Ueyama <[email protected]>
+Date: Wed, 11 Jun 2025 10:16:07 +0900
+Subject: [PATCH] Close fd when doing LTO
+
+Fixes https://github.com/rui314/mold/issues/1362
+---
+ src/lto-unix.cc | 11 ++++-------
+ 1 file changed, 4 insertions(+), 7 deletions(-)
+
+diff --git a/src/lto-unix.cc b/src/lto-unix.cc
+index ba7e984e31..8fc0acfc48 100644
+--- a/src/lto-unix.cc
++++ b/src/lto-unix.cc
+@@ -638,13 +638,10 @@ ObjectFile<E> *read_lto_object(Context<E> &ctx, 
MappedFile *mf) {
+                << " please make sure you are using the same compiler of the"
+                << " same version for all object files";
+ 
+-  // It looks like GCC doesn't need fd after claim_file_hook() while
+-  // LLVM needs it and takes the ownership of fd. To prevent "too many
+-  // open files" issue, we close fd only for GCC. This is ugly, though.
+-  if (!is_llvm(ctx)) {
+-    MappedFile *mf2 = mf->parent ? mf->parent : mf;
+-    mf2->close_fd();
+-  }
++  if (mf->parent)
++    mf->parent->close_fd();
++  else
++    mf->close_fd();
+ 
+   // Create a symbol strtab
+   i64 strtab_size = 1;

diff --git a/sys-devel/mold/mold-2.40.1.ebuild 
b/sys-devel/mold/mold-2.40.1.ebuild
new file mode 100644
index 000000000000..4882ac441eec
--- /dev/null
+++ b/sys-devel/mold/mold-2.40.1.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}/${P}-fix-clang-fd-leak.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
+}

Reply via email to