git: 6cf38ee5e828 - main - lang/v8: Misc build fixes

From: Xin LI <delphij_at_FreeBSD.org>
Date: Sun, 11 Oct 2026 20:10:53 UTC
The branch main has been updated by delphij:

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

commit 6cf38ee5e828080822db6636d77d348f7390d43b
Author:     Xin LI <delphij@FreeBSD.org>
AuthorDate: 2026-10-11 20:09:49 +0000
Commit:     Xin LI <delphij@FreeBSD.org>
CommitDate: 2026-10-11 20:09:49 +0000

    lang/v8: Misc build fixes
    
    - aarch64: do not enable PartitionAlloc's ARM memory tagging support,
      which needs Linux's <asm/hwcap.h>.  It was enabled because the port
      makes FreeBSD pass for Linux in GN.
    - i386: V8 only uses PartitionAlloc together with pointer compression,
      so its libraries are not built there.  Do not try to install them.
    - d8 refuses to start when the first 4 GB of the address space can not
      be reserved.  Only have it do so when ASLR is active, as
      position-independent executables are loaded below 4 GB otherwise.
    - Drop patches for files the build does not use, the EXAMPLES
      leftovers and a substitution that no longer matches anything.
---
 lang/v8/Makefile                                   | 33 ++++++++------
 lang/v8/files/patch-build_detect__host__arch.py    | 15 ------
 lang/v8/files/patch-build_gn__run__binary.py       | 11 -----
 lang/v8/files/patch-build_linux_chrome.map         | 29 ------------
 lang/v8/files/patch-build_linux_libpci_BUILD.gn    | 53 ----------------------
 lang/v8/files/patch-build_linux_unbundle_libusb.gn | 27 -----------
 lang/v8/files/patch-src_d8_d8.cc                   | 32 +++++++++++++
 ...rd__party_partition__alloc_partition__alloc.gni | 13 +++++-
 lang/v8/pkg-plist                                  |  6 +--
 9 files changed, 66 insertions(+), 153 deletions(-)

diff --git a/lang/v8/Makefile b/lang/v8/Makefile
index 7d4a375a08c2..1530cfd086fb 100644
--- a/lang/v8/Makefile
+++ b/lang/v8/Makefile
@@ -5,6 +5,7 @@
 
 PORTNAME=	v8
 PORTVERSION=	15.5.35.20
+PORTREVISION=	1
 CATEGORIES=	lang
 
 MAINTAINER=	delphij@FreeBSD.org
@@ -127,8 +128,8 @@ GN_ARGS+=	clang_base_path="${LLVM_PREFIX}" \
 		enable_rust=false \
 		extra_cxxflags="${CXXFLAGS}" \
 		extra_ldflags="${LDFLAGS} -Wl,--icf=none" \
-		is_clang=true \
 		icu_use_data_file=false \
+		is_clang=true \
 		is_component_build=true \
 		is_debug=false \
 		treat_warnings_as_errors=false \
@@ -141,8 +142,6 @@ GN_ARGS+=	clang_base_path="${LLVM_PREFIX}" \
 		v8_metagen_libclang_so="${LLVM_PREFIX}/lib/libclang.so" \
 		v8_use_external_startup_data=false
 
-#OPTIONS_DEFINE=	EXAMPLES
-
 # GH_TUPLE group:path-on-chromium.googlesource.com pairs.  The distfiles come
 # from the unofficial chromium-full-mirror on GitHub and are compared against
 # chromium.googlesource.com by verify-mirror.  FETCH_ENV is deliberately not
@@ -179,8 +178,23 @@ _GS_DEPS=		absl:chromium/src/third_party/abseil-cpp \
 _GS_DIFF_ARGS_jsoncpp=	--strip-trailing-cr
 _GS_SITE=		https://chromium.googlesource.com
 _GS_VERIFY=		${WRKDIR}/.verify-mirror
+_V8_LIBS=		libchrome_zlib.so libthird_party_abseil-cpp_absl.so \
+			libv8.so libv8_libbase.so libv8_libplatform.so
 _V8_OUTDIR=		${WRKSRC}/out/Release
 
+.include <bsd.port.options.mk>
+
+# V8 only uses PartitionAlloc together with pointer compression, which needs
+# 64-bit pointers.
+.if ${ARCH} == i386
+PLIST_SUB+=	PARTITION_ALLOC="@comment "
+.else
+PLIST_SUB+=	PARTITION_ALLOC=""
+_V8_LIBS+=	libthird_party_partition_alloc_src_partition_alloc_allocator_base.so \
+		libthird_party_partition_alloc_src_partition_alloc_allocator_core.so \
+		libthird_party_partition_alloc_src_partition_alloc_allocator_shim.so
+.endif
+
 # "make makesum" fetches with these two set; hook the verification in there so
 # that distinfo can not be regenerated without it.
 .if defined(NO_CHECKSUM) && defined(DISABLE_SIZE)
@@ -228,7 +242,6 @@ post-extract:
 	@${CP} ${FILESDIR}/temporal_capi-lib.rs ${CARGO_WRKSRC}/src/lib.rs
 
 post-patch:
-	@${REINPLACE_CMD} -i '' 's|%%LOCALBASE%%|${LOCALBASE}|' ${WRKSRC}/build/toolchain/gcc_toolchain.gni
 # https://github.com/klzgrad/naiveproxy/blob/master/src/build/config/gclient_args.gni
 	@${ECHO_CMD} 'checkout_google_benchmark = false' > ${WRKSRC}/build/config/gclient_args.gni
 	@${SED} -e 's|%%TEMPORAL_CAPI_DIR%%|${TEMPORAL_CAPI_DIR}|' \
@@ -237,7 +250,7 @@ post-patch:
 
 # Use ICU from ports and create needed directory
 pre-configure:
-	@cd ${WRKSRC} && ${SETENV} ${CONFIGURE_ENV} ${PYTHON_CMD} ./build/linux/unbundle/replace_gn_files.py --system-libraries icu # || ${FALSE}
+	@cd ${WRKSRC} && ${SETENV} ${CONFIGURE_ENV} ${PYTHON_CMD} ./build/linux/unbundle/replace_gn_files.py --system-libraries icu
 	@${MKDIR} ${_V8_OUTDIR}/gen/shim_headers/icui18n_shim/third_party/icu/source/i18n/unicode \
 		${_V8_OUTDIR}/gen/shim_headers/icuuc_shim/third_party/icu/source/common/unicode \
 		${_V8_OUTDIR}/gen/include
@@ -259,11 +272,7 @@ do-install:
 .for prog in d8 mkgrokdump mksnapshot v8_shell
 	${INSTALL_PROGRAM} ${_V8_OUTDIR}/${prog} ${STAGEDIR}${PREFIX}/bin/${prog}
 .endfor
-.for lib in libchrome_zlib.so libv8.so libv8_libbase.so libv8_libplatform.so \
-	libthird_party_abseil-cpp_absl.so \
-	libthird_party_partition_alloc_src_partition_alloc_allocator_base.so \
-	libthird_party_partition_alloc_src_partition_alloc_allocator_core.so \
-	libthird_party_partition_alloc_src_partition_alloc_allocator_shim.so
+.for lib in ${_V8_LIBS}
 	${INSTALL_LIB} ${_V8_OUTDIR}/${lib} ${STAGEDIR}${PREFIX}/lib/${lib}
 .endfor
 	${INSTALL_DATA} ${WRKSRC}/include/*.h ${STAGEDIR}${PREFIX}/include/
@@ -271,8 +280,4 @@ do-install:
 	${INSTALL_DATA} ${WRKSRC}/include/libplatform/*.h ${STAGEDIR}${PREFIX}/include/libplatform/
 	${INSTALL_DATA} ${WRKDIR}/v8*.pc ${STAGEDIR}${PREFIX}/libdata/pkgconfig/
 
-do-install-EXAMPLES-on:
-	${MKDIR} ${STAGEDIR}${EXAMPLESDIR}
-	${INSTALL_PROGRAM} ${_V8_OUTDIR}/v8_simple_* ${STAGEDIR}${EXAMPLESDIR}
-
 .include <bsd.port.mk>
diff --git a/lang/v8/files/patch-build_detect__host__arch.py b/lang/v8/files/patch-build_detect__host__arch.py
deleted file mode 100644
index 635ebc3ef9eb..000000000000
--- a/lang/v8/files/patch-build_detect__host__arch.py
+++ /dev/null
@@ -1,15 +0,0 @@
---- build/detect_host_arch.py.orig	2026-09-13 16:54:58 UTC
-+++ build/detect_host_arch.py
-@@ -19,10 +19,10 @@ def HostArch():
-         host_arch = 'ia32'
-     elif host_arch in ['x86_64', 'amd64']:
-         host_arch = 'x64'
-+    elif host_arch.startswith('arm64') or host_arch.startswith('aarch64'):
-+        host_arch = 'arm64'
-     elif host_arch.startswith('arm'):
-         host_arch = 'arm'
--    elif host_arch.startswith('aarch64'):
--        host_arch = 'arm64'
-     elif host_arch.startswith('mips64'):
-         host_arch = 'mips64'
-     elif host_arch.startswith('mips'):
diff --git a/lang/v8/files/patch-build_gn__run__binary.py b/lang/v8/files/patch-build_gn__run__binary.py
deleted file mode 100644
index eec511204afc..000000000000
--- a/lang/v8/files/patch-build_gn__run__binary.py
+++ /dev/null
@@ -1,11 +0,0 @@
---- build/gn_run_binary.py.orig	2026-09-13 16:45:17 UTC
-+++ build/gn_run_binary.py
-@@ -22,7 +22,7 @@ args = [path] + sys.argv[2:]
- # The rest of the arguments are passed directly to the executable.
- args = [path] + sys.argv[2:]
- 
--ret = subprocess.call(args)
-+ret = subprocess.call(args, env={"CHROME_EXE_PATH":"${WRKSRC}/out/Release/chrome"})
- if ret != 0:
-     if ret <= -100:
-         # Windows error codes such as 0xC0000005 and 0xC0000409 are much easier to
diff --git a/lang/v8/files/patch-build_linux_chrome.map b/lang/v8/files/patch-build_linux_chrome.map
deleted file mode 100644
index 1e5b9aa350bf..000000000000
--- a/lang/v8/files/patch-build_linux_chrome.map
+++ /dev/null
@@ -1,29 +0,0 @@
---- build/linux/chrome.map.orig	2026-09-30 02:11:56 UTC
-+++ build/linux/chrome.map
-@@ -1,4 +1,7 @@
- {
-+local:
-+  *;
-+
- global:
-   __bss_start;
-   __data_start;
-@@ -20,6 +23,10 @@ global:
-   # Program entry point.
-   _start;
- 
-+  # FreeBSD specific variables.
-+  __progname;
-+  environ;
-+
-   # Memory allocation symbols.  We want chrome and any libraries to
-   # share the same heap, so it is correct to export these symbols.
-   aligned_alloc;
-@@ -111,7 +118,4 @@ global:
-   getaddrinfo;
- 
-   v8dbg_*;
--
--local:
--  *;
- };
diff --git a/lang/v8/files/patch-build_linux_libpci_BUILD.gn b/lang/v8/files/patch-build_linux_libpci_BUILD.gn
deleted file mode 100644
index 86373b5ebf39..000000000000
--- a/lang/v8/files/patch-build_linux_libpci_BUILD.gn
+++ /dev/null
@@ -1,53 +0,0 @@
---- build/linux/libpci/BUILD.gn.orig	2019-03-11 22:00:52 UTC
-+++ build/linux/libpci/BUILD.gn
-@@ -3,20 +3,36 @@
- # found in the LICENSE file.
- 
- import("//tools/generate_library_loader/generate_library_loader.gni")
-+import("//build/config/linux/pkg_config.gni")
- 
--# This generates a target named "libpci".
--generate_library_loader("libpci") {
--  name = "LibPciLoader"
--  output_h = "libpci.h"
--  output_cc = "libpci_loader.cc"
--  header = "<pci/pci.h>"
-+declare_args() {
-+  use_system_libpci = is_bsd
-+}
- 
--  functions = [
--    "pci_alloc",
--    "pci_init",
--    "pci_cleanup",
--    "pci_scan_bus",
--    "pci_fill_info",
--    "pci_lookup_name",
--  ]
-+if (use_system_libpci) {
-+  pkg_config("system_libpci") {
-+    packages = [ "libpci" ]
-+  }
-+
-+  source_set("libpci") {
-+    public_configs = [ ":system_libpci" ]
-+  }
-+
-+} else {
-+  # This generates a target named "libpci".
-+  generate_library_loader("libpci") {
-+    name = "LibPciLoader"
-+    output_h = "libpci.h"
-+    output_cc = "libpci_loader.cc"
-+    header = "<pci/pci.h>"
-+
-+    functions = [
-+      "pci_alloc",
-+      "pci_init",
-+      "pci_cleanup",
-+      "pci_scan_bus",
-+      "pci_fill_info",
-+      "pci_lookup_name",
-+    ]
-+  }
- }
diff --git a/lang/v8/files/patch-build_linux_unbundle_libusb.gn b/lang/v8/files/patch-build_linux_unbundle_libusb.gn
deleted file mode 100644
index 57bfad8669c7..000000000000
--- a/lang/v8/files/patch-build_linux_unbundle_libusb.gn
+++ /dev/null
@@ -1,27 +0,0 @@
---- build/linux/unbundle/libusb.gn.orig	2026-05-26 06:33:28 UTC
-+++ build/linux/unbundle/libusb.gn
-@@ -1,3 +1,7 @@
-+# Copyright 2016 The Chromium Authors. All rights reserved.
-+# Use of this source code is governed by a BSD-style license that can be
-+# found in the LICENSE file.
-+
- import("//build/config/linux/pkg_config.gni")
- import("//build/shim_headers.gni")
- 
-@@ -7,10 +11,14 @@ shim_headers("libusb_shim") {
- 
- shim_headers("libusb_shim") {
-   root_path = "src/libusb"
--  headers = [ "libusb.h" ]
-+  headers = [
-+    "libusb.h",
-+  ]
- }
- 
- source_set("libusb") {
--  deps = [ ":libusb_shim" ]
-+  deps = [
-+    ":libusb_shim",
-+  ]
-   public_configs = [ ":system_libusb" ]
- }
diff --git a/lang/v8/files/patch-src_d8_d8.cc b/lang/v8/files/patch-src_d8_d8.cc
new file mode 100644
index 000000000000..24995802cc53
--- /dev/null
+++ b/lang/v8/files/patch-src_d8_d8.cc
@@ -0,0 +1,32 @@
+--- src/d8/d8.cc.orig	2026-10-05 07:40:58 UTC
++++ src/d8/d8.cc
+@@ -109,6 +109,11 @@
+ #include <signal.h>
+ #endif  // V8_OS_POSIX
+ 
++#if V8_OS_FREEBSD
++#include <sys/procctl.h>
++#include <unistd.h>
++#endif  // V8_OS_FREEBSD
++
+ #ifdef V8_FUZZILLI
+ // gn check complains when not using the v8_fuzzilli arg since the public dep.
+ // is added conditionally
+@@ -8032,7 +8037,17 @@ int Shell::Main(int argc, char* argv[]) {
+ 
+   // TODO(40925855): Enable this more broadly outside of d8.
+ #if defined(PA_ENABLE_USER_SPACE_ZERO_SEGMENT)
++#if V8_OS_FREEBSD
++  // Without ASLR, FreeBSD loads position-independent executables below 4GB,
++  // so the first 4GB of the address space can not be reserved.
++  int aslr_status = 0;
++  if (procctl(P_PID, getpid(), PROC_ASLR_STATUS, &aslr_status) == 0 &&
++      (aslr_status & PROC_ASLR_ACTIVE) != 0) {
++    i::v8_flags.sandbox_prohibit_insecure_mode = true;
++  }
++#else
+   i::v8_flags.sandbox_prohibit_insecure_mode = true;
++#endif  // V8_OS_FREEBSD
+ #endif
+ 
+   if (!v8::Shell::SetOptions(argc, argv)) return 1;
diff --git a/lang/v8/files/patch-third__party_partition__alloc_partition__alloc.gni b/lang/v8/files/patch-third__party_partition__alloc_partition__alloc.gni
index 90a55845f6d3..d88b0eec9be0 100644
--- a/lang/v8/files/patch-third__party_partition__alloc_partition__alloc.gni
+++ b/lang/v8/files/patch-third__party_partition__alloc_partition__alloc.gni
@@ -1,5 +1,16 @@
---- third_party/partition_alloc/partition_alloc.gni.orig	2026-09-13 16:45:48 UTC
+--- third_party/partition_alloc/partition_alloc.gni.orig	2026-09-01 03:39:43 UTC
 +++ third_party/partition_alloc/partition_alloc.gni
+@@ -110,8 +110,8 @@ use_large_empty_slot_span_ring = true
+ # TODO(crbug.com/329199197): Clean this up when experiments are complete.
+ use_large_empty_slot_span_ring = true
+ 
+-has_memory_tagging = current_cpu == "arm64" && is_clang && !is_asan &&
+-                     !is_hwasan && (is_linux || is_android)
++has_memory_tagging = current_cpu == "arm64" && !is_bsd && is_clang &&
++                     !is_asan && !is_hwasan && (is_linux || is_android)
+ 
+ declare_args() {
+   # Whether PartitionAlloc is built in official mode.
 @@ -540,7 +540,8 @@ is_pkeys_available =
  # dependencies that use partition_allocator are compiled in AOSP against a
  # version of glibc that does not include pkeys syscall numbers.
diff --git a/lang/v8/pkg-plist b/lang/v8/pkg-plist
index aa4f5ab83f34..ae400df24c62 100644
--- a/lang/v8/pkg-plist
+++ b/lang/v8/pkg-plist
@@ -116,9 +116,9 @@ include/v8.h
 include/v8config.h
 lib/libchrome_zlib.so
 lib/libthird_party_abseil-cpp_absl.so
-lib/libthird_party_partition_alloc_src_partition_alloc_allocator_base.so
-lib/libthird_party_partition_alloc_src_partition_alloc_allocator_core.so
-lib/libthird_party_partition_alloc_src_partition_alloc_allocator_shim.so
+%%PARTITION_ALLOC%%lib/libthird_party_partition_alloc_src_partition_alloc_allocator_base.so
+%%PARTITION_ALLOC%%lib/libthird_party_partition_alloc_src_partition_alloc_allocator_core.so
+%%PARTITION_ALLOC%%lib/libthird_party_partition_alloc_src_partition_alloc_allocator_shim.so
 lib/libv8.so
 lib/libv8_libbase.so
 lib/libv8_libplatform.so