diff --git a/www/chromium/Makefile b/www/chromium/Makefile index 1dd3e43c87a9..023f8f9f95f5 100644 --- a/www/chromium/Makefile +++ b/www/chromium/Makefile @@ -1,387 +1,388 @@ PORTNAME= chromium PORTVERSION= 136.0.7103.113 +PORTREVISION= 1 PULSEMV= 16 PULSEV= ${PULSEMV}.1 CATEGORIES= www wayland MASTER_SITES= https://commondatastorage.googleapis.com/chromium-browser-official/ \ https://nerd.hu/distfiles/:external \ https://freedesktop.org/software/pulseaudio/releases/:pulseaudio DISTFILES= ${DISTNAME}${EXTRACT_SUFX} \ pulseaudio-${PULSEV}.tar.gz:pulseaudio MAINTAINER= chromium@FreeBSD.org COMMENT= Google web browser based on WebKit WWW= https://www.chromium.org/Home LICENSE= BSD3CLAUSE LGPL21 MPL11 LICENSE_COMB= multi ONLY_FOR_ARCHS= aarch64 amd64 BUILD_DEPENDS= bash:shells/bash \ ${PYTHON_PKGNAMEPREFIX}Jinja2>0:devel/py-Jinja2@${PY_FLAVOR} \ ${PYTHON_PKGNAMEPREFIX}ply>0:devel/py-ply@${PY_FLAVOR} \ bindgen:devel/rust-bindgen-cli \ gperf:devel/gperf \ flock:sysutils/flock \ node:www/node \ rustc:lang/rust \ xcb-proto>0:x11/xcb-proto \ ${LOCALBASE}/include/linux/videodev2.h:multimedia/v4l_compat \ ${LOCALBASE}/share/usbids/usb.ids:misc/usbids \ ${PYTHON_PKGNAMEPREFIX}html5lib>0:www/py-html5lib@${PY_FLAVOR} \ ${LOCALBASE}/include/va/va.h:multimedia/libva \ ${LOCALBASE}/libdata/pkgconfig/dri.pc:graphics/mesa-dri \ ${LOCALBASE}/libdata/pkgconfig/Qt5Core.pc:devel/qt5-core \ ${LOCALBASE}/libdata/pkgconfig/Qt5Widgets.pc:x11-toolkits/qt5-widgets LIB_DEPENDS= libatk-bridge-2.0.so:accessibility/at-spi2-core \ libatspi.so:accessibility/at-spi2-core \ libspeechd.so:accessibility/speech-dispatcher \ libFLAC.so:audio/flac \ libopus.so:audio/opus \ libspeex.so:audio/speex \ libdbus-1.so:devel/dbus \ libdbus-glib-1.so:devel/dbus-glib \ libepoll-shim.so:devel/libepoll-shim \ libevent.so:devel/libevent \ libffi.so:devel/libffi \ libicuuc.so:devel/icu \ libjsoncpp.so:devel/jsoncpp \ libpci.so:devel/libpci \ libnspr4.so:devel/nspr \ libre2.so:devel/re2 \ libcairo.so:graphics/cairo \ libdrm.so:graphics/libdrm \ libexif.so:graphics/libexif \ libpng.so:graphics/png \ libwebp.so:graphics/webp \ libdav1d.so:multimedia/dav1d \ libopenh264.so:multimedia/openh264 \ libfreetype.so:print/freetype2 \ libharfbuzz.so:print/harfbuzz \ libharfbuzz-icu.so:print/harfbuzz-icu \ libgcrypt.so:security/libgcrypt \ libsecret-1.so:security/libsecret \ libnss3.so:security/nss \ libexpat.so:textproc/expat2 \ libfontconfig.so:x11-fonts/fontconfig \ libwayland-client.so:graphics/wayland \ libxkbcommon.so:x11/libxkbcommon \ libxshmfence.so:x11/libxshmfence RUN_DEPENDS= xdg-open:devel/xdg-utils \ noto-basic>0:x11-fonts/noto-basic USES= bison compiler:c++17-lang cpe desktop-file-utils gl gmake gnome \ iconv:wchar_t jpeg localbase:ldflags ninja perl5 pkgconfig \ python:build qt:5 shebangfix tar:xz xorg CPE_VENDOR= google CPE_PRODUCT= chrome USE_GL= gbm gl USE_GNOME= atk dconf gdkpixbuf glib20 gtk30 libxml2 libxslt USE_LDCONFIG= ${DATADIR} USE_PERL5= build USE_XORG= x11 xcb xcomposite xcursor xext xdamage xfixes xi \ xorgproto xrandr xrender xscrnsaver xtst USE_QT= buildtools:build SHEBANG_FILES= chrome/tools/build/linux/chrome-wrapper #buildtools/linux64/clang-format MAKE_ARGS= -C out/${BUILDTYPE} ALL_TARGET= chrome BINARY_ALIAS= python3=${PYTHON_CMD} \ moc=${PREFIX}/bin/moc-qt5 # TODO bz@ : install libwidevinecdm.so (see third_party/widevine/cdm/BUILD.gn) # # Run "./out/${BUILDTYPE}/gn args out/${BUILDTYPE} --list" for all variables. # Some parts don't have use_system_* flag, and can be turned on/off by using # replace_gn_files.py script, some parts just turned on/off for target host # OS "target_os == is_bsd", like libusb, libpci. GN_ARGS+= clang_use_chrome_plugins=false \ enable_backup_ref_ptr_support=false \ enable_hangout_services_extension=true \ enable_nacl=false \ enable_remoting=false \ enable_widevine=true \ fatal_linker_warnings=false \ icu_use_data_file=false \ is_clang=true \ optimize_webui=true \ toolkit_views=true \ treat_warnings_as_errors=false \ use_allocator_shim=false \ use_aura=true \ use_custom_libcxx=true \ use_custom_libunwind=true \ use_lld=true \ use_partition_alloc=true \ use_partition_alloc_as_malloc=false \ use_sysroot=false \ use_system_freetype=false \ use_system_harfbuzz=true \ use_system_libffi=true \ use_system_libjpeg=true \ use_udev=false \ extra_cxxflags="${CXXFLAGS} -I${LOCALBASE}/include/libepoll-shim ${PINCLUDES}" \ extra_ldflags="${LDFLAGS}" \ ffmpeg_branding="${FFMPEG_BRAND}" # TODO: investigate building with these options: # use_system_minigbm GN_BOOTSTRAP_FLAGS= --no-clean --no-rebuild --skip-generate-buildfiles # FreeBSD Chromium Api Key # Set up Google API keys, see http://www.chromium.org/developers/how-tos/api-keys . # Note: these are for FreeBSD use ONLY. For your own distribution, # please get your own set of keys. GN_ARGS+= google_api_key="AIzaSyBsp9n41JLW8jCokwn7vhoaMejDFRd1mp8" SUB_FILES= chromium-browser.desktop chrome SUB_LIST+= COMMENT="${COMMENT}" OPTIONS_DEFINE= CODECS CUPS DEBUG DRIVER KERBEROS LTO PIPEWIRE TEST WIDEVINE OPTIONS_DEFAULT= CODECS CUPS DRIVER KERBEROS PIPEWIRE SNDIO ALSA PULSEAUDIO OPTIONS_EXCLUDE_aarch64=LTO OPTIONS_GROUP= AUDIO OPTIONS_GROUP_AUDIO= ALSA PULSEAUDIO SNDIO OPTIONS_RADIO= KERBEROS OPTIONS_RADIO_KERBEROS= HEIMDAL HEIMDAL_BASE MIT OPTIONS_SUB= yes CODECS_DESC= Compile and enable patented codecs like H.264 DRIVER_DESC= Install chromedriver HEIMDAL_BASE_DESC= Heimdal Kerberos (base) HEIMDAL_DESC= Heimdal Kerberos (security/heimdal) MIT_DESC= MIT Kerberos (security/krb5) ALSA_LIB_DEPENDS= libasound.so:audio/alsa-lib ALSA_RUN_DEPENDS= ${LOCALBASE}/lib/alsa-lib/libasound_module_pcm_oss.so:audio/alsa-plugins \ alsa-lib>=1.1.1_1:audio/alsa-lib ALSA_VARS= GN_ARGS+=use_alsa=true ALSA_VARS_OFF= GN_ARGS+=use_alsa=false CODECS_VARS= GN_ARGS+=proprietary_codecs=true \ FFMPEG_BRAND="Chrome" CODECS_VARS_OFF= GN_ARGS+=proprietary_codecs=false \ FFMPEG_BRAND="Chromium" CUPS_LIB_DEPENDS= libcups.so:print/cups CUPS_VARS= GN_ARGS+=use_cups=true CUPS_VARS_OFF= GN_ARGS+=use_cups=false DEBUG_BUILD_DEPENDS= esbuild:devel/esbuild DEBUG_VARS= BUILDTYPE=Debug \ GN_ARGS+=is_debug=true \ GN_ARGS+=is_component_build=false \ GN_ARGS+=symbol_level=1 \ GN_BOOTSTRAP_FLAGS+=--debug \ WANTSPACE="60 GB" \ WANTMEM="32 GB" DEBUG_VARS_OFF= BUILDTYPE=Release \ GN_ARGS+=blink_symbol_level=0 \ GN_ARGS+=is_debug=false \ GN_ARGS+=is_official_build=true \ GN_ARGS+=symbol_level=0 \ WANTSPACE="35 GB" \ WANTMEM="8 GB" DRIVER_MAKE_ARGS= chromedriver HEIMDAL_LIB_DEPENDS= libkrb.so.26:security/heimdal KERBEROS_VARS= GN_ARGS+=use_kerberos=true KERBEROS_VARS_OFF= GN_ARGS+=use_kerberos=false LTO_VARS= GN_ARGS+=use_thin_lto=true \ GN_ARGS+=thin_lto_enable_optimizations=true \ WANTSPACE="40 GB" \ WANTMEM="16 GB" LTO_VARS_OFF= GN_ARGS+=use_thin_lto=false MIT_LIB_DEPENDS= libkrb.so.3:security/krb5 PIPEWIRE_DESC= Screen capture via PipeWire PIPEWIRE_LIB_DEPENDS= libpipewire-0.3.so:multimedia/pipewire PIPEWIRE_VARS= GN_ARGS+=rtc_use_pipewire=true \ GN_ARGS+=rtc_link_pipewire=true PIPEWIRE_VARS_OFF= GN_ARGS+=rtc_use_pipewire=false \ GN_ARGS+=rtc_link_pipewire=false PULSEAUDIO_VARS= GN_ARGS+=use_pulseaudio=true \ PINCLUDES="-I${WRKDIR}/pulseaudio-${PULSEV}/src -DPA_MAJOR=${PULSEMV}" PULSEAUDIO_VARS_OFF= GN_ARGS+=use_pulseaudio=false SNDIO_LIB_DEPENDS= libsndio.so:audio/sndio SNDIO_VARS= GN_ARGS+=use_sndio=true SNDIO_VARS_OFF= GN_ARGS+=use_sndio=false WIDEVINE_DESC= Depend on foreign-cdm to enable playback of DRM content WIDEVINE_RUN_DEPENDS= foreign-cdm>0:www/foreign-cdm .include "Makefile.tests" TEST_DISTFILES= ${PORTNAME}-${DISTVERSION}-testdata${EXTRACT_SUFX} TEST_ALL_TARGET= ${TEST_TARGETS} .include .include # for COMPILER_VERSION .if ${PORT_OPTIONS:MHEIMDAL_BASE} && !exists(/usr/lib/libkrb5.so) IGNORE= you have selected HEIMDAL_BASE but do not have Heimdal installed in base .endif LLVM_DEFAULT= 19 BUILD_DEPENDS+= clang${LLVM_DEFAULT}:devel/llvm${LLVM_DEFAULT} BINARY_ALIAS+= cpp=${LOCALBASE}/bin/clang-cpp${LLVM_DEFAULT} \ cc=${LOCALBASE}/bin/clang${LLVM_DEFAULT} \ c++=${LOCALBASE}/bin/clang++${LLVM_DEFAULT} \ ar=${LOCALBASE}/bin/llvm-ar${LLVM_DEFAULT} \ nm=${LOCALBASE}/bin/llvm-nm${LLVM_DEFAULT} \ ld=${LOCALBASE}/bin/ld.lld${LLVM_DEFAULT} # - swiftshader/lib/{libEGL.so,libGLESv2.so} is x86 only # - map ffmpeg target to ${ARCH} .if ${ARCH} == aarch64 PLIST_SUB+= NOT_AARCH64="@comment " FFMPEG_TARGET= arm64 .elif ${ARCH} == amd64 BUILD_DEPENDS+= nasm:devel/nasm PLIST_SUB+= NOT_AARCH64="" FFMPEG_TARGET= x64 .elif ${ARCH} == i386 BUILD_DEPENDS+= nasm:devel/nasm PLIST_SUB+= NOT_AARCH64="" FFMPEG_TARGET= ia32 .endif FFMPEG_BDIR= ${WRKSRC}/third_party/ffmpeg/build.${FFMPEG_TARGET}.freebsd/${FFMPEG_BRAND} FFMPEG_CDIR= ${WRKSRC}/third_party/ffmpeg/chromium/config/${FFMPEG_BRAND}/freebsd/${FFMPEG_TARGET} # Allow relocations against read-only segments (override lld default) LDFLAGS_i386= -Wl,-znotext # TODO: -isystem, would be just as ugly as this approach, but more reliably # build would fail without C_INCLUDE_PATH/CPLUS_INCLUDE_PATH env var set. MAKE_ENV+= C_INCLUDE_PATH=${LOCALBASE}/include \ CPLUS_INCLUDE_PATH=${LOCALBASE}/include # rust RUSTC_VERSION!= rustc -V 2>/dev/null || true MAKE_ENV+= RUSTC_BOOTSTRAP=1 GN_ARGS+= enable_rust=true \ rust_sysroot_absolute="${LOCALBASE}" \ rustc_version="${RUSTC_VERSION}" pre-everything:: @${ECHO_MSG} @${ECHO_MSG} "To build ${PORTNAME}, you should have at least:" @${ECHO_MSG} "- ${WANTMEM} of memory" @${ECHO_MSG} "- ${WANTSPACE} of free disk space" @${ECHO_MSG} "- 1.5 million free inodes" @${ECHO_MSG} pre-configure: # We used to remove bundled libraries to be sure that chromium uses # system libraries and not shipped ones. # cd ${WRKSRC} && ${PYTHON_CMD} \ #./build/linux/unbundle/remove_bundled_libraries.py [list of preserved] cd ${WRKSRC} && ${SETENV} ${CONFIGURE_ENV} ${PYTHON_CMD} \ ./build/linux/unbundle/replace_gn_files.py --system-libraries \ dav1d flac fontconfig harfbuzz-ng libdrm libpng \ libusb libwebp libxml libxslt openh264 opus || ${FALSE} # Chromium uses an unreleased version of FFmpeg, so configure it cd ${WRKSRC}/media/ffmpeg && \ ${PYTHON_CMD} scripts/build_ffmpeg.py freebsd ${FFMPEG_TARGET} \ --config-only --branding=${FFMPEG_BRAND} cd ${FFMPEG_BDIR} && ${GMAKE} ffversion.h ${MKDIR} ${FFMPEG_CDIR} .for _e in config.h config.asm config_components.h libavcodec libavformat libavutil -${CP} -pR ${FFMPEG_BDIR}/${_e} ${FFMPEG_CDIR} .endfor touch ${WRKDIR}/pulseaudio-${PULSEV}/src/pulse/version.h @${REINPLACE_CMD} -e 's|$${LOCALBASE}|${LOCALBASE}|;s|$${MODCLANG_VERSION}|${LLVM_DEFAULT}|' \ ${WRKSRC}/build/rust/rust_bindgen.gni \ ${WRKSRC}/build/rust/rust_bindgen_generator.gni do-configure: # GN generator bootstrapping and generating ninja files cd ${WRKSRC} && ${SETENV} ${CONFIGURE_ENV} CC=${CC} CXX=${CXX} LD=${CXX} \ READELF=${READELF} AR=${AR} NM=${NM} ${PYTHON_CMD} \ ./tools/gn/bootstrap/bootstrap.py ${GN_BOOTSTRAP_FLAGS} cd ${WRKSRC} && ${SETENV} ${CONFIGURE_ENV} ./out/${BUILDTYPE}/gn \ gen --args='${GN_ARGS}' out/${BUILDTYPE} # Setup nodejs dependency @${MKDIR} ${WRKSRC}/third_party/node/freebsd/node-freebsd/bin ${LN} -sf ${LOCALBASE}/bin/node ${WRKSRC}/third_party/node/freebsd/node-freebsd/bin/node # Setup buildtools/freebsd @${MKDIR} ${WRKSRC}/buildtools/freebsd ${LN} -sf ${WRKSRC}/buildtools/linux64/clang-format ${WRKSRC}/buildtools/freebsd ${LN} -sf ${WRKSRC}/out/${BUILDTYPE}/gn ${WRKSRC}/buildtools/freebsd ${LN} -sf /usr/bin/strip ${WRKSRC}/buildtools/freebsd/strip do-install: @${MKDIR} ${STAGEDIR}${DATADIR} ${INSTALL_MAN} ${WRKSRC}/chrome/app/resources/manpage.1.in \ ${STAGEDIR}${PREFIX}/share/man/man1/chrome.1 @${SED} -i "" -e 's,\@\@PACKAGE\@\@,chromium,g;s,\@\@MENUNAME\@\@,Chromium Web Browser,g' \ ${STAGEDIR}${PREFIX}/share/man/man1/chrome.1 ${CP} ${WRKSRC}/chrome/app/theme/chromium/product_logo_22_mono.png ${WRKSRC}/chrome/app/theme/chromium/product_logo_22.png .for s in 22 24 48 64 128 256 @${MKDIR} ${STAGEDIR}${PREFIX}/share/icons/hicolor/${s}x${s}/apps ${INSTALL_DATA} ${WRKSRC}/chrome/app/theme/chromium/product_logo_${s}.png \ ${STAGEDIR}${PREFIX}/share/icons/hicolor/${s}x${s}/apps/chrome.png .endfor ${INSTALL_DATA} ${WRKSRC}/out/${BUILDTYPE}/*.png ${STAGEDIR}${DATADIR} ${INSTALL_DATA} ${WRKSRC}/out/${BUILDTYPE}/*.pak ${STAGEDIR}${DATADIR} .for d in protoc mksnapshot ${INSTALL_PROGRAM} ${WRKSRC}/out/${BUILDTYPE}/${d} ${STAGEDIR}${DATADIR} .endfor .for d in snapshot_blob.bin v8_context_snapshot.bin ${INSTALL_DATA} ${WRKSRC}/out/${BUILDTYPE}/${d} ${STAGEDIR}${DATADIR} .endfor ${INSTALL_PROGRAM} ${WRKSRC}/out/${BUILDTYPE}/chrome \ ${STAGEDIR}${DATADIR} cd ${WRKSRC}/out/${BUILDTYPE} && \ ${COPYTREE_SHARE} "locales resources" ${STAGEDIR}${DATADIR} @${MKDIR} ${STAGEDIR}${DESKTOPDIR} ${INSTALL_DATA} ${WRKDIR}/chromium-browser.desktop \ ${STAGEDIR}${DESKTOPDIR} ${INSTALL_SCRIPT} ${WRKDIR}/chrome ${STAGEDIR}${PREFIX}/bin ${INSTALL_SCRIPT} ${WRKSRC}/chrome/tools/build/linux/chrome-wrapper \ ${STAGEDIR}${DATADIR} # ANGLE, EGL, Vk .for f in libEGL.so libGLESv2.so libVkICD_mock_icd.so ${INSTALL_LIB} ${WRKSRC}/out/${BUILDTYPE}/${f} ${STAGEDIR}${DATADIR} .endfor ${INSTALL_LIB} ${WRKSRC}/out/${BUILDTYPE}/libvulkan.so.1 \ ${STAGEDIR}${DATADIR}/libvulkan.so .if ${BUILDTYPE} == Debug ${INSTALL_LIB} ${WRKSRC}/out/${BUILDTYPE}/libVkLayer_khronos_validation.so ${STAGEDIR}${DATADIR} .endif # SwiftShader .if ${ARCH} != aarch64 ${INSTALL_LIB} ${WRKSRC}/out/${BUILDTYPE}/libvk_swiftshader.so ${STAGEDIR}${DATADIR} ${INSTALL_DATA} ${WRKSRC}/out/${BUILDTYPE}/vk_swiftshader_icd.json ${STAGEDIR}${DATADIR} .endif post-install-DEBUG-on: ${INSTALL_LIB} ${WRKSRC}/out/${BUILDTYPE}/*.so \ ${STAGEDIR}${DATADIR} ${INSTALL_PROGRAM} ${WRKSRC}/out/${BUILDTYPE}/character_data_generator \ ${STAGEDIR}${DATADIR} post-install-DRIVER-on: ${INSTALL_PROGRAM} ${WRKSRC}/out/${BUILDTYPE}/chromedriver.unstripped \ ${STAGEDIR}${PREFIX}/bin/chromedriver do-test-TEST-on: .for t in ${TEST_TARGETS} cd ${WRKSRC}/out/${BUILDTYPE} && ${SETENV} LC_ALL=en_US.UTF-8 \ ./${t} --gtest_filter=-${EXCLUDE_${t}:ts:} || ${TRUE} .endfor .include diff --git a/www/chromium/files/patch-build_rust_allocator_BUILD.gn b/www/chromium/files/patch-build_rust_allocator_BUILD.gn new file mode 100644 index 000000000000..cb1633140dcc --- /dev/null +++ b/www/chromium/files/patch-build_rust_allocator_BUILD.gn @@ -0,0 +1,109 @@ +--- build/rust/allocator/BUILD.gn.orig 2025-05-20 09:16:26 UTC ++++ build/rust/allocator/BUILD.gn +@@ -0,0 +1,106 @@ ++# Copyright 2025 The Chromium Authors ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++import("//build/buildflag_header.gni") ++import("//build/config/rust.gni") ++import("//build/rust/rust_static_library.gni") ++ ++rust_allocator_uses_partition_alloc = false ++if (build_with_chromium) { ++ import("//base/allocator/partition_allocator/partition_alloc.gni") ++ rust_allocator_uses_partition_alloc = use_partition_alloc_as_malloc ++} ++ ++# In ASAN builds, PartitionAlloc-Everywhere is disabled, meaning malloc() and ++# friends in C++ do not go to PartitionAlloc. So we also don't point the Rust ++# allocation functions at PartitionAlloc. Generally, this means we just direct ++# them to the Standard Library's allocator. ++# ++# However, on Windows the Standard Library uses HeapAlloc() and Windows ASAN ++# does *not* hook that method, so ASAN does not get to hear about allocations ++# made in Rust. To resolve this, we redirect allocation to _aligned_malloc ++# which Windows ASAN *does* hook. ++# ++# Note that there is a runtime option to make ASAN hook HeapAlloc() but ++# enabling it breaks Win32 APIs like CreateProcess: ++# https://crbug.com/368070343#comment29 ++rust_allocator_uses_aligned_malloc = false ++if (!rust_allocator_uses_partition_alloc && is_win && is_asan) { ++ rust_allocator_uses_aligned_malloc = true ++} ++ ++rust_allocator_uses_allocator_impls_h = ++ rust_allocator_uses_partition_alloc || rust_allocator_uses_aligned_malloc ++ ++buildflag_header("buildflags") { ++ header = "buildflags.h" ++ flags = [ ++ "RUST_ALLOCATOR_USES_PARTITION_ALLOC=$rust_allocator_uses_partition_alloc", ++ "RUST_ALLOCATOR_USES_ALIGNED_MALLOC=$rust_allocator_uses_aligned_malloc", ++ ] ++ visibility = [ ":*" ] ++} ++ ++if (toolchain_has_rust) { ++ # All targets which depend on Rust code but are not linked by rustc must ++ # depend on this. Usually, this dependency will come from the rust_target() GN ++ # template. However, cargo_crate() does *not* include this dependency so any ++ # C++ targets which directly depend on a cargo_crate() must depend on this. ++ rust_static_library("allocator") { ++ sources = [ "lib.rs" ] ++ crate_root = "lib.rs" ++ cxx_bindings = [ "lib.rs" ] ++ ++ deps = [ ":alloc_error_handler_impl" ] ++ if (rust_allocator_uses_allocator_impls_h) { ++ deps += [ ":allocator_impls" ] ++ } ++ ++ no_chromium_prelude = true ++ no_allocator_crate = true ++ allow_unsafe = true ++ ++ rustflags = [] ++ if (rust_allocator_uses_allocator_impls_h) { ++ rustflags += [ "--cfg=rust_allocator_uses_allocator_impls_h" ] ++ cxx_bindings += [ "allocator_impls_ffi.rs" ] ++ sources += [ "allocator_impls_ffi.rs" ] ++ } ++ ++ # TODO(https://crbug.com/410596442): Stop using unstable features here. ++ configs -= [ "//build/config/compiler:disallow_unstable_features" ] ++ } ++ ++ if (rust_allocator_uses_allocator_impls_h) { ++ static_library("allocator_impls") { ++ public_deps = [] ++ if (rust_allocator_uses_partition_alloc) { ++ public_deps += ++ [ "//base/allocator/partition_allocator:partition_alloc" ] ++ } ++ ++ sources = [ ++ "allocator_impls.cc", ++ "allocator_impls.h", ++ ] ++ deps = [ ":buildflags" ] ++ visibility = [ ":*" ] ++ } ++ } ++ ++ static_library("alloc_error_handler_impl") { ++ sources = [ ++ # `alias.*`, `compiler_specific.h`, and `immediate_crash.*` have been ++ # copied from `//base`. ++ # TODO(crbug.com/40279749): Avoid duplication / reuse code. ++ "alias.cc", ++ "alias.h", ++ "alloc_error_handler_impl.cc", ++ "alloc_error_handler_impl.h", ++ "compiler_specific.h", ++ "immediate_crash.h", ++ ] ++ visibility = [ ":*" ] ++ } ++} diff --git a/www/chromium/files/patch-build_rust_allocator_DEPS b/www/chromium/files/patch-build_rust_allocator_DEPS new file mode 100644 index 000000000000..74bb2d6c2421 --- /dev/null +++ b/www/chromium/files/patch-build_rust_allocator_DEPS @@ -0,0 +1,12 @@ +--- build/rust/allocator/DEPS.orig 2025-05-20 09:16:26 UTC ++++ build/rust/allocator/DEPS +@@ -0,0 +1,9 @@ ++include_rules = [ ++ "-base", ++] ++ ++specific_include_rules = { ++ "allocator_impls.cc" : [ ++ "+partition_alloc" ++ ] ++} diff --git a/www/chromium/files/patch-build_rust_allocator_alias.cc b/www/chromium/files/patch-build_rust_allocator_alias.cc new file mode 100644 index 000000000000..5280641f27e1 --- /dev/null +++ b/www/chromium/files/patch-build_rust_allocator_alias.cc @@ -0,0 +1,25 @@ +--- build/rust/allocator/alias.cc.orig 2025-05-20 09:16:26 UTC ++++ build/rust/allocator/alias.cc +@@ -0,0 +1,22 @@ ++// Copyright 2023 The Chromium Authors ++// Use of this source code is governed by a BSD-style license that can be ++// found in the LICENSE file. ++ ++// This file has been copied from //base/debug/alias.cc ( additionally the APIs ++// were moved into the `build_rust_std` namespace). ++// ++// TODO(crbug.com/40279749): Avoid code duplication / reuse code. ++ ++#include "build/rust/allocator/alias.h" ++ ++#include "build/rust/allocator/compiler_specific.h" ++ ++namespace build_rust_std { ++namespace debug { ++ ++// This file/function should be excluded from LTO/LTCG to ensure that the ++// compiler can't see this function's implementation when compiling calls to it. ++NOINLINE void Alias(const void* var) {} ++ ++} // namespace debug ++} // namespace build_rust_std diff --git a/www/chromium/files/patch-build_rust_allocator_alias.h b/www/chromium/files/patch-build_rust_allocator_alias.h new file mode 100644 index 000000000000..6530c6ae8779 --- /dev/null +++ b/www/chromium/files/patch-build_rust_allocator_alias.h @@ -0,0 +1,40 @@ +--- build/rust/allocator/alias.h.orig 2025-05-20 09:16:26 UTC ++++ build/rust/allocator/alias.h +@@ -0,0 +1,37 @@ ++// Copyright 2023 The Chromium Authors ++// Use of this source code is governed by a BSD-style license that can be ++// found in the LICENSE file. ++ ++// This file has been copied from //base/debug/alias.h (and then trimmed to just ++// the APIs / macros needed by //build/rust/std; additionally the APIs were ++// moved into the `build_rust_std` namespace). ++// ++// TODO(crbug.com/40279749): Avoid code duplication / reuse code. ++ ++#ifndef BUILD_RUST_ALLOCATOR_ALIAS_H_ ++#define BUILD_RUST_ALLOCATOR_ALIAS_H_ ++ ++#include ++ ++namespace build_rust_std { ++namespace debug { ++ ++// Make the optimizer think that |var| is aliased. This can be used to prevent a ++// local variable from being optimized out (which is something that ++// `NO_CODE_FOLDING` macro definition below depends on). See ++// //base/debug/alias.h for more details. ++void Alias(const void* var); ++ ++} // namespace debug ++ ++} // namespace build_rust_std ++ ++// Prevent code folding (where a linker identifies functions that are ++// bit-identical and overlays them, which saves space but it leads to confusing ++// call stacks because multiple symbols are at the same address). See ++// //base/debug/alias.h for more details. ++#define NO_CODE_FOLDING() \ ++ const int line_number = __LINE__; \ ++ build_rust_std::debug::Alias(&line_number) ++ ++#endif // BUILD_RUST_ALLOCATOR_ALIAS_H_ diff --git a/www/chromium/files/patch-build_rust_allocator_alloc__error__handler__impl.cc b/www/chromium/files/patch-build_rust_allocator_alloc__error__handler__impl.cc new file mode 100644 index 000000000000..048c267abefa --- /dev/null +++ b/www/chromium/files/patch-build_rust_allocator_alloc__error__handler__impl.cc @@ -0,0 +1,20 @@ +--- build/rust/allocator/alloc_error_handler_impl.cc.orig 2025-05-20 09:16:26 UTC ++++ build/rust/allocator/alloc_error_handler_impl.cc +@@ -0,0 +1,17 @@ ++// Copyright 2025 The Chromium Authors ++// Use of this source code is governed by a BSD-style license that can be ++// found in the LICENSE file. ++ ++#include "build/rust/allocator/alloc_error_handler_impl.h" ++ ++#include "build/rust/allocator/alias.h" ++#include "build/rust/allocator/immediate_crash.h" ++ ++namespace rust_allocator_internal { ++ ++void alloc_error_handler_impl() { ++ NO_CODE_FOLDING(); ++ IMMEDIATE_CRASH(); ++} ++ ++} // namespace rust_allocator_internal diff --git a/www/chromium/files/patch-build_rust_allocator_alloc__error__handler__impl.h b/www/chromium/files/patch-build_rust_allocator_alloc__error__handler__impl.h new file mode 100644 index 000000000000..887ea602b027 --- /dev/null +++ b/www/chromium/files/patch-build_rust_allocator_alloc__error__handler__impl.h @@ -0,0 +1,24 @@ +--- build/rust/allocator/alloc_error_handler_impl.h.orig 2025-05-20 09:16:26 UTC ++++ build/rust/allocator/alloc_error_handler_impl.h +@@ -0,0 +1,21 @@ ++// Copyright 2025 The Chromium Authors ++// Use of this source code is governed by a BSD-style license that can be ++// found in the LICENSE file. ++ ++#ifndef BUILD_RUST_ALLOCATOR_ALLOC_ERROR_HANDLER_IMPL_H_ ++#define BUILD_RUST_ALLOCATOR_ALLOC_ERROR_HANDLER_IMPL_H_ ++ ++// This header exposes to Rust a C++ implementation of quickly crashing after an ++// allocation error. (The API below is called from `__rust_alloc_error_handler` ++// in `lib.rs`.) ++// ++// TODO(lukasza): Investigate if we can delete this `.h` / `.cc` and just call ++// `std::process::abort()` (or something else?) directly from `.rs`. The main ++// open question is how much we care about `NO_CODE_FOLDING`. ++namespace rust_allocator_internal { ++ ++void alloc_error_handler_impl(); ++ ++} // namespace rust_allocator_internal ++ ++#endif // BUILD_RUST_ALLOCATOR_ALLOC_ERROR_HANDLER_IMPL_H_ diff --git a/www/chromium/files/patch-build_rust_allocator_allocator__impls.cc b/www/chromium/files/patch-build_rust_allocator_allocator__impls.cc new file mode 100644 index 000000000000..94e04d7b966a --- /dev/null +++ b/www/chromium/files/patch-build_rust_allocator_allocator__impls.cc @@ -0,0 +1,108 @@ +--- build/rust/allocator/allocator_impls.cc.orig 2025-05-20 09:16:26 UTC ++++ build/rust/allocator/allocator_impls.cc +@@ -0,0 +1,105 @@ ++// Copyright 2021 The Chromium Authors ++// Use of this source code is governed by a BSD-style license that can be ++// found in the LICENSE file. ++ ++#include "build/rust/allocator/allocator_impls.h" ++ ++#ifdef UNSAFE_BUFFERS_BUILD ++// TODO(crbug.com/390223051): Remove C-library calls to fix the errors. ++#pragma allow_unsafe_libc_calls ++#endif ++ ++#include ++#include ++ ++#include "build/build_config.h" ++#include "build/rust/allocator/buildflags.h" ++ ++#if BUILDFLAG(RUST_ALLOCATOR_USES_PARTITION_ALLOC) ++#include "partition_alloc/partition_alloc_constants.h" // nogncheck ++#include "partition_alloc/shim/allocator_shim.h" // nogncheck ++#elif BUILDFLAG(RUST_ALLOCATOR_USES_ALIGNED_MALLOC) ++#include ++#endif ++ ++namespace rust_allocator_internal { ++ ++unsigned char* alloc(size_t size, size_t align) { ++#if BUILDFLAG(RUST_ALLOCATOR_USES_PARTITION_ALLOC) ++ // PartitionAlloc will crash if given an alignment larger than this. ++ if (align > partition_alloc::internal::kMaxSupportedAlignment) { ++ return nullptr; ++ } ++ ++ // We use unchecked allocation paths in PartitionAlloc rather than going ++ // through its shims in `malloc()` etc so that we can support fallible ++ // allocation paths such as Vec::try_reserve without crashing on allocation ++ // failure. ++ if (align <= alignof(std::max_align_t)) { ++ return static_cast(allocator_shim::UncheckedAlloc(size)); ++ } else { ++ return static_cast( ++ allocator_shim::UncheckedAlignedAlloc(size, align)); ++ } ++#elif BUILDFLAG(RUST_ALLOCATOR_USES_ALIGNED_MALLOC) ++ return static_cast(_aligned_malloc(size, align)); ++#else ++#error This configuration is not supported. ++#endif ++} ++ ++void dealloc(unsigned char* p, size_t size, size_t align) { ++#if BUILDFLAG(RUST_ALLOCATOR_USES_PARTITION_ALLOC) ++ if (align <= alignof(std::max_align_t)) { ++ allocator_shim::UncheckedFree(p); ++ } else { ++ allocator_shim::UncheckedAlignedFree(p); ++ } ++#elif BUILDFLAG(RUST_ALLOCATOR_USES_ALIGNED_MALLOC) ++ return _aligned_free(p); ++#else ++#error This configuration is not supported. ++#endif ++} ++ ++unsigned char* realloc(unsigned char* p, ++ size_t old_size, ++ size_t align, ++ size_t new_size) { ++#if BUILDFLAG(RUST_ALLOCATOR_USES_PARTITION_ALLOC) ++ // We use unchecked allocation paths in PartitionAlloc rather than going ++ // through its shims in `malloc()` etc so that we can support fallible ++ // allocation paths such as Vec::try_reserve without crashing on allocation ++ // failure. ++ if (align <= alignof(std::max_align_t)) { ++ return static_cast( ++ allocator_shim::UncheckedRealloc(p, new_size)); ++ } else { ++ return static_cast( ++ allocator_shim::UncheckedAlignedRealloc(p, new_size, align)); ++ } ++#elif BUILDFLAG(RUST_ALLOCATOR_USES_ALIGNED_MALLOC) ++ return static_cast(_aligned_realloc(p, new_size, align)); ++#else ++#error This configuration is not supported. ++#endif ++} ++ ++unsigned char* alloc_zeroed(size_t size, size_t align) { ++#if BUILDFLAG(RUST_ALLOCATOR_USES_PARTITION_ALLOC) || \ ++ BUILDFLAG(RUST_ALLOCATOR_USES_ALIGNED_MALLOC) ++ // TODO(danakj): When RUST_ALLOCATOR_USES_PARTITION_ALLOC is true, it's ++ // possible that a partition_alloc::UncheckedAllocZeroed() call would perform ++ // better than partition_alloc::UncheckedAlloc() + memset. But there is no ++ // such API today. See b/342251590. ++ unsigned char* p = alloc(size, align); ++ if (p) { ++ memset(p, 0, size); ++ } ++ return p; ++#else ++#error This configuration is not supported. ++#endif ++} ++ ++} // namespace rust_allocator_internal diff --git a/www/chromium/files/patch-build_rust_allocator_allocator__impls.h b/www/chromium/files/patch-build_rust_allocator_allocator__impls.h new file mode 100644 index 000000000000..9249cdc938d2 --- /dev/null +++ b/www/chromium/files/patch-build_rust_allocator_allocator__impls.h @@ -0,0 +1,27 @@ +--- build/rust/allocator/allocator_impls.h.orig 2025-05-20 09:16:26 UTC ++++ build/rust/allocator/allocator_impls.h +@@ -0,0 +1,24 @@ ++// Copyright 2025 The Chromium Authors ++// Use of this source code is governed by a BSD-style license that can be ++// found in the LICENSE file. ++ ++#ifndef BUILD_RUST_ALLOCATOR_ALLOCATOR_IMPLS_H_ ++#define BUILD_RUST_ALLOCATOR_ALLOCATOR_IMPLS_H_ ++ ++#include ++ ++// This header exposes a C++ allocator (e.g. PartitionAlloc) to Rust. ++// The APIs below are called from `impl GlobalAlloc` in `lib.rs`. ++namespace rust_allocator_internal { ++ ++unsigned char* alloc(size_t size, size_t align); ++void dealloc(unsigned char* p, size_t size, size_t align); ++unsigned char* realloc(unsigned char* p, ++ size_t old_size, ++ size_t align, ++ size_t new_size); ++unsigned char* alloc_zeroed(size_t size, size_t align); ++ ++} // namespace rust_allocator_internal ++ ++#endif // BUILD_RUST_ALLOCATOR_ALLOCATOR_IMPLS_H_ diff --git a/www/chromium/files/patch-build_rust_allocator_allocator__impls__ffi.rs b/www/chromium/files/patch-build_rust_allocator_allocator__impls__ffi.rs new file mode 100644 index 000000000000..8f0baf1576ce --- /dev/null +++ b/www/chromium/files/patch-build_rust_allocator_allocator__impls__ffi.rs @@ -0,0 +1,22 @@ +--- build/rust/allocator/allocator_impls_ffi.rs.orig 2025-05-20 09:16:26 UTC ++++ build/rust/allocator/allocator_impls_ffi.rs +@@ -0,0 +1,19 @@ ++// Copyright 2025 The Chromium Authors ++// Use of this source code is governed by a BSD-style license that can be ++// found in the LICENSE file. ++ ++//! FFI for `allocator_impls.h` is in a separate `.rs` file/module to ++//! better support conditional compilation (these functions are only ++//! used under `#[cfg(rust_allocator_uses_allocator_impls_h)]`. ++ ++#[cxx::bridge(namespace = "rust_allocator_internal")] ++pub mod ffi { ++ extern "C++" { ++ include!("build/rust/allocator/allocator_impls.h"); ++ ++ unsafe fn alloc(size: usize, align: usize) -> *mut u8; ++ unsafe fn dealloc(p: *mut u8, size: usize, align: usize); ++ unsafe fn realloc(p: *mut u8, old_size: usize, align: usize, new_size: usize) -> *mut u8; ++ unsafe fn alloc_zeroed(size: usize, align: usize) -> *mut u8; ++ } ++} diff --git a/www/chromium/files/patch-build_rust_allocator_compiler__specific.h b/www/chromium/files/patch-build_rust_allocator_compiler__specific.h new file mode 100644 index 000000000000..7feb0c739d79 --- /dev/null +++ b/www/chromium/files/patch-build_rust_allocator_compiler__specific.h @@ -0,0 +1,41 @@ +--- build/rust/allocator/compiler_specific.h.orig 2025-05-20 09:16:26 UTC ++++ build/rust/allocator/compiler_specific.h +@@ -0,0 +1,38 @@ ++// Copyright 2023 The Chromium Authors ++// Use of this source code is governed by a BSD-style license that can be ++// found in the LICENSE file. ++ ++// This file has been copied from //base/compiler_specific.h (and then ++// significantly trimmed to just the APIs / macros needed by //build/rust/std). ++// ++// TODO(crbug.com/40279749): Avoid code duplication / reuse code. ++ ++#ifndef BUILD_RUST_ALLOCATOR_COMPILER_SPECIFIC_H_ ++#define BUILD_RUST_ALLOCATOR_COMPILER_SPECIFIC_H_ ++ ++#include "build/build_config.h" ++ ++#if defined(COMPILER_MSVC) && !defined(__clang__) ++#error "Only clang-cl is supported on Windows, see https://crbug.com/988071" ++#endif ++ ++#if defined(__has_attribute) ++#define HAS_ATTRIBUTE(x) __has_attribute(x) ++#else ++#define HAS_ATTRIBUTE(x) 0 ++#endif ++ ++// Annotate a function indicating it should not be inlined. ++// Use like: ++// NOINLINE void DoStuff() { ... } ++#if defined(__clang__) && HAS_ATTRIBUTE(noinline) ++#define NOINLINE [[clang::noinline]] ++#elif defined(COMPILER_GCC) && HAS_ATTRIBUTE(noinline) ++#define NOINLINE __attribute__((noinline)) ++#elif defined(COMPILER_MSVC) ++#define NOINLINE __declspec(noinline) ++#else ++#define NOINLINE ++#endif ++ ++#endif // BUILD_RUST_ALLOCATOR_COMPILER_SPECIFIC_H_ diff --git a/www/chromium/files/patch-build_rust_allocator_immediate__crash.h b/www/chromium/files/patch-build_rust_allocator_immediate__crash.h new file mode 100644 index 000000000000..7ab0f9d9c34c --- /dev/null +++ b/www/chromium/files/patch-build_rust_allocator_immediate__crash.h @@ -0,0 +1,174 @@ +--- build/rust/allocator/immediate_crash.h.orig 2025-05-20 09:16:26 UTC ++++ build/rust/allocator/immediate_crash.h +@@ -0,0 +1,171 @@ ++// Copyright 2021 The Chromium Authors ++// Use of this source code is governed by a BSD-style license that can be ++// found in the LICENSE file. ++ ++// This file has been copied from //base/immediate_crash.h. ++// TODO(crbug.com/40279749): Avoid code duplication / reuse code. ++ ++#ifndef BUILD_RUST_ALLOCATOR_IMMEDIATE_CRASH_H_ ++#define BUILD_RUST_ALLOCATOR_IMMEDIATE_CRASH_H_ ++ ++#include "build/build_config.h" ++ ++// Crashes in the fastest possible way with no attempt at logging. ++// There are several constraints; see http://crbug.com/664209 for more context. ++// ++// - TRAP_SEQUENCE_() must be fatal. It should not be possible to ignore the ++// resulting exception or simply hit 'continue' to skip over it in a debugger. ++// - Different instances of TRAP_SEQUENCE_() must not be folded together, to ++// ensure crash reports are debuggable. Unlike __builtin_trap(), asm volatile ++// blocks will not be folded together. ++// Note: TRAP_SEQUENCE_() previously required an instruction with a unique ++// nonce since unlike clang, GCC folds together identical asm volatile ++// blocks. ++// - TRAP_SEQUENCE_() must produce a signal that is distinct from an invalid ++// memory access. ++// - TRAP_SEQUENCE_() must be treated as a set of noreturn instructions. ++// __builtin_unreachable() is used to provide that hint here. clang also uses ++// this as a heuristic to pack the instructions in the function epilogue to ++// improve code density. ++// ++// Additional properties that are nice to have: ++// - TRAP_SEQUENCE_() should be as compact as possible. ++// - The first instruction of TRAP_SEQUENCE_() should not change, to avoid ++// shifting crash reporting clusters. As a consequence of this, explicit ++// assembly is preferred over intrinsics. ++// Note: this last bullet point may no longer be true, and may be removed in ++// the future. ++ ++// Note: TRAP_SEQUENCE Is currently split into two macro helpers due to the fact ++// that clang emits an actual instruction for __builtin_unreachable() on certain ++// platforms (see https://crbug.com/958675). In addition, the int3/bkpt/brk will ++// be removed in followups, so splitting it up like this now makes it easy to ++// land the followups. ++ ++#if defined(COMPILER_GCC) ++ ++#if BUILDFLAG(IS_NACL) ++ ++// Crash report accuracy is not guaranteed on NaCl. ++#define TRAP_SEQUENCE1_() __builtin_trap() ++#define TRAP_SEQUENCE2_() asm volatile("") ++ ++#elif defined(ARCH_CPU_X86_FAMILY) ++ ++// TODO(crbug.com/40625592): In theory, it should be possible to use just ++// int3. However, there are a number of crashes with SIGILL as the exception ++// code, so it seems likely that there's a signal handler that allows execution ++// to continue after SIGTRAP. ++#define TRAP_SEQUENCE1_() asm volatile("int3") ++ ++#if BUILDFLAG(IS_APPLE) ++// Intentionally empty: __builtin_unreachable() is always part of the sequence ++// (see IMMEDIATE_CRASH below) and already emits a ud2 on Mac. ++#define TRAP_SEQUENCE2_() asm volatile("") ++#else ++#define TRAP_SEQUENCE2_() asm volatile("ud2") ++#endif // BUILDFLAG(IS_APPLE) ++ ++#elif defined(ARCH_CPU_ARMEL) ++ ++// bkpt will generate a SIGBUS when running on armv7 and a SIGTRAP when running ++// as a 32 bit userspace app on arm64. There doesn't seem to be any way to ++// cause a SIGTRAP from userspace without using a syscall (which would be a ++// problem for sandboxing). ++// TODO(crbug.com/40625592): Remove bkpt from this sequence. ++#define TRAP_SEQUENCE1_() asm volatile("bkpt #0") ++#define TRAP_SEQUENCE2_() asm volatile("udf #0") ++ ++#elif defined(ARCH_CPU_ARM64) ++ ++// This will always generate a SIGTRAP on arm64. ++// TODO(crbug.com/40625592): Remove brk from this sequence. ++#define TRAP_SEQUENCE1_() asm volatile("brk #0") ++#define TRAP_SEQUENCE2_() asm volatile("hlt #0") ++ ++#else ++ ++// Crash report accuracy will not be guaranteed on other architectures, but at ++// least this will crash as expected. ++#define TRAP_SEQUENCE1_() __builtin_trap() ++#define TRAP_SEQUENCE2_() asm volatile("") ++ ++#endif // ARCH_CPU_* ++ ++#elif defined(COMPILER_MSVC) ++ ++#if !defined(__clang__) ++ ++// MSVC x64 doesn't support inline asm, so use the MSVC intrinsic. ++#define TRAP_SEQUENCE1_() __debugbreak() ++#define TRAP_SEQUENCE2_() ++ ++#elif defined(ARCH_CPU_ARM64) ++ ++// Windows ARM64 uses "BRK #F000" as its breakpoint instruction, and ++// __debugbreak() generates that in both VC++ and clang. ++#define TRAP_SEQUENCE1_() __debugbreak() ++// Intentionally empty: __builtin_unreachable() is always part of the sequence ++// (see IMMEDIATE_CRASH below) and already emits a ud2 on Win64, ++// https://crbug.com/958373 ++#define TRAP_SEQUENCE2_() __asm volatile("") ++ ++#else ++ ++#define TRAP_SEQUENCE1_() asm volatile("int3") ++#define TRAP_SEQUENCE2_() asm volatile("ud2") ++ ++#endif // __clang__ ++ ++#else ++ ++#error No supported trap sequence! ++ ++#endif // COMPILER_GCC ++ ++#define TRAP_SEQUENCE_() \ ++ do { \ ++ TRAP_SEQUENCE1_(); \ ++ TRAP_SEQUENCE2_(); \ ++ } while (false) ++ ++// CHECK() and the trap sequence can be invoked from a constexpr function. ++// This could make compilation fail on GCC, as it forbids directly using inline ++// asm inside a constexpr function. However, it allows calling a lambda ++// expression including the same asm. ++// The side effect is that the top of the stacktrace will not point to the ++// calling function, but to this anonymous lambda. This is still useful as the ++// full name of the lambda will typically include the name of the function that ++// calls CHECK() and the debugger will still break at the right line of code. ++#if !defined(COMPILER_GCC) || defined(__clang__) ++ ++#define WRAPPED_TRAP_SEQUENCE_() TRAP_SEQUENCE_() ++ ++#else ++ ++#define WRAPPED_TRAP_SEQUENCE_() \ ++ do { \ ++ [] { TRAP_SEQUENCE_(); }(); \ ++ } while (false) ++ ++#endif // !defined(COMPILER_GCC) || defined(__clang__) ++ ++#if defined(__clang__) || defined(COMPILER_GCC) ++ ++// __builtin_unreachable() hints to the compiler that this is noreturn and can ++// be packed in the function epilogue. ++#define IMMEDIATE_CRASH() \ ++ ({ \ ++ WRAPPED_TRAP_SEQUENCE_(); \ ++ __builtin_unreachable(); \ ++ }) ++ ++#else ++ ++// This is supporting non-chromium user of logging.h to build with MSVC, like ++// pdfium. On MSVC there is no __builtin_unreachable(). ++#define IMMEDIATE_CRASH() WRAPPED_TRAP_SEQUENCE_() ++ ++#endif // defined(__clang__) || defined(COMPILER_GCC) ++ ++#endif // BUILD_RUST_ALLOCATOR_IMMEDIATE_CRASH_H_ diff --git a/www/chromium/files/patch-build_rust_allocator_lib.rs b/www/chromium/files/patch-build_rust_allocator_lib.rs new file mode 100644 index 000000000000..89fddf278294 --- /dev/null +++ b/www/chromium/files/patch-build_rust_allocator_lib.rs @@ -0,0 +1,122 @@ +--- build/rust/allocator/lib.rs.orig 2025-05-20 09:16:26 UTC ++++ build/rust/allocator/lib.rs +@@ -0,0 +1,119 @@ ++// Copyright 2025 The Chromium Authors ++// Use of this source code is governed by a BSD-style license that can be ++// found in the LICENSE file. ++ ++//! Define the allocator that Rust code in Chrome should use. ++//! ++//! Any final artifact that depends on this crate, even transitively, will use ++//! the allocator defined here. ++//! ++//! List of known issues: ++//! ++//! 1. We'd like to use PartitionAlloc on Windows, but the stdlib uses Windows ++//! heap functions directly that PartitionAlloc can not intercept. ++//! 2. We'd like `Vec::try_reserve` to fail at runtime on Linux instead of ++//! crashing in malloc() where PartitionAlloc replaces that function. ++ ++// Required to apply weak linkage to symbols. ++// ++// TODO(https://crbug.com/410596442): Stop using unstable features here. ++// https://github.com/rust-lang/rust/issues/29603 tracks stabilization of the `linkage` feature. ++#![feature(linkage)] ++// Required to apply `#[rustc_std_internal_symbol]` to our alloc error handler ++// so the name is correctly mangled as rustc expects. ++// ++// TODO(https://crbug.com/410596442): Stop using internal features here. ++#![allow(internal_features)] ++#![feature(rustc_attrs)] ++ ++// This module is in a separate source file to avoid having to teach `cxxbridge` ++// about conditional compilation. ++#[cfg(rust_allocator_uses_allocator_impls_h)] ++mod allocator_impls_ffi; ++ ++/// Module that provides `#[global_allocator]` / `GlobalAlloc` interface for ++/// using an allocator from C++. ++#[cfg(rust_allocator_uses_allocator_impls_h)] ++mod cpp_allocator { ++ use super::allocator_impls_ffi::ffi; ++ use std::alloc::{GlobalAlloc, Layout}; ++ ++ struct Allocator; ++ ++ unsafe impl GlobalAlloc for Allocator { ++ unsafe fn alloc(&self, layout: Layout) -> *mut u8 { ++ unsafe { ffi::alloc(layout.size(), layout.align()) } ++ } ++ ++ unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) { ++ unsafe { ++ ffi::dealloc(ptr, layout.size(), layout.align()); ++ } ++ } ++ ++ unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 { ++ unsafe { ffi::alloc_zeroed(layout.size(), layout.align()) } ++ } ++ ++ unsafe fn realloc(&self, ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 { ++ unsafe { ffi::realloc(ptr, layout.size(), layout.align(), new_size) } ++ } ++ } ++ ++ #[global_allocator] ++ static GLOBAL: Allocator = Allocator; ++} ++ ++/// Module that provides `#[global_allocator]` / `GlobalAlloc` interface for ++/// using the default Rust allocator. ++#[cfg(not(rust_allocator_uses_allocator_impls_h))] ++mod rust_allocator { ++ #[global_allocator] ++ static GLOBAL: std::alloc::System = std::alloc::System; ++} ++ ++/// Module that provides global symbols that are needed both by `cpp_allocator` ++/// and `rust_allocator`. ++/// ++/// When `rustc` drives linking, then it will define the symbols below. But ++/// Chromium only uses `rustc` to link Rust-only executables (e.g. `build.rs` ++/// scripts) and otherwise uses a non-Rust linker. This is why we have to ++/// manually define a few symbols below. We define those symbols ++/// as "weak" symbols, so that Rust-provided symbols "win" in case where Rust ++/// actually does drive the linking. This hack works (not only for Chromium, ++/// but also for google3 and other projects), but isn't officially supported by ++/// `rustc`. ++/// ++/// TODO(https://crbug.com/410596442): Stop using internal features here. ++mod both_allocators { ++ /// As part of rustc's contract for using `#[global_allocator]` without ++ /// rustc-generated shims we must define this symbol, since we are opting in ++ /// to unstable functionality. See https://github.com/rust-lang/rust/issues/123015 ++ #[no_mangle] ++ #[linkage = "weak"] ++ static __rust_no_alloc_shim_is_unstable: u8 = 0; ++ ++ // Mangle the symbol name as rustc expects. ++ #[rustc_std_internal_symbol] ++ #[allow(non_upper_case_globals)] ++ #[linkage = "weak"] ++ static __rust_alloc_error_handler_should_panic: u8 = 0; ++ ++ // Mangle the symbol name as rustc expects. ++ #[rustc_std_internal_symbol] ++ #[allow(non_upper_case_globals)] ++ #[linkage = "weak"] ++ fn __rust_alloc_error_handler(_size: usize, _align: usize) { ++ // TODO(lukasza): Investigate if we can just call `std::process::abort()` here. ++ // (Not really _needed_, but it could simplify code a little bit.) ++ unsafe { ffi::alloc_error_handler_impl() } ++ } ++ ++ #[cxx::bridge(namespace = "rust_allocator_internal")] ++ mod ffi { ++ extern "C++" { ++ include!("build/rust/allocator/alloc_error_handler_impl.h"); ++ unsafe fn alloc_error_handler_impl(); ++ } ++ } ++} diff --git a/www/chromium/files/patch-build_rust_cargo__crate.gni b/www/chromium/files/patch-build_rust_cargo__crate.gni new file mode 100644 index 000000000000..a1590f727aa3 --- /dev/null +++ b/www/chromium/files/patch-build_rust_cargo__crate.gni @@ -0,0 +1,25 @@ +--- build/rust/cargo_crate.gni.orig 2025-05-20 09:16:26 UTC ++++ build/rust/cargo_crate.gni +@@ -259,6 +259,12 @@ template("cargo_crate") { + # Don't import the `chromium` crate into third-party code. + no_chromium_prelude = true + ++ # Don't depend on the chrome-specific #[global_allocator] crate from ++ # third-party code. This avoids some dependency cycle issues. The allocator ++ # crate will still be used if it exists anywhere in the dependency graph for ++ # a given linked artifact. ++ no_allocator_crate = true ++ + rustc_metadata = _rustc_metadata + + # TODO(crbug.com/40259764): don't default to true. This requires changes to +@@ -482,6 +488,9 @@ template("cargo_crate") { + + # Don't import the `chromium` crate into third-party code. + no_chromium_prelude = true ++ ++ # Build scripts do not need to link to chrome's allocator. ++ no_allocator_crate = true + + # The ${_build_script_name}_output target looks for the exe in this + # location. Due to how the Windows component build works, this has to diff --git a/www/chromium/files/patch-build_rust_rust__macro.gni b/www/chromium/files/patch-build_rust_rust__macro.gni new file mode 100644 index 000000000000..0dafc3819aa1 --- /dev/null +++ b/www/chromium/files/patch-build_rust_rust__macro.gni @@ -0,0 +1,12 @@ +--- build/rust/rust_macro.gni.orig 2025-05-20 09:16:26 UTC ++++ build/rust/rust_macro.gni +@@ -16,6 +16,9 @@ template("rust_macro") { + forward_variables_from(invoker, TESTONLY_AND_VISIBILITY) + proc_macro_configs = invoker.configs + target_type = "rust_proc_macro" ++ ++ # Macros are loaded by rustc and shouldn't use chrome's allocation routines. ++ no_allocator_crate = true + } + } + diff --git a/www/chromium/files/patch-build_rust_rust__target.gni b/www/chromium/files/patch-build_rust_rust__target.gni new file mode 100644 index 000000000000..f4ad6f04fc45 --- /dev/null +++ b/www/chromium/files/patch-build_rust_rust__target.gni @@ -0,0 +1,13 @@ +--- build/rust/rust_target.gni.orig 2025-05-20 09:16:26 UTC ++++ build/rust/rust_target.gni +@@ -339,6 +339,10 @@ template("rust_target") { + _rust_deps += [ "//build/rust/std" ] + } + ++ if (!defined(invoker.no_allocator_crate) || !invoker.no_allocator_crate) { ++ _rust_deps += [ "//build/rust/allocator" ] ++ } ++ + if (_build_unit_tests) { + _unit_test_target = "${_target_name}_unittests" + if (defined(invoker.unit_test_target)) { diff --git a/www/chromium/files/patch-build_rust_std_BUILD.gn b/www/chromium/files/patch-build_rust_std_BUILD.gn index 0a5335d58d48..c6c2801bd47d 100644 --- a/www/chromium/files/patch-build_rust_std_BUILD.gn +++ b/www/chromium/files/patch-build_rust_std_BUILD.gn @@ -1,32 +1,106 @@ ---- build/rust/std/BUILD.gn.orig 2025-04-05 13:54:50 UTC +--- build/rust/std/BUILD.gn.orig 2025-05-20 09:16:26 UTC +++ build/rust/std/BUILD.gn -@@ -89,13 +89,20 @@ if (toolchain_has_rust) { +@@ -15,51 +15,12 @@ + # allocator functions to PartitionAlloc when `use_partition_alloc_as_malloc` is + # true, so that Rust and C++ use the same allocator backend. + +-import("//build/buildflag_header.gni") + import("//build/config/compiler/compiler.gni") + import("//build/config/coverage/coverage.gni") + import("//build/config/rust.gni") + import("//build/config/sanitizers/sanitizers.gni") + +-rust_allocator_uses_partition_alloc = false +-if (build_with_chromium) { +- import("//base/allocator/partition_allocator/partition_alloc.gni") +- rust_allocator_uses_partition_alloc = use_partition_alloc_as_malloc +-} +- +-buildflag_header("buildflags") { +- header = "buildflags.h" +- flags = [ +- "RUST_ALLOCATOR_USES_PARTITION_ALLOC=$rust_allocator_uses_partition_alloc", +- ] +- visibility = [ ":*" ] +-} +- + if (toolchain_has_rust) { +- # If clang performs the link step, we need to provide the allocator symbols +- # that are normally injected by rustc during linking. +- # +- # We also "happen to" use this to redirect allocations to PartitionAlloc, +- # though that would be better done through a #[global_allocator] crate (see +- # above). +- source_set("remap_alloc") { +- public_deps = [] +- if (rust_allocator_uses_partition_alloc) { +- public_deps += [ "//base/allocator/partition_allocator:partition_alloc" ] +- } +- deps = [ ":buildflags" ] +- sources = [ +- # `alias.*`, `compiler_specific.h`, and `immediate_crash.*` have been +- # copied from `//base`. +- # TODO(crbug.com/40279749): Avoid duplication / reuse code. +- "alias.cc", +- "alias.h", +- "compiler_specific.h", +- "immediate_crash.h", +- "remap_alloc.cc", +- ] +- } +- + # List of Rust stdlib rlibs which are present in the official Rust toolchain + # we are using from the Android team. This is usually a version or two behind + # nightly. Generally this matches the toolchain we build ourselves, but if +@@ -89,13 +50,20 @@ if (toolchain_has_rust) { # These are no longer present in the Windows toolchain. stdlib_files += [ "addr2line", - "adler2", "gimli", "libc", "memchr", "miniz_oxide", "object", ] + + rust_revision_pieces = string_split(rustc_revision, " ") + rust_version_pieces = string_split(rust_revision_pieces[1], ".") + if (rust_version_pieces[1] == "85") { + stdlib_files += [ "adler" ] + } else { + stdlib_files += [ "adler2" ] + } } if (toolchain_for_rust_host_build_tools) { -@@ -115,7 +122,6 @@ if (toolchain_has_rust) { +@@ -115,7 +83,6 @@ if (toolchain_has_rust) { # don't need to pass to the C++ linker because they're used for specialized # purposes. skip_stdlib_files = [ - "profiler_builtins", "rustc_std_workspace_alloc", "rustc_std_workspace_core", "rustc_std_workspace_std", +@@ -269,8 +236,6 @@ if (toolchain_has_rust) { + foreach(libname, stdlib_files + skip_stdlib_files) { + deps += [ "rules:$libname" ] + } +- +- public_deps = [ ":remap_alloc" ] + } + } else { + action("find_stdlib") { +@@ -396,12 +361,6 @@ if (toolchain_has_rust) { + ":stdlib_public_dependent_libs", + ] + deps = [ ":prebuilt_rustc_copy_to_sysroot" ] +- +- # The host builds tools toolchain supports Rust only and does not use +- # the allocator remapping to point it to PartitionAlloc. +- if (!toolchain_for_rust_host_build_tools) { +- deps += [ ":remap_alloc" ] +- } + } + } + } diff --git a/www/iridium/Makefile b/www/iridium/Makefile index 40178f0ec7ba..5c87dc11671a 100644 --- a/www/iridium/Makefile +++ b/www/iridium/Makefile @@ -1,360 +1,361 @@ PORTNAME= iridium PORTVERSION= 2025.05.136.2 +PORTREVISION= 1 PULSEMV= 16 PULSEV= ${PULSEMV}.1 CATEGORIES= www wayland MASTER_SITES= https://downloads.iridiumbrowser.de/source/ \ https://freedesktop.org/software/pulseaudio/releases/:pulseaudio PKGNAMESUFFIX= -browser DISTNAME= ${PORTNAME}${PKGNAMESUFFIX}-${PORTVERSION} DISTFILES= ${DISTNAME}${EXTRACT_SUFX} \ pulseaudio-${PULSEV}.tar.gz:pulseaudio MAINTAINER= chromium@FreeBSD.org COMMENT= Iridium browser WWW= https://iridiumbrowser.de/ LICENSE= BSD3CLAUSE LGPL21 MPL11 LICENSE_COMB= multi ONLY_FOR_ARCHS= aarch64 amd64 BUILD_DEPENDS= bash:shells/bash \ ${PYTHON_PKGNAMEPREFIX}Jinja2>0:devel/py-Jinja2@${PY_FLAVOR} \ ${PYTHON_PKGNAMEPREFIX}ply>0:devel/py-ply@${PY_FLAVOR} \ bindgen:devel/rust-bindgen-cli \ gperf:devel/gperf \ flock:sysutils/flock \ node:www/node \ rustc:lang/rust \ xcb-proto>0:x11/xcb-proto \ ${LOCALBASE}/include/linux/videodev2.h:multimedia/v4l_compat \ ${LOCALBASE}/share/usbids/usb.ids:misc/usbids \ ${PYTHON_PKGNAMEPREFIX}html5lib>0:www/py-html5lib@${PY_FLAVOR} \ ${LOCALBASE}/include/va/va.h:multimedia/libva \ ${LOCALBASE}/libdata/pkgconfig/dri.pc:graphics/mesa-dri \ ${LOCALBASE}/libdata/pkgconfig/Qt5Core.pc:devel/qt5-core \ ${LOCALBASE}/libdata/pkgconfig/Qt5Widgets.pc:x11-toolkits/qt5-widgets LIB_DEPENDS= libatk-bridge-2.0.so:accessibility/at-spi2-core \ libatspi.so:accessibility/at-spi2-core \ libspeechd.so:accessibility/speech-dispatcher \ libFLAC.so:audio/flac \ libopus.so:audio/opus \ libspeex.so:audio/speex \ libdbus-1.so:devel/dbus \ libdbus-glib-1.so:devel/dbus-glib \ libepoll-shim.so:devel/libepoll-shim \ libffi.so:devel/libffi \ libicuuc.so:devel/icu \ libjsoncpp.so:devel/jsoncpp \ libpci.so:devel/libpci \ libnspr4.so:devel/nspr \ libre2.so:devel/re2 \ libcairo.so:graphics/cairo \ libdrm.so:graphics/libdrm \ libexif.so:graphics/libexif \ libpng.so:graphics/png \ libwebp.so:graphics/webp \ libdav1d.so:multimedia/dav1d \ libopenh264.so:multimedia/openh264 \ libfreetype.so:print/freetype2 \ libharfbuzz.so:print/harfbuzz \ libharfbuzz-icu.so:print/harfbuzz-icu \ libgcrypt.so:security/libgcrypt \ libsecret-1.so:security/libsecret \ libnss3.so:security/nss \ libexpat.so:textproc/expat2 \ libfontconfig.so:x11-fonts/fontconfig \ libwayland-client.so:graphics/wayland \ libxkbcommon.so:x11/libxkbcommon \ libxshmfence.so:x11/libxshmfence RUN_DEPENDS= xdg-open:devel/xdg-utils \ noto-basic>0:x11-fonts/noto-basic USES= bison compiler:c++17-lang cpe desktop-file-utils gl gmake gnome \ iconv:wchar_t jpeg localbase:ldflags ninja perl5 pkgconfig \ python:build qt:5 shebangfix tar:xz xorg CPE_VENDOR= google CPE_PRODUCT= chrome USE_GL= gbm gl USE_GNOME= atk dconf gdkpixbuf glib20 gtk30 libxml2 libxslt USE_LDCONFIG= ${DATADIR} USE_PERL5= build USE_XORG= x11 xcb xcomposite xcursor xext xdamage xfixes xi \ xorgproto xrandr xrender xscrnsaver xtst USE_QT= buildtools:build SHEBANG_FILES= chrome/tools/build/linux/chrome-wrapper buildtools/linux64/clang-format MAKE_ARGS= -C out/${BUILDTYPE} ALL_TARGET= chrome BINARY_ALIAS= python3=${PYTHON_CMD} \ moc=${PREFIX}/bin/moc-qt5 # TODO bz@ : install libwidevinecdm.so (see third_party/widevine/cdm/BUILD.gn) # # Run "./out/${BUILDTYPE}/gn args out/${BUILDTYPE} --list" for all variables. # Some parts don't have use_system_* flag, and can be turned on/off by using # replace_gn_files.py script, some parts just turned on/off for target host # OS "target_os == is_bsd", like libusb, libpci. GN_ARGS+= clang_use_chrome_plugins=false \ chrome_pgo_phase=0 \ enable_backup_ref_ptr_support=false \ enable_hangout_services_extension=true \ enable_nacl=false \ enable_remoting=false \ fatal_linker_warnings=false \ icu_use_data_file=false \ is_clang=true \ optimize_webui=true \ toolkit_views=true \ treat_warnings_as_errors=false \ use_allocator_shim=false \ use_aura=true \ use_custom_libcxx=true \ use_custom_libunwind=true \ use_lld=true \ use_partition_alloc=true \ use_partition_alloc_as_malloc=false \ use_sysroot=false \ use_system_freetype=false \ use_system_harfbuzz=true \ use_system_libffi=true \ use_system_libjpeg=true \ use_udev=false \ extra_cxxflags="${CXXFLAGS} -I${LOCALBASE}/include/libepoll-shim ${PINCLUDES}" \ extra_ldflags="${LDFLAGS}" \ ffmpeg_branding="${FFMPEG_BRAND}" # TODO: investigate building with these options: # use_system_minigbm GN_BOOTSTRAP_FLAGS= --no-clean --no-rebuild --skip-generate-buildfiles SUB_FILES= iridium-browser.desktop iridium SUB_LIST+= COMMENT="${COMMENT}" OPTIONS_DEFINE= CODECS CUPS DEBUG KERBEROS LTO PIPEWIRE OPTIONS_DEFAULT= CODECS CUPS KERBEROS PIPEWIRE SNDIO ALSA PULSEAUDIO OPTIONS_EXCLUDE_aarch64=LTO OPTIONS_GROUP= AUDIO OPTIONS_GROUP_AUDIO= ALSA PULSEAUDIO SNDIO OPTIONS_RADIO= KERBEROS OPTIONS_RADIO_KERBEROS= HEIMDAL HEIMDAL_BASE MIT OPTIONS_SUB= yes CODECS_DESC= Compile and enable patented codecs like H.264 HEIMDAL_BASE_DESC= Heimdal Kerberos (base) HEIMDAL_DESC= Heimdal Kerberos (security/heimdal) MIT_DESC= MIT Kerberos (security/krb5) ALSA_LIB_DEPENDS= libasound.so:audio/alsa-lib ALSA_RUN_DEPENDS= ${LOCALBASE}/lib/alsa-lib/libasound_module_pcm_oss.so:audio/alsa-plugins \ alsa-lib>=1.1.1_1:audio/alsa-lib ALSA_VARS= GN_ARGS+=use_alsa=true ALSA_VARS_OFF= GN_ARGS+=use_alsa=false CODECS_VARS= GN_ARGS+=proprietary_codecs=true \ FFMPEG_BRAND="Chrome" CODECS_VARS_OFF= GN_ARGS+=proprietary_codecs=false \ FFMPEG_BRAND="Chromium" CUPS_LIB_DEPENDS= libcups.so:print/cups CUPS_VARS= GN_ARGS+=use_cups=true CUPS_VARS_OFF= GN_ARGS+=use_cups=false DEBUG_VARS= BUILDTYPE=Debug \ GN_ARGS+=is_debug=true \ GN_ARGS+=is_component_build=false \ GN_ARGS+=symbol_level=1 \ GN_BOOTSTRAP_FLAGS+=--debug \ WANTSPACE="60 GB" \ WANTMEM="32 GB" DEBUG_VARS_OFF= BUILDTYPE=Release \ GN_ARGS+=blink_symbol_level=0 \ GN_ARGS+=is_debug=false \ GN_ARGS+=is_official_build=true \ GN_ARGS+=symbol_level=0 \ WANTSPACE="35 GB" \ WANTMEM="8 GB" HEIMDAL_LIB_DEPENDS= libkrb.so.26:security/heimdal KERBEROS_VARS= GN_ARGS+=use_kerberos=true KERBEROS_VARS_OFF= GN_ARGS+=use_kerberos=false LTO_VARS= GN_ARGS+=use_thin_lto=true \ GN_ARGS+=thin_lto_enable_optimizations=true \ WANTSPACE="40 GB" \ WANTMEM="16 GB" LTO_VARS_OFF= GN_ARGS+=use_thin_lto=false MIT_LIB_DEPENDS= libkrb.so.3:security/krb5 PIPEWIRE_DESC= Screen capture via PipeWire PIPEWIRE_LIB_DEPENDS= libpipewire-0.3.so:multimedia/pipewire PIPEWIRE_VARS= GN_ARGS+=rtc_use_pipewire=true \ GN_ARGS+=rtc_link_pipewire=true PIPEWIRE_VARS_OFF= GN_ARGS+=rtc_use_pipewire=false \ GN_ARGS+=rtc_link_pipewire=false PULSEAUDIO_VARS= GN_ARGS+=use_pulseaudio=true \ PINCLUDES="-I${WRKDIR}/pulseaudio-${PULSEV}/src -DPA_MAJOR=${PULSEMV}" PULSEAUDIO_VARS_OFF= GN_ARGS+=use_pulseaudio=false SNDIO_LIB_DEPENDS= libsndio.so:audio/sndio SNDIO_VARS= GN_ARGS+=use_sndio=true SNDIO_VARS_OFF= GN_ARGS+=use_sndio=false .include .include # for COMPILER_VERSION .if ${PORT_OPTIONS:MHEIMDAL_BASE} && !exists(/usr/lib/libkrb5.so) IGNORE= you have selected HEIMDAL_BASE but do not have Heimdal installed in base .endif LLVM_DEFAULT= 19 BUILD_DEPENDS+= clang${LLVM_DEFAULT}:devel/llvm${LLVM_DEFAULT} BINARY_ALIAS+= cpp=${LOCALBASE}/bin/clang-cpp${LLVM_DEFAULT} \ cc=${LOCALBASE}/bin/clang${LLVM_DEFAULT} \ c++=${LOCALBASE}/bin/clang++${LLVM_DEFAULT} \ ar=${LOCALBASE}/bin/llvm-ar${LLVM_DEFAULT} \ nm=${LOCALBASE}/bin/llvm-nm${LLVM_DEFAULT} \ ld=${LOCALBASE}/bin/ld.lld${LLVM_DEFAULT} # - swiftshader/lib/{libEGL.so,libGLESv2.so} is x86 only # - map ffmpeg target to ${ARCH} .if ${ARCH} == aarch64 PLIST_SUB+= NOT_AARCH64="@comment " FFMPEG_TARGET= arm64 .elif ${ARCH} == amd64 BUILD_DEPENDS+= nasm:devel/nasm PLIST_SUB+= NOT_AARCH64="" FFMPEG_TARGET= x64 .elif ${ARCH} == i386 BUILD_DEPENDS+= nasm:devel/nasm PLIST_SUB+= NOT_AARCH64="" FFMPEG_TARGET= ia32 .endif FFMPEG_BDIR= ${WRKSRC}/third_party/ffmpeg/build.${FFMPEG_TARGET}.freebsd/${FFMPEG_BRAND} FFMPEG_CDIR= ${WRKSRC}/third_party/ffmpeg/chromium/config/${FFMPEG_BRAND}/freebsd/${FFMPEG_TARGET} # Allow relocations against read-only segments (override lld default) LDFLAGS_i386= -Wl,-znotext # TODO: -isystem, would be just as ugly as this approach, but more reliably # build would fail without C_INCLUDE_PATH/CPLUS_INCLUDE_PATH env var set. MAKE_ENV+= C_INCLUDE_PATH=${LOCALBASE}/include \ CPLUS_INCLUDE_PATH=${LOCALBASE}/include # rust RUSTC_VERSION!= rustc -V 2>/dev/null || true MAKE_ENV+= RUSTC_BOOTSTRAP=1 GN_ARGS+= enable_rust=true \ rust_sysroot_absolute="${LOCALBASE}" \ rustc_version="${RUSTC_VERSION}" pre-everything:: @${ECHO_MSG} @${ECHO_MSG} "To build ${PORTNAME}, you should have at least:" @${ECHO_MSG} "- ${WANTMEM} of memory" @${ECHO_MSG} "- ${WANTSPACE} of free disk space" @${ECHO_MSG} "- 1.5 million free inodes" @${ECHO_MSG} pre-configure: # We used to remove bundled libraries to be sure that chromium uses # system libraries and not shipped ones. # cd ${WRKSRC} && ${PYTHON_CMD} \ #./build/linux/unbundle/remove_bundled_libraries.py [list of preserved] cd ${WRKSRC} && ${SETENV} ${CONFIGURE_ENV} ${PYTHON_CMD} \ ./build/linux/unbundle/replace_gn_files.py --system-libraries \ dav1d flac fontconfig harfbuzz-ng libdrm libpng \ libusb libwebp libxml libxslt openh264 opus || ${FALSE} # Iridium uses an unreleased version of FFmpeg, so configure it cd ${WRKSRC}/media/ffmpeg && \ ${PYTHON_CMD} scripts/build_ffmpeg.py freebsd ${FFMPEG_TARGET} \ --config-only --branding=${FFMPEG_BRAND} cd ${FFMPEG_BDIR} && ${GMAKE} ffversion.h ${MKDIR} ${FFMPEG_CDIR} .for _e in config.h config.asm config_components.h libavcodec libavformat libavutil -${CP} -pR ${FFMPEG_BDIR}/${_e} ${FFMPEG_CDIR} .endfor touch ${WRKDIR}/pulseaudio-${PULSEV}/src/pulse/version.h @${REINPLACE_CMD} -e 's|$${LOCALBASE}|${LOCALBASE}|;s|$${MODCLANG_VERSION}|${LLVM_DEFAULT}|' \ ${WRKSRC}/build/rust/rust_bindgen.gni \ ${WRKSRC}/build/rust/rust_bindgen_generator.gni do-configure: # GN generator bootstrapping and generating ninja files cd ${WRKSRC} && ${SETENV} ${CONFIGURE_ENV} CC=${CC} CXX=${CXX} LD=${CXX} \ READELF=${READELF} AR=${AR} NM=${NM} ${PYTHON_CMD} \ ./tools/gn/bootstrap/bootstrap.py ${GN_BOOTSTRAP_FLAGS} cd ${WRKSRC} && ${SETENV} ${CONFIGURE_ENV} ./out/${BUILDTYPE}/gn \ gen --args='${GN_ARGS}' out/${BUILDTYPE} # Setup nodejs dependency @${MKDIR} ${WRKSRC}/third_party/node/freebsd/node-freebsd/bin ${LN} -sf ${LOCALBASE}/bin/node ${WRKSRC}/third_party/node/freebsd/node-freebsd/bin/node # Setup buildtools/freebsd @${MKDIR} ${WRKSRC}/buildtools/freebsd ${LN} -sf ${WRKSRC}/buildtools/linux64/clang-format ${WRKSRC}/buildtools/freebsd ${LN} -sf ${WRKSRC}/out/${BUILDTYPE}/gn ${WRKSRC}/buildtools/freebsd ${LN} -sf /usr/bin/strip ${WRKSRC}/buildtools/freebsd/strip do-install: @${MKDIR} ${STAGEDIR}${DATADIR} ${INSTALL_MAN} ${WRKSRC}/chrome/app/resources/manpage.1.in \ ${STAGEDIR}${PREFIX}/share/man/man1/iridium.1 @${SED} -i "" -e 's,\@\@PACKAGE\@\@,chromium,g;s,\@\@MENUNAME\@\@,Iridium Web Browser,g' \ ${STAGEDIR}${PREFIX}/share/man/man1/iridium.1 ${CP} ${WRKSRC}/chrome/app/theme/chromium/product_logo_22_mono.png ${WRKSRC}/chrome/app/theme/chromium/product_logo_22.png .for s in 22 24 48 64 128 256 @${MKDIR} ${STAGEDIR}${PREFIX}/share/icons/hicolor/${s}x${s}/apps ${INSTALL_DATA} ${WRKSRC}/chrome/app/theme/chromium/product_logo_${s}.png \ ${STAGEDIR}${PREFIX}/share/icons/hicolor/${s}x${s}/apps/iridium.png .endfor ${INSTALL_DATA} ${WRKSRC}/out/${BUILDTYPE}/*.png ${STAGEDIR}${DATADIR} ${INSTALL_DATA} ${WRKSRC}/out/${BUILDTYPE}/*.pak ${STAGEDIR}${DATADIR} .for d in protoc mksnapshot ${INSTALL_PROGRAM} ${WRKSRC}/out/${BUILDTYPE}/${d} ${STAGEDIR}${DATADIR} .endfor .for d in snapshot_blob.bin v8_context_snapshot.bin ${INSTALL_DATA} ${WRKSRC}/out/${BUILDTYPE}/${d} ${STAGEDIR}${DATADIR} .endfor ${INSTALL_PROGRAM} ${WRKSRC}/out/${BUILDTYPE}/chrome \ ${STAGEDIR}${DATADIR}/iridium cd ${WRKSRC}/out/${BUILDTYPE} && \ ${COPYTREE_SHARE} "locales resources" ${STAGEDIR}${DATADIR} @${MKDIR} ${STAGEDIR}${DESKTOPDIR} ${INSTALL_DATA} ${WRKDIR}/iridium-browser.desktop \ ${STAGEDIR}${DESKTOPDIR} ${INSTALL_SCRIPT} ${WRKDIR}/iridium ${STAGEDIR}${PREFIX}/bin # ANGLE, EGL, Vk .for f in libEGL.so libGLESv2.so libVkICD_mock_icd.so ${INSTALL_LIB} ${WRKSRC}/out/${BUILDTYPE}/${f} ${STAGEDIR}${DATADIR} .endfor ${INSTALL_LIB} ${WRKSRC}/out/${BUILDTYPE}/libvulkan.so.1 \ ${STAGEDIR}${DATADIR}/libvulkan.so .if ${BUILDTYPE} == Debug ${INSTALL_LIB} ${WRKSRC}/out/${BUILDTYPE}/libVkLayer_khronos_validation.so ${STAGEDIR}${DATADIR} .endif # SwiftShader .if ${ARCH} != aarch64 @${MKDIR} ${STAGEDIR}${DATADIR}/swiftshader ${INSTALL_LIB} ${WRKSRC}/out/${BUILDTYPE}/libvk_swiftshader.so ${STAGEDIR}${DATADIR} ${INSTALL_DATA} ${WRKSRC}/out/${BUILDTYPE}/vk_swiftshader_icd.json ${STAGEDIR}${DATADIR} .endif post-install-DEBUG-on: ${INSTALL_LIB} ${WRKSRC}/out/${BUILDTYPE}/*.so \ ${STAGEDIR}${DATADIR} ${INSTALL_PROGRAM} ${WRKSRC}/out/${BUILDTYPE}/character_data_generator \ ${STAGEDIR}${DATADIR} .include diff --git a/www/iridium/files/patch-build_rust_allocator_BUILD.gn b/www/iridium/files/patch-build_rust_allocator_BUILD.gn new file mode 100644 index 000000000000..cb1633140dcc --- /dev/null +++ b/www/iridium/files/patch-build_rust_allocator_BUILD.gn @@ -0,0 +1,109 @@ +--- build/rust/allocator/BUILD.gn.orig 2025-05-20 09:16:26 UTC ++++ build/rust/allocator/BUILD.gn +@@ -0,0 +1,106 @@ ++# Copyright 2025 The Chromium Authors ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++import("//build/buildflag_header.gni") ++import("//build/config/rust.gni") ++import("//build/rust/rust_static_library.gni") ++ ++rust_allocator_uses_partition_alloc = false ++if (build_with_chromium) { ++ import("//base/allocator/partition_allocator/partition_alloc.gni") ++ rust_allocator_uses_partition_alloc = use_partition_alloc_as_malloc ++} ++ ++# In ASAN builds, PartitionAlloc-Everywhere is disabled, meaning malloc() and ++# friends in C++ do not go to PartitionAlloc. So we also don't point the Rust ++# allocation functions at PartitionAlloc. Generally, this means we just direct ++# them to the Standard Library's allocator. ++# ++# However, on Windows the Standard Library uses HeapAlloc() and Windows ASAN ++# does *not* hook that method, so ASAN does not get to hear about allocations ++# made in Rust. To resolve this, we redirect allocation to _aligned_malloc ++# which Windows ASAN *does* hook. ++# ++# Note that there is a runtime option to make ASAN hook HeapAlloc() but ++# enabling it breaks Win32 APIs like CreateProcess: ++# https://crbug.com/368070343#comment29 ++rust_allocator_uses_aligned_malloc = false ++if (!rust_allocator_uses_partition_alloc && is_win && is_asan) { ++ rust_allocator_uses_aligned_malloc = true ++} ++ ++rust_allocator_uses_allocator_impls_h = ++ rust_allocator_uses_partition_alloc || rust_allocator_uses_aligned_malloc ++ ++buildflag_header("buildflags") { ++ header = "buildflags.h" ++ flags = [ ++ "RUST_ALLOCATOR_USES_PARTITION_ALLOC=$rust_allocator_uses_partition_alloc", ++ "RUST_ALLOCATOR_USES_ALIGNED_MALLOC=$rust_allocator_uses_aligned_malloc", ++ ] ++ visibility = [ ":*" ] ++} ++ ++if (toolchain_has_rust) { ++ # All targets which depend on Rust code but are not linked by rustc must ++ # depend on this. Usually, this dependency will come from the rust_target() GN ++ # template. However, cargo_crate() does *not* include this dependency so any ++ # C++ targets which directly depend on a cargo_crate() must depend on this. ++ rust_static_library("allocator") { ++ sources = [ "lib.rs" ] ++ crate_root = "lib.rs" ++ cxx_bindings = [ "lib.rs" ] ++ ++ deps = [ ":alloc_error_handler_impl" ] ++ if (rust_allocator_uses_allocator_impls_h) { ++ deps += [ ":allocator_impls" ] ++ } ++ ++ no_chromium_prelude = true ++ no_allocator_crate = true ++ allow_unsafe = true ++ ++ rustflags = [] ++ if (rust_allocator_uses_allocator_impls_h) { ++ rustflags += [ "--cfg=rust_allocator_uses_allocator_impls_h" ] ++ cxx_bindings += [ "allocator_impls_ffi.rs" ] ++ sources += [ "allocator_impls_ffi.rs" ] ++ } ++ ++ # TODO(https://crbug.com/410596442): Stop using unstable features here. ++ configs -= [ "//build/config/compiler:disallow_unstable_features" ] ++ } ++ ++ if (rust_allocator_uses_allocator_impls_h) { ++ static_library("allocator_impls") { ++ public_deps = [] ++ if (rust_allocator_uses_partition_alloc) { ++ public_deps += ++ [ "//base/allocator/partition_allocator:partition_alloc" ] ++ } ++ ++ sources = [ ++ "allocator_impls.cc", ++ "allocator_impls.h", ++ ] ++ deps = [ ":buildflags" ] ++ visibility = [ ":*" ] ++ } ++ } ++ ++ static_library("alloc_error_handler_impl") { ++ sources = [ ++ # `alias.*`, `compiler_specific.h`, and `immediate_crash.*` have been ++ # copied from `//base`. ++ # TODO(crbug.com/40279749): Avoid duplication / reuse code. ++ "alias.cc", ++ "alias.h", ++ "alloc_error_handler_impl.cc", ++ "alloc_error_handler_impl.h", ++ "compiler_specific.h", ++ "immediate_crash.h", ++ ] ++ visibility = [ ":*" ] ++ } ++} diff --git a/www/iridium/files/patch-build_rust_allocator_DEPS b/www/iridium/files/patch-build_rust_allocator_DEPS new file mode 100644 index 000000000000..74bb2d6c2421 --- /dev/null +++ b/www/iridium/files/patch-build_rust_allocator_DEPS @@ -0,0 +1,12 @@ +--- build/rust/allocator/DEPS.orig 2025-05-20 09:16:26 UTC ++++ build/rust/allocator/DEPS +@@ -0,0 +1,9 @@ ++include_rules = [ ++ "-base", ++] ++ ++specific_include_rules = { ++ "allocator_impls.cc" : [ ++ "+partition_alloc" ++ ] ++} diff --git a/www/iridium/files/patch-build_rust_allocator_alias.cc b/www/iridium/files/patch-build_rust_allocator_alias.cc new file mode 100644 index 000000000000..5280641f27e1 --- /dev/null +++ b/www/iridium/files/patch-build_rust_allocator_alias.cc @@ -0,0 +1,25 @@ +--- build/rust/allocator/alias.cc.orig 2025-05-20 09:16:26 UTC ++++ build/rust/allocator/alias.cc +@@ -0,0 +1,22 @@ ++// Copyright 2023 The Chromium Authors ++// Use of this source code is governed by a BSD-style license that can be ++// found in the LICENSE file. ++ ++// This file has been copied from //base/debug/alias.cc ( additionally the APIs ++// were moved into the `build_rust_std` namespace). ++// ++// TODO(crbug.com/40279749): Avoid code duplication / reuse code. ++ ++#include "build/rust/allocator/alias.h" ++ ++#include "build/rust/allocator/compiler_specific.h" ++ ++namespace build_rust_std { ++namespace debug { ++ ++// This file/function should be excluded from LTO/LTCG to ensure that the ++// compiler can't see this function's implementation when compiling calls to it. ++NOINLINE void Alias(const void* var) {} ++ ++} // namespace debug ++} // namespace build_rust_std diff --git a/www/iridium/files/patch-build_rust_allocator_alias.h b/www/iridium/files/patch-build_rust_allocator_alias.h new file mode 100644 index 000000000000..6530c6ae8779 --- /dev/null +++ b/www/iridium/files/patch-build_rust_allocator_alias.h @@ -0,0 +1,40 @@ +--- build/rust/allocator/alias.h.orig 2025-05-20 09:16:26 UTC ++++ build/rust/allocator/alias.h +@@ -0,0 +1,37 @@ ++// Copyright 2023 The Chromium Authors ++// Use of this source code is governed by a BSD-style license that can be ++// found in the LICENSE file. ++ ++// This file has been copied from //base/debug/alias.h (and then trimmed to just ++// the APIs / macros needed by //build/rust/std; additionally the APIs were ++// moved into the `build_rust_std` namespace). ++// ++// TODO(crbug.com/40279749): Avoid code duplication / reuse code. ++ ++#ifndef BUILD_RUST_ALLOCATOR_ALIAS_H_ ++#define BUILD_RUST_ALLOCATOR_ALIAS_H_ ++ ++#include ++ ++namespace build_rust_std { ++namespace debug { ++ ++// Make the optimizer think that |var| is aliased. This can be used to prevent a ++// local variable from being optimized out (which is something that ++// `NO_CODE_FOLDING` macro definition below depends on). See ++// //base/debug/alias.h for more details. ++void Alias(const void* var); ++ ++} // namespace debug ++ ++} // namespace build_rust_std ++ ++// Prevent code folding (where a linker identifies functions that are ++// bit-identical and overlays them, which saves space but it leads to confusing ++// call stacks because multiple symbols are at the same address). See ++// //base/debug/alias.h for more details. ++#define NO_CODE_FOLDING() \ ++ const int line_number = __LINE__; \ ++ build_rust_std::debug::Alias(&line_number) ++ ++#endif // BUILD_RUST_ALLOCATOR_ALIAS_H_ diff --git a/www/iridium/files/patch-build_rust_allocator_alloc__error__handler__impl.cc b/www/iridium/files/patch-build_rust_allocator_alloc__error__handler__impl.cc new file mode 100644 index 000000000000..048c267abefa --- /dev/null +++ b/www/iridium/files/patch-build_rust_allocator_alloc__error__handler__impl.cc @@ -0,0 +1,20 @@ +--- build/rust/allocator/alloc_error_handler_impl.cc.orig 2025-05-20 09:16:26 UTC ++++ build/rust/allocator/alloc_error_handler_impl.cc +@@ -0,0 +1,17 @@ ++// Copyright 2025 The Chromium Authors ++// Use of this source code is governed by a BSD-style license that can be ++// found in the LICENSE file. ++ ++#include "build/rust/allocator/alloc_error_handler_impl.h" ++ ++#include "build/rust/allocator/alias.h" ++#include "build/rust/allocator/immediate_crash.h" ++ ++namespace rust_allocator_internal { ++ ++void alloc_error_handler_impl() { ++ NO_CODE_FOLDING(); ++ IMMEDIATE_CRASH(); ++} ++ ++} // namespace rust_allocator_internal diff --git a/www/iridium/files/patch-build_rust_allocator_alloc__error__handler__impl.h b/www/iridium/files/patch-build_rust_allocator_alloc__error__handler__impl.h new file mode 100644 index 000000000000..887ea602b027 --- /dev/null +++ b/www/iridium/files/patch-build_rust_allocator_alloc__error__handler__impl.h @@ -0,0 +1,24 @@ +--- build/rust/allocator/alloc_error_handler_impl.h.orig 2025-05-20 09:16:26 UTC ++++ build/rust/allocator/alloc_error_handler_impl.h +@@ -0,0 +1,21 @@ ++// Copyright 2025 The Chromium Authors ++// Use of this source code is governed by a BSD-style license that can be ++// found in the LICENSE file. ++ ++#ifndef BUILD_RUST_ALLOCATOR_ALLOC_ERROR_HANDLER_IMPL_H_ ++#define BUILD_RUST_ALLOCATOR_ALLOC_ERROR_HANDLER_IMPL_H_ ++ ++// This header exposes to Rust a C++ implementation of quickly crashing after an ++// allocation error. (The API below is called from `__rust_alloc_error_handler` ++// in `lib.rs`.) ++// ++// TODO(lukasza): Investigate if we can delete this `.h` / `.cc` and just call ++// `std::process::abort()` (or something else?) directly from `.rs`. The main ++// open question is how much we care about `NO_CODE_FOLDING`. ++namespace rust_allocator_internal { ++ ++void alloc_error_handler_impl(); ++ ++} // namespace rust_allocator_internal ++ ++#endif // BUILD_RUST_ALLOCATOR_ALLOC_ERROR_HANDLER_IMPL_H_ diff --git a/www/iridium/files/patch-build_rust_allocator_allocator__impls.cc b/www/iridium/files/patch-build_rust_allocator_allocator__impls.cc new file mode 100644 index 000000000000..94e04d7b966a --- /dev/null +++ b/www/iridium/files/patch-build_rust_allocator_allocator__impls.cc @@ -0,0 +1,108 @@ +--- build/rust/allocator/allocator_impls.cc.orig 2025-05-20 09:16:26 UTC ++++ build/rust/allocator/allocator_impls.cc +@@ -0,0 +1,105 @@ ++// Copyright 2021 The Chromium Authors ++// Use of this source code is governed by a BSD-style license that can be ++// found in the LICENSE file. ++ ++#include "build/rust/allocator/allocator_impls.h" ++ ++#ifdef UNSAFE_BUFFERS_BUILD ++// TODO(crbug.com/390223051): Remove C-library calls to fix the errors. ++#pragma allow_unsafe_libc_calls ++#endif ++ ++#include ++#include ++ ++#include "build/build_config.h" ++#include "build/rust/allocator/buildflags.h" ++ ++#if BUILDFLAG(RUST_ALLOCATOR_USES_PARTITION_ALLOC) ++#include "partition_alloc/partition_alloc_constants.h" // nogncheck ++#include "partition_alloc/shim/allocator_shim.h" // nogncheck ++#elif BUILDFLAG(RUST_ALLOCATOR_USES_ALIGNED_MALLOC) ++#include ++#endif ++ ++namespace rust_allocator_internal { ++ ++unsigned char* alloc(size_t size, size_t align) { ++#if BUILDFLAG(RUST_ALLOCATOR_USES_PARTITION_ALLOC) ++ // PartitionAlloc will crash if given an alignment larger than this. ++ if (align > partition_alloc::internal::kMaxSupportedAlignment) { ++ return nullptr; ++ } ++ ++ // We use unchecked allocation paths in PartitionAlloc rather than going ++ // through its shims in `malloc()` etc so that we can support fallible ++ // allocation paths such as Vec::try_reserve without crashing on allocation ++ // failure. ++ if (align <= alignof(std::max_align_t)) { ++ return static_cast(allocator_shim::UncheckedAlloc(size)); ++ } else { ++ return static_cast( ++ allocator_shim::UncheckedAlignedAlloc(size, align)); ++ } ++#elif BUILDFLAG(RUST_ALLOCATOR_USES_ALIGNED_MALLOC) ++ return static_cast(_aligned_malloc(size, align)); ++#else ++#error This configuration is not supported. ++#endif ++} ++ ++void dealloc(unsigned char* p, size_t size, size_t align) { ++#if BUILDFLAG(RUST_ALLOCATOR_USES_PARTITION_ALLOC) ++ if (align <= alignof(std::max_align_t)) { ++ allocator_shim::UncheckedFree(p); ++ } else { ++ allocator_shim::UncheckedAlignedFree(p); ++ } ++#elif BUILDFLAG(RUST_ALLOCATOR_USES_ALIGNED_MALLOC) ++ return _aligned_free(p); ++#else ++#error This configuration is not supported. ++#endif ++} ++ ++unsigned char* realloc(unsigned char* p, ++ size_t old_size, ++ size_t align, ++ size_t new_size) { ++#if BUILDFLAG(RUST_ALLOCATOR_USES_PARTITION_ALLOC) ++ // We use unchecked allocation paths in PartitionAlloc rather than going ++ // through its shims in `malloc()` etc so that we can support fallible ++ // allocation paths such as Vec::try_reserve without crashing on allocation ++ // failure. ++ if (align <= alignof(std::max_align_t)) { ++ return static_cast( ++ allocator_shim::UncheckedRealloc(p, new_size)); ++ } else { ++ return static_cast( ++ allocator_shim::UncheckedAlignedRealloc(p, new_size, align)); ++ } ++#elif BUILDFLAG(RUST_ALLOCATOR_USES_ALIGNED_MALLOC) ++ return static_cast(_aligned_realloc(p, new_size, align)); ++#else ++#error This configuration is not supported. ++#endif ++} ++ ++unsigned char* alloc_zeroed(size_t size, size_t align) { ++#if BUILDFLAG(RUST_ALLOCATOR_USES_PARTITION_ALLOC) || \ ++ BUILDFLAG(RUST_ALLOCATOR_USES_ALIGNED_MALLOC) ++ // TODO(danakj): When RUST_ALLOCATOR_USES_PARTITION_ALLOC is true, it's ++ // possible that a partition_alloc::UncheckedAllocZeroed() call would perform ++ // better than partition_alloc::UncheckedAlloc() + memset. But there is no ++ // such API today. See b/342251590. ++ unsigned char* p = alloc(size, align); ++ if (p) { ++ memset(p, 0, size); ++ } ++ return p; ++#else ++#error This configuration is not supported. ++#endif ++} ++ ++} // namespace rust_allocator_internal diff --git a/www/iridium/files/patch-build_rust_allocator_allocator__impls.h b/www/iridium/files/patch-build_rust_allocator_allocator__impls.h new file mode 100644 index 000000000000..9249cdc938d2 --- /dev/null +++ b/www/iridium/files/patch-build_rust_allocator_allocator__impls.h @@ -0,0 +1,27 @@ +--- build/rust/allocator/allocator_impls.h.orig 2025-05-20 09:16:26 UTC ++++ build/rust/allocator/allocator_impls.h +@@ -0,0 +1,24 @@ ++// Copyright 2025 The Chromium Authors ++// Use of this source code is governed by a BSD-style license that can be ++// found in the LICENSE file. ++ ++#ifndef BUILD_RUST_ALLOCATOR_ALLOCATOR_IMPLS_H_ ++#define BUILD_RUST_ALLOCATOR_ALLOCATOR_IMPLS_H_ ++ ++#include ++ ++// This header exposes a C++ allocator (e.g. PartitionAlloc) to Rust. ++// The APIs below are called from `impl GlobalAlloc` in `lib.rs`. ++namespace rust_allocator_internal { ++ ++unsigned char* alloc(size_t size, size_t align); ++void dealloc(unsigned char* p, size_t size, size_t align); ++unsigned char* realloc(unsigned char* p, ++ size_t old_size, ++ size_t align, ++ size_t new_size); ++unsigned char* alloc_zeroed(size_t size, size_t align); ++ ++} // namespace rust_allocator_internal ++ ++#endif // BUILD_RUST_ALLOCATOR_ALLOCATOR_IMPLS_H_ diff --git a/www/iridium/files/patch-build_rust_allocator_allocator__impls__ffi.rs b/www/iridium/files/patch-build_rust_allocator_allocator__impls__ffi.rs new file mode 100644 index 000000000000..8f0baf1576ce --- /dev/null +++ b/www/iridium/files/patch-build_rust_allocator_allocator__impls__ffi.rs @@ -0,0 +1,22 @@ +--- build/rust/allocator/allocator_impls_ffi.rs.orig 2025-05-20 09:16:26 UTC ++++ build/rust/allocator/allocator_impls_ffi.rs +@@ -0,0 +1,19 @@ ++// Copyright 2025 The Chromium Authors ++// Use of this source code is governed by a BSD-style license that can be ++// found in the LICENSE file. ++ ++//! FFI for `allocator_impls.h` is in a separate `.rs` file/module to ++//! better support conditional compilation (these functions are only ++//! used under `#[cfg(rust_allocator_uses_allocator_impls_h)]`. ++ ++#[cxx::bridge(namespace = "rust_allocator_internal")] ++pub mod ffi { ++ extern "C++" { ++ include!("build/rust/allocator/allocator_impls.h"); ++ ++ unsafe fn alloc(size: usize, align: usize) -> *mut u8; ++ unsafe fn dealloc(p: *mut u8, size: usize, align: usize); ++ unsafe fn realloc(p: *mut u8, old_size: usize, align: usize, new_size: usize) -> *mut u8; ++ unsafe fn alloc_zeroed(size: usize, align: usize) -> *mut u8; ++ } ++} diff --git a/www/iridium/files/patch-build_rust_allocator_compiler__specific.h b/www/iridium/files/patch-build_rust_allocator_compiler__specific.h new file mode 100644 index 000000000000..7feb0c739d79 --- /dev/null +++ b/www/iridium/files/patch-build_rust_allocator_compiler__specific.h @@ -0,0 +1,41 @@ +--- build/rust/allocator/compiler_specific.h.orig 2025-05-20 09:16:26 UTC ++++ build/rust/allocator/compiler_specific.h +@@ -0,0 +1,38 @@ ++// Copyright 2023 The Chromium Authors ++// Use of this source code is governed by a BSD-style license that can be ++// found in the LICENSE file. ++ ++// This file has been copied from //base/compiler_specific.h (and then ++// significantly trimmed to just the APIs / macros needed by //build/rust/std). ++// ++// TODO(crbug.com/40279749): Avoid code duplication / reuse code. ++ ++#ifndef BUILD_RUST_ALLOCATOR_COMPILER_SPECIFIC_H_ ++#define BUILD_RUST_ALLOCATOR_COMPILER_SPECIFIC_H_ ++ ++#include "build/build_config.h" ++ ++#if defined(COMPILER_MSVC) && !defined(__clang__) ++#error "Only clang-cl is supported on Windows, see https://crbug.com/988071" ++#endif ++ ++#if defined(__has_attribute) ++#define HAS_ATTRIBUTE(x) __has_attribute(x) ++#else ++#define HAS_ATTRIBUTE(x) 0 ++#endif ++ ++// Annotate a function indicating it should not be inlined. ++// Use like: ++// NOINLINE void DoStuff() { ... } ++#if defined(__clang__) && HAS_ATTRIBUTE(noinline) ++#define NOINLINE [[clang::noinline]] ++#elif defined(COMPILER_GCC) && HAS_ATTRIBUTE(noinline) ++#define NOINLINE __attribute__((noinline)) ++#elif defined(COMPILER_MSVC) ++#define NOINLINE __declspec(noinline) ++#else ++#define NOINLINE ++#endif ++ ++#endif // BUILD_RUST_ALLOCATOR_COMPILER_SPECIFIC_H_ diff --git a/www/iridium/files/patch-build_rust_allocator_immediate__crash.h b/www/iridium/files/patch-build_rust_allocator_immediate__crash.h new file mode 100644 index 000000000000..7ab0f9d9c34c --- /dev/null +++ b/www/iridium/files/patch-build_rust_allocator_immediate__crash.h @@ -0,0 +1,174 @@ +--- build/rust/allocator/immediate_crash.h.orig 2025-05-20 09:16:26 UTC ++++ build/rust/allocator/immediate_crash.h +@@ -0,0 +1,171 @@ ++// Copyright 2021 The Chromium Authors ++// Use of this source code is governed by a BSD-style license that can be ++// found in the LICENSE file. ++ ++// This file has been copied from //base/immediate_crash.h. ++// TODO(crbug.com/40279749): Avoid code duplication / reuse code. ++ ++#ifndef BUILD_RUST_ALLOCATOR_IMMEDIATE_CRASH_H_ ++#define BUILD_RUST_ALLOCATOR_IMMEDIATE_CRASH_H_ ++ ++#include "build/build_config.h" ++ ++// Crashes in the fastest possible way with no attempt at logging. ++// There are several constraints; see http://crbug.com/664209 for more context. ++// ++// - TRAP_SEQUENCE_() must be fatal. It should not be possible to ignore the ++// resulting exception or simply hit 'continue' to skip over it in a debugger. ++// - Different instances of TRAP_SEQUENCE_() must not be folded together, to ++// ensure crash reports are debuggable. Unlike __builtin_trap(), asm volatile ++// blocks will not be folded together. ++// Note: TRAP_SEQUENCE_() previously required an instruction with a unique ++// nonce since unlike clang, GCC folds together identical asm volatile ++// blocks. ++// - TRAP_SEQUENCE_() must produce a signal that is distinct from an invalid ++// memory access. ++// - TRAP_SEQUENCE_() must be treated as a set of noreturn instructions. ++// __builtin_unreachable() is used to provide that hint here. clang also uses ++// this as a heuristic to pack the instructions in the function epilogue to ++// improve code density. ++// ++// Additional properties that are nice to have: ++// - TRAP_SEQUENCE_() should be as compact as possible. ++// - The first instruction of TRAP_SEQUENCE_() should not change, to avoid ++// shifting crash reporting clusters. As a consequence of this, explicit ++// assembly is preferred over intrinsics. ++// Note: this last bullet point may no longer be true, and may be removed in ++// the future. ++ ++// Note: TRAP_SEQUENCE Is currently split into two macro helpers due to the fact ++// that clang emits an actual instruction for __builtin_unreachable() on certain ++// platforms (see https://crbug.com/958675). In addition, the int3/bkpt/brk will ++// be removed in followups, so splitting it up like this now makes it easy to ++// land the followups. ++ ++#if defined(COMPILER_GCC) ++ ++#if BUILDFLAG(IS_NACL) ++ ++// Crash report accuracy is not guaranteed on NaCl. ++#define TRAP_SEQUENCE1_() __builtin_trap() ++#define TRAP_SEQUENCE2_() asm volatile("") ++ ++#elif defined(ARCH_CPU_X86_FAMILY) ++ ++// TODO(crbug.com/40625592): In theory, it should be possible to use just ++// int3. However, there are a number of crashes with SIGILL as the exception ++// code, so it seems likely that there's a signal handler that allows execution ++// to continue after SIGTRAP. ++#define TRAP_SEQUENCE1_() asm volatile("int3") ++ ++#if BUILDFLAG(IS_APPLE) ++// Intentionally empty: __builtin_unreachable() is always part of the sequence ++// (see IMMEDIATE_CRASH below) and already emits a ud2 on Mac. ++#define TRAP_SEQUENCE2_() asm volatile("") ++#else ++#define TRAP_SEQUENCE2_() asm volatile("ud2") ++#endif // BUILDFLAG(IS_APPLE) ++ ++#elif defined(ARCH_CPU_ARMEL) ++ ++// bkpt will generate a SIGBUS when running on armv7 and a SIGTRAP when running ++// as a 32 bit userspace app on arm64. There doesn't seem to be any way to ++// cause a SIGTRAP from userspace without using a syscall (which would be a ++// problem for sandboxing). ++// TODO(crbug.com/40625592): Remove bkpt from this sequence. ++#define TRAP_SEQUENCE1_() asm volatile("bkpt #0") ++#define TRAP_SEQUENCE2_() asm volatile("udf #0") ++ ++#elif defined(ARCH_CPU_ARM64) ++ ++// This will always generate a SIGTRAP on arm64. ++// TODO(crbug.com/40625592): Remove brk from this sequence. ++#define TRAP_SEQUENCE1_() asm volatile("brk #0") ++#define TRAP_SEQUENCE2_() asm volatile("hlt #0") ++ ++#else ++ ++// Crash report accuracy will not be guaranteed on other architectures, but at ++// least this will crash as expected. ++#define TRAP_SEQUENCE1_() __builtin_trap() ++#define TRAP_SEQUENCE2_() asm volatile("") ++ ++#endif // ARCH_CPU_* ++ ++#elif defined(COMPILER_MSVC) ++ ++#if !defined(__clang__) ++ ++// MSVC x64 doesn't support inline asm, so use the MSVC intrinsic. ++#define TRAP_SEQUENCE1_() __debugbreak() ++#define TRAP_SEQUENCE2_() ++ ++#elif defined(ARCH_CPU_ARM64) ++ ++// Windows ARM64 uses "BRK #F000" as its breakpoint instruction, and ++// __debugbreak() generates that in both VC++ and clang. ++#define TRAP_SEQUENCE1_() __debugbreak() ++// Intentionally empty: __builtin_unreachable() is always part of the sequence ++// (see IMMEDIATE_CRASH below) and already emits a ud2 on Win64, ++// https://crbug.com/958373 ++#define TRAP_SEQUENCE2_() __asm volatile("") ++ ++#else ++ ++#define TRAP_SEQUENCE1_() asm volatile("int3") ++#define TRAP_SEQUENCE2_() asm volatile("ud2") ++ ++#endif // __clang__ ++ ++#else ++ ++#error No supported trap sequence! ++ ++#endif // COMPILER_GCC ++ ++#define TRAP_SEQUENCE_() \ ++ do { \ ++ TRAP_SEQUENCE1_(); \ ++ TRAP_SEQUENCE2_(); \ ++ } while (false) ++ ++// CHECK() and the trap sequence can be invoked from a constexpr function. ++// This could make compilation fail on GCC, as it forbids directly using inline ++// asm inside a constexpr function. However, it allows calling a lambda ++// expression including the same asm. ++// The side effect is that the top of the stacktrace will not point to the ++// calling function, but to this anonymous lambda. This is still useful as the ++// full name of the lambda will typically include the name of the function that ++// calls CHECK() and the debugger will still break at the right line of code. ++#if !defined(COMPILER_GCC) || defined(__clang__) ++ ++#define WRAPPED_TRAP_SEQUENCE_() TRAP_SEQUENCE_() ++ ++#else ++ ++#define WRAPPED_TRAP_SEQUENCE_() \ ++ do { \ ++ [] { TRAP_SEQUENCE_(); }(); \ ++ } while (false) ++ ++#endif // !defined(COMPILER_GCC) || defined(__clang__) ++ ++#if defined(__clang__) || defined(COMPILER_GCC) ++ ++// __builtin_unreachable() hints to the compiler that this is noreturn and can ++// be packed in the function epilogue. ++#define IMMEDIATE_CRASH() \ ++ ({ \ ++ WRAPPED_TRAP_SEQUENCE_(); \ ++ __builtin_unreachable(); \ ++ }) ++ ++#else ++ ++// This is supporting non-chromium user of logging.h to build with MSVC, like ++// pdfium. On MSVC there is no __builtin_unreachable(). ++#define IMMEDIATE_CRASH() WRAPPED_TRAP_SEQUENCE_() ++ ++#endif // defined(__clang__) || defined(COMPILER_GCC) ++ ++#endif // BUILD_RUST_ALLOCATOR_IMMEDIATE_CRASH_H_ diff --git a/www/iridium/files/patch-build_rust_allocator_lib.rs b/www/iridium/files/patch-build_rust_allocator_lib.rs new file mode 100644 index 000000000000..89fddf278294 --- /dev/null +++ b/www/iridium/files/patch-build_rust_allocator_lib.rs @@ -0,0 +1,122 @@ +--- build/rust/allocator/lib.rs.orig 2025-05-20 09:16:26 UTC ++++ build/rust/allocator/lib.rs +@@ -0,0 +1,119 @@ ++// Copyright 2025 The Chromium Authors ++// Use of this source code is governed by a BSD-style license that can be ++// found in the LICENSE file. ++ ++//! Define the allocator that Rust code in Chrome should use. ++//! ++//! Any final artifact that depends on this crate, even transitively, will use ++//! the allocator defined here. ++//! ++//! List of known issues: ++//! ++//! 1. We'd like to use PartitionAlloc on Windows, but the stdlib uses Windows ++//! heap functions directly that PartitionAlloc can not intercept. ++//! 2. We'd like `Vec::try_reserve` to fail at runtime on Linux instead of ++//! crashing in malloc() where PartitionAlloc replaces that function. ++ ++// Required to apply weak linkage to symbols. ++// ++// TODO(https://crbug.com/410596442): Stop using unstable features here. ++// https://github.com/rust-lang/rust/issues/29603 tracks stabilization of the `linkage` feature. ++#![feature(linkage)] ++// Required to apply `#[rustc_std_internal_symbol]` to our alloc error handler ++// so the name is correctly mangled as rustc expects. ++// ++// TODO(https://crbug.com/410596442): Stop using internal features here. ++#![allow(internal_features)] ++#![feature(rustc_attrs)] ++ ++// This module is in a separate source file to avoid having to teach `cxxbridge` ++// about conditional compilation. ++#[cfg(rust_allocator_uses_allocator_impls_h)] ++mod allocator_impls_ffi; ++ ++/// Module that provides `#[global_allocator]` / `GlobalAlloc` interface for ++/// using an allocator from C++. ++#[cfg(rust_allocator_uses_allocator_impls_h)] ++mod cpp_allocator { ++ use super::allocator_impls_ffi::ffi; ++ use std::alloc::{GlobalAlloc, Layout}; ++ ++ struct Allocator; ++ ++ unsafe impl GlobalAlloc for Allocator { ++ unsafe fn alloc(&self, layout: Layout) -> *mut u8 { ++ unsafe { ffi::alloc(layout.size(), layout.align()) } ++ } ++ ++ unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) { ++ unsafe { ++ ffi::dealloc(ptr, layout.size(), layout.align()); ++ } ++ } ++ ++ unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 { ++ unsafe { ffi::alloc_zeroed(layout.size(), layout.align()) } ++ } ++ ++ unsafe fn realloc(&self, ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 { ++ unsafe { ffi::realloc(ptr, layout.size(), layout.align(), new_size) } ++ } ++ } ++ ++ #[global_allocator] ++ static GLOBAL: Allocator = Allocator; ++} ++ ++/// Module that provides `#[global_allocator]` / `GlobalAlloc` interface for ++/// using the default Rust allocator. ++#[cfg(not(rust_allocator_uses_allocator_impls_h))] ++mod rust_allocator { ++ #[global_allocator] ++ static GLOBAL: std::alloc::System = std::alloc::System; ++} ++ ++/// Module that provides global symbols that are needed both by `cpp_allocator` ++/// and `rust_allocator`. ++/// ++/// When `rustc` drives linking, then it will define the symbols below. But ++/// Chromium only uses `rustc` to link Rust-only executables (e.g. `build.rs` ++/// scripts) and otherwise uses a non-Rust linker. This is why we have to ++/// manually define a few symbols below. We define those symbols ++/// as "weak" symbols, so that Rust-provided symbols "win" in case where Rust ++/// actually does drive the linking. This hack works (not only for Chromium, ++/// but also for google3 and other projects), but isn't officially supported by ++/// `rustc`. ++/// ++/// TODO(https://crbug.com/410596442): Stop using internal features here. ++mod both_allocators { ++ /// As part of rustc's contract for using `#[global_allocator]` without ++ /// rustc-generated shims we must define this symbol, since we are opting in ++ /// to unstable functionality. See https://github.com/rust-lang/rust/issues/123015 ++ #[no_mangle] ++ #[linkage = "weak"] ++ static __rust_no_alloc_shim_is_unstable: u8 = 0; ++ ++ // Mangle the symbol name as rustc expects. ++ #[rustc_std_internal_symbol] ++ #[allow(non_upper_case_globals)] ++ #[linkage = "weak"] ++ static __rust_alloc_error_handler_should_panic: u8 = 0; ++ ++ // Mangle the symbol name as rustc expects. ++ #[rustc_std_internal_symbol] ++ #[allow(non_upper_case_globals)] ++ #[linkage = "weak"] ++ fn __rust_alloc_error_handler(_size: usize, _align: usize) { ++ // TODO(lukasza): Investigate if we can just call `std::process::abort()` here. ++ // (Not really _needed_, but it could simplify code a little bit.) ++ unsafe { ffi::alloc_error_handler_impl() } ++ } ++ ++ #[cxx::bridge(namespace = "rust_allocator_internal")] ++ mod ffi { ++ extern "C++" { ++ include!("build/rust/allocator/alloc_error_handler_impl.h"); ++ unsafe fn alloc_error_handler_impl(); ++ } ++ } ++} diff --git a/www/iridium/files/patch-build_rust_cargo__crate.gni b/www/iridium/files/patch-build_rust_cargo__crate.gni new file mode 100644 index 000000000000..a1590f727aa3 --- /dev/null +++ b/www/iridium/files/patch-build_rust_cargo__crate.gni @@ -0,0 +1,25 @@ +--- build/rust/cargo_crate.gni.orig 2025-05-20 09:16:26 UTC ++++ build/rust/cargo_crate.gni +@@ -259,6 +259,12 @@ template("cargo_crate") { + # Don't import the `chromium` crate into third-party code. + no_chromium_prelude = true + ++ # Don't depend on the chrome-specific #[global_allocator] crate from ++ # third-party code. This avoids some dependency cycle issues. The allocator ++ # crate will still be used if it exists anywhere in the dependency graph for ++ # a given linked artifact. ++ no_allocator_crate = true ++ + rustc_metadata = _rustc_metadata + + # TODO(crbug.com/40259764): don't default to true. This requires changes to +@@ -482,6 +488,9 @@ template("cargo_crate") { + + # Don't import the `chromium` crate into third-party code. + no_chromium_prelude = true ++ ++ # Build scripts do not need to link to chrome's allocator. ++ no_allocator_crate = true + + # The ${_build_script_name}_output target looks for the exe in this + # location. Due to how the Windows component build works, this has to diff --git a/www/iridium/files/patch-build_rust_rust__macro.gni b/www/iridium/files/patch-build_rust_rust__macro.gni new file mode 100644 index 000000000000..0dafc3819aa1 --- /dev/null +++ b/www/iridium/files/patch-build_rust_rust__macro.gni @@ -0,0 +1,12 @@ +--- build/rust/rust_macro.gni.orig 2025-05-20 09:16:26 UTC ++++ build/rust/rust_macro.gni +@@ -16,6 +16,9 @@ template("rust_macro") { + forward_variables_from(invoker, TESTONLY_AND_VISIBILITY) + proc_macro_configs = invoker.configs + target_type = "rust_proc_macro" ++ ++ # Macros are loaded by rustc and shouldn't use chrome's allocation routines. ++ no_allocator_crate = true + } + } + diff --git a/www/iridium/files/patch-build_rust_rust__target.gni b/www/iridium/files/patch-build_rust_rust__target.gni new file mode 100644 index 000000000000..f4ad6f04fc45 --- /dev/null +++ b/www/iridium/files/patch-build_rust_rust__target.gni @@ -0,0 +1,13 @@ +--- build/rust/rust_target.gni.orig 2025-05-20 09:16:26 UTC ++++ build/rust/rust_target.gni +@@ -339,6 +339,10 @@ template("rust_target") { + _rust_deps += [ "//build/rust/std" ] + } + ++ if (!defined(invoker.no_allocator_crate) || !invoker.no_allocator_crate) { ++ _rust_deps += [ "//build/rust/allocator" ] ++ } ++ + if (_build_unit_tests) { + _unit_test_target = "${_target_name}_unittests" + if (defined(invoker.unit_test_target)) { diff --git a/www/iridium/files/patch-build_rust_std_BUILD.gn b/www/iridium/files/patch-build_rust_std_BUILD.gn index d0b722a2cab3..c6c2801bd47d 100644 --- a/www/iridium/files/patch-build_rust_std_BUILD.gn +++ b/www/iridium/files/patch-build_rust_std_BUILD.gn @@ -1,32 +1,106 @@ ---- build/rust/std/BUILD.gn.orig 2025-05-07 06:48:23 UTC +--- build/rust/std/BUILD.gn.orig 2025-05-20 09:16:26 UTC +++ build/rust/std/BUILD.gn -@@ -89,13 +89,20 @@ if (toolchain_has_rust) { +@@ -15,51 +15,12 @@ + # allocator functions to PartitionAlloc when `use_partition_alloc_as_malloc` is + # true, so that Rust and C++ use the same allocator backend. + +-import("//build/buildflag_header.gni") + import("//build/config/compiler/compiler.gni") + import("//build/config/coverage/coverage.gni") + import("//build/config/rust.gni") + import("//build/config/sanitizers/sanitizers.gni") + +-rust_allocator_uses_partition_alloc = false +-if (build_with_chromium) { +- import("//base/allocator/partition_allocator/partition_alloc.gni") +- rust_allocator_uses_partition_alloc = use_partition_alloc_as_malloc +-} +- +-buildflag_header("buildflags") { +- header = "buildflags.h" +- flags = [ +- "RUST_ALLOCATOR_USES_PARTITION_ALLOC=$rust_allocator_uses_partition_alloc", +- ] +- visibility = [ ":*" ] +-} +- + if (toolchain_has_rust) { +- # If clang performs the link step, we need to provide the allocator symbols +- # that are normally injected by rustc during linking. +- # +- # We also "happen to" use this to redirect allocations to PartitionAlloc, +- # though that would be better done through a #[global_allocator] crate (see +- # above). +- source_set("remap_alloc") { +- public_deps = [] +- if (rust_allocator_uses_partition_alloc) { +- public_deps += [ "//base/allocator/partition_allocator:partition_alloc" ] +- } +- deps = [ ":buildflags" ] +- sources = [ +- # `alias.*`, `compiler_specific.h`, and `immediate_crash.*` have been +- # copied from `//base`. +- # TODO(crbug.com/40279749): Avoid duplication / reuse code. +- "alias.cc", +- "alias.h", +- "compiler_specific.h", +- "immediate_crash.h", +- "remap_alloc.cc", +- ] +- } +- + # List of Rust stdlib rlibs which are present in the official Rust toolchain + # we are using from the Android team. This is usually a version or two behind + # nightly. Generally this matches the toolchain we build ourselves, but if +@@ -89,13 +50,20 @@ if (toolchain_has_rust) { # These are no longer present in the Windows toolchain. stdlib_files += [ "addr2line", - "adler2", "gimli", "libc", "memchr", "miniz_oxide", "object", ] + + rust_revision_pieces = string_split(rustc_revision, " ") + rust_version_pieces = string_split(rust_revision_pieces[1], ".") + if (rust_version_pieces[1] == "85") { + stdlib_files += [ "adler" ] + } else { + stdlib_files += [ "adler2" ] + } } if (toolchain_for_rust_host_build_tools) { -@@ -115,7 +122,6 @@ if (toolchain_has_rust) { +@@ -115,7 +83,6 @@ if (toolchain_has_rust) { # don't need to pass to the C++ linker because they're used for specialized # purposes. skip_stdlib_files = [ - "profiler_builtins", "rustc_std_workspace_alloc", "rustc_std_workspace_core", "rustc_std_workspace_std", +@@ -269,8 +236,6 @@ if (toolchain_has_rust) { + foreach(libname, stdlib_files + skip_stdlib_files) { + deps += [ "rules:$libname" ] + } +- +- public_deps = [ ":remap_alloc" ] + } + } else { + action("find_stdlib") { +@@ -396,12 +361,6 @@ if (toolchain_has_rust) { + ":stdlib_public_dependent_libs", + ] + deps = [ ":prebuilt_rustc_copy_to_sysroot" ] +- +- # The host builds tools toolchain supports Rust only and does not use +- # the allocator remapping to point it to PartitionAlloc. +- if (!toolchain_for_rust_host_build_tools) { +- deps += [ ":remap_alloc" ] +- } + } + } + } diff --git a/www/ungoogled-chromium/Makefile b/www/ungoogled-chromium/Makefile index 11d2fde1f6f1..1c0da59d7a65 100644 --- a/www/ungoogled-chromium/Makefile +++ b/www/ungoogled-chromium/Makefile @@ -1,415 +1,416 @@ PORTNAME= ungoogled-chromium PORTVERSION= 136.0.7103.113 +PORTREVISION= 1 PULSEMV= 16 PULSEV= ${PULSEMV}.1 UGVERSION= ${DISTVERSION}-1 CATEGORIES= www wayland MASTER_SITES= https://commondatastorage.googleapis.com/chromium-browser-official/:goo \ https://freedesktop.org/software/pulseaudio/releases/:pulseaudio DISTFILES= chromium-${DISTVERSION}${EXTRACT_SUFX}:goo \ pulseaudio-${PULSEV}.tar.gz:pulseaudio USE_GITHUB= yes GH_ACCOUNT= ungoogled-software GH_TAGNAME= ${UGVERSION} MAINTAINER= chromium@FreeBSD.org COMMENT= Google web browser based on WebKit sans integration with Google WWW= https://github.com/ungoogled-software/ungoogled-chromium LICENSE= BSD3CLAUSE LGPL21 MPL11 LICENSE_COMB= multi ONLY_FOR_ARCHS= aarch64 amd64 PATCH_DEPENDS= gpatch:devel/patch \ ${PYTHON_VERSION}:lang/python${PYTHON_SUFFIX} BUILD_DEPENDS= bash:shells/bash \ ${PYTHON_PKGNAMEPREFIX}Jinja2>0:devel/py-Jinja2@${PY_FLAVOR} \ ${PYTHON_PKGNAMEPREFIX}ply>0:devel/py-ply@${PY_FLAVOR} \ bindgen:devel/rust-bindgen-cli \ gperf:devel/gperf \ flock:sysutils/flock \ node:www/node \ rustc:lang/rust \ xcb-proto>0:x11/xcb-proto \ ${LOCALBASE}/include/linux/videodev2.h:multimedia/v4l_compat \ ${LOCALBASE}/share/usbids/usb.ids:misc/usbids \ ${PYTHON_PKGNAMEPREFIX}html5lib>0:www/py-html5lib@${PY_FLAVOR} \ ${LOCALBASE}/include/va/va.h:multimedia/libva \ ${LOCALBASE}/libdata/pkgconfig/dri.pc:graphics/mesa-dri \ ${LOCALBASE}/libdata/pkgconfig/Qt5Core.pc:devel/qt5-core \ ${LOCALBASE}/libdata/pkgconfig/Qt5Widgets.pc:x11-toolkits/qt5-widgets LIB_DEPENDS= libatk-bridge-2.0.so:accessibility/at-spi2-core \ libatspi.so:accessibility/at-spi2-core \ libspeechd.so:accessibility/speech-dispatcher \ libFLAC.so:audio/flac \ libopus.so:audio/opus \ libspeex.so:audio/speex \ libdbus-1.so:devel/dbus \ libdbus-glib-1.so:devel/dbus-glib \ libepoll-shim.so:devel/libepoll-shim \ libevent.so:devel/libevent \ libffi.so:devel/libffi \ libicuuc.so:devel/icu \ libjsoncpp.so:devel/jsoncpp \ libpci.so:devel/libpci \ libnspr4.so:devel/nspr \ libre2.so:devel/re2 \ libcairo.so:graphics/cairo \ libdrm.so:graphics/libdrm \ libexif.so:graphics/libexif \ libpng.so:graphics/png \ libwebp.so:graphics/webp \ libdav1d.so:multimedia/dav1d \ libopenh264.so:multimedia/openh264 \ libfreetype.so:print/freetype2 \ libharfbuzz.so:print/harfbuzz \ libharfbuzz-icu.so:print/harfbuzz-icu \ libgcrypt.so:security/libgcrypt \ libsecret-1.so:security/libsecret \ libnss3.so:security/nss \ libexpat.so:textproc/expat2 \ libfontconfig.so:x11-fonts/fontconfig \ libwayland-client.so:graphics/wayland \ libxkbcommon.so:x11/libxkbcommon \ libxshmfence.so:x11/libxshmfence RUN_DEPENDS= xdg-open:devel/xdg-utils \ noto-basic>0:x11-fonts/noto-basic USES= bison compiler:c++17-lang cpe desktop-file-utils gl gmake gnome \ iconv:wchar_t jpeg localbase:ldflags ninja perl5 pkgconfig \ python:build qt:5 shebangfix tar:xz xorg CPE_VENDOR= google CPE_PRODUCT= chrome USE_GL= gbm gl USE_GNOME= atk dconf gdkpixbuf glib20 gtk30 libxml2 libxslt USE_LDCONFIG= ${DATADIR} USE_PERL5= build USE_XORG= x11 xcb xcomposite xcursor xext xdamage xfixes xi \ xorgproto xrandr xrender xscrnsaver xtst USE_QT= buildtools:build SHEBANG_FILES= chrome/tools/build/linux/chrome-wrapper MAKE_ARGS= -C out/${BUILDTYPE} ALL_TARGET= chrome BINARY_ALIAS= python3=${PYTHON_CMD} \ moc=${PREFIX}/bin/moc-qt5 # TODO bz@ : install libwidevinecdm.so (see third_party/widevine/cdm/BUILD.gn) # # Run "./out/${BUILDTYPE}/gn args out/${BUILDTYPE} --list" for all variables. # Some parts don't have use_system_* flag, and can be turned on/off by using # replace_gn_files.py script, some parts just turned on/off for target host # OS "target_os == is_bsd", like libusb, libpci. GN_ARGS+= enable_widevine=true \ fatal_linker_warnings=false \ icu_use_data_file=false \ is_clang=true \ optimize_webui=true \ toolkit_views=true \ use_allocator_shim=false \ use_aura=true \ use_custom_libcxx=true \ use_custom_libunwind=true \ use_lld=true \ use_partition_alloc=true \ use_partition_alloc_as_malloc=false \ use_sysroot=false \ use_system_freetype=false \ use_system_harfbuzz=true \ use_system_libffi=true \ use_system_libjpeg=true \ use_udev=false \ extra_cxxflags="${CXXFLAGS} -I${LOCALBASE}/include/libepoll-shim ${PINCLUDES}" \ extra_ldflags="${LDFLAGS}" \ ffmpeg_branding="${FFMPEG_BRAND}" # sync with flags.gni GN_ARGS+= build_with_tflite_lib=false \ chrome_pgo_phase=0 \ clang_use_chrome_plugins=false \ disable_fieldtrial_testing_config=true \ enable_backup_ref_ptr_support=false \ enable_hangout_services_extension=false \ enable_mdns=false \ enable_nacl=false \ enable_reading_list=false \ enable_remoting=false \ enable_reporting=false \ enable_service_discovery=false \ exclude_unwind_tables=true \ google_api_key="" \ google_default_client_id="" \ google_default_client_secret="" \ safe_browsing_mode=0 \ treat_warnings_as_errors=false \ use_official_google_api_keys=false \ use_unofficial_version_number=false # TODO: investigate building with these options: # use_system_minigbm GN_BOOTSTRAP_FLAGS= --no-clean --no-rebuild --skip-generate-buildfiles SUB_FILES= ungoogled-chromium.desktop ungoogled-chromium SUB_LIST+= COMMENT="${COMMENT}" OPTIONS_DEFINE= CODECS CUPS DEBUG DRIVER KERBEROS LTO PIPEWIRE TEST WIDEVINE OPTIONS_DEFAULT= CODECS CUPS DRIVER KERBEROS PIPEWIRE SNDIO ALSA PULSEAUDIO OPTIONS_EXCLUDE_aarch64=LTO OPTIONS_GROUP= AUDIO OPTIONS_GROUP_AUDIO= ALSA PULSEAUDIO SNDIO OPTIONS_RADIO= KERBEROS OPTIONS_RADIO_KERBEROS= HEIMDAL HEIMDAL_BASE MIT OPTIONS_SUB= yes CODECS_DESC= Compile and enable patented codecs like H.264 DRIVER_DESC= Install chromedriver HEIMDAL_BASE_DESC= Heimdal Kerberos (base) HEIMDAL_DESC= Heimdal Kerberos (security/heimdal) MIT_DESC= MIT Kerberos (security/krb5) ALSA_LIB_DEPENDS= libasound.so:audio/alsa-lib ALSA_RUN_DEPENDS= ${LOCALBASE}/lib/alsa-lib/libasound_module_pcm_oss.so:audio/alsa-plugins \ alsa-lib>=1.1.1_1:audio/alsa-lib ALSA_VARS= GN_ARGS+=use_alsa=true ALSA_VARS_OFF= GN_ARGS+=use_alsa=false CODECS_VARS= GN_ARGS+=proprietary_codecs=true \ FFMPEG_BRAND="Chrome" CODECS_VARS_OFF= GN_ARGS+=proprietary_codecs=false \ FFMPEG_BRAND="Chromium" CUPS_LIB_DEPENDS= libcups.so:print/cups CUPS_VARS= GN_ARGS+=use_cups=true CUPS_VARS_OFF= GN_ARGS+=use_cups=false DEBUG_BUILD_DEPENDS= esbuild:devel/esbuild DEBUG_VARS= BUILDTYPE=Debug \ GN_ARGS+=is_debug=true \ GN_ARGS+=is_component_build=false \ GN_ARGS+=symbol_level=1 \ GN_BOOTSTRAP_FLAGS+=--debug \ WANTSPACE="60 GB" \ WANTMEM="8 GB" DEBUG_VARS_OFF= BUILDTYPE=Release \ GN_ARGS+=blink_symbol_level=0 \ GN_ARGS+=is_debug=false \ GN_ARGS+=is_official_build=true \ GN_ARGS+=symbol_level=0 \ WANTSPACE="35 GB" \ WANTMEM="8 GB" DRIVER_MAKE_ARGS= chromedriver HEIMDAL_LIB_DEPENDS= libkrb.so.26:security/heimdal KERBEROS_VARS= GN_ARGS+=use_kerberos=true KERBEROS_VARS_OFF= GN_ARGS+=use_kerberos=false LTO_VARS= GN_ARGS+=use_thin_lto=true \ GN_ARGS+=thin_lto_enable_optimizations=true \ WANTSPACE="40 GB" \ WANTMEM="16 GB" LTO_VARS_OFF= GN_ARGS+=use_thin_lto=false MIT_LIB_DEPENDS= libkrb.so.3:security/krb5 PIPEWIRE_DESC= Screen capture via PipeWire PIPEWIRE_LIB_DEPENDS= libpipewire-0.3.so:multimedia/pipewire PIPEWIRE_VARS= GN_ARGS+=rtc_use_pipewire=true \ GN_ARGS+=rtc_link_pipewire=true PIPEWIRE_VARS_OFF= GN_ARGS+=rtc_use_pipewire=false \ GN_ARGS+=rtc_link_pipewire=false PULSEAUDIO_VARS= GN_ARGS+=use_pulseaudio=true \ PINCLUDES="-I${WRKDIR}/pulseaudio-${PULSEV}/src -DPA_MAJOR=${PULSEMV}" PULSEAUDIO_VARS_OFF= GN_ARGS+=use_pulseaudio=false SNDIO_LIB_DEPENDS= libsndio.so:audio/sndio SNDIO_VARS= GN_ARGS+=use_sndio=true SNDIO_VARS_OFF= GN_ARGS+=use_sndio=false WIDEVINE_DESC= Depend on foreign-cdm to enable playback of DRM content WIDEVINE_RUN_DEPENDS= foreign-cdm>0:www/foreign-cdm .include "Makefile.tests" TEST_DISTFILES= chromium-${DISTVERSION}-testdata${EXTRACT_SUFX} TEST_ALL_TARGET= ${TEST_TARGETS} .include .include # for COMPILER_VERSION .if ${PORT_OPTIONS:MHEIMDAL_BASE} && !exists(/usr/lib/libkrb5.so) IGNORE= you have selected HEIMDAL_BASE but do not have Heimdal installed in base .endif LLVM_DEFAULT= 19 BUILD_DEPENDS+= clang${LLVM_DEFAULT}:devel/llvm${LLVM_DEFAULT} BINARY_ALIAS+= cpp=${LOCALBASE}/bin/clang-cpp${LLVM_DEFAULT} \ cc=${LOCALBASE}/bin/clang${LLVM_DEFAULT} \ c++=${LOCALBASE}/bin/clang++${LLVM_DEFAULT} \ ar=${LOCALBASE}/bin/llvm-ar${LLVM_DEFAULT} \ nm=${LOCALBASE}/bin/llvm-nm${LLVM_DEFAULT} \ ld=${LOCALBASE}/bin/ld.lld${LLVM_DEFAULT} # - swiftshader/lib/{libEGL.so,libGLESv2.so} is x86 only # - map ffmpeg target to ${ARCH} .if ${ARCH} == aarch64 PLIST_SUB+= NOT_AARCH64="@comment " FFMPEG_TARGET= arm64 .elif ${ARCH} == amd64 BUILD_DEPENDS+= nasm:devel/nasm PLIST_SUB+= NOT_AARCH64="" FFMPEG_TARGET= x64 .elif ${ARCH} == i386 BUILD_DEPENDS+= nasm:devel/nasm PLIST_SUB+= NOT_AARCH64="" FFMPEG_TARGET= ia32 .endif FFMPEG_BDIR= ${WRKSRC}/third_party/ffmpeg/build.${FFMPEG_TARGET}.freebsd/${FFMPEG_BRAND} FFMPEG_CDIR= ${WRKSRC}/third_party/ffmpeg/chromium/config/${FFMPEG_BRAND}/freebsd/${FFMPEG_TARGET} # Allow relocations against read-only segments (override lld default) LDFLAGS_i386= -Wl,-znotext # TODO: -isystem, would be just as ugly as this approach, but more reliably # build would fail without C_INCLUDE_PATH/CPLUS_INCLUDE_PATH env var set. MAKE_ENV+= C_INCLUDE_PATH=${LOCALBASE}/include \ CPLUS_INCLUDE_PATH=${LOCALBASE}/include WRKSRC= ${WRKDIR}/chromium-${DISTVERSION} # rust RUSTC_VERSION!= rustc -V 2>/dev/null || true MAKE_ENV+= RUSTC_BOOTSTRAP=1 GN_ARGS+= enable_rust=true \ rust_sysroot_absolute="${LOCALBASE}" \ rustc_version="${RUSTC_VERSION}" pre-everything:: @${ECHO_MSG} @${ECHO_MSG} "To build ${PORTNAME}, you should have at least:" @${ECHO_MSG} "- ${WANTMEM} of memory" @${ECHO_MSG} "- ${WANTSPACE} of free disk space" @${ECHO_MSG} "- 1.5 million free inodes" @${ECHO_MSG} pre-patch: cd ${WRKDIR}/ungoogled-chromium-${UGVERSION} && ${PYTHON_CMD} \ utils/prune_binaries.py ${WRKSRC} pruning.list cd ${WRKDIR}/ungoogled-chromium-${UGVERSION} && PATCH_BIN=gpatch \ ${PYTHON_CMD} utils/patches.py apply ${WRKSRC} patches cd ${WRKDIR}/ungoogled-chromium-${UGVERSION} && ${PYTHON_CMD} \ utils/domain_substitution.py apply -r domain_regex.list -f \ domain_substitution.list -c ${WRKSRC}/domsubcache.tar.gz ${WRKSRC} pre-configure: # We used to remove bundled libraries to be sure that chromium uses # system libraries and not shipped ones. # cd ${WRKSRC} && ${PYTHON_CMD} \ #./build/linux/unbundle/remove_bundled_libraries.py [list of preserved] cd ${WRKSRC} && ${SETENV} ${CONFIGURE_ENV} ${PYTHON_CMD} \ ./build/linux/unbundle/replace_gn_files.py --system-libraries \ dav1d flac fontconfig harfbuzz-ng libdrm libpng \ libusb libwebp libxml libxslt openh264 opus || ${FALSE} # Chromium uses an unreleased version of FFmpeg, so configure it cd ${WRKSRC}/media/ffmpeg && \ ${PYTHON_CMD} scripts/build_ffmpeg.py freebsd ${FFMPEG_TARGET} \ --config-only --branding=${FFMPEG_BRAND} cd ${FFMPEG_BDIR} && ${GMAKE} ffversion.h ${MKDIR} ${FFMPEG_CDIR} .for _e in config.h config.asm config_components.h libavcodec libavformat libavutil -${CP} -pR ${FFMPEG_BDIR}/${_e} ${FFMPEG_CDIR} .endfor touch ${WRKDIR}/pulseaudio-${PULSEV}/src/pulse/version.h @${REINPLACE_CMD} -e 's|$${LOCALBASE}|${LOCALBASE}|;s|$${MODCLANG_VERSION}|${LLVM_DEFAULT}|' \ ${WRKSRC}/build/rust/rust_bindgen.gni \ ${WRKSRC}/build/rust/rust_bindgen_generator.gni do-configure: # GN generator bootstrapping and generating ninja files cd ${WRKSRC} && ${SETENV} ${CONFIGURE_ENV} CC=${CC} CXX=${CXX} LD=${CXX} \ READELF=${READELF} AR=${AR} NM=${NM} ${PYTHON_CMD} \ ./tools/gn/bootstrap/bootstrap.py ${GN_BOOTSTRAP_FLAGS} cd ${WRKSRC} && ${SETENV} ${CONFIGURE_ENV} ./out/${BUILDTYPE}/gn \ gen --args='${GN_ARGS}' out/${BUILDTYPE} # Setup nodejs dependency @${MKDIR} ${WRKSRC}/third_party/node/freebsd/node-freebsd/bin ${LN} -sf ${LOCALBASE}/bin/node ${WRKSRC}/third_party/node/freebsd/node-freebsd/bin/node # Setup buildtools/freebsd @${MKDIR} ${WRKSRC}/buildtools/freebsd ${LN} -sf ${WRKSRC}/buildtools/linux64/clang-format ${WRKSRC}/buildtools/freebsd ${LN} -sf ${WRKSRC}/out/${BUILDTYPE}/gn ${WRKSRC}/buildtools/freebsd ${LN} -sf /usr/bin/strip ${WRKSRC}/buildtools/freebsd/strip do-install: @${MKDIR} ${STAGEDIR}${DATADIR} ${INSTALL_MAN} ${WRKSRC}/chrome/app/resources/manpage.1.in \ ${STAGEDIR}${PREFIX}/share/man/man1/ungoogled-chromium.1 @${SED} -i "" -e 's,\@\@PACKAGE\@\@,chromium,g;s,\@\@MENUNAME\@\@,Chromium Web Browser,g' \ ${STAGEDIR}${PREFIX}/share/man/man1/ungoogled-chromium.1 ${CP} ${WRKSRC}/chrome/app/theme/chromium/product_logo_22_mono.png ${WRKSRC}/chrome/app/theme/chromium/product_logo_22.png .for s in 22 24 48 64 128 256 @${MKDIR} ${STAGEDIR}${PREFIX}/share/icons/hicolor/${s}x${s}/apps ${INSTALL_DATA} ${WRKSRC}/chrome/app/theme/chromium/product_logo_${s}.png \ ${STAGEDIR}${PREFIX}/share/icons/hicolor/${s}x${s}/apps/ungoogled-chromium.png .endfor ${INSTALL_DATA} ${WRKSRC}/out/${BUILDTYPE}/*.png ${STAGEDIR}${DATADIR} ${INSTALL_DATA} ${WRKSRC}/out/${BUILDTYPE}/*.pak ${STAGEDIR}${DATADIR} .for d in protoc mksnapshot ${INSTALL_PROGRAM} ${WRKSRC}/out/${BUILDTYPE}/${d} ${STAGEDIR}${DATADIR} .endfor .for d in snapshot_blob.bin v8_context_snapshot.bin ${INSTALL_DATA} ${WRKSRC}/out/${BUILDTYPE}/${d} ${STAGEDIR}${DATADIR} .endfor ${INSTALL_PROGRAM} ${WRKSRC}/out/${BUILDTYPE}/chrome \ ${STAGEDIR}${DATADIR}/ungoogled-chromium cd ${WRKSRC}/out/${BUILDTYPE} && \ ${COPYTREE_SHARE} "locales resources" ${STAGEDIR}${DATADIR} @${MKDIR} ${STAGEDIR}${DESKTOPDIR} ${INSTALL_DATA} ${WRKDIR}/ungoogled-chromium.desktop \ ${STAGEDIR}${DESKTOPDIR} ${INSTALL_SCRIPT} ${WRKDIR}/ungoogled-chromium ${STAGEDIR}${PREFIX}/bin ${INSTALL_SCRIPT} ${WRKSRC}/chrome/tools/build/linux/chrome-wrapper \ ${STAGEDIR}${DATADIR} # ANGLE, EGL, Vk .for f in libEGL.so libGLESv2.so libVkICD_mock_icd.so ${INSTALL_LIB} ${WRKSRC}/out/${BUILDTYPE}/${f} ${STAGEDIR}${DATADIR} .endfor ${INSTALL_LIB} ${WRKSRC}/out/${BUILDTYPE}/libvulkan.so.1 \ ${STAGEDIR}${DATADIR}/libvulkan.so .if ${BUILDTYPE} == Debug ${INSTALL_LIB} ${WRKSRC}/out/${BUILDTYPE}/libVkLayer_khronos_validation.so ${STAGEDIR}${DATADIR} .endif # SwiftShader .if ${ARCH} != aarch64 ${INSTALL_LIB} ${WRKSRC}/out/${BUILDTYPE}/libvk_swiftshader.so ${STAGEDIR}${DATADIR} ${INSTALL_DATA} ${WRKSRC}/out/${BUILDTYPE}/vk_swiftshader_icd.json ${STAGEDIR}${DATADIR} .endif post-install-DEBUG-on: ${INSTALL_LIB} ${WRKSRC}/out/${BUILDTYPE}/*.so \ ${STAGEDIR}${DATADIR} ${INSTALL_PROGRAM} ${WRKSRC}/out/${BUILDTYPE}/character_data_generator \ ${STAGEDIR}${DATADIR} post-install-DRIVER-on: ${INSTALL_PROGRAM} ${WRKSRC}/out/${BUILDTYPE}/chromedriver \ ${STAGEDIR}${PREFIX}/bin/ungoogled-chromedriver do-test-TEST-on: .for t in ${TEST_TARGETS} cd ${WRKSRC}/out/${BUILDTYPE} && ${SETENV} LC_ALL=en_US.UTF-8 \ ./${t} --gtest_filter=-${EXCLUDE_${t}:ts:} || ${TRUE} .endfor .include diff --git a/www/ungoogled-chromium/files/patch-build_rust_allocator_BUILD.gn b/www/ungoogled-chromium/files/patch-build_rust_allocator_BUILD.gn new file mode 100644 index 000000000000..cb1633140dcc --- /dev/null +++ b/www/ungoogled-chromium/files/patch-build_rust_allocator_BUILD.gn @@ -0,0 +1,109 @@ +--- build/rust/allocator/BUILD.gn.orig 2025-05-20 09:16:26 UTC ++++ build/rust/allocator/BUILD.gn +@@ -0,0 +1,106 @@ ++# Copyright 2025 The Chromium Authors ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++import("//build/buildflag_header.gni") ++import("//build/config/rust.gni") ++import("//build/rust/rust_static_library.gni") ++ ++rust_allocator_uses_partition_alloc = false ++if (build_with_chromium) { ++ import("//base/allocator/partition_allocator/partition_alloc.gni") ++ rust_allocator_uses_partition_alloc = use_partition_alloc_as_malloc ++} ++ ++# In ASAN builds, PartitionAlloc-Everywhere is disabled, meaning malloc() and ++# friends in C++ do not go to PartitionAlloc. So we also don't point the Rust ++# allocation functions at PartitionAlloc. Generally, this means we just direct ++# them to the Standard Library's allocator. ++# ++# However, on Windows the Standard Library uses HeapAlloc() and Windows ASAN ++# does *not* hook that method, so ASAN does not get to hear about allocations ++# made in Rust. To resolve this, we redirect allocation to _aligned_malloc ++# which Windows ASAN *does* hook. ++# ++# Note that there is a runtime option to make ASAN hook HeapAlloc() but ++# enabling it breaks Win32 APIs like CreateProcess: ++# https://crbug.com/368070343#comment29 ++rust_allocator_uses_aligned_malloc = false ++if (!rust_allocator_uses_partition_alloc && is_win && is_asan) { ++ rust_allocator_uses_aligned_malloc = true ++} ++ ++rust_allocator_uses_allocator_impls_h = ++ rust_allocator_uses_partition_alloc || rust_allocator_uses_aligned_malloc ++ ++buildflag_header("buildflags") { ++ header = "buildflags.h" ++ flags = [ ++ "RUST_ALLOCATOR_USES_PARTITION_ALLOC=$rust_allocator_uses_partition_alloc", ++ "RUST_ALLOCATOR_USES_ALIGNED_MALLOC=$rust_allocator_uses_aligned_malloc", ++ ] ++ visibility = [ ":*" ] ++} ++ ++if (toolchain_has_rust) { ++ # All targets which depend on Rust code but are not linked by rustc must ++ # depend on this. Usually, this dependency will come from the rust_target() GN ++ # template. However, cargo_crate() does *not* include this dependency so any ++ # C++ targets which directly depend on a cargo_crate() must depend on this. ++ rust_static_library("allocator") { ++ sources = [ "lib.rs" ] ++ crate_root = "lib.rs" ++ cxx_bindings = [ "lib.rs" ] ++ ++ deps = [ ":alloc_error_handler_impl" ] ++ if (rust_allocator_uses_allocator_impls_h) { ++ deps += [ ":allocator_impls" ] ++ } ++ ++ no_chromium_prelude = true ++ no_allocator_crate = true ++ allow_unsafe = true ++ ++ rustflags = [] ++ if (rust_allocator_uses_allocator_impls_h) { ++ rustflags += [ "--cfg=rust_allocator_uses_allocator_impls_h" ] ++ cxx_bindings += [ "allocator_impls_ffi.rs" ] ++ sources += [ "allocator_impls_ffi.rs" ] ++ } ++ ++ # TODO(https://crbug.com/410596442): Stop using unstable features here. ++ configs -= [ "//build/config/compiler:disallow_unstable_features" ] ++ } ++ ++ if (rust_allocator_uses_allocator_impls_h) { ++ static_library("allocator_impls") { ++ public_deps = [] ++ if (rust_allocator_uses_partition_alloc) { ++ public_deps += ++ [ "//base/allocator/partition_allocator:partition_alloc" ] ++ } ++ ++ sources = [ ++ "allocator_impls.cc", ++ "allocator_impls.h", ++ ] ++ deps = [ ":buildflags" ] ++ visibility = [ ":*" ] ++ } ++ } ++ ++ static_library("alloc_error_handler_impl") { ++ sources = [ ++ # `alias.*`, `compiler_specific.h`, and `immediate_crash.*` have been ++ # copied from `//base`. ++ # TODO(crbug.com/40279749): Avoid duplication / reuse code. ++ "alias.cc", ++ "alias.h", ++ "alloc_error_handler_impl.cc", ++ "alloc_error_handler_impl.h", ++ "compiler_specific.h", ++ "immediate_crash.h", ++ ] ++ visibility = [ ":*" ] ++ } ++} diff --git a/www/ungoogled-chromium/files/patch-build_rust_allocator_DEPS b/www/ungoogled-chromium/files/patch-build_rust_allocator_DEPS new file mode 100644 index 000000000000..74bb2d6c2421 --- /dev/null +++ b/www/ungoogled-chromium/files/patch-build_rust_allocator_DEPS @@ -0,0 +1,12 @@ +--- build/rust/allocator/DEPS.orig 2025-05-20 09:16:26 UTC ++++ build/rust/allocator/DEPS +@@ -0,0 +1,9 @@ ++include_rules = [ ++ "-base", ++] ++ ++specific_include_rules = { ++ "allocator_impls.cc" : [ ++ "+partition_alloc" ++ ] ++} diff --git a/www/ungoogled-chromium/files/patch-build_rust_allocator_alias.cc b/www/ungoogled-chromium/files/patch-build_rust_allocator_alias.cc new file mode 100644 index 000000000000..5280641f27e1 --- /dev/null +++ b/www/ungoogled-chromium/files/patch-build_rust_allocator_alias.cc @@ -0,0 +1,25 @@ +--- build/rust/allocator/alias.cc.orig 2025-05-20 09:16:26 UTC ++++ build/rust/allocator/alias.cc +@@ -0,0 +1,22 @@ ++// Copyright 2023 The Chromium Authors ++// Use of this source code is governed by a BSD-style license that can be ++// found in the LICENSE file. ++ ++// This file has been copied from //base/debug/alias.cc ( additionally the APIs ++// were moved into the `build_rust_std` namespace). ++// ++// TODO(crbug.com/40279749): Avoid code duplication / reuse code. ++ ++#include "build/rust/allocator/alias.h" ++ ++#include "build/rust/allocator/compiler_specific.h" ++ ++namespace build_rust_std { ++namespace debug { ++ ++// This file/function should be excluded from LTO/LTCG to ensure that the ++// compiler can't see this function's implementation when compiling calls to it. ++NOINLINE void Alias(const void* var) {} ++ ++} // namespace debug ++} // namespace build_rust_std diff --git a/www/ungoogled-chromium/files/patch-build_rust_allocator_alias.h b/www/ungoogled-chromium/files/patch-build_rust_allocator_alias.h new file mode 100644 index 000000000000..6530c6ae8779 --- /dev/null +++ b/www/ungoogled-chromium/files/patch-build_rust_allocator_alias.h @@ -0,0 +1,40 @@ +--- build/rust/allocator/alias.h.orig 2025-05-20 09:16:26 UTC ++++ build/rust/allocator/alias.h +@@ -0,0 +1,37 @@ ++// Copyright 2023 The Chromium Authors ++// Use of this source code is governed by a BSD-style license that can be ++// found in the LICENSE file. ++ ++// This file has been copied from //base/debug/alias.h (and then trimmed to just ++// the APIs / macros needed by //build/rust/std; additionally the APIs were ++// moved into the `build_rust_std` namespace). ++// ++// TODO(crbug.com/40279749): Avoid code duplication / reuse code. ++ ++#ifndef BUILD_RUST_ALLOCATOR_ALIAS_H_ ++#define BUILD_RUST_ALLOCATOR_ALIAS_H_ ++ ++#include ++ ++namespace build_rust_std { ++namespace debug { ++ ++// Make the optimizer think that |var| is aliased. This can be used to prevent a ++// local variable from being optimized out (which is something that ++// `NO_CODE_FOLDING` macro definition below depends on). See ++// //base/debug/alias.h for more details. ++void Alias(const void* var); ++ ++} // namespace debug ++ ++} // namespace build_rust_std ++ ++// Prevent code folding (where a linker identifies functions that are ++// bit-identical and overlays them, which saves space but it leads to confusing ++// call stacks because multiple symbols are at the same address). See ++// //base/debug/alias.h for more details. ++#define NO_CODE_FOLDING() \ ++ const int line_number = __LINE__; \ ++ build_rust_std::debug::Alias(&line_number) ++ ++#endif // BUILD_RUST_ALLOCATOR_ALIAS_H_ diff --git a/www/ungoogled-chromium/files/patch-build_rust_allocator_alloc__error__handler__impl.cc b/www/ungoogled-chromium/files/patch-build_rust_allocator_alloc__error__handler__impl.cc new file mode 100644 index 000000000000..048c267abefa --- /dev/null +++ b/www/ungoogled-chromium/files/patch-build_rust_allocator_alloc__error__handler__impl.cc @@ -0,0 +1,20 @@ +--- build/rust/allocator/alloc_error_handler_impl.cc.orig 2025-05-20 09:16:26 UTC ++++ build/rust/allocator/alloc_error_handler_impl.cc +@@ -0,0 +1,17 @@ ++// Copyright 2025 The Chromium Authors ++// Use of this source code is governed by a BSD-style license that can be ++// found in the LICENSE file. ++ ++#include "build/rust/allocator/alloc_error_handler_impl.h" ++ ++#include "build/rust/allocator/alias.h" ++#include "build/rust/allocator/immediate_crash.h" ++ ++namespace rust_allocator_internal { ++ ++void alloc_error_handler_impl() { ++ NO_CODE_FOLDING(); ++ IMMEDIATE_CRASH(); ++} ++ ++} // namespace rust_allocator_internal diff --git a/www/ungoogled-chromium/files/patch-build_rust_allocator_alloc__error__handler__impl.h b/www/ungoogled-chromium/files/patch-build_rust_allocator_alloc__error__handler__impl.h new file mode 100644 index 000000000000..887ea602b027 --- /dev/null +++ b/www/ungoogled-chromium/files/patch-build_rust_allocator_alloc__error__handler__impl.h @@ -0,0 +1,24 @@ +--- build/rust/allocator/alloc_error_handler_impl.h.orig 2025-05-20 09:16:26 UTC ++++ build/rust/allocator/alloc_error_handler_impl.h +@@ -0,0 +1,21 @@ ++// Copyright 2025 The Chromium Authors ++// Use of this source code is governed by a BSD-style license that can be ++// found in the LICENSE file. ++ ++#ifndef BUILD_RUST_ALLOCATOR_ALLOC_ERROR_HANDLER_IMPL_H_ ++#define BUILD_RUST_ALLOCATOR_ALLOC_ERROR_HANDLER_IMPL_H_ ++ ++// This header exposes to Rust a C++ implementation of quickly crashing after an ++// allocation error. (The API below is called from `__rust_alloc_error_handler` ++// in `lib.rs`.) ++// ++// TODO(lukasza): Investigate if we can delete this `.h` / `.cc` and just call ++// `std::process::abort()` (or something else?) directly from `.rs`. The main ++// open question is how much we care about `NO_CODE_FOLDING`. ++namespace rust_allocator_internal { ++ ++void alloc_error_handler_impl(); ++ ++} // namespace rust_allocator_internal ++ ++#endif // BUILD_RUST_ALLOCATOR_ALLOC_ERROR_HANDLER_IMPL_H_ diff --git a/www/ungoogled-chromium/files/patch-build_rust_allocator_allocator__impls.cc b/www/ungoogled-chromium/files/patch-build_rust_allocator_allocator__impls.cc new file mode 100644 index 000000000000..94e04d7b966a --- /dev/null +++ b/www/ungoogled-chromium/files/patch-build_rust_allocator_allocator__impls.cc @@ -0,0 +1,108 @@ +--- build/rust/allocator/allocator_impls.cc.orig 2025-05-20 09:16:26 UTC ++++ build/rust/allocator/allocator_impls.cc +@@ -0,0 +1,105 @@ ++// Copyright 2021 The Chromium Authors ++// Use of this source code is governed by a BSD-style license that can be ++// found in the LICENSE file. ++ ++#include "build/rust/allocator/allocator_impls.h" ++ ++#ifdef UNSAFE_BUFFERS_BUILD ++// TODO(crbug.com/390223051): Remove C-library calls to fix the errors. ++#pragma allow_unsafe_libc_calls ++#endif ++ ++#include ++#include ++ ++#include "build/build_config.h" ++#include "build/rust/allocator/buildflags.h" ++ ++#if BUILDFLAG(RUST_ALLOCATOR_USES_PARTITION_ALLOC) ++#include "partition_alloc/partition_alloc_constants.h" // nogncheck ++#include "partition_alloc/shim/allocator_shim.h" // nogncheck ++#elif BUILDFLAG(RUST_ALLOCATOR_USES_ALIGNED_MALLOC) ++#include ++#endif ++ ++namespace rust_allocator_internal { ++ ++unsigned char* alloc(size_t size, size_t align) { ++#if BUILDFLAG(RUST_ALLOCATOR_USES_PARTITION_ALLOC) ++ // PartitionAlloc will crash if given an alignment larger than this. ++ if (align > partition_alloc::internal::kMaxSupportedAlignment) { ++ return nullptr; ++ } ++ ++ // We use unchecked allocation paths in PartitionAlloc rather than going ++ // through its shims in `malloc()` etc so that we can support fallible ++ // allocation paths such as Vec::try_reserve without crashing on allocation ++ // failure. ++ if (align <= alignof(std::max_align_t)) { ++ return static_cast(allocator_shim::UncheckedAlloc(size)); ++ } else { ++ return static_cast( ++ allocator_shim::UncheckedAlignedAlloc(size, align)); ++ } ++#elif BUILDFLAG(RUST_ALLOCATOR_USES_ALIGNED_MALLOC) ++ return static_cast(_aligned_malloc(size, align)); ++#else ++#error This configuration is not supported. ++#endif ++} ++ ++void dealloc(unsigned char* p, size_t size, size_t align) { ++#if BUILDFLAG(RUST_ALLOCATOR_USES_PARTITION_ALLOC) ++ if (align <= alignof(std::max_align_t)) { ++ allocator_shim::UncheckedFree(p); ++ } else { ++ allocator_shim::UncheckedAlignedFree(p); ++ } ++#elif BUILDFLAG(RUST_ALLOCATOR_USES_ALIGNED_MALLOC) ++ return _aligned_free(p); ++#else ++#error This configuration is not supported. ++#endif ++} ++ ++unsigned char* realloc(unsigned char* p, ++ size_t old_size, ++ size_t align, ++ size_t new_size) { ++#if BUILDFLAG(RUST_ALLOCATOR_USES_PARTITION_ALLOC) ++ // We use unchecked allocation paths in PartitionAlloc rather than going ++ // through its shims in `malloc()` etc so that we can support fallible ++ // allocation paths such as Vec::try_reserve without crashing on allocation ++ // failure. ++ if (align <= alignof(std::max_align_t)) { ++ return static_cast( ++ allocator_shim::UncheckedRealloc(p, new_size)); ++ } else { ++ return static_cast( ++ allocator_shim::UncheckedAlignedRealloc(p, new_size, align)); ++ } ++#elif BUILDFLAG(RUST_ALLOCATOR_USES_ALIGNED_MALLOC) ++ return static_cast(_aligned_realloc(p, new_size, align)); ++#else ++#error This configuration is not supported. ++#endif ++} ++ ++unsigned char* alloc_zeroed(size_t size, size_t align) { ++#if BUILDFLAG(RUST_ALLOCATOR_USES_PARTITION_ALLOC) || \ ++ BUILDFLAG(RUST_ALLOCATOR_USES_ALIGNED_MALLOC) ++ // TODO(danakj): When RUST_ALLOCATOR_USES_PARTITION_ALLOC is true, it's ++ // possible that a partition_alloc::UncheckedAllocZeroed() call would perform ++ // better than partition_alloc::UncheckedAlloc() + memset. But there is no ++ // such API today. See b/342251590. ++ unsigned char* p = alloc(size, align); ++ if (p) { ++ memset(p, 0, size); ++ } ++ return p; ++#else ++#error This configuration is not supported. ++#endif ++} ++ ++} // namespace rust_allocator_internal diff --git a/www/ungoogled-chromium/files/patch-build_rust_allocator_allocator__impls.h b/www/ungoogled-chromium/files/patch-build_rust_allocator_allocator__impls.h new file mode 100644 index 000000000000..9249cdc938d2 --- /dev/null +++ b/www/ungoogled-chromium/files/patch-build_rust_allocator_allocator__impls.h @@ -0,0 +1,27 @@ +--- build/rust/allocator/allocator_impls.h.orig 2025-05-20 09:16:26 UTC ++++ build/rust/allocator/allocator_impls.h +@@ -0,0 +1,24 @@ ++// Copyright 2025 The Chromium Authors ++// Use of this source code is governed by a BSD-style license that can be ++// found in the LICENSE file. ++ ++#ifndef BUILD_RUST_ALLOCATOR_ALLOCATOR_IMPLS_H_ ++#define BUILD_RUST_ALLOCATOR_ALLOCATOR_IMPLS_H_ ++ ++#include ++ ++// This header exposes a C++ allocator (e.g. PartitionAlloc) to Rust. ++// The APIs below are called from `impl GlobalAlloc` in `lib.rs`. ++namespace rust_allocator_internal { ++ ++unsigned char* alloc(size_t size, size_t align); ++void dealloc(unsigned char* p, size_t size, size_t align); ++unsigned char* realloc(unsigned char* p, ++ size_t old_size, ++ size_t align, ++ size_t new_size); ++unsigned char* alloc_zeroed(size_t size, size_t align); ++ ++} // namespace rust_allocator_internal ++ ++#endif // BUILD_RUST_ALLOCATOR_ALLOCATOR_IMPLS_H_ diff --git a/www/ungoogled-chromium/files/patch-build_rust_allocator_allocator__impls__ffi.rs b/www/ungoogled-chromium/files/patch-build_rust_allocator_allocator__impls__ffi.rs new file mode 100644 index 000000000000..8f0baf1576ce --- /dev/null +++ b/www/ungoogled-chromium/files/patch-build_rust_allocator_allocator__impls__ffi.rs @@ -0,0 +1,22 @@ +--- build/rust/allocator/allocator_impls_ffi.rs.orig 2025-05-20 09:16:26 UTC ++++ build/rust/allocator/allocator_impls_ffi.rs +@@ -0,0 +1,19 @@ ++// Copyright 2025 The Chromium Authors ++// Use of this source code is governed by a BSD-style license that can be ++// found in the LICENSE file. ++ ++//! FFI for `allocator_impls.h` is in a separate `.rs` file/module to ++//! better support conditional compilation (these functions are only ++//! used under `#[cfg(rust_allocator_uses_allocator_impls_h)]`. ++ ++#[cxx::bridge(namespace = "rust_allocator_internal")] ++pub mod ffi { ++ extern "C++" { ++ include!("build/rust/allocator/allocator_impls.h"); ++ ++ unsafe fn alloc(size: usize, align: usize) -> *mut u8; ++ unsafe fn dealloc(p: *mut u8, size: usize, align: usize); ++ unsafe fn realloc(p: *mut u8, old_size: usize, align: usize, new_size: usize) -> *mut u8; ++ unsafe fn alloc_zeroed(size: usize, align: usize) -> *mut u8; ++ } ++} diff --git a/www/ungoogled-chromium/files/patch-build_rust_allocator_compiler__specific.h b/www/ungoogled-chromium/files/patch-build_rust_allocator_compiler__specific.h new file mode 100644 index 000000000000..7feb0c739d79 --- /dev/null +++ b/www/ungoogled-chromium/files/patch-build_rust_allocator_compiler__specific.h @@ -0,0 +1,41 @@ +--- build/rust/allocator/compiler_specific.h.orig 2025-05-20 09:16:26 UTC ++++ build/rust/allocator/compiler_specific.h +@@ -0,0 +1,38 @@ ++// Copyright 2023 The Chromium Authors ++// Use of this source code is governed by a BSD-style license that can be ++// found in the LICENSE file. ++ ++// This file has been copied from //base/compiler_specific.h (and then ++// significantly trimmed to just the APIs / macros needed by //build/rust/std). ++// ++// TODO(crbug.com/40279749): Avoid code duplication / reuse code. ++ ++#ifndef BUILD_RUST_ALLOCATOR_COMPILER_SPECIFIC_H_ ++#define BUILD_RUST_ALLOCATOR_COMPILER_SPECIFIC_H_ ++ ++#include "build/build_config.h" ++ ++#if defined(COMPILER_MSVC) && !defined(__clang__) ++#error "Only clang-cl is supported on Windows, see https://crbug.com/988071" ++#endif ++ ++#if defined(__has_attribute) ++#define HAS_ATTRIBUTE(x) __has_attribute(x) ++#else ++#define HAS_ATTRIBUTE(x) 0 ++#endif ++ ++// Annotate a function indicating it should not be inlined. ++// Use like: ++// NOINLINE void DoStuff() { ... } ++#if defined(__clang__) && HAS_ATTRIBUTE(noinline) ++#define NOINLINE [[clang::noinline]] ++#elif defined(COMPILER_GCC) && HAS_ATTRIBUTE(noinline) ++#define NOINLINE __attribute__((noinline)) ++#elif defined(COMPILER_MSVC) ++#define NOINLINE __declspec(noinline) ++#else ++#define NOINLINE ++#endif ++ ++#endif // BUILD_RUST_ALLOCATOR_COMPILER_SPECIFIC_H_ diff --git a/www/ungoogled-chromium/files/patch-build_rust_allocator_immediate__crash.h b/www/ungoogled-chromium/files/patch-build_rust_allocator_immediate__crash.h new file mode 100644 index 000000000000..7ab0f9d9c34c --- /dev/null +++ b/www/ungoogled-chromium/files/patch-build_rust_allocator_immediate__crash.h @@ -0,0 +1,174 @@ +--- build/rust/allocator/immediate_crash.h.orig 2025-05-20 09:16:26 UTC ++++ build/rust/allocator/immediate_crash.h +@@ -0,0 +1,171 @@ ++// Copyright 2021 The Chromium Authors ++// Use of this source code is governed by a BSD-style license that can be ++// found in the LICENSE file. ++ ++// This file has been copied from //base/immediate_crash.h. ++// TODO(crbug.com/40279749): Avoid code duplication / reuse code. ++ ++#ifndef BUILD_RUST_ALLOCATOR_IMMEDIATE_CRASH_H_ ++#define BUILD_RUST_ALLOCATOR_IMMEDIATE_CRASH_H_ ++ ++#include "build/build_config.h" ++ ++// Crashes in the fastest possible way with no attempt at logging. ++// There are several constraints; see http://crbug.com/664209 for more context. ++// ++// - TRAP_SEQUENCE_() must be fatal. It should not be possible to ignore the ++// resulting exception or simply hit 'continue' to skip over it in a debugger. ++// - Different instances of TRAP_SEQUENCE_() must not be folded together, to ++// ensure crash reports are debuggable. Unlike __builtin_trap(), asm volatile ++// blocks will not be folded together. ++// Note: TRAP_SEQUENCE_() previously required an instruction with a unique ++// nonce since unlike clang, GCC folds together identical asm volatile ++// blocks. ++// - TRAP_SEQUENCE_() must produce a signal that is distinct from an invalid ++// memory access. ++// - TRAP_SEQUENCE_() must be treated as a set of noreturn instructions. ++// __builtin_unreachable() is used to provide that hint here. clang also uses ++// this as a heuristic to pack the instructions in the function epilogue to ++// improve code density. ++// ++// Additional properties that are nice to have: ++// - TRAP_SEQUENCE_() should be as compact as possible. ++// - The first instruction of TRAP_SEQUENCE_() should not change, to avoid ++// shifting crash reporting clusters. As a consequence of this, explicit ++// assembly is preferred over intrinsics. ++// Note: this last bullet point may no longer be true, and may be removed in ++// the future. ++ ++// Note: TRAP_SEQUENCE Is currently split into two macro helpers due to the fact ++// that clang emits an actual instruction for __builtin_unreachable() on certain ++// platforms (see https://crbug.com/958675). In addition, the int3/bkpt/brk will ++// be removed in followups, so splitting it up like this now makes it easy to ++// land the followups. ++ ++#if defined(COMPILER_GCC) ++ ++#if BUILDFLAG(IS_NACL) ++ ++// Crash report accuracy is not guaranteed on NaCl. ++#define TRAP_SEQUENCE1_() __builtin_trap() ++#define TRAP_SEQUENCE2_() asm volatile("") ++ ++#elif defined(ARCH_CPU_X86_FAMILY) ++ ++// TODO(crbug.com/40625592): In theory, it should be possible to use just ++// int3. However, there are a number of crashes with SIGILL as the exception ++// code, so it seems likely that there's a signal handler that allows execution ++// to continue after SIGTRAP. ++#define TRAP_SEQUENCE1_() asm volatile("int3") ++ ++#if BUILDFLAG(IS_APPLE) ++// Intentionally empty: __builtin_unreachable() is always part of the sequence ++// (see IMMEDIATE_CRASH below) and already emits a ud2 on Mac. ++#define TRAP_SEQUENCE2_() asm volatile("") ++#else ++#define TRAP_SEQUENCE2_() asm volatile("ud2") ++#endif // BUILDFLAG(IS_APPLE) ++ ++#elif defined(ARCH_CPU_ARMEL) ++ ++// bkpt will generate a SIGBUS when running on armv7 and a SIGTRAP when running ++// as a 32 bit userspace app on arm64. There doesn't seem to be any way to ++// cause a SIGTRAP from userspace without using a syscall (which would be a ++// problem for sandboxing). ++// TODO(crbug.com/40625592): Remove bkpt from this sequence. ++#define TRAP_SEQUENCE1_() asm volatile("bkpt #0") ++#define TRAP_SEQUENCE2_() asm volatile("udf #0") ++ ++#elif defined(ARCH_CPU_ARM64) ++ ++// This will always generate a SIGTRAP on arm64. ++// TODO(crbug.com/40625592): Remove brk from this sequence. ++#define TRAP_SEQUENCE1_() asm volatile("brk #0") ++#define TRAP_SEQUENCE2_() asm volatile("hlt #0") ++ ++#else ++ ++// Crash report accuracy will not be guaranteed on other architectures, but at ++// least this will crash as expected. ++#define TRAP_SEQUENCE1_() __builtin_trap() ++#define TRAP_SEQUENCE2_() asm volatile("") ++ ++#endif // ARCH_CPU_* ++ ++#elif defined(COMPILER_MSVC) ++ ++#if !defined(__clang__) ++ ++// MSVC x64 doesn't support inline asm, so use the MSVC intrinsic. ++#define TRAP_SEQUENCE1_() __debugbreak() ++#define TRAP_SEQUENCE2_() ++ ++#elif defined(ARCH_CPU_ARM64) ++ ++// Windows ARM64 uses "BRK #F000" as its breakpoint instruction, and ++// __debugbreak() generates that in both VC++ and clang. ++#define TRAP_SEQUENCE1_() __debugbreak() ++// Intentionally empty: __builtin_unreachable() is always part of the sequence ++// (see IMMEDIATE_CRASH below) and already emits a ud2 on Win64, ++// https://crbug.com/958373 ++#define TRAP_SEQUENCE2_() __asm volatile("") ++ ++#else ++ ++#define TRAP_SEQUENCE1_() asm volatile("int3") ++#define TRAP_SEQUENCE2_() asm volatile("ud2") ++ ++#endif // __clang__ ++ ++#else ++ ++#error No supported trap sequence! ++ ++#endif // COMPILER_GCC ++ ++#define TRAP_SEQUENCE_() \ ++ do { \ ++ TRAP_SEQUENCE1_(); \ ++ TRAP_SEQUENCE2_(); \ ++ } while (false) ++ ++// CHECK() and the trap sequence can be invoked from a constexpr function. ++// This could make compilation fail on GCC, as it forbids directly using inline ++// asm inside a constexpr function. However, it allows calling a lambda ++// expression including the same asm. ++// The side effect is that the top of the stacktrace will not point to the ++// calling function, but to this anonymous lambda. This is still useful as the ++// full name of the lambda will typically include the name of the function that ++// calls CHECK() and the debugger will still break at the right line of code. ++#if !defined(COMPILER_GCC) || defined(__clang__) ++ ++#define WRAPPED_TRAP_SEQUENCE_() TRAP_SEQUENCE_() ++ ++#else ++ ++#define WRAPPED_TRAP_SEQUENCE_() \ ++ do { \ ++ [] { TRAP_SEQUENCE_(); }(); \ ++ } while (false) ++ ++#endif // !defined(COMPILER_GCC) || defined(__clang__) ++ ++#if defined(__clang__) || defined(COMPILER_GCC) ++ ++// __builtin_unreachable() hints to the compiler that this is noreturn and can ++// be packed in the function epilogue. ++#define IMMEDIATE_CRASH() \ ++ ({ \ ++ WRAPPED_TRAP_SEQUENCE_(); \ ++ __builtin_unreachable(); \ ++ }) ++ ++#else ++ ++// This is supporting non-chromium user of logging.h to build with MSVC, like ++// pdfium. On MSVC there is no __builtin_unreachable(). ++#define IMMEDIATE_CRASH() WRAPPED_TRAP_SEQUENCE_() ++ ++#endif // defined(__clang__) || defined(COMPILER_GCC) ++ ++#endif // BUILD_RUST_ALLOCATOR_IMMEDIATE_CRASH_H_ diff --git a/www/ungoogled-chromium/files/patch-build_rust_allocator_lib.rs b/www/ungoogled-chromium/files/patch-build_rust_allocator_lib.rs new file mode 100644 index 000000000000..89fddf278294 --- /dev/null +++ b/www/ungoogled-chromium/files/patch-build_rust_allocator_lib.rs @@ -0,0 +1,122 @@ +--- build/rust/allocator/lib.rs.orig 2025-05-20 09:16:26 UTC ++++ build/rust/allocator/lib.rs +@@ -0,0 +1,119 @@ ++// Copyright 2025 The Chromium Authors ++// Use of this source code is governed by a BSD-style license that can be ++// found in the LICENSE file. ++ ++//! Define the allocator that Rust code in Chrome should use. ++//! ++//! Any final artifact that depends on this crate, even transitively, will use ++//! the allocator defined here. ++//! ++//! List of known issues: ++//! ++//! 1. We'd like to use PartitionAlloc on Windows, but the stdlib uses Windows ++//! heap functions directly that PartitionAlloc can not intercept. ++//! 2. We'd like `Vec::try_reserve` to fail at runtime on Linux instead of ++//! crashing in malloc() where PartitionAlloc replaces that function. ++ ++// Required to apply weak linkage to symbols. ++// ++// TODO(https://crbug.com/410596442): Stop using unstable features here. ++// https://github.com/rust-lang/rust/issues/29603 tracks stabilization of the `linkage` feature. ++#![feature(linkage)] ++// Required to apply `#[rustc_std_internal_symbol]` to our alloc error handler ++// so the name is correctly mangled as rustc expects. ++// ++// TODO(https://crbug.com/410596442): Stop using internal features here. ++#![allow(internal_features)] ++#![feature(rustc_attrs)] ++ ++// This module is in a separate source file to avoid having to teach `cxxbridge` ++// about conditional compilation. ++#[cfg(rust_allocator_uses_allocator_impls_h)] ++mod allocator_impls_ffi; ++ ++/// Module that provides `#[global_allocator]` / `GlobalAlloc` interface for ++/// using an allocator from C++. ++#[cfg(rust_allocator_uses_allocator_impls_h)] ++mod cpp_allocator { ++ use super::allocator_impls_ffi::ffi; ++ use std::alloc::{GlobalAlloc, Layout}; ++ ++ struct Allocator; ++ ++ unsafe impl GlobalAlloc for Allocator { ++ unsafe fn alloc(&self, layout: Layout) -> *mut u8 { ++ unsafe { ffi::alloc(layout.size(), layout.align()) } ++ } ++ ++ unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) { ++ unsafe { ++ ffi::dealloc(ptr, layout.size(), layout.align()); ++ } ++ } ++ ++ unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 { ++ unsafe { ffi::alloc_zeroed(layout.size(), layout.align()) } ++ } ++ ++ unsafe fn realloc(&self, ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 { ++ unsafe { ffi::realloc(ptr, layout.size(), layout.align(), new_size) } ++ } ++ } ++ ++ #[global_allocator] ++ static GLOBAL: Allocator = Allocator; ++} ++ ++/// Module that provides `#[global_allocator]` / `GlobalAlloc` interface for ++/// using the default Rust allocator. ++#[cfg(not(rust_allocator_uses_allocator_impls_h))] ++mod rust_allocator { ++ #[global_allocator] ++ static GLOBAL: std::alloc::System = std::alloc::System; ++} ++ ++/// Module that provides global symbols that are needed both by `cpp_allocator` ++/// and `rust_allocator`. ++/// ++/// When `rustc` drives linking, then it will define the symbols below. But ++/// Chromium only uses `rustc` to link Rust-only executables (e.g. `build.rs` ++/// scripts) and otherwise uses a non-Rust linker. This is why we have to ++/// manually define a few symbols below. We define those symbols ++/// as "weak" symbols, so that Rust-provided symbols "win" in case where Rust ++/// actually does drive the linking. This hack works (not only for Chromium, ++/// but also for google3 and other projects), but isn't officially supported by ++/// `rustc`. ++/// ++/// TODO(https://crbug.com/410596442): Stop using internal features here. ++mod both_allocators { ++ /// As part of rustc's contract for using `#[global_allocator]` without ++ /// rustc-generated shims we must define this symbol, since we are opting in ++ /// to unstable functionality. See https://github.com/rust-lang/rust/issues/123015 ++ #[no_mangle] ++ #[linkage = "weak"] ++ static __rust_no_alloc_shim_is_unstable: u8 = 0; ++ ++ // Mangle the symbol name as rustc expects. ++ #[rustc_std_internal_symbol] ++ #[allow(non_upper_case_globals)] ++ #[linkage = "weak"] ++ static __rust_alloc_error_handler_should_panic: u8 = 0; ++ ++ // Mangle the symbol name as rustc expects. ++ #[rustc_std_internal_symbol] ++ #[allow(non_upper_case_globals)] ++ #[linkage = "weak"] ++ fn __rust_alloc_error_handler(_size: usize, _align: usize) { ++ // TODO(lukasza): Investigate if we can just call `std::process::abort()` here. ++ // (Not really _needed_, but it could simplify code a little bit.) ++ unsafe { ffi::alloc_error_handler_impl() } ++ } ++ ++ #[cxx::bridge(namespace = "rust_allocator_internal")] ++ mod ffi { ++ extern "C++" { ++ include!("build/rust/allocator/alloc_error_handler_impl.h"); ++ unsafe fn alloc_error_handler_impl(); ++ } ++ } ++} diff --git a/www/ungoogled-chromium/files/patch-build_rust_cargo__crate.gni b/www/ungoogled-chromium/files/patch-build_rust_cargo__crate.gni new file mode 100644 index 000000000000..a1590f727aa3 --- /dev/null +++ b/www/ungoogled-chromium/files/patch-build_rust_cargo__crate.gni @@ -0,0 +1,25 @@ +--- build/rust/cargo_crate.gni.orig 2025-05-20 09:16:26 UTC ++++ build/rust/cargo_crate.gni +@@ -259,6 +259,12 @@ template("cargo_crate") { + # Don't import the `chromium` crate into third-party code. + no_chromium_prelude = true + ++ # Don't depend on the chrome-specific #[global_allocator] crate from ++ # third-party code. This avoids some dependency cycle issues. The allocator ++ # crate will still be used if it exists anywhere in the dependency graph for ++ # a given linked artifact. ++ no_allocator_crate = true ++ + rustc_metadata = _rustc_metadata + + # TODO(crbug.com/40259764): don't default to true. This requires changes to +@@ -482,6 +488,9 @@ template("cargo_crate") { + + # Don't import the `chromium` crate into third-party code. + no_chromium_prelude = true ++ ++ # Build scripts do not need to link to chrome's allocator. ++ no_allocator_crate = true + + # The ${_build_script_name}_output target looks for the exe in this + # location. Due to how the Windows component build works, this has to diff --git a/www/ungoogled-chromium/files/patch-build_rust_rust__macro.gni b/www/ungoogled-chromium/files/patch-build_rust_rust__macro.gni new file mode 100644 index 000000000000..0dafc3819aa1 --- /dev/null +++ b/www/ungoogled-chromium/files/patch-build_rust_rust__macro.gni @@ -0,0 +1,12 @@ +--- build/rust/rust_macro.gni.orig 2025-05-20 09:16:26 UTC ++++ build/rust/rust_macro.gni +@@ -16,6 +16,9 @@ template("rust_macro") { + forward_variables_from(invoker, TESTONLY_AND_VISIBILITY) + proc_macro_configs = invoker.configs + target_type = "rust_proc_macro" ++ ++ # Macros are loaded by rustc and shouldn't use chrome's allocation routines. ++ no_allocator_crate = true + } + } + diff --git a/www/ungoogled-chromium/files/patch-build_rust_rust__target.gni b/www/ungoogled-chromium/files/patch-build_rust_rust__target.gni new file mode 100644 index 000000000000..f4ad6f04fc45 --- /dev/null +++ b/www/ungoogled-chromium/files/patch-build_rust_rust__target.gni @@ -0,0 +1,13 @@ +--- build/rust/rust_target.gni.orig 2025-05-20 09:16:26 UTC ++++ build/rust/rust_target.gni +@@ -339,6 +339,10 @@ template("rust_target") { + _rust_deps += [ "//build/rust/std" ] + } + ++ if (!defined(invoker.no_allocator_crate) || !invoker.no_allocator_crate) { ++ _rust_deps += [ "//build/rust/allocator" ] ++ } ++ + if (_build_unit_tests) { + _unit_test_target = "${_target_name}_unittests" + if (defined(invoker.unit_test_target)) { diff --git a/www/ungoogled-chromium/files/patch-build_rust_std_BUILD.gn b/www/ungoogled-chromium/files/patch-build_rust_std_BUILD.gn index 0a5335d58d48..c6c2801bd47d 100644 --- a/www/ungoogled-chromium/files/patch-build_rust_std_BUILD.gn +++ b/www/ungoogled-chromium/files/patch-build_rust_std_BUILD.gn @@ -1,32 +1,106 @@ ---- build/rust/std/BUILD.gn.orig 2025-04-05 13:54:50 UTC +--- build/rust/std/BUILD.gn.orig 2025-05-20 09:16:26 UTC +++ build/rust/std/BUILD.gn -@@ -89,13 +89,20 @@ if (toolchain_has_rust) { +@@ -15,51 +15,12 @@ + # allocator functions to PartitionAlloc when `use_partition_alloc_as_malloc` is + # true, so that Rust and C++ use the same allocator backend. + +-import("//build/buildflag_header.gni") + import("//build/config/compiler/compiler.gni") + import("//build/config/coverage/coverage.gni") + import("//build/config/rust.gni") + import("//build/config/sanitizers/sanitizers.gni") + +-rust_allocator_uses_partition_alloc = false +-if (build_with_chromium) { +- import("//base/allocator/partition_allocator/partition_alloc.gni") +- rust_allocator_uses_partition_alloc = use_partition_alloc_as_malloc +-} +- +-buildflag_header("buildflags") { +- header = "buildflags.h" +- flags = [ +- "RUST_ALLOCATOR_USES_PARTITION_ALLOC=$rust_allocator_uses_partition_alloc", +- ] +- visibility = [ ":*" ] +-} +- + if (toolchain_has_rust) { +- # If clang performs the link step, we need to provide the allocator symbols +- # that are normally injected by rustc during linking. +- # +- # We also "happen to" use this to redirect allocations to PartitionAlloc, +- # though that would be better done through a #[global_allocator] crate (see +- # above). +- source_set("remap_alloc") { +- public_deps = [] +- if (rust_allocator_uses_partition_alloc) { +- public_deps += [ "//base/allocator/partition_allocator:partition_alloc" ] +- } +- deps = [ ":buildflags" ] +- sources = [ +- # `alias.*`, `compiler_specific.h`, and `immediate_crash.*` have been +- # copied from `//base`. +- # TODO(crbug.com/40279749): Avoid duplication / reuse code. +- "alias.cc", +- "alias.h", +- "compiler_specific.h", +- "immediate_crash.h", +- "remap_alloc.cc", +- ] +- } +- + # List of Rust stdlib rlibs which are present in the official Rust toolchain + # we are using from the Android team. This is usually a version or two behind + # nightly. Generally this matches the toolchain we build ourselves, but if +@@ -89,13 +50,20 @@ if (toolchain_has_rust) { # These are no longer present in the Windows toolchain. stdlib_files += [ "addr2line", - "adler2", "gimli", "libc", "memchr", "miniz_oxide", "object", ] + + rust_revision_pieces = string_split(rustc_revision, " ") + rust_version_pieces = string_split(rust_revision_pieces[1], ".") + if (rust_version_pieces[1] == "85") { + stdlib_files += [ "adler" ] + } else { + stdlib_files += [ "adler2" ] + } } if (toolchain_for_rust_host_build_tools) { -@@ -115,7 +122,6 @@ if (toolchain_has_rust) { +@@ -115,7 +83,6 @@ if (toolchain_has_rust) { # don't need to pass to the C++ linker because they're used for specialized # purposes. skip_stdlib_files = [ - "profiler_builtins", "rustc_std_workspace_alloc", "rustc_std_workspace_core", "rustc_std_workspace_std", +@@ -269,8 +236,6 @@ if (toolchain_has_rust) { + foreach(libname, stdlib_files + skip_stdlib_files) { + deps += [ "rules:$libname" ] + } +- +- public_deps = [ ":remap_alloc" ] + } + } else { + action("find_stdlib") { +@@ -396,12 +361,6 @@ if (toolchain_has_rust) { + ":stdlib_public_dependent_libs", + ] + deps = [ ":prebuilt_rustc_copy_to_sysroot" ] +- +- # The host builds tools toolchain supports Rust only and does not use +- # the allocator remapping to point it to PartitionAlloc. +- if (!toolchain_for_rust_host_build_tools) { +- deps += [ ":remap_alloc" ] +- } + } + } + }