commit:     3a538523c8039763c9c3bdea27095115cf728c01
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Thu May  1 01:37:48 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Thu May  1 01:40:15 2025 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=3a538523

sys-devel/mold: backport 2 fixes to 2.38.1

* Fix -Wl,--default-symver vs -Wl,--version-script which shows up as breakage
  in dev-libs/jansson vs dev-libs/json-c in net-firewall/firewalld (like in
  bug #812119). Thanks to Chewi for digging into it & reporting it upstream.

  There's a chance that it may help with bug #937990 too
  and maybe (but less likely?) bug #933197.

* Fix --omagic hang (upstream report says it was a regression in 2.38.1
  vs 2.38.0, so let's fix it while here).

* Skip test failing for me on one machine (seems to be Clang not picking
  up that it should use mold/lld for the test, or the plugin maybe not
  being around; not going to worry about it for now).

Bug: https://bugs.gentoo.org/812119
Bug: https://bugs.gentoo.org/933197
Bug: https://bugs.gentoo.org/937990
Signed-off-by: Sam James <sam <AT> gentoo.org>

 .../mold/files/mold-2.38.1-default-symver.patch    | 70 ++++++++++++++++++++++
 sys-devel/mold/files/mold-2.38.1-omagic-loop.patch | 28 +++++++++
 .../{mold-9999.ebuild => mold-2.38.1-r1.ebuild}    | 10 ++++
 sys-devel/mold/mold-9999.ebuild                    |  5 ++
 4 files changed, 113 insertions(+)

diff --git a/sys-devel/mold/files/mold-2.38.1-default-symver.patch 
b/sys-devel/mold/files/mold-2.38.1-default-symver.patch
new file mode 100644
index 000000000000..4f5e874db420
--- /dev/null
+++ b/sys-devel/mold/files/mold-2.38.1-default-symver.patch
@@ -0,0 +1,70 @@
+https://github.com/rui314/mold/commit/8bae43b842f1ded33830a95b8fc7ba8b0a53086f
+
+From 8bae43b842f1ded33830a95b8fc7ba8b0a53086f Mon Sep 17 00:00:00 2001
+From: Rui Ueyama <[email protected]>
+Date: Wed, 30 Apr 2025 20:37:14 +0900
+Subject: [PATCH] Make --default-symver work with version scripts
+
+Previously, symbols specified with the `global:` label were unversioned
+even if --default-symver was given. Now, such symbols are versioned with
+the output file's soname.
+
+Fixes https://github.com/rui314/mold/issues/1448
+---
+ src/cmdline.cc                        |  2 --
+ src/output-chunks.cc                  |  8 ++++++++
+ test/default-symver-version-script.sh | 11 +++++++++++
+ 3 files changed, 19 insertions(+), 2 deletions(-)
+ create mode 100755 test/default-symver-version-script.sh
+
+diff --git a/src/cmdline.cc b/src/cmdline.cc
+index d27f6bdc3d..a6471d5bba 100644
+--- a/src/cmdline.cc
++++ b/src/cmdline.cc
+@@ -1510,9 +1510,7 @@ std::vector<std::string> 
parse_nonpositional_args(Context<E> &ctx) {
+     std::string ver = ctx.arg.soname;
+     if (ver.empty())
+       ver = path_filename(ctx.arg.output);
+-
+     ctx.arg.version_definitions.push_back(ver);
+-    ctx.default_version = VER_NDX_LAST_RESERVED + 1;
+   }
+ 
+   for (std::string_view path : version_scripts) {
+diff --git a/src/output-chunks.cc b/src/output-chunks.cc
+index 605f3c2f50..838ee838f3 100644
+--- a/src/output-chunks.cc
++++ b/src/output-chunks.cc
+@@ -2632,6 +2632,14 @@ void VerdefSection<E>::construct(Context<E> &ctx) {
+   if (ctx.arg.version_definitions.empty())
+     return;
+ 
++  // Handle --default-symver
++  if (ctx.arg.default_symver)
++    for (Symbol<E> *sym : ctx.dynsym->symbols)
++      if (sym && !sym->file->is_dso)
++        if (u16 ver = sym->ver_idx;
++            ver == VER_NDX_GLOBAL || ver == VER_NDX_UNSPECIFIED)
++          sym->ver_idx = VER_NDX_LAST_RESERVED + 1;
++
+   // Resize .gnu.version and write to it
+   ctx.versym->contents.resize(ctx.dynsym->symbols.size(), VER_NDX_GLOBAL);
+   ctx.versym->contents[0] = VER_NDX_LOCAL;
+diff --git a/test/default-symver-version-script.sh 
b/test/default-symver-version-script.sh
+new file mode 100755
+index 0000000000..5b3d22b24f
+--- /dev/null
++++ b/test/default-symver-version-script.sh
+@@ -0,0 +1,11 @@
++#!/bin/bash
++. $(dirname $0)/common.inc
++
++cat <<EOF | $CC -o $t/a.o -c -xc -
++void foo() {}
++EOF
++
++echo '{ global: foo; local: *; };' > $t/b.ver
++
++$CC -B. -o $t/c.so -shared $t/a.o -Wl,--default-symver 
-Wl,--version-script=$t/b.ver
++readelf --dyn-syms $t/c.so | grep -F ' foo@@c.so'
+

diff --git a/sys-devel/mold/files/mold-2.38.1-omagic-loop.patch 
b/sys-devel/mold/files/mold-2.38.1-omagic-loop.patch
new file mode 100644
index 000000000000..44c8e3e39102
--- /dev/null
+++ b/sys-devel/mold/files/mold-2.38.1-omagic-loop.patch
@@ -0,0 +1,28 @@
+https://github.com/rui314/mold/issues/1447
+https://github.com/rui314/mold/commit/83dd35397955bd179723ce31d52fc30836a65eed
+
+From 83dd35397955bd179723ce31d52fc30836a65eed Mon Sep 17 00:00:00 2001
+From: Rui Ueyama <[email protected]>
+Date: Thu, 1 May 2025 09:33:52 +0900
+Subject: [PATCH] Prevent oscillation when computing the size of the phdr
+
+Fixes https://github.com/rui314/mold/issues/1447
+---
+ src/passes.cc | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/src/passes.cc b/src/passes.cc
+index a2f1ed3347..5845dd6a19 100644
+--- a/src/passes.cc
++++ b/src/passes.cc
+@@ -2780,7 +2780,7 @@ i64 set_osec_offsets(Context<E> &ctx) {
+     if (ctx.phdr) {
+       i64 sz = ctx.phdr->shdr.sh_size;
+       ctx.phdr->update_shdr(ctx);
+-      if (sz != ctx.phdr->shdr.sh_size)
++      if (sz < ctx.phdr->shdr.sh_size)
+         continue;
+     }
+ 
+
+

diff --git a/sys-devel/mold/mold-9999.ebuild 
b/sys-devel/mold/mold-2.38.1-r1.ebuild
similarity index 90%
copy from sys-devel/mold/mold-9999.ebuild
copy to sys-devel/mold/mold-2.38.1-r1.ebuild
index f675a8309da7..263989f96286 100644
--- a/sys-devel/mold/mold-9999.ebuild
+++ b/sys-devel/mold/mold-2.38.1-r1.ebuild
@@ -35,6 +35,11 @@ RDEPEND="
 "
 DEPEND="${RDEPEND}"
 
+PATCHES=(
+       "${FILESDIR}"/${P}-default-symver.patch
+       "${FILESDIR}"/${P}-omagic-loop.patch
+)
+
 pkg_pretend() {
        # Requires a c++20 compiler, see #831473
        if [[ ${MERGE_TYPE} != binary ]]; then
@@ -64,6 +69,11 @@ src_prepare() {
        # 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

diff --git a/sys-devel/mold/mold-9999.ebuild b/sys-devel/mold/mold-9999.ebuild
index f675a8309da7..7117deff952b 100644
--- a/sys-devel/mold/mold-9999.ebuild
+++ b/sys-devel/mold/mold-9999.ebuild
@@ -64,6 +64,11 @@ src_prepare() {
        # 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

Reply via email to