sys-devel/mold: backport musl test fix

Signed-off-by: Sam James <sam@gentoo.org>
This commit is contained in:
Sam James
2023-07-29 05:28:38 +01:00
parent e0d3c80c9c
commit 11f5aee951
2 changed files with 151 additions and 0 deletions
@@ -0,0 +1,58 @@
https://github.com/rui314/mold/issues/1067
https://github.com/rui314/mold/commit/1582b720d58df61bc4c0ae39fa269e3b250b94df
From 1582b720d58df61bc4c0ae39fa269e3b250b94df Mon Sep 17 00:00:00 2001
From: Rui Ueyama <ruiu@bluewhale.systems>
Date: Fri, 28 Jul 2023 14:58:57 +0900
Subject: [PATCH] Weak undefs should not keep DSOs alive
Fixes https://github.com/rui314/mold/issues/1067
--- a/elf/input-files.cc
+++ b/elf/input-files.cc
@@ -1396,7 +1396,8 @@ SharedFile<E>::mark_live_objects(Context<E> &ctx,
if (sym.is_traced)
print_trace_symbol(ctx, *this, esym, sym);
- if (esym.is_undef() && sym.file && !sym.file->is_alive.test_and_set()) {
+ if (esym.is_undef() && !esym.is_weak() && sym.file &&
+ !sym.file->is_alive.test_and_set()) {
feeder(sym.file);
if (sym.is_traced)
--- /dev/null
+++ b/test/elf/as-needed-dso2.sh
@@ -0,0 +1,33 @@
+#!/bin/bash
+. $(dirname $0)/common.inc
+
+cat <<EOF | $CC -c -fPIC -o $t/a.o -xc -
+int foo() {
+ return 0;
+}
+EOF
+
+cat <<EOF | $CC -c -fPIC -o $t/b.o -xc -
+__attribute__((weak)) int foo();
+
+int bar() {
+ if (foo) return foo();
+ return 0;
+}
+EOF
+
+cat <<EOF | $CC -xc -c -o $t/c.o -
+int bar();
+
+int main() {
+ return bar();
+}
+EOF
+
+$CC -B. -shared -o $t/libfoo.so $t/a.o
+$CC -B. -shared -o $t/libbar.so $t/b.o
+$CC -B. -o $t/exe $t/c.o -L$t -Wl,--as-needed -lfoo -lbar
+
+readelf --dynamic $t/exe > $t/log
+! grep libfoo.so $t/log || false
+grep -q libbar.so $t/log
+93
View File
@@ -0,0 +1,93 @@
# Copyright 2021-2023 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
EAPI=8
inherit cmake 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"
KEYWORDS="~amd64 ~arm64 ~ppc64 ~riscv ~x86"
fi
# mold (MIT)
# - xxhash (BSD-2)
LICENSE="MIT BSD-2"
SLOT="0"
RDEPEND="
app-arch/zstd:=
>=dev-cpp/tbb-2021.7.0-r1:=
sys-libs/zlib
!kernel_Darwin? (
>=dev-libs/mimalloc-2:=
dev-libs/openssl:=
)
"
DEPEND="${RDEPEND}"
PATCHES=(
"${FILESDIR}"/${P}-reloc-test-fix.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/elf/{{dead,compress}-debug-sections,compressed-debug-info}.sh || die
# Heavy tests, need qemu
rm test/elf/gdb-index-{compress-output,dwarf{2,3,4,5}}.sh || die
rm test/elf/lto-{archive,dso,gcc,llvm,version-script}.sh || die
# Sandbox sadness
rm test/elf/run.sh || die
sed -i 's|`pwd`/mold-wrapper.so|"& ${LD_PRELOAD}"|' \
test/elf/mold-wrapper{,2}.sh || die
# static-pie tests require glibc built with static-pie support
if ! has_version -d 'sys-libs/glibc[static-pie(+)]'; then
rm test/elf/{,ifunc-}static-pie.sh || die
fi
}
src_configure() {
local mycmakeargs=(
-DMOLD_ENABLE_QEMU_TESTS=OFF
-DMOLD_LTO=OFF # Should be up to the user to decide this with CXXFLAGS.
-DMOLD_USE_SYSTEM_MIMALLOC=ON
-DMOLD_USE_SYSTEM_TBB=ON
)
cmake_src_configure
}
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 ../../../usr/bin/${PN} /usr/libexec/${PN}/ld
}