git: b98196b9038f - main - www/pomerium-envoy-custom: Fix build on aarch64

From: Xin LI <delphij_at_FreeBSD.org>
Date: Mon, 19 Oct 2026 04:19:35 UTC
The branch main has been updated by delphij:

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

commit b98196b9038fe722e50550501d0dec237e0f7dc5
Author:     Xin LI <delphij@FreeBSD.org>
AuthorDate: 2026-10-19 04:16:03 +0000
Commit:     Xin LI <delphij@FreeBSD.org>
CommitDate: 2026-10-19 04:18:10 +0000

    www/pomerium-envoy-custom: Fix build on aarch64
    
    gperftools has no way to read the program counter from a signal's
    ucontext on FreeBSD/aarch64, so its CPU profiler, which Envoy builds
    with --define tcmalloc=gperftools, failed to compile:
    
      getpc-inl.h:393:22: error: no member named 'Get' in ...
    
    On FreeBSD/aarch64 the kernel stores the interrupted PC in
    uc_mcontext.mc_gpregs.gp_elr.  Add an accessor for it to gperftools
    and apply the patch through the gperftools http_archive in envoy's
    bazel/repositories.bzl, the same way the msgpack patch is applied.
    The hunk offsets of the other entries in that patch are refreshed
    while here.
    
    The gperftools change has been verified with getpc_test on an Ampere
    eMAG running FreeBSD 15.1 and submitted upstream.  The full port has
    only been test-built on amd64 so far.
    
    Upstream PR: https://github.com/gperftools/gperftools/pull/1647
---
 www/pomerium-envoy-custom/Makefile                 |  6 ++--
 .../files/gperftools_freebsd.patch                 | 38 ++++++++++++++++++++++
 .../files/patches_envoy_freebsd-repositories.patch | 17 +++++++---
 3 files changed, 55 insertions(+), 6 deletions(-)

diff --git a/www/pomerium-envoy-custom/Makefile b/www/pomerium-envoy-custom/Makefile
index 7420bfec9cb4..777e316801c6 100644
--- a/www/pomerium-envoy-custom/Makefile
+++ b/www/pomerium-envoy-custom/Makefile
@@ -482,12 +482,14 @@ post-patch:
 	done
 # FreeBSD: copy per-dependency FreeBSD patches to WRKSRC/bazel/ so Bazel can
 # reference them as @pomerium_envoy//bazel:<name> from the http_archive patches
-# lists injected by freebsd-repositories.patch (v8, msgpack, dd_trace,
-# rules_foreign_cc) and the WORKSPACE luajit definition.
+# lists injected by freebsd-repositories.patch (v8, msgpack, gperftools,
+# dd_trace, rules_foreign_cc) and the WORKSPACE luajit definition.
 	${CP} ${FILESDIR}/v8_freebsd.patch \
 		${WRKSRC}/bazel/v8_freebsd.patch
 	${CP} ${FILESDIR}/msgpack_freebsd.patch \
 		${WRKSRC}/bazel/msgpack_freebsd.patch
+	${CP} ${FILESDIR}/gperftools_freebsd.patch \
+		${WRKSRC}/bazel/gperftools_freebsd.patch
 	${CP} ${FILESDIR}/dd_trace_freebsd.patch \
 		${WRKSRC}/bazel/dd_trace_freebsd.patch
 	${CP} ${FILESDIR}/luajit_freebsd.patch \
diff --git a/www/pomerium-envoy-custom/files/gperftools_freebsd.patch b/www/pomerium-envoy-custom/files/gperftools_freebsd.patch
new file mode 100644
index 000000000000..2e526aa3417a
--- /dev/null
+++ b/www/pomerium-envoy-custom/files/gperftools_freebsd.patch
@@ -0,0 +1,38 @@
+FreeBSD/aarch64: read the interrupted PC from uc_mcontext.mc_gpregs.gp_elr.
+Without it the CPU profiler fails to compile ("no member named 'Get'").
+
+Upstream: https://github.com/gperftools/gperftools/issues/1362
+
+--- a/src/getpc-inl.h
++++ b/src/getpc-inl.h
+@@ -230,6 +230,18 @@
+   static void* Get(const U* uc) {
+     // FreeBSD/x86_64
+     return (void*)(uc->uc_mcontext.mc_rip);
++  }
++};
++
++// FreeBSD/aarch64
++template <class U, class P, class = void>
++struct get_2e7fb68f : public P {
++};
++template <class U, class P>
++struct get_2e7fb68f<U, P, void_t<decltype(((U*){})->uc_mcontext.mc_gpregs.gp_elr)>> : public P {
++  static void* Get(const U* uc) {
++    // FreeBSD/aarch64
++    return (void*)(uc->uc_mcontext.mc_gpregs.gp_elr);
+   }
+ };
+ 
+@@ -360,8 +372,10 @@
+   using g_92fcd89a = get_92fcd89a<ucontext_t, g_773e27c8>;
+   // OS X (i386, <=10.4)
+   using g_880f83fe = get_880f83fe<ucontext_t, g_92fcd89a>;
++  // FreeBSD/aarch64
++  using g_2e7fb68f = get_2e7fb68f<ucontext_t, g_880f83fe>;
+   // FreeBSD/x86_64
+-  using g_5bb1da03 = get_5bb1da03<ucontext_t, g_880f83fe>;
++  using g_5bb1da03 = get_5bb1da03<ucontext_t, g_2e7fb68f>;
+   // FreeBSD/ppc
+   using g_2812b129 = get_2812b129<ucontext_t, g_5bb1da03>;
+   // FreeBSD/i386
diff --git a/www/pomerium-envoy-custom/files/patches_envoy_freebsd-repositories.patch b/www/pomerium-envoy-custom/files/patches_envoy_freebsd-repositories.patch
index 0f70d80562f2..c99eeb69c9a5 100644
--- a/www/pomerium-envoy-custom/files/patches_envoy_freebsd-repositories.patch
+++ b/www/pomerium-envoy-custom/files/patches_envoy_freebsd-repositories.patch
@@ -1,6 +1,6 @@
 --- a/bazel/repositories.bzl
 +++ b/bazel/repositories.bzl
-@@ -636,6 +636,8 @@
+@@ -622,6 +622,8 @@
          name = "msgpack-cxx",
          location_name = "msgpack_cxx",
          build_file = "@envoy//bazel/external:msgpack.BUILD",
@@ -9,7 +9,7 @@
      )
  
  def _hyperscan():
-@@ -669,6 +671,8 @@
+@@ -655,6 +657,8 @@
          "dd-trace-cpp",
          location_name = "dd_trace_cpp",
          repo_mapping = {"@com_google_absl": "@abseil-cpp"},
@@ -18,7 +18,7 @@
      )
  
  def _cpp2sky():
-@@ -761,6 +765,7 @@
+@@ -747,6 +751,7 @@
              "@envoy//bazel:v8_ppc64le.patch",
              # https://issues.chromium.org/issues/423403090
              "@envoy//bazel:v8_python.patch",
@@ -26,7 +26,16 @@
          ],
          patch_args = ["-p1"],
          patch_cmds = [
-@@ -1039,7 +1044,7 @@
+@@ -928,6 +933,8 @@
+ def _gperftools():
+     external_http_archive(
+         name = "gperftools",
++        patches = ["@pomerium_envoy//bazel:gperftools_freebsd.patch"],
++        patch_args = ["-p1"],
+     )
+ 
+ def _jemalloc():
+@@ -1034,7 +1041,7 @@
  def _foreign_cc_dependencies():
      external_http_archive(
          name = "rules_foreign_cc",