git: 3d864ab97210 - main - devel/valgrind: patch for ifuncs

From: Fernando Apesteguía <fernape_at_FreeBSD.org>
Date: Wed, 20 Sep 2023 11:42:32 UTC
The branch main has been updated by fernape:

URL: https://cgit.FreeBSD.org/ports/commit/?id=3d864ab9721054806c92c3c0588b8a45f80d8aa2

commit 3d864ab9721054806c92c3c0588b8a45f80d8aa2
Author:     Paul Floyd <pjfloyd@wanadoo.fr>
AuthorDate: 2023-09-20 07:54:04 +0000
Commit:     Fernando Apesteguía <fernape@FreeBSD.org>
CommitDate: 2023-09-20 11:42:11 +0000

    devel/valgrind: patch for ifuncs
    
    The work for simd support uses @gnu_indirect_function. When Valgrind sees
    binaries using such function it expects to have its own ifunc_handler. Until now
    there wasn't one for FreeBSD so Valgrind terminates with an abort.
    
    This patch merges the fix maintainer and creator made upstream.
    
    PR:             273955
    Reported by:    pjfloyd@wanadoo.fr (maintainer)
---
 devel/valgrind/Makefile                            | 28 ++++++++++---------
 .../valgrind/files/patch-coregrind-vg_preloaded.c  | 31 ++++++++++++++++++++++
 2 files changed, 47 insertions(+), 12 deletions(-)

diff --git a/devel/valgrind/Makefile b/devel/valgrind/Makefile
index 0eb2d678cbb1..33f46d7e86d7 100644
--- a/devel/valgrind/Makefile
+++ b/devel/valgrind/Makefile
@@ -1,6 +1,6 @@
 PORTNAME=	valgrind
 PORTVERSION=	3.21.0
-PORTREVISION=	1
+PORTREVISION=	2
 PORTEPOCH=	1
 CATEGORIES=	devel
 MASTER_SITES=	SOURCEWARE/valgrind
@@ -14,9 +14,12 @@ LICENSE_FILE=	${WRKSRC}/COPYING
 
 ONLY_FOR_ARCHS=	amd64 i386
 
-USES=		autoreconf cpe gmake pathfix perl5 pkgconfig shebangfix python:3.9+,run tar:bz2
+USES=		autoreconf cpe gmake pathfix perl5 pkgconfig shebangfix \
+		python:3.9+,run tar:bz2
 USE_PERL5=	build
-SHEBANG_FILES= callgrind/callgrind_annotate.in callgrind/callgrind_control.in cachegrind/cg_merge.in cachegrind/cg_diff.in cachegrind/cg_annotate.in
+SHEBANG_FILES=	callgrind/callgrind_annotate.in callgrind/callgrind_control.in \
+		cachegrind/cg_merge.in cachegrind/cg_diff.in \
+		cachegrind/cg_annotate.in
 GNU_CONFIGURE=	yes
 CONFIGURE_ENV+=	ac_cv_path_PERL=${PERL}
 
@@ -24,7 +27,16 @@ SSP_UNSAFE=	yes
 LIB32_PATH?=	/usr/lib32/libc.so
 
 CONFLICTS=	valgrind-devel
-PORTDOCS=	html
+
+# Valgrind needs to read debuginfo from its own preload shared libraries
+# (quote from README_PACKAGERS
+#-- Don't strip the debug info off lib/valgrind/$platform/vgpreload*.so
+#   in the installation tree.  Either Valgrind won't work at all, or it
+#   will still work if you do, but will generate less helpful error
+#   messages.)
+STRIP=			# empty
+
+PORTDOCS=		html
 
 OPTIONS_DEFINE=		DOCS MANPAGES MPI
 OPTIONS_DEFINE_amd64=	32BIT
@@ -34,14 +46,6 @@ OPTIONS_DEFAULT_amd64=	32BIT
 .endif
 OPTIONS_SUB=		yes
 
-# Valgrind needs to read debuginfo from its own preload shared libraries
-# (quote from README_PACKAGERS
-#-- Don't strip the debug info off lib/valgrind/$platform/vgpreload*.so
-#   in the installation tree.  Either Valgrind won't work at all, or it
-#   will still work if you do, but will generate less helpful error
-#   messages.)
-STRIP=          # empty
-
 32BIT_DESC=	Enable debugging of 32-bit programs (requires lib32)
 MPI_DESC=	Enable build of MPI wrappers
 
diff --git a/devel/valgrind/files/patch-coregrind-vg_preloaded.c b/devel/valgrind/files/patch-coregrind-vg_preloaded.c
new file mode 100644
index 000000000000..870626ec4edd
--- /dev/null
+++ b/devel/valgrind/files/patch-coregrind-vg_preloaded.c
@@ -0,0 +1,31 @@
+--- coregrind/vg_preloaded.c.orig	2023-09-19 20:30:09.413386000 +0200
++++ coregrind/vg_preloaded.c	2023-09-19 20:32:14.366333000 +0200
+@@ -228,7 +228,27 @@
+ 
+ #elif defined(VGO_freebsd)
+ 
+-// nothing specific currently
++#if (FREEBSD_VERS >= FREEBSD_14)
++
++void * VG_NOTIFY_ON_LOAD(ifunc_wrapper) (void);
++void * VG_NOTIFY_ON_LOAD(ifunc_wrapper) (void)
++{
++    OrigFn fn;
++    Addr result = 0;
++    Addr fnentry;
++
++    /* Call the original indirect function and get it's result */
++    VALGRIND_GET_ORIG_FN(fn);
++    CALL_FN_W_v(result, fn);
++
++    fnentry = result;
++
++    VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__ADD_IFUNC_TARGET,
++                                    fn.nraddr, fnentry, 0, 0, 0);
++    return (void*)result;
++}
++
++#endif
+ 
+ #elif defined(VGO_solaris)
+