New package: electron35-35.7.2

This commit is contained in:
Duncaen 2025-07-19 00:02:44 +02:00
parent 25c69b90a6
commit f24e8a0101
No known key found for this signature in database
GPG key ID: 335C1D17EC3D6E35
48 changed files with 3111 additions and 0 deletions

1
srcpkgs/electron35-devel Symbolic link
View file

@ -0,0 +1 @@
electron35

View file

@ -0,0 +1,11 @@
--- a/buildtools/third_party/libc++/__config_site
+++ b/buildtools/third_party/libc++/__config_site
@@ -25,7 +25,7 @@
#define _LIBCPP_HAS_THREADS 1
#define _LIBCPP_HAS_MONOTONIC_CLOCK 1
#define _LIBCPP_HAS_TERMINAL 1
-#define _LIBCPP_HAS_MUSL_LIBC 0
+#define _LIBCPP_HAS_MUSL_LIBC 1
#ifdef _WIN32
#define _LIBCPP_HAS_THREAD_API_PTHREAD 0

View file

@ -0,0 +1,125 @@
Source: https://git.alpinelinux.org/aports/tree/community/chromium/musl-sandbox.patch
musl uses different syscalls from glibc for some functions, so the sandbox has
to account for that
--
diff --git a/sandbox/linux/seccomp-bpf-helpers/syscall_parameters_restrictions.cc ./sandbox/linux/seccomp-bpf-helpers/syscall_parameters_restrictions.cc
index ff5a1c0..da56b9b 100644
--- a/sandbox/linux/seccomp-bpf-helpers/syscall_parameters_restrictions.cc
+++ ./sandbox/linux/seccomp-bpf-helpers/syscall_parameters_restrictions.cc
@@ -139,21 +139,11 @@ namespace sandbox {
// present (as in newer versions of posix_spawn).
ResultExpr RestrictCloneToThreadsAndEPERMFork() {
const Arg<unsigned long> flags(0);
-
- // TODO(mdempsky): Extend DSL to support (flags & ~mask1) == mask2.
- const uint64_t kAndroidCloneMask = CLONE_VM | CLONE_FS | CLONE_FILES |
- CLONE_SIGHAND | CLONE_THREAD |
- CLONE_SYSVSEM;
- const uint64_t kObsoleteAndroidCloneMask = kAndroidCloneMask | CLONE_DETACHED;
-
- const uint64_t kGlibcPthreadFlags =
- CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGHAND | CLONE_THREAD |
- CLONE_SYSVSEM | CLONE_SETTLS | CLONE_PARENT_SETTID | CLONE_CHILD_CLEARTID;
- const BoolExpr glibc_test = flags == kGlibcPthreadFlags;
-
- const BoolExpr android_test =
- AnyOf(flags == kAndroidCloneMask, flags == kObsoleteAndroidCloneMask,
- flags == kGlibcPthreadFlags);
+ const int required = CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGHAND |
+ CLONE_THREAD | CLONE_SYSVSEM;
+ const int safe = CLONE_SETTLS | CLONE_PARENT_SETTID | CLONE_CHILD_CLEARTID |
+ CLONE_DETACHED;
+ const BoolExpr thread_clone_ok = (flags&~safe)==required;
// The following two flags are the two important flags in any vfork-emulating
// clone call. EPERM any clone call that contains both of them.
@@ -163,7 +153,7 @@ ResultExpr RestrictCloneToThreadsAndEPERMFork() {
AnyOf((flags & (CLONE_VM | CLONE_THREAD)) == 0,
(flags & kImportantCloneVforkFlags) == kImportantCloneVforkFlags);
- return If(IsAndroid() ? android_test : glibc_test, Allow())
+ return If(thread_clone_ok, Allow())
.ElseIf(is_fork_or_clone_vfork, Error(EPERM))
.Else(CrashSIGSYSClone());
}
diff --git a/sandbox/linux/seccomp-bpf-helpers/syscall_sets.cc ./sandbox/linux/seccomp-bpf-helpers/syscall_sets.cc
index d9d1882..0567557 100644
--- a/sandbox/linux/seccomp-bpf-helpers/syscall_sets.cc
+++ ./sandbox/linux/seccomp-bpf-helpers/syscall_sets.cc
@@ -392,6 +392,7 @@ bool SyscallSets::IsAllowedProcessStartOrDeath(int sysno) {
#if defined(__i386__)
case __NR_waitpid:
#endif
+ case __NR_set_tid_address:
return true;
case __NR_clone: // Should be parameter-restricted.
case __NR_setns: // Privileged.
@@ -404,7 +405,6 @@ bool SyscallSets::IsAllowedProcessStartOrDeath(int sysno) {
#if defined(__i386__) || defined(__x86_64__) || defined(__mips__)
case __NR_set_thread_area:
#endif
- case __NR_set_tid_address:
case __NR_unshare:
#if !defined(__mips__) && !defined(__aarch64__)
case __NR_vfork:
@@ -514,6 +514,8 @@ bool SyscallSets::IsAllowedAddressSpaceAccess(int sysno) {
case __NR_munlock:
case __NR_munmap:
case __NR_mseal:
+ case __NR_mremap:
+ case __NR_membarrier:
return true;
case __NR_madvise:
case __NR_mincore:
@@ -531,7 +533,6 @@ bool SyscallSets::IsAllowedAddressSpaceAccess(int sysno) {
case __NR_modify_ldt:
#endif
case __NR_mprotect:
- case __NR_mremap:
case __NR_msync:
case __NR_munlockall:
case __NR_readahead:
diff --git a/sandbox/linux/system_headers/linux_syscalls.h ./sandbox/linux/system_headers/linux_syscalls.h
index 2b78a0c..b6fedb5 100644
--- a/sandbox/linux/system_headers/linux_syscalls.h
+++ b/sandbox/linux/system_headers/linux_syscalls.h
@@ -10,6 +10,7 @@
#define SANDBOX_LINUX_SYSTEM_HEADERS_LINUX_SYSCALLS_H_
#include "build/build_config.h"
+#include <sys/syscall.h>
#if defined(__x86_64__)
#include "sandbox/linux/system_headers/x86_64_linux_syscalls.h"
--- a/sandbox/policy/linux/bpf_renderer_policy_linux.cc
+++ b/sandbox/policy/linux/bpf_renderer_policy_linux.cc
@@ -94,6 +94,9 @@
case __NR_pwrite64:
case __NR_sched_get_priority_max:
case __NR_sched_get_priority_min:
+ case __NR_sched_getparam:
+ case __NR_sched_getscheduler:
+ case __NR_sched_setscheduler:
case __NR_sysinfo:
case __NR_times:
case __NR_uname:
--- a/sandbox/linux/seccomp-bpf-helpers/baseline_policy.cc
+++ b/sandbox/linux/seccomp-bpf-helpers/baseline_policy.cc
@@ -225,10 +225,15 @@
if (sysno == __NR_getpriority || sysno ==__NR_setpriority)
return RestrictGetSetpriority(current_pid);
+ // XXX: hacks for musl sandbox, calls needed?
+ if (sysno == __NR_sched_getparam || sysno == __NR_sched_getscheduler ||
+ sysno == __NR_sched_setscheduler) {
+ return Allow();
+ }
+
// The scheduling syscalls are used in threading libraries and also heavily in
// abseil. See for example https://crbug.com/1370394.
- if (sysno == __NR_sched_getaffinity || sysno == __NR_sched_getparam ||
- sysno == __NR_sched_getscheduler || sysno == __NR_sched_setscheduler) {
+ if (sysno == __NR_sched_getaffinity) {
return RestrictSchedTarget(current_pid, sysno);
}

View file

@ -0,0 +1,86 @@
Source: https://git.alpinelinux.org/aports/plain/community/chromium/musl-tid-caching.patch
the sandbox caching of thread id's only works with glibc
see: https://gitlab.alpinelinux.org/alpine/aports/-/merge_requests/32356
see: https://gitlab.alpinelinux.org/alpine/aports/-/issues/13579
--
--- a/sandbox/linux/services/namespace_sandbox.cc
+++ b/sandbox/linux/services/namespace_sandbox.cc
@@ -209,6 +209,70 @@
return base::LaunchProcess(argv, launch_options_copy);
}
+#if defined(__aarch64__) || defined(__arm__) || defined(__powerpc__)
+#define TLS_ABOVE_TP
+#endif
+
+struct musl_pthread
+{
+ /* Part 1 -- these fields may be external or
+ * internal (accessed via asm) ABI. Do not change. */
+ struct pthread *self;
+#ifndef TLS_ABOVE_TP
+ uintptr_t *dtv;
+#endif
+ struct pthread *prev, *next; /* non-ABI */
+ uintptr_t sysinfo;
+#ifndef TLS_ABOVE_TP
+#ifdef CANARY_PAD
+ uintptr_t canary_pad;
+#endif
+ uintptr_t canary;
+#endif
+
+/* Part 2 -- implementation details, non-ABI. */
+ int tid;
+ int errno_val;
+ volatile int detach_state;
+ volatile int cancel;
+ volatile unsigned char canceldisable, cancelasync;
+ unsigned char tsd_used:1;
+ unsigned char dlerror_flag:1;
+ unsigned char *map_base;
+ size_t map_size;
+ void *stack;
+ size_t stack_size;
+ size_t guard_size;
+ void *result;
+ struct __ptcb *cancelbuf;
+ void **tsd;
+ struct {
+ volatile void *volatile head;
+ long off;
+ volatile void *volatile pending;
+ } robust_list;
+ int h_errno_val;
+ volatile int timer_id;
+ locale_t locale;
+ volatile int killlock[1];
+ char *dlerror_buf;
+ void *stdio_locks;
+
+ /* Part 3 -- the positions of these fields relative to
+ * the end of the structure is external and internal ABI. */
+#ifdef TLS_ABOVE_TP
+ uintptr_t canary;
+ uintptr_t *dtv;
+#endif
+};
+
+void MaybeUpdateMuslTidCache()
+{
+ pid_t real_tid = sys_gettid();
+ pid_t* cached_tid_location = &reinterpret_cast<struct musl_pthread*>(pthread_self())->tid;
+ *cached_tid_location = real_tid;
+}
+
// static
pid_t NamespaceSandbox::ForkInNewPidNamespace(bool drop_capabilities_in_child) {
const pid_t pid =
@@ -226,6 +290,7 @@
#if defined(LIBC_GLIBC)
MaybeUpdateGlibcTidCache();
#endif
+ MaybeUpdateMuslTidCache();
return 0;
}

View file

@ -0,0 +1,33 @@
Source: https://git.alpinelinux.org/aports/plain/community/chromium/no-res-ninit-nclose.patch
similar to dns-resolver.patch, musl doesn't have res_ninit and so on
--
--- a/net/dns/public/scoped_res_state.cc
+++ b/net/dns/public/scoped_res_state.cc
@@ -13,7 +13,7 @@
namespace net {
ScopedResState::ScopedResState() {
-#if BUILDFLAG(IS_OPENBSD) || BUILDFLAG(IS_FUCHSIA)
+#if BUILDFLAG(IS_OPENBSD) || BUILDFLAG(IS_FUCHSIA) || defined(_GNU_SOURCE)
// Note: res_ninit in glibc always returns 0 and sets RES_INIT.
// res_init behaves the same way.
memset(&_res, 0, sizeof(_res));
@@ -25,16 +25,8 @@
}
ScopedResState::~ScopedResState() {
-#if !BUILDFLAG(IS_OPENBSD) && !BUILDFLAG(IS_FUCHSIA)
-
- // Prefer res_ndestroy where available.
-#if BUILDFLAG(IS_APPLE) || BUILDFLAG(IS_FREEBSD)
- res_ndestroy(&res_);
-#else
- res_nclose(&res_);
-#endif // BUILDFLAG(IS_APPLE) || BUILDFLAG(IS_FREEBSD)
-
-#endif // !BUILDFLAG(IS_OPENBSD) && !BUILDFLAG(IS_FUCHSIA)
+ // musl res_init() doesn't actually do anything
+ // no destruction is necessary as no memory has been allocated
}
bool ScopedResState::IsValid() const {

View file

@ -0,0 +1,730 @@
From c854a92a215d0cf39c704bbadd3611e552073d5f Mon Sep 17 00:00:00 2001
From: Collin Baker <collinbaker@chromium.org>
Date: Fri, 4 Apr 2025 14:08:18 -0700
Subject: [PATCH] Reland "Use #[global_allocator] to provide Rust allocator
implementation"
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
This is a reland of commit cfa3beef52625e03ba6ce2b2ac98e1b89dde5cdb
Original was reverted due to a cronet gn2bp failure. The script
filtered out GN rules in //build/rust/std, but this caused an exception
when //build/rust/std:allocator was referenced later.
Moving the rules to //build/rust/allocator sidesteps the issue.
Original change's description:
> Use #[global_allocator] to provide Rust allocator implementation
>
> The allocator shim hack we have been using no longer works with
> upstream Rust. Replace it with a less-unsupported method: provide a
> https://github.com/rust-lang/rust/issues/123015, which still requires
> us to provide a few symbol definitions.
>
> Bug: 408221149, 407024458
> Change-Id: If1808ca24b12dc80ead35a25521313a3d2e148d5
>
> Cq-Include-Trybots: luci.chromium.try:android-rust-arm32-rel,android-rust-arm64-dbg,android-rust-arm64-rel,linux-rust-x64-dbg,linux-rust-x64-rel,mac-rust-x64-dbg,win-rust-x64-dbg,win-rust-x64-rel
> Change-Id: If1808ca24b12dc80ead35a25521313a3d2e148d5
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6427855
> Reviewed-by: Alan Zhao <ayzhao@google.com>
> Reviewed-by: Lei Zhang <thestig@chromium.org>
> Reviewed-by: Łukasz Anforowicz <lukasza@chromium.org>
> Commit-Queue: Collin Baker <collinbaker@chromium.org>
> Auto-Submit: Collin Baker <collinbaker@chromium.org>
> Cr-Commit-Position: refs/heads/main@{#1442472}
Bug: 408221149, 407024458
Cq-Include-Trybots: luci.chromium.try:android-rust-arm32-rel,android-rust-arm64-dbg,android-rust-arm64-rel,linux-rust-x64-dbg,linux-rust-x64-rel,mac-rust-x64-dbg,win-rust-x64-dbg,win-rust-x64-rel
Change-Id: I36fef217297bfe64ae81519be24b8c653f6fdfa1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6432410
Reviewed-by: Mohannad Farrag <aymanm@google.com>
Reviewed-by: Łukasz Anforowicz <lukasza@chromium.org>
Auto-Submit: Collin Baker <collinbaker@chromium.org>
Commit-Queue: Łukasz Anforowicz <lukasza@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1442922}
---
build/rust/allocator/BUILD.gn | 90 ++++++++++++++++
build/rust/{std => allocator}/alias.cc | 4 +-
build/rust/{std => allocator}/alias.h | 6 +-
.../allocator_impls.cc} | 100 ++++++++----------
build/rust/allocator/allocator_impls.h | 25 +++++
.../allocator/allocator_shim_definitions.cc | 30 ++++++
.../{std => allocator}/compiler_specific.h | 6 +-
.../rust/{std => allocator}/immediate_crash.h | 6 +-
build/rust/allocator/lib.rs | 48 +++++++++
build/rust/cargo_crate.gni | 9 ++
build/rust/rust_macro.gni | 3 +
build/rust/rust_target.gni | 4 +
build/rust/std/BUILD.gn | 41 -------
components/cronet/android/dependencies.txt | 1 +
third_party/breakpad/BUILD.gn | 10 +-
15 files changed, 272 insertions(+), 111 deletions(-)
create mode 100644 build/rust/allocator/BUILD.gn
rename build/rust/{std => allocator}/alias.cc (87%)
rename build/rust/{std => allocator}/alias.h (91%)
rename build/rust/{std/remap_alloc.cc => allocator/allocator_impls.cc} (67%)
create mode 100644 build/rust/allocator/allocator_impls.h
create mode 100644 build/rust/allocator/allocator_shim_definitions.cc
rename build/rust/{std => allocator}/compiler_specific.h (87%)
rename build/rust/{std => allocator}/immediate_crash.h (97%)
create mode 100644 build/rust/allocator/lib.rs
diff --git a/build/rust/allocator/BUILD.gn b/build/rust/allocator/BUILD.gn
new file mode 100644
index 0000000000000..06aa47f097c9c
--- /dev/null
+++ b/build/rust/allocator/BUILD.gn
@@ -0,0 +1,90 @@
+# 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
+}
+
+buildflag_header("buildflags") {
+ header = "buildflags.h"
+ flags = [
+ "RUST_ALLOCATOR_USES_PARTITION_ALLOC=$rust_allocator_uses_partition_alloc",
+ ]
+ 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 = [
+ ":allocator_impls",
+ ":allocator_shim_definitions",
+ ]
+
+ no_chromium_prelude = true
+ no_allocator_crate = true
+ allow_unsafe = true
+ }
+
+ 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 = [
+ ":allocator_cpp_shared",
+ ":buildflags",
+
+ # TODO(crbug.com/408221149): remove the C++ -> Rust dependency for the
+ # default allocator.
+ "//build/rust/std",
+ ]
+
+ visibility = [ ":*" ]
+ }
+
+ source_set("allocator_shim_definitions") {
+ sources = [ "allocator_shim_definitions.cc" ]
+
+ deps = [ ":allocator_cpp_shared" ]
+
+ visibility = [ ":*" ]
+ }
+
+ source_set("allocator_cpp_shared") {
+ 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",
+ ]
+
+ visibility = [
+ ":allocator_impls",
+ ":allocator_shim_definitions",
+ ]
+ }
+}
diff --git a/build/rust/std/alias.cc b/build/rust/allocator/alias.cc
similarity index 87%
rename from build/rust/std/alias.cc
rename to build/rust/allocator/alias.cc
index 42febac3ed1fc..ca20986f8ed49 100644
--- a/build/rust/std/alias.cc
+++ b/build/rust/allocator/alias.cc
@@ -7,9 +7,9 @@
//
// TODO(crbug.com/40279749): Avoid code duplication / reuse code.
-#include "build/rust/std/alias.h"
+#include "build/rust/allocator/alias.h"
-#include "build/rust/std/compiler_specific.h"
+#include "build/rust/allocator/compiler_specific.h"
namespace build_rust_std {
namespace debug {
diff --git a/build/rust/std/alias.h b/build/rust/allocator/alias.h
similarity index 91%
rename from build/rust/std/alias.h
rename to build/rust/allocator/alias.h
index 0eaba6766148f..80995ecfb045e 100644
--- a/build/rust/std/alias.h
+++ b/build/rust/allocator/alias.h
@@ -8,8 +8,8 @@
//
// TODO(crbug.com/40279749): Avoid code duplication / reuse code.
-#ifndef BUILD_RUST_STD_ALIAS_H_
-#define BUILD_RUST_STD_ALIAS_H_
+#ifndef BUILD_RUST_ALLOCATOR_ALIAS_H_
+#define BUILD_RUST_ALLOCATOR_ALIAS_H_
#include <stddef.h>
@@ -34,4 +34,4 @@ void Alias(const void* var);
const int line_number = __LINE__; \
build_rust_std::debug::Alias(&line_number)
-#endif // BUILD_RUST_STD_ALIAS_H_
+#endif // BUILD_RUST_ALLOCATOR_ALIAS_H_
diff --git a/build/rust/std/remap_alloc.cc b/build/rust/allocator/allocator_impls.cc
similarity index 67%
rename from build/rust/std/remap_alloc.cc
rename to build/rust/allocator/allocator_impls.cc
index a443b11ec513d..1fde98f23cd12 100644
--- a/build/rust/std/remap_alloc.cc
+++ b/build/rust/allocator/allocator_impls.cc
@@ -2,6 +2,8 @@
// 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
@@ -11,9 +13,9 @@
#include <cstring>
#include "build/build_config.h"
-#include "build/rust/std/alias.h"
-#include "build/rust/std/buildflags.h"
-#include "build/rust/std/immediate_crash.h"
+#include "build/rust/allocator/alias.h"
+#include "build/rust/allocator/buildflags.h"
+#include "build/rust/allocator/immediate_crash.h"
#if BUILDFLAG(RUST_ALLOCATOR_USES_PARTITION_ALLOC)
#include "partition_alloc/partition_alloc_constants.h" // nogncheck
@@ -22,6 +24,11 @@
#include <cstdlib>
#endif
+// NOTE: this documentation is outdated.
+//
+// TODO(crbug.com/408221149): update this documentation, or replace it with docs
+// in the Rust allocator implementation.
+//
// When linking a final binary, rustc has to pick between either:
// * The default Rust allocator
// * Any #[global_allocator] defined in *any rlib in its dependency tree*
@@ -87,19 +94,6 @@
// enabling it breaks Win32 APIs like CreateProcess:
// https://issues.chromium.org/u/1/issues/368070343#comment29
-extern "C" {
-
-#ifdef COMPONENT_BUILD
-#if BUILDFLAG(IS_WIN)
-#define REMAP_ALLOC_ATTRIBUTES __declspec(dllexport) __attribute__((weak))
-#else
-#define REMAP_ALLOC_ATTRIBUTES \
- __attribute__((visibility("default"))) __attribute__((weak))
-#endif
-#else
-#define REMAP_ALLOC_ATTRIBUTES __attribute__((weak))
-#endif // COMPONENT_BUILD
-
#if !BUILDFLAG(RUST_ALLOCATOR_USES_PARTITION_ALLOC) && BUILDFLAG(IS_WIN) && \
defined(ADDRESS_SANITIZER)
#define USE_WIN_ALIGNED_MALLOC 1
@@ -107,17 +101,19 @@ extern "C" {
#define USE_WIN_ALIGNED_MALLOC 0
#endif
-// This must exist as the stdlib depends on it to prove that we know the
-// alloc shims below are unstable. In the future we may be required to replace
-// them with a #[global_allocator] crate (see file comment above for more).
-//
-// Marked as weak as when Rust drives linking it includes this symbol itself,
-// and we don't want a collision due to C++ being in the same link target, where
-// C++ causes us to explicitly link in the stdlib and this symbol here.
-[[maybe_unused]]
-__attribute__((weak)) unsigned char __rust_no_alloc_shim_is_unstable;
+// The default allocator functions provided by the Rust standard library.
+extern "C" void* __rdl_alloc(size_t size, size_t align);
+extern "C" void __rdl_dealloc(void* p, size_t size, size_t align);
+extern "C" void* __rdl_realloc(void* p,
+ size_t old_size,
+ size_t align,
+ size_t new_size);
+
+extern "C" void* __rdl_alloc_zeroed(size_t size, size_t align);
+
+namespace rust_allocator_internal {
-REMAP_ALLOC_ATTRIBUTES void* __rust_alloc(size_t size, size_t align) {
+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) {
@@ -125,19 +121,19 @@ REMAP_ALLOC_ATTRIBUTES void* __rust_alloc(size_t size, size_t align) {
}
if (align <= alignof(std::max_align_t)) {
- return allocator_shim::UncheckedAlloc(size);
+ return static_cast<unsigned char*>(allocator_shim::UncheckedAlloc(size));
} else {
- return allocator_shim::UncheckedAlignedAlloc(size, align);
+ return static_cast<unsigned char*>(
+ allocator_shim::UncheckedAlignedAlloc(size, align));
}
#elif USE_WIN_ALIGNED_MALLOC
- return _aligned_malloc(size, align);
+ return static_cast<unsigned char*>(_aligned_malloc(size, align));
#else
- extern void* __rdl_alloc(size_t size, size_t align);
- return __rdl_alloc(size, align);
+ return static_cast<unsigned char*>(__rdl_alloc(size, align));
#endif
}
-REMAP_ALLOC_ATTRIBUTES void __rust_dealloc(void* p, size_t size, size_t align) {
+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);
@@ -147,54 +143,44 @@ REMAP_ALLOC_ATTRIBUTES void __rust_dealloc(void* p, size_t size, size_t align) {
#elif USE_WIN_ALIGNED_MALLOC
return _aligned_free(p);
#else
- extern void __rdl_dealloc(void* p, size_t size, size_t align);
__rdl_dealloc(p, size, align);
#endif
}
-REMAP_ALLOC_ATTRIBUTES void* __rust_realloc(void* p,
- size_t old_size,
- size_t align,
- size_t new_size) {
+unsigned char* realloc(unsigned char* p,
+ size_t old_size,
+ size_t align,
+ size_t new_size) {
#if BUILDFLAG(RUST_ALLOCATOR_USES_PARTITION_ALLOC)
if (align <= alignof(std::max_align_t)) {
- return allocator_shim::UncheckedRealloc(p, new_size);
+ return static_cast<unsigned char*>(
+ allocator_shim::UncheckedRealloc(p, new_size));
} else {
- return allocator_shim::UncheckedAlignedRealloc(p, new_size, align);
+ return static_cast<unsigned char*>(
+ allocator_shim::UncheckedAlignedRealloc(p, new_size, align));
}
#elif USE_WIN_ALIGNED_MALLOC
- return _aligned_realloc(p, new_size, align);
+ return static_cast<unsigned char*>(_aligned_realloc(p, new_size, align));
#else
- extern void* __rdl_realloc(void* p, size_t old_size, size_t align,
- size_t new_size);
- return __rdl_realloc(p, old_size, align, new_size);
+ return static_cast<unsigned char*>(
+ __rdl_realloc(p, old_size, align, new_size));
#endif
}
-REMAP_ALLOC_ATTRIBUTES void* __rust_alloc_zeroed(size_t size, size_t align) {
+unsigned char* alloc_zeroed(size_t size, size_t align) {
#if BUILDFLAG(RUST_ALLOCATOR_USES_PARTITION_ALLOC) || USE_WIN_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.
- void* p = __rust_alloc(size, align);
+ unsigned char* p = alloc(size, align);
if (p) {
memset(p, 0, size);
}
return p;
#else
- extern void* __rdl_alloc_zeroed(size_t size, size_t align);
- return __rdl_alloc_zeroed(size, align);
+ return static_cast<unsigned char*>(__rdl_alloc_zeroed(size, align));
#endif
}
-REMAP_ALLOC_ATTRIBUTES void __rust_alloc_error_handler(size_t size,
- size_t align) {
- NO_CODE_FOLDING();
- IMMEDIATE_CRASH();
-}
-
-REMAP_ALLOC_ATTRIBUTES extern const unsigned char
- __rust_alloc_error_handler_should_panic = 0;
-
-} // extern "C"
+} // namespace rust_allocator_internal
diff --git a/build/rust/allocator/allocator_impls.h b/build/rust/allocator/allocator_impls.h
new file mode 100644
index 0000000000000..afb335412faf9
--- /dev/null
+++ b/build/rust/allocator/allocator_impls.h
@@ -0,0 +1,25 @@
+// 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 <cstddef>
+
+#include "build/build_config.h"
+#include "build/rust/allocator/buildflags.h"
+
+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/build/rust/allocator/allocator_shim_definitions.cc b/build/rust/allocator/allocator_shim_definitions.cc
new file mode 100644
index 0000000000000..a4d1bd77b7016
--- /dev/null
+++ b/build/rust/allocator/allocator_shim_definitions.cc
@@ -0,0 +1,30 @@
+// 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 <cstddef>
+
+#include "build/rust/allocator/alias.h"
+#include "build/rust/allocator/immediate_crash.h"
+
+extern "C" {
+
+// 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
+//
+// Mark it weak since rustc will generate it when it drives linking.
+[[maybe_unused]]
+__attribute__((weak)) unsigned char __rust_no_alloc_shim_is_unstable;
+
+__attribute__((weak)) void __rust_alloc_error_handler(size_t size,
+ size_t align) {
+ NO_CODE_FOLDING();
+ IMMEDIATE_CRASH();
+}
+
+__attribute__((
+ weak)) extern const unsigned char __rust_alloc_error_handler_should_panic =
+ 0;
+
+} // extern "C"
diff --git a/build/rust/std/compiler_specific.h b/build/rust/allocator/compiler_specific.h
similarity index 87%
rename from build/rust/std/compiler_specific.h
rename to build/rust/allocator/compiler_specific.h
index ea79a7a8dc284..f9079679a3e9a 100644
--- a/build/rust/std/compiler_specific.h
+++ b/build/rust/allocator/compiler_specific.h
@@ -7,8 +7,8 @@
//
// TODO(crbug.com/40279749): Avoid code duplication / reuse code.
-#ifndef BUILD_RUST_STD_COMPILER_SPECIFIC_H_
-#define BUILD_RUST_STD_COMPILER_SPECIFIC_H_
+#ifndef BUILD_RUST_ALLOCATOR_COMPILER_SPECIFIC_H_
+#define BUILD_RUST_ALLOCATOR_COMPILER_SPECIFIC_H_
#include "build/build_config.h"
@@ -35,4 +35,4 @@
#define NOINLINE
#endif
-#endif // BUILD_RUST_STD_COMPILER_SPECIFIC_H_
+#endif // BUILD_RUST_ALLOCATOR_COMPILER_SPECIFIC_H_
diff --git a/build/rust/std/immediate_crash.h b/build/rust/allocator/immediate_crash.h
similarity index 97%
rename from build/rust/std/immediate_crash.h
rename to build/rust/allocator/immediate_crash.h
index e4fd5a09d9379..9cbf9fd65f3e0 100644
--- a/build/rust/std/immediate_crash.h
+++ b/build/rust/allocator/immediate_crash.h
@@ -5,8 +5,8 @@
// This file has been copied from //base/immediate_crash.h.
// TODO(crbug.com/40279749): Avoid code duplication / reuse code.
-#ifndef BUILD_RUST_STD_IMMEDIATE_CRASH_H_
-#define BUILD_RUST_STD_IMMEDIATE_CRASH_H_
+#ifndef BUILD_RUST_ALLOCATOR_IMMEDIATE_CRASH_H_
+#define BUILD_RUST_ALLOCATOR_IMMEDIATE_CRASH_H_
#include "build/build_config.h"
@@ -168,4 +168,4 @@
#endif // defined(__clang__) || defined(COMPILER_GCC)
-#endif // BUILD_RUST_STD_IMMEDIATE_CRASH_H_
+#endif // BUILD_RUST_ALLOCATOR_IMMEDIATE_CRASH_H_
diff --git a/build/rust/allocator/lib.rs b/build/rust/allocator/lib.rs
new file mode 100644
index 0000000000000..7f4a0fc245694
--- /dev/null
+++ b/build/rust/allocator/lib.rs
@@ -0,0 +1,48 @@
+// 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. Currently this is a thin wrapper around
+//! allocator_impls.cc's functions; see the documentation there.
+
+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;
+
+#[cxx::bridge(namespace = "rust_allocator_internal")]
+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/build/rust/cargo_crate.gni b/build/rust/cargo_crate.gni
index 6d11c538bf4d5..d9912722b4ecd 100644
--- a/build/rust/cargo_crate.gni
+++ b/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
@@ -483,6 +489,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
# be $root_out_dir for all EXEs. In component build, C++ links to the
diff --git a/build/rust/rust_macro.gni b/build/rust/rust_macro.gni
index bcbb30ed44111..41d857632ccdc 100644
--- a/build/rust/rust_macro.gni
+++ b/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/build/rust/rust_target.gni b/build/rust/rust_target.gni
index 1a2f96337d436..1003a7b678352 100644
--- a/build/rust/rust_target.gni
+++ b/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/build/rust/std/BUILD.gn b/build/rust/std/BUILD.gn
index 6b996aa1fe386..25db126076b2f 100644
--- a/build/rust/std/BUILD.gn
+++ b/build/rust/std/BUILD.gn
@@ -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
@@ -269,8 +230,6 @@ if (toolchain_has_rust) {
foreach(libname, stdlib_files + skip_stdlib_files) {
deps += [ "rules:$libname" ]
}
-
- public_deps = [ ":remap_alloc" ]
}
} else {
action("find_stdlib") {
diff --git a/components/cronet/android/dependencies.txt b/components/cronet/android/dependencies.txt
index bf56bc45ed41f..c0e41ef7c6766 100644
--- a/components/cronet/android/dependencies.txt
+++ b/components/cronet/android/dependencies.txt
@@ -14,6 +14,7 @@
//build/config
//build/config/compiler
//build/rust
+//build/rust/allocator
//build/rust/chromium_prelude
//build/rust/std
//build/rust/std/rules
diff --git a/third_party/breakpad/BUILD.gn b/third_party/breakpad/BUILD.gn
index 007fdff16e92e..00da4fa484998 100644
--- a/third_party/breakpad/BUILD.gn
+++ b/third_party/breakpad/BUILD.gn
@@ -495,7 +495,10 @@ if (is_mac) {
defines = [ "HAVE_MACH_O_NLIST_H" ]
# Rust demangle support.
- deps = [ "//third_party/rust/rustc_demangle_capi/v0_1:lib" ]
+ deps = [
+ "//build/rust/allocator",
+ "//third_party/rust/rustc_demangle_capi/v0_1:lib",
+ ]
defines += [ "HAVE_RUSTC_DEMANGLE" ]
include_dirs += [ "//third_party/rust/chromium_crates_io/vendor/rustc-demangle-capi-0.1.0/include" ]
sources += [ "//third_party/rust/chromium_crates_io/vendor/rustc-demangle-capi-0.1.0/include/rustc_demangle.h" ]
@@ -743,7 +746,10 @@ if (is_linux || is_chromeos || is_android) {
include_dirs = [ "breakpad/src" ]
# Rust demangle support.
- deps = [ "//third_party/rust/rustc_demangle_capi/v0_1:lib" ]
+ deps = [
+ "//build/rust/allocator",
+ "//third_party/rust/rustc_demangle_capi/v0_1:lib",
+ ]
defines += [ "HAVE_RUSTC_DEMANGLE" ]
include_dirs += [ "//third_party/rust/chromium_crates_io/vendor/rustc-demangle-capi-0.1.0/include" ]
sources += [ "//third_party/rust/chromium_crates_io/vendor/rustc-demangle-capi-0.1.0/include/rustc_demangle.h" ]

View file

@ -0,0 +1,319 @@
From 5032162442c5f2f3093cd7646f3a06f826d7f7a8 Mon Sep 17 00:00:00 2001
From: Collin Baker <collinbaker@chromium.org>
Date: Mon, 7 Apr 2025 12:48:17 -0700
Subject: [PATCH] Call Rust default allocator directly from Rust
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
The Chromium `#[global_allocator] crate forwarded calls to the C++
implementation, which in turn called into the Rust standard library
implementations in some build configurations.
This Rust -> C++ -> Rust round trip is unnecessary, and the references
to these symbols is blocking a toolchain update: upstream, these
symbol names are now mangled.
Instead, use Rust conditional compilation to choose between the
Chromium and the libstd-provided allocators.
Additionally, the remaining internal symbols defined in C++ are moved
to Rust.
Bug: 408221149, 407024458
Change-Id: I78f8c90d51a36a73099aa7d333091d7b8aded3c0
Cq-Include-Trybots: luci.chromium.try:android-rust-arm32-rel,android-rust-arm64-dbg,android-rust-arm64-rel,linux-rust-x64-dbg,linux-rust-x64-rel,mac-rust-x64-dbg,win-rust-x64-dbg,win-rust-x64-rel
Change-Id: I78f8c90d51a36a73099aa7d333091d7b8aded3c0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6434355
Reviewed-by: Łukasz Anforowicz <lukasza@chromium.org>
Commit-Queue: Collin Baker <collinbaker@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1443703}
---
build/rust/allocator/BUILD.gn | 54 +++++++------------
build/rust/allocator/allocator_impls.cc | 28 +++++-----
build/rust/allocator/allocator_impls.h | 2 +
.../allocator/allocator_shim_definitions.cc | 30 -----------
build/rust/allocator/lib.rs | 38 +++++++++++++
5 files changed, 73 insertions(+), 79 deletions(-)
delete mode 100644 build/rust/allocator/allocator_shim_definitions.cc
diff --git a/build/rust/allocator/BUILD.gn b/build/rust/allocator/BUILD.gn
index 06aa47f097c9c..f09314afc8158 100644
--- a/build/rust/allocator/BUILD.gn
+++ b/build/rust/allocator/BUILD.gn
@@ -12,6 +12,9 @@ if (build_with_chromium) {
rust_allocator_uses_partition_alloc = use_partition_alloc_as_malloc
}
+use_cpp_allocator_impls =
+ rust_allocator_uses_partition_alloc || (is_win && is_asan)
+
buildflag_header("buildflags") {
header = "buildflags.h"
flags = [
@@ -30,61 +33,44 @@ if (toolchain_has_rust) {
crate_root = "lib.rs"
cxx_bindings = [ "lib.rs" ]
- deps = [
- ":allocator_impls",
- ":allocator_shim_definitions",
- ]
+ deps = [ ":allocator_impls" ]
no_chromium_prelude = true
no_allocator_crate = true
allow_unsafe = true
+
+ if (use_cpp_allocator_impls) {
+ rustflags = [
+ "--cfg",
+ "use_cpp_allocator_impls",
+ ]
+ }
+
+ configs -= [ "//build/config/compiler:disallow_unstable_features" ]
}
+ # TODO(crbug.com/408221149): don't build this when `use_cpp_allocator_impls`
+ # is false.
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 = [
- ":allocator_cpp_shared",
- ":buildflags",
-
- # TODO(crbug.com/408221149): remove the C++ -> Rust dependency for the
- # default allocator.
- "//build/rust/std",
- ]
-
- visibility = [ ":*" ]
- }
-
- source_set("allocator_shim_definitions") {
- sources = [ "allocator_shim_definitions.cc" ]
-
- deps = [ ":allocator_cpp_shared" ]
-
- visibility = [ ":*" ]
- }
-
- source_set("allocator_cpp_shared") {
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",
+ "allocator_impls.cc",
+ "allocator_impls.h",
"compiler_specific.h",
"immediate_crash.h",
]
- visibility = [
- ":allocator_impls",
- ":allocator_shim_definitions",
- ]
+ deps = [ ":buildflags" ]
+
+ visibility = [ ":*" ]
}
}
diff --git a/build/rust/allocator/allocator_impls.cc b/build/rust/allocator/allocator_impls.cc
index 1fde98f23cd12..bf3c2a301adf5 100644
--- a/build/rust/allocator/allocator_impls.cc
+++ b/build/rust/allocator/allocator_impls.cc
@@ -101,16 +101,6 @@
#define USE_WIN_ALIGNED_MALLOC 0
#endif
-// The default allocator functions provided by the Rust standard library.
-extern "C" void* __rdl_alloc(size_t size, size_t align);
-extern "C" void __rdl_dealloc(void* p, size_t size, size_t align);
-extern "C" void* __rdl_realloc(void* p,
- size_t old_size,
- size_t align,
- size_t new_size);
-
-extern "C" void* __rdl_alloc_zeroed(size_t size, size_t align);
-
namespace rust_allocator_internal {
unsigned char* alloc(size_t size, size_t align) {
@@ -129,7 +119,8 @@ unsigned char* alloc(size_t size, size_t align) {
#elif USE_WIN_ALIGNED_MALLOC
return static_cast<unsigned char*>(_aligned_malloc(size, align));
#else
- return static_cast<unsigned char*>(__rdl_alloc(size, align));
+ // TODO(crbug.com/408221149): don't build this file in this case.
+ IMMEDIATE_CRASH();
#endif
}
@@ -143,7 +134,8 @@ void dealloc(unsigned char* p, size_t size, size_t align) {
#elif USE_WIN_ALIGNED_MALLOC
return _aligned_free(p);
#else
- __rdl_dealloc(p, size, align);
+ // TODO(crbug.com/408221149): don't build this file in this case.
+ IMMEDIATE_CRASH();
#endif
}
@@ -162,8 +154,8 @@ unsigned char* realloc(unsigned char* p,
#elif USE_WIN_ALIGNED_MALLOC
return static_cast<unsigned char*>(_aligned_realloc(p, new_size, align));
#else
- return static_cast<unsigned char*>(
- __rdl_realloc(p, old_size, align, new_size));
+ // TODO(crbug.com/408221149): don't build this file in this case.
+ IMMEDIATE_CRASH();
#endif
}
@@ -179,8 +171,14 @@ unsigned char* alloc_zeroed(size_t size, size_t align) {
}
return p;
#else
- return static_cast<unsigned char*>(__rdl_alloc_zeroed(size, align));
+ // TODO(crbug.com/408221149): don't build this file in this case.
+ IMMEDIATE_CRASH();
#endif
}
+void crash_immediately() {
+ NO_CODE_FOLDING();
+ IMMEDIATE_CRASH();
+}
+
} // namespace rust_allocator_internal
diff --git a/build/rust/allocator/allocator_impls.h b/build/rust/allocator/allocator_impls.h
index afb335412faf9..e90ab7cd422c1 100644
--- a/build/rust/allocator/allocator_impls.h
+++ b/build/rust/allocator/allocator_impls.h
@@ -20,6 +20,8 @@ unsigned char* realloc(unsigned char* p,
size_t new_size);
unsigned char* alloc_zeroed(size_t size, size_t align);
+void crash_immediately();
+
} // namespace rust_allocator_internal
#endif // BUILD_RUST_ALLOCATOR_ALLOCATOR_IMPLS_H_
diff --git a/build/rust/allocator/allocator_shim_definitions.cc b/build/rust/allocator/allocator_shim_definitions.cc
deleted file mode 100644
index a4d1bd77b7016..0000000000000
--- a/build/rust/allocator/allocator_shim_definitions.cc
+++ /dev/null
@@ -1,30 +0,0 @@
-// 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 <cstddef>
-
-#include "build/rust/allocator/alias.h"
-#include "build/rust/allocator/immediate_crash.h"
-
-extern "C" {
-
-// 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
-//
-// Mark it weak since rustc will generate it when it drives linking.
-[[maybe_unused]]
-__attribute__((weak)) unsigned char __rust_no_alloc_shim_is_unstable;
-
-__attribute__((weak)) void __rust_alloc_error_handler(size_t size,
- size_t align) {
- NO_CODE_FOLDING();
- IMMEDIATE_CRASH();
-}
-
-__attribute__((
- weak)) extern const unsigned char __rust_alloc_error_handler_should_panic =
- 0;
-
-} // extern "C"
diff --git a/build/rust/allocator/lib.rs b/build/rust/allocator/lib.rs
index 7f4a0fc245694..b8b67d9c6c649 100644
--- a/build/rust/allocator/lib.rs
+++ b/build/rust/allocator/lib.rs
@@ -8,10 +8,20 @@
//! the allocator defined here. Currently this is a thin wrapper around
//! allocator_impls.cc's functions; see the documentation there.
+// Required to apply weak linkage to symbols.
+#![feature(linkage)]
+// Required to apply `#[rustc_std_internal_symbol]` to our alloc error handler
+// so the name is correctly mangled as rustc expects.
+#![cfg_attr(mangle_alloc_error_handler, allow(internal_features))]
+#![cfg_attr(mangle_alloc_error_handler, feature(rustc_attrs))]
+
+#[cfg(use_cpp_allocator_impls)]
use std::alloc::{GlobalAlloc, Layout};
+#[cfg(use_cpp_allocator_impls)]
struct Allocator;
+#[cfg(use_cpp_allocator_impls)]
unsafe impl GlobalAlloc for Allocator {
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
unsafe { ffi::alloc(layout.size(), layout.align()) }
@@ -32,9 +42,36 @@ unsafe impl GlobalAlloc for Allocator {
}
}
+#[cfg(use_cpp_allocator_impls)]
#[global_allocator]
static GLOBAL: Allocator = Allocator;
+#[cfg(not(use_cpp_allocator_impls))]
+#[global_allocator]
+static GLOBAL: std::alloc::System = std::alloc::System;
+
+// 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;
+
+#[no_mangle]
+#[linkage = "weak"]
+static __rust_alloc_error_handler_should_panic: u8 = 0;
+
+// Mangle the symbol name as rustc expects.
+#[cfg_attr(mangle_alloc_error_handler, rustc_std_internal_symbol)]
+#[cfg_attr(not(mangle_alloc_error_handler), no_mangle)]
+#[linkage = "weak"]
+fn __rust_alloc_error_handler(_size: usize, _align: usize) {
+ unsafe { ffi::crash_immediately() }
+}
+
+// TODO(crbug.com/408221149): conditionally include the FFI glue based on
+// `use_cpp_allocator_impls`
+#[allow(dead_code)]
#[cxx::bridge(namespace = "rust_allocator_internal")]
mod ffi {
extern "C++" {
@@ -44,5 +81,6 @@ mod ffi {
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;
+ unsafe fn crash_immediately();
}
}

View file

@ -0,0 +1,102 @@
reduced -lnl
From e201e2d467b0daad6cdbbfcd5b0e34760e4099c1 Mon Sep 17 00:00:00 2001
From: Alan Zhao <ayzhao@google.com>
Date: Mon, 7 Apr 2025 18:15:01 -0700
Subject: [PATCH] Roll rust *only* f7b43542838f0a4a6cfdb17fbeadf45002042a77-1 :
3f690c2257b7080cd3a8cce64e082fc972148990-1
https://chromium.googlesource.com/external/github.com/rust-lang/rust/+log/f7b43542838f..3f690c2257b7
Ran: ./tools/clang/scripts/upload_revision.py 5b36835df010c5813808d34e45428c624fb52ff1
Additionally, add fixes to the rust allocator to address https://crbug.com/407024458.
Bug: 404285928,407024458
Disable-Rts: True
Cq-Include-Trybots: chromium/try:chromeos-amd64-generic-cfi-thin-lto-rel
Cq-Include-Trybots: chromium/try:dawn-win10-x86-deps-rel
Cq-Include-Trybots: chromium/try:linux-chromeos-dbg
Cq-Include-Trybots: chromium/try:linux_chromium_cfi_rel_ng
Cq-Include-Trybots: chromium/try:linux_chromium_chromeos_msan_rel_ng
Cq-Include-Trybots: chromium/try:linux_chromium_msan_rel_ng
Cq-Include-Trybots: chromium/try:mac11-arm64-rel,mac_chromium_asan_rel_ng
Cq-Include-Trybots: chromium/try:ios-catalyst,win-asan,android-official
Cq-Include-Trybots: chromium/try:fuchsia-arm64-cast-receiver-rel
Cq-Include-Trybots: chromium/try:mac-official,linux-official
Cq-Include-Trybots: chromium/try:win-official,win32-official
Cq-Include-Trybots: chromium/try:win-swangle-try-x86
Cq-Include-Trybots: chromium/try:android-cronet-riscv64-dbg
Cq-Include-Trybots: chromium/try:android-cronet-riscv64-rel
Cq-Include-Trybots: chrome/try:iphone-device
Cq-Include-Trybots: chrome/try:linux-chromeos-chrome
Cq-Include-Trybots: chrome/try:win-chrome,win64-chrome,linux-chrome,mac-chrome
Cq-Include-Trybots: chrome/try:linux-pgo,mac-pgo,win32-pgo,win64-pgo
Cq-Include-Trybots: luci.chromium.try:linux-cast-x64-rel
Cq-Include-Trybots: chromium/try:android-rust-arm32-rel
Cq-Include-Trybots: chromium/try:android-rust-arm64-dbg
Cq-Include-Trybots: chromium/try:android-rust-arm64-rel
Cq-Include-Trybots: chromium/try:linux-rust-x64-dbg
Cq-Include-Trybots: chromium/try:linux-rust-x64-rel
Cq-Include-Trybots: chromium/try:mac-rust-x64-dbg
Cq-Include-Trybots: chromium/try:win-rust-x64-dbg
Cq-Include-Trybots: chromium/try:win-rust-x64-rel
Change-Id: Iec99681a89deaf3f2c79c76f9c4d1c2b2b7d6fe1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6439711
Reviewed-by: Collin Baker <collinbaker@chromium.org>
Commit-Queue: Alan Zhao <ayzhao@google.com>
Cr-Commit-Position: refs/heads/main@{#1443873}
---
build/rust/allocator/BUILD.gn | 6 +-
build/rust/allocator/lib.rs | 6 +-
build/rust/std/rules/BUILD.gn | 476 +++++++++++++++++-----------------
tools/rust/update_rust.py | 2 +-
4 files changed, 251 insertions(+), 239 deletions(-)
diff --git a/build/rust/allocator/BUILD.gn b/build/rust/allocator/BUILD.gn
index f09314afc8158..ca581630c76c9 100644
--- a/build/rust/allocator/BUILD.gn
+++ b/build/rust/allocator/BUILD.gn
@@ -32,6 +32,10 @@ if (toolchain_has_rust) {
sources = [ "lib.rs" ]
crate_root = "lib.rs"
cxx_bindings = [ "lib.rs" ]
+ rustflags = [
+ "--cfg",
+ "mangle_alloc_error_handler",
+ ]
deps = [ ":allocator_impls" ]
@@ -40,7 +44,7 @@ if (toolchain_has_rust) {
allow_unsafe = true
if (use_cpp_allocator_impls) {
- rustflags = [
+ rustflags += [
"--cfg",
"use_cpp_allocator_impls",
]
diff --git a/build/rust/allocator/lib.rs b/build/rust/allocator/lib.rs
index b8b67d9c6c649..4e2dad3d542a8 100644
--- a/build/rust/allocator/lib.rs
+++ b/build/rust/allocator/lib.rs
@@ -57,13 +57,17 @@ static GLOBAL: std::alloc::System = std::alloc::System;
#[linkage = "weak"]
static __rust_no_alloc_shim_is_unstable: u8 = 0;
-#[no_mangle]
+// Mangle the symbol name as rustc expects.
+#[cfg_attr(mangle_alloc_error_handler, rustc_std_internal_symbol)]
+#[cfg_attr(not(mangle_alloc_error_handler), no_mangle)]
+#[allow(non_upper_case_globals)]
#[linkage = "weak"]
static __rust_alloc_error_handler_should_panic: u8 = 0;
// Mangle the symbol name as rustc expects.
#[cfg_attr(mangle_alloc_error_handler, rustc_std_internal_symbol)]
#[cfg_attr(not(mangle_alloc_error_handler), no_mangle)]
+#[allow(non_upper_case_globals)]
#[linkage = "weak"]
fn __rust_alloc_error_handler(_size: usize, _align: usize) {
unsafe { ffi::crash_immediately() }

View file

@ -0,0 +1,44 @@
From 4a0377f0b847af505915b0e0a6c4178d4e7c3244 Mon Sep 17 00:00:00 2001
From: Matt Jolly <kangie@gentoo.org>
Date: Mon, 14 Apr 2025 20:16:46 -0700
Subject: [PATCH] Drop `remap_alloc` dep
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
commit e3a1797dbab3eaa1c808d53215b32c8759d27ac7 dropped the source set
that this refers to, in favour of a more modern, crate-based solution.
This seems to have been overlooked, possibly as it only appears to
be called if using the unbundle toolchain.
Bug: 408221149
Signed-off-by: Matt Jolly <kangie@gentoo.org>
Change-Id: I1703d8e1e456161aa2b736169eec407235847099
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6456604
Reviewed-by: Andrew Grieve <agrieve@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Łukasz Anforowicz <lukasza@chromium.org>
Reviewed-by: Łukasz Anforowicz <lukasza@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1446912}
---
build/rust/std/BUILD.gn | 6 ------
1 file changed, 6 deletions(-)
diff --git a/build/rust/std/BUILD.gn b/build/rust/std/BUILD.gn
index 25db126076b2f..bb2c9884520b3 100644
--- a/build/rust/std/BUILD.gn
+++ b/build/rust/std/BUILD.gn
@@ -355,12 +355,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" ]
- }
}
}
}

View file

@ -0,0 +1,322 @@
From e65cb388e5da56d1236607e0db9cadf89e50eded Mon Sep 17 00:00:00 2001
From: Lukasz Anforowicz <lukasza@chromium.org>
Date: Tue, 15 Apr 2025 11:10:19 -0700
Subject: [PATCH] [rust] Clean up `//build/rust/allocator` after a Rust
toolchain roll.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
This CL makes minor tweaks and changes under `//build/rust/allocator`:
* Thanks to the Rust toolchain roll, we no longer need to keep two
implementations, picking between them using the
`mangle_alloc_error_handler` configuration knob.
* The `#[cfg(use_cpp_allocator_impls)]` vs
`#[cfg(not(use_cpp_allocator_impls))]` choices have been deduplicated
by putting the related/conditional stuff under `mod cpp_allocator` and
`rust_allocator`.
* Closes a minor gap missed in https://crrev.com/c/6432410:
- Moving `DEPS` file to the new source location
Bug: 408221149
Change-Id: Id541797e03da113a5271b02a5f60eb2be08254a9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6454872
Reviewed-by: Alan Zhao <ayzhao@google.com>
Commit-Queue: Łukasz Anforowicz <lukasza@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1447241}
---
build/rust/allocator/BUILD.gn | 11 +-
build/rust/{std => allocator}/DEPS | 2 +-
build/rust/allocator/allocator_impls.cc | 65 ++----------
build/rust/allocator/allocator_impls.h | 2 +
build/rust/allocator/lib.rs | 132 +++++++++++++++---------
5 files changed, 97 insertions(+), 115 deletions(-)
rename build/rust/{std => allocator}/DEPS (76%)
diff --git a/build/rust/std/DEPS b/build/rust/allocator/DEPS
similarity index 76%
rename from build/rust/std/DEPS
rename to build/rust/allocator/DEPS
index eb524c0a06acd..923a2e07c80f4 100644
--- a/build/rust/std/DEPS
+++ b/build/rust/allocator/DEPS
@@ -3,7 +3,7 @@ include_rules = [
]
specific_include_rules = {
- "remap_alloc.cc" : [
+ "allocator_impls.cc" : [
"+partition_alloc"
]
}
diff --git a/build/rust/allocator/allocator_impls.cc b/build/rust/allocator/allocator_impls.cc
index bf3c2a301adf5..8887752f3dfad 100644
--- a/build/rust/allocator/allocator_impls.cc
+++ b/build/rust/allocator/allocator_impls.cc
@@ -24,62 +24,6 @@
#include <cstdlib>
#endif
-// NOTE: this documentation is outdated.
-//
-// TODO(crbug.com/408221149): update this documentation, or replace it with docs
-// in the Rust allocator implementation.
-//
-// When linking a final binary, rustc has to pick between either:
-// * The default Rust allocator
-// * Any #[global_allocator] defined in *any rlib in its dependency tree*
-// (https://doc.rust-lang.org/edition-guide/rust-2018/platform-and-target-support/global-allocators.html)
-//
-// In this latter case, this fact will be recorded in some of the metadata
-// within the .rlib file. (An .rlib file is just a .a file, but does have
-// additional metadata for use by rustc. This is, as far as I know, the only
-// such metadata we would ideally care about.)
-//
-// In all the linked rlibs,
-// * If 0 crates define a #[global_allocator], rustc uses its default allocator
-// * If 1 crate defines a #[global_allocator], rustc uses that
-// * If >1 crates define a #[global_allocator], rustc bombs out.
-//
-// Because rustc does these checks, it doesn't just have the __rust_alloc
-// symbols defined anywhere (neither in the stdlib nor in any of these
-// crates which have a #[global_allocator] defined.)
-//
-// Instead:
-// Rust's final linking stage invokes dynamic LLVM codegen to create symbols
-// for the basic heap allocation operations. It literally creates a
-// __rust_alloc symbol at link time. Unless any crate has specified a
-// #[global_allocator], it simply calls from __rust_alloc into
-// __rdl_alloc, which is the default Rust allocator. The same applies to a
-// few other symbols.
-//
-// We're not (always) using rustc for final linking. For cases where we're not
-// Rustc as the final linker, we'll define those symbols here instead. This
-// allows us to redirect allocation to PartitionAlloc if clang is doing the
-// link.
-//
-// 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.
-//
-// In future, we should build a crate with a #[global_allocator] and
-// redirect these symbols back to Rust in order to use to that crate instead.
-// This would allow Rust-linked executables to:
-// 1. Use PartitionAlloc on Windows. The stdlib uses Windows heap functions
-// directly that PartitionAlloc can not intercept.
-// 2. Have `Vec::try_reserve` to fail at runtime on Linux instead of crashing in
-// malloc() where PartitionAlloc replaces that function.
-//
-// They're weak symbols, because this file will sometimes end up in targets
-// which are linked by rustc, and thus we would otherwise get duplicate
-// definitions. The following definitions will therefore only end up being
-// used in targets which are linked by our C++ toolchain.
-//
-// # On Windows ASAN
-//
// 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
@@ -93,7 +37,6 @@
// Note that there is a runtime option to make ASAN hook HeapAlloc() but
// enabling it breaks Win32 APIs like CreateProcess:
// https://issues.chromium.org/u/1/issues/368070343#comment29
-
#if !BUILDFLAG(RUST_ALLOCATOR_USES_PARTITION_ALLOC) && BUILDFLAG(IS_WIN) && \
defined(ADDRESS_SANITIZER)
#define USE_WIN_ALIGNED_MALLOC 1
@@ -110,6 +53,10 @@ unsigned char* alloc(size_t size, size_t align) {
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<unsigned char*>(allocator_shim::UncheckedAlloc(size));
} else {
@@ -144,6 +91,10 @@ unsigned char* realloc(unsigned char* p,
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<unsigned char*>(
allocator_shim::UncheckedRealloc(p, new_size));
diff --git a/build/rust/allocator/allocator_impls.h b/build/rust/allocator/allocator_impls.h
index e90ab7cd422c1..e562a877d886e 100644
--- a/build/rust/allocator/allocator_impls.h
+++ b/build/rust/allocator/allocator_impls.h
@@ -10,6 +10,8 @@
#include "build/build_config.h"
#include "build/rust/allocator/buildflags.h"
+// This header exposes PartitionAlloc to Rust
+// (most APIs below are called from `impl GlobalAlloc` in `lib.rs`).
namespace rust_allocator_internal {
unsigned char* alloc(size_t size, size_t align);
diff --git a/build/rust/allocator/lib.rs b/build/rust/allocator/lib.rs
index 4e2dad3d542a8..a4f898f9b107f 100644
--- a/build/rust/allocator/lib.rs
+++ b/build/rust/allocator/lib.rs
@@ -5,72 +5,106 @@
//! 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. Currently this is a thin wrapper around
-//! allocator_impls.cc's functions; see the documentation there.
+//! 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.
-#![cfg_attr(mangle_alloc_error_handler, allow(internal_features))]
-#![cfg_attr(mangle_alloc_error_handler, feature(rustc_attrs))]
+//
+// TODO(https://crbug.com/410596442): Stop using internal features here.
+#![allow(internal_features)]
+#![feature(rustc_attrs)]
+/// Module that provides `#[global_allocator]` / `GlobalAlloc` interface for
+/// using an allocator from C++.
#[cfg(use_cpp_allocator_impls)]
-use std::alloc::{GlobalAlloc, Layout};
+mod cpp_allocator {
+ use super::ffi;
+ use std::alloc::{GlobalAlloc, Layout};
-#[cfg(use_cpp_allocator_impls)]
-struct Allocator;
+ struct Allocator;
-#[cfg(use_cpp_allocator_impls)]
-unsafe impl GlobalAlloc for Allocator {
- unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
- unsafe { ffi::alloc(layout.size(), layout.align()) }
- }
+ 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 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 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) }
+ unsafe fn realloc(&self, ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 {
+ unsafe { ffi::realloc(ptr, layout.size(), layout.align(), new_size) }
+ }
}
-}
-#[cfg(use_cpp_allocator_impls)]
-#[global_allocator]
-static GLOBAL: Allocator = Allocator;
+ #[global_allocator]
+ static GLOBAL: Allocator = Allocator;
+}
+/// Module that provides `#[global_allocator]` / `GlobalAlloc` interface for
+/// using the default Rust allocator.
#[cfg(not(use_cpp_allocator_impls))]
-#[global_allocator]
-static GLOBAL: std::alloc::System = std::alloc::System;
-
-// 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.
-#[cfg_attr(mangle_alloc_error_handler, rustc_std_internal_symbol)]
-#[cfg_attr(not(mangle_alloc_error_handler), no_mangle)]
-#[allow(non_upper_case_globals)]
-#[linkage = "weak"]
-static __rust_alloc_error_handler_should_panic: u8 = 0;
-
-// Mangle the symbol name as rustc expects.
-#[cfg_attr(mangle_alloc_error_handler, rustc_std_internal_symbol)]
-#[cfg_attr(not(mangle_alloc_error_handler), no_mangle)]
-#[allow(non_upper_case_globals)]
-#[linkage = "weak"]
-fn __rust_alloc_error_handler(_size: usize, _align: usize) {
- unsafe { ffi::crash_immediately() }
+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 {
+ use super::ffi;
+
+ /// 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::crash_immediately() }
+ }
}
// TODO(crbug.com/408221149): conditionally include the FFI glue based on

View file

@ -0,0 +1,39 @@
Patch-Source: https://github.com/archlinux/svntogit-packages/blob/a353833a5a731abfaa465b658f61894a516aa49b/trunk/angle-wayland-include-protocol.patch
diff -upr third_party/angle.orig/BUILD.gn third_party/angle/BUILD.gn
--- a/third_party/angle.orig/BUILD.gn 2022-08-17 19:38:11.000000000 +0000
+++ b/third_party/angle/BUILD.gn 2022-08-18 11:04:09.061751111 +0000
@@ -489,6 +489,12 @@ config("angle_vulkan_wayland_config") {
if (angle_enable_vulkan && angle_use_wayland &&
defined(vulkan_wayland_include_dirs)) {
include_dirs = vulkan_wayland_include_dirs
+ } else if (angle_enable_vulkan && angle_use_wayland) {
+ include_dirs = [
+ "$wayland_gn_dir/src/src",
+ "$wayland_gn_dir/include/src",
+ "$wayland_gn_dir/include/protocol",
+ ]
}
}
@@ -1073,6 +1079,7 @@ if (angle_use_wayland) {
include_dirs = [
"$wayland_dir/egl",
"$wayland_dir/src",
+ "$wayland_gn_dir/include/protocol",
]
}
diff -upr third_party/angle.orig/src/third_party/volk/BUILD.gn third_party/angle/src/third_party/volk/BUILD.gn
--- a/third_party/angle.orig/src/third_party/volk/BUILD.gn 2022-08-17 19:38:12.000000000 +0000
+++ b/third_party/angle/src/third_party/volk/BUILD.gn 2022-08-18 11:04:36.499828006 +0000
@@ -21,6 +21,9 @@ source_set("volk") {
configs += [ "$angle_root:angle_no_cfi_icall" ]
public_deps = [ "$angle_vulkan_headers_dir:vulkan_headers" ]
if (angle_use_wayland) {
- include_dirs = [ "$wayland_dir/src" ]
+ include_dirs = [
+ "$wayland_dir/src",
+ "$wayland_gn_dir/include/protocol",
+ ]
}
}

View file

@ -0,0 +1,35 @@
--- a/build/toolchain/toolchain.gni
+++ b/build/toolchain/toolchain.gni
@@ -51,6 +51,10 @@
}
}
+declare_args() {
+ is_musl = false
+}
+
# Extension for shared library files (including leading dot).
if (is_apple) {
shlib_extension = ".dylib"
--- a/build/config/rust.gni
+++ b/build/config/rust.gni
@@ -196,7 +196,18 @@
# a cargo project that dumps the `CARGO_CFG_TARGET_ABI` from its build.rs. See
# https://issues.chromium.org/u/1/issues/372512092#comment5 for an example.
rust_abi_target = ""
-if (is_linux || is_chromeos) {
+if (is_musl) {
+ if (current_cpu == "arm64") {
+ rust_abi_target = "aarch64-unknown-linux-musl"
+ cargo_target_abi = ""
+ } else if (current_cpu == "x86") {
+ rust_abi_target = "i686-unknown-linux-musl"
+ cargo_target_abi = ""
+ } else if (current_cpu == "x64") {
+ rust_abi_target = "x86_64-unknown-linux-musl"
+ cargo_target_abi = ""
+ }
+} else if (is_linux || is_chromeos) {
if (current_cpu == "arm64") {
rust_abi_target = "aarch64-unknown-linux-gnu"
cargo_target_abi = ""

View file

@ -0,0 +1,27 @@
Patch-Source: https://src.fedoraproject.org/rpms/chromium/blob/1f8fd846d2cc72c90c73c9867619f0da43b9c816/f/chromium-115-compiler-SkColor4f.patch
diff -up chromium-115.0.5790.40/third_party/blink/renderer/modules/canvas/canvas2d/canvas_style.cc.me chromium-115.0.5790.40/third_party/blink/renderer/modules/canvas/canvas2d/canvas_style.cc
--- chromium-115.0.5790.40/third_party/blink/renderer/modules/canvas/canvas2d/canvas_style.cc.me 2023-06-24 10:38:11.011511463 +0200
+++ chromium-115.0.5790.40/third_party/blink/renderer/modules/canvas/canvas2d/canvas_style.cc 2023-06-24 13:07:35.865375884 +0200
@@ -84,6 +84,7 @@ CanvasStyle::CanvasStyle(const CanvasSty
void CanvasStyle::ApplyToFlags(cc::PaintFlags& flags,
float global_alpha) const {
+ SkColor4f custom_color = SkColor4f{0.0f, 0.0f, 0.0f, global_alpha};
switch (type_) {
case kColor:
ApplyColorToFlags(flags, global_alpha);
@@ -91,12 +92,12 @@ void CanvasStyle::ApplyToFlags(cc::Paint
case kGradient:
GetCanvasGradient()->GetGradient()->ApplyToFlags(flags, SkMatrix::I(),
ImageDrawOptions());
- flags.setColor(SkColor4f(0.0f, 0.0f, 0.0f, global_alpha));
+ flags.setColor(custom_color);
break;
case kImagePattern:
GetCanvasPattern()->GetPattern()->ApplyToFlags(
flags, AffineTransformToSkMatrix(GetCanvasPattern()->GetTransform()));
- flags.setColor(SkColor4f(0.0f, 0.0f, 0.0f, global_alpha));
+ flags.setColor(custom_color);
break;
default:
NOTREACHED();

View file

@ -0,0 +1,21 @@
diff -up chromium-117.0.5938.62/net/dns/host_resolver_cache.cc.me chromium-117.0.5938.62/net/dns/host_resolver_cache.cc
diff -up chromium-117.0.5938.62/net/dns/host_resolver_cache.h.me chromium-117.0.5938.62/net/dns/host_resolver_cache.h
--- chromium-117.0.5938.62/net/dns/host_resolver_cache.h.me 2023-09-14 15:21:24.632965004 +0200
+++ chromium-117.0.5938.62/net/dns/host_resolver_cache.h 2023-09-15 09:15:48.511300845 +0200
@@ -143,12 +143,14 @@ class NET_EXPORT HostResolverCache final
}
bool operator()(const Key& lhs, const KeyRef& rhs) const {
+ const std::string rhs_domain_name{rhs.domain_name};
return std::tie(lhs.domain_name, lhs.network_anonymization_key) <
- std::tie(rhs.domain_name, *rhs.network_anonymization_key);
+ std::tie(rhs_domain_name, *rhs.network_anonymization_key);
}
bool operator()(const KeyRef& lhs, const Key& rhs) const {
- return std::tie(lhs.domain_name, *lhs.network_anonymization_key) <
+ const std::string lhs_domain_name{lhs.domain_name};
+ return std::tie(lhs_domain_name, *lhs.network_anonymization_key) <
std::tie(rhs.domain_name, rhs.network_anonymization_key);
}
};

View file

@ -0,0 +1,11 @@
--- a/v8/src/base/cpu.cc
+++ b/v8/src/base/cpu.cc
@@ -14,7 +14,7 @@
#if V8_OS_LINUX
#include <linux/auxvec.h> // AT_HWCAP
#endif
-#if V8_GLIBC_PREREQ(2, 16) || V8_OS_ANDROID
+#if V8_OS_LINUX || V8_OS_ANDROID
#include <sys/auxv.h> // getauxval()
#endif
#if V8_OS_QNX

View file

@ -0,0 +1,22 @@
--- a/build/config/clang/BUILD.gn
+++ b/build/config/clang/BUILD.gn
@@ -128,14 +128,15 @@
} else if (is_apple) {
_dir = "darwin"
} else if (is_linux || is_chromeos) {
+ _dir = "linux"
if (current_cpu == "x64") {
- _dir = "x86_64-unknown-linux-gnu"
+ _suffix = "-x86_64"
} else if (current_cpu == "x86") {
- _dir = "i386-unknown-linux-gnu"
+ _suffix = "-i386"
} else if (current_cpu == "arm") {
- _dir = "armv7-unknown-linux-gnueabihf"
+ _suffix = "-armhf"
} else if (current_cpu == "arm64") {
- _dir = "aarch64-unknown-linux-gnu"
+ _suffix = "-aarch64"
} else {
assert(false) # Unhandled cpu type
}

View file

@ -0,0 +1,10 @@
--- a/build/rust/std/BUILD.gn
+++ b/build/rust/std/BUILD.gn
@@ -100,7 +100,6 @@
# 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",

View file

@ -0,0 +1,24 @@
From cf993f56ce699ca0ed66ca5a6b88fe7b31c03a75 Mon Sep 17 00:00:00 2001
From: "lauren n. liberda" <lauren@selfisekai.rocks>
Date: Fri, 5 Apr 2024 06:08:21 +0200
Subject: [PATCH] iwyu: sys/select.h in terminal utils
required for fd_set. fixes building on musl libc
Change-Id: I5c03d58c8337c1af871024a436b09117ad9206d4
---
src/tint/utils/system/terminal_posix.cc | 1 +
1 file changed, 1 insertion(+)
diff --git a/third_party/dawn/src/tint/utils/system/terminal_posix.cc b/third_party/dawn/src/tint/utils/system/terminal_posix.cc
index e820774244..a97eab7db8 100644
--- a/third_party/dawn/src/tint/utils/system/terminal_posix.cc
+++ b/third_party/dawn/src/tint/utils/system/terminal_posix.cc
@@ -27,6 +27,7 @@
// GEN_BUILD:CONDITION(tint_build_is_linux || tint_build_is_mac)
+#include <sys/select.h>
#include <unistd.h>
#include <termios.h>

View file

@ -0,0 +1,28 @@
diff -up chromium-126.0.6478.26/build/config/compiler/BUILD.gn.me chromium-126.0.6478.26/build/config/compiler/BUILD.gn
--- chromium-126.0.6478.26/build/config/compiler/BUILD.gn.me 2024-06-02 14:02:52.516602574 +0200
+++ chromium-126.0.6478.26/build/config/compiler/BUILD.gn 2024-06-02 14:17:24.527503540 +0200
@@ -575,24 +575,6 @@ config("compiler") {
}
}
- # TODO(crbug.com/40283598): This causes binary size growth and potentially
- # other problems.
- # TODO(crbug.com/40284925): This isn't supported by Cronet's mainline llvm version.
- if (default_toolchain != "//build/toolchain/cros:target" &&
- !llvm_android_mainline) {
- cflags += [
- "-mllvm",
- "-split-threshold-for-reg-with-hint=0",
- ]
- if (use_thin_lto && is_a_target_toolchain) {
- if (is_win) {
- ldflags += [ "-mllvm:-split-threshold-for-reg-with-hint=0" ]
- } else {
- ldflags += [ "-Wl,-mllvm,-split-threshold-for-reg-with-hint=0" ]
- }
- }
- }
-
# TODO(crbug.com/40192287): Investigate why/if this should be needed.
if (is_win) {
cflags += [ "/clang:-ffp-contract=off" ]

View file

@ -0,0 +1,15 @@
This was dropped for some reason in 6951c37cecd05979b232a39e5c10e6346a0f74ef
--- a/third_party/closure_compiler/compiler.py 2021-05-20 04:17:53.000000000 +0200
+++ b/third_party/closure_compiler/compiler.py 2021-05-20 04:17:53.000000000 +0200
@@ -13,8 +13,9 @@
_CURRENT_DIR = os.path.join(os.path.dirname(__file__))
-_JAVA_PATH = os.path.join(_CURRENT_DIR, "..", "jdk", "current", "bin", "java")
-assert os.path.isfile(_JAVA_PATH), "java only allowed in android builds"
+_JAVA_BIN = "java"
+_JDK_PATH = os.path.join(_CURRENT_DIR, "..", "jdk", "current", "bin", "java")
+_JAVA_PATH = _JDK_PATH if os.path.isfile(_JDK_PATH) else _JAVA_BIN
class Compiler(object):
"""Runs the Closure compiler on given source files to typecheck them

View file

@ -0,0 +1,21 @@
--- a/third_party/node/node.py
+++ b/third_party/node/node.py
@@ -11,17 +11,7 @@
def GetBinaryPath():
- if platform.machine() == 'arm64':
- darwin_path = 'mac_arm64'
- darwin_name = 'node-darwin-arm64'
- else:
- darwin_path = 'mac'
- darwin_name = 'node-darwin-x64'
- return os_path.join(os_path.dirname(__file__), *{
- 'Darwin': (darwin_path, darwin_name, 'bin', 'node'),
- 'Linux': ('linux', 'node-linux-x64', 'bin', 'node'),
- 'Windows': ('win', 'node.exe'),
- }[platform.system()])
+ return "/usr/bin/node"
def RunNode(cmd_parts, stdout=None):

View file

@ -0,0 +1,54 @@
--- a/build/config/compiler/BUILD.gn
+++ b/build/config/compiler/BUILD.gn
@@ -1257,8 +1257,13 @@
} else if (current_cpu == "arm64") {
if (is_clang && !is_android && !is_nacl && !is_fuchsia &&
!is_chromeos_device) {
- cflags += [ "--target=aarch64-linux-gnu" ]
- ldflags += [ "--target=aarch64-linux-gnu" ]
+ if (is_musl) {
+ cflags += [ "--target=aarch64-linux-musl" ]
+ ldflags += [ "--target=aarch64-linux-musl" ]
+ } else {
+ cflags += [ "--target=aarch64-linux-gnu" ]
+ ldflags += [ "--target=aarch64-linux-gnu" ]
+ }
}
} else if (current_cpu == "mipsel" && !is_nacl) {
ldflags += [ "-Wl,--hash-style=sysv" ]
--- a/build/toolchain/linux/unbundle/BUILD.gn.orig
+++ b/build/toolchain/linux/unbundle/BUILD.gn
@@ -39,3 +39,22 @@
current_os = host_os
}
}
+
+gcc_toolchain("v8_snapshot_cross") {
+ cc = getenv("BUILD_CC")
+ cxx = getenv("BUILD_CXX")
+ ar = getenv("BUILD_AR")
+ nm = getenv("BUILD_NM")
+ ld = cxx
+
+ extra_cflags = getenv("BUILD_CFLAGS")
+ extra_cppflags = getenv("BUILD_CPPFLAGS")
+ extra_cxxflags = getenv("BUILD_CXXFLAGS")
+ extra_ldflags = getenv("BUILD_LDFLAGS")
+
+ toolchain_args = {
+ current_cpu = host_cpu
+ current_os = host_os
+ v8_current_cpu = target_cpu
+ }
+}
--- a/build/config/linux/pkg_config.gni.orig
+++ b/build/config/linux/pkg_config.gni
@@ -91,7 +91,7 @@
assert(defined(invoker.packages),
"Variable |packages| must be defined to be a list in pkg_config.")
config(target_name) {
- if (host_toolchain == current_toolchain) {
+ if (current_cpu != target_cpu) {
args = common_pkg_config_args + host_pkg_config_args + invoker.packages
} else {
args = common_pkg_config_args + pkg_config_args + invoker.packages

View file

@ -0,0 +1,13 @@
instead of hardcoding the version, use the defined macro.
--
--- a/third_party/test_fonts/fontconfig/generate_fontconfig_caches.cc
+++ b/third_party/test_fonts/fontconfig/generate_fontconfig_caches.cc
@@ -56,7 +56,7 @@
FcFini();
// Check existence of intended fontconfig cache file.
- auto cache = fontconfig_caches + "/" + kCacheKey + "-le64.cache-9";
+ auto cache = fontconfig_caches + "/" + kCacheKey + "-le64.cache-" + FC_CACHE_VERSION;
bool cache_exists = access(cache.c_str(), F_OK) == 0;
return !cache_exists;
}

View file

@ -0,0 +1,29 @@
--- a/base/allocator/partition_allocator/src/partition_alloc/tagging.cc
+++ b/base/allocator/partition_allocator/src/partition_alloc/tagging.cc
@@ -28,13 +28,25 @@
#endif
#endif
-#ifndef HAS_PR_MTE_MACROS
+#ifndef PR_MTE_TCF_SHIFT
#define PR_MTE_TCF_SHIFT 1
+#endif
+#ifndef PR_MTE_TCF_NONE
#define PR_MTE_TCF_NONE (0UL << PR_MTE_TCF_SHIFT)
+#endif
+#ifndef PR_MTE_TCF_SYNC
#define PR_MTE_TCF_SYNC (1UL << PR_MTE_TCF_SHIFT)
+#endif
+#ifndef PR_MTE_TCF_ASYNC
#define PR_MTE_TCF_ASYNC (2UL << PR_MTE_TCF_SHIFT)
+#endif
+#ifndef PR_MTE_TCF_MASK
#define PR_MTE_TCF_MASK (3UL << PR_MTE_TCF_SHIFT)
+#endif
+#ifndef PR_MTE_TAG_SHIFT
#define PR_MTE_TAG_SHIFT 3
+#endif
+#ifndef PR_MTE_TAG_MASK
#define PR_MTE_TAG_MASK (0xffffUL << PR_MTE_TAG_SHIFT)
#endif
#endif

View file

@ -0,0 +1,11 @@
--- a/extensions/renderer/bindings/argument_spec.cc
+++ b/extensions/renderer/bindings/argument_spec.cc
@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include <cmath>
+
#include "extensions/renderer/bindings/argument_spec.h"
#include "base/check.h"

View file

@ -0,0 +1,21 @@
This macro is defined in glibc, but not musl.
--- a/sandbox/linux/suid/process_util.h.orig
+++ b/sandbox/linux/suid/process_util.h
@@ -11,6 +11,16 @@
#include <stdint.h>
#include <sys/types.h>
+// Some additional functions
+#if !defined(TEMP_FAILURE_RETRY)
+# define TEMP_FAILURE_RETRY(expression) \
+ (__extension__ \
+ ({ long int __result; \
+ do __result = (long int) (expression); \
+ while (__result == -1L && errno == EINTR); \
+ __result; }))
+#endif
+
// This adjusts /proc/process/oom_score_adj so the Linux OOM killer
// will prefer certain process types over others. The range for the
// adjustment is [-1000, 1000], with [0, 1000] being user accessible.

View file

@ -0,0 +1,10 @@
--- a/net/third_party/quiche/src/quiche/http2/adapter/window_manager.h
+++ b/net/third_party/quiche/src/quiche/http2/adapter/window_manager.h
@@ -3,6 +3,7 @@
#include <stddef.h>
+#include <cstdint>
#include <functional>
#include "quiche/common/platform/api/quiche_export.h"

View file

@ -0,0 +1,10 @@
--- a/sandbox/linux/services/credentials.h
+++ b/sandbox/linux/services/credentials.h
@@ -13,6 +13,7 @@
#include <string>
#include <vector>
+#include <unistd.h>
#include "sandbox/linux/system_headers/capability.h"
#include "sandbox/sandbox_export.h"

View file

@ -0,0 +1,22 @@
--- a/third_party/perfetto/include/perfetto/ext/base/thread_utils.h
+++ b/third_party/perfetto/include/perfetto/ext/base/thread_utils.h
@@ -30,7 +30,8 @@
#include <algorithm>
#endif
-#if PERFETTO_BUILDFLAG(PERFETTO_OS_ANDROID)
+#if PERFETTO_BUILDFLAG(PERFETTO_OS_ANDROID) || \
+ (PERFETTO_BUILDFLAG(PERFETTO_OS_LINUX) && !defined(__GLIBC__))
#include <sys/prctl.h>
#endif
@@ -58,7 +59,8 @@
inline bool GetThreadName(std::string& out_result) {
char buf[16] = {};
-#if PERFETTO_BUILDFLAG(PERFETTO_OS_ANDROID)
+#if PERFETTO_BUILDFLAG(PERFETTO_OS_ANDROID) || \
+ (PERFETTO_BUILDFLAG(PERFETTO_OS_LINUX) && !defined(__GLIBC__))
if (prctl(PR_GET_NAME, buf) != 0)
return false;
#else

View file

@ -0,0 +1,34 @@
--- a/base/process/memory_linux.cc
+++ b/base/process/memory_linux.cc
@@ -18,6 +18,13 @@
#include "base/threading/thread_restrictions.h"
#include "build/build_config.h"
+#if defined(LIBC_GLIBC)
+extern "C" {
+extern void *__libc_malloc(size_t size);
+extern void *__libc_free(void *ptr);
+}
+#endif
+
namespace base {
namespace {
@@ -111,7 +118,7 @@
#elif defined(MEMORY_TOOL_REPLACES_ALLOCATOR) || !defined(LIBC_GLIBC)
*result = malloc(size);
#elif defined(LIBC_GLIBC)
- *result = __libc_malloc(size);
+ *result = ::__libc_malloc(size);
#endif
return *result != nullptr;
}
@@ -122,7 +129,7 @@
#elif defined(MEMORY_TOOL_REPLACES_ALLOCATOR) || !defined(LIBC_GLIBC)
free(ptr);
#elif defined(LIBC_GLIBC)
- __libc_free(ptr);
+ ::__libc_free(ptr);
#endif
}

View file

@ -0,0 +1,68 @@
musl does not have execinfo.h, and hence no implementation of
. backtrace()
. backtrace_symbols()
for discussion about this, see https://www.openwall.com/lists/musl/2021/07/16/1
--
--- a/v8/src/codegen/external-reference-table.cc
+++ b/v8/src/codegen/external-reference-table.cc
@@ -11,7 +11,9 @@
#if defined(DEBUG) && defined(V8_OS_LINUX) && !defined(V8_OS_ANDROID)
#define SYMBOLIZE_FUNCTION
+#if defined(__GLIBC__)
#include <execinfo.h>
+#endif
#include <vector>
@@ -96,7 +98,7 @@
}
const char* ExternalReferenceTable::ResolveSymbol(void* address) {
-#ifdef SYMBOLIZE_FUNCTION
+#if defined(SYMBOLIZE_FUNCTION) && defined(__GLIBC__)
char** names = backtrace_symbols(&address, 1);
const char* name = names[0];
// The array of names is malloc'ed. However, each name string is static
--- a/third_party/swiftshader/third_party/llvm-subzero/build/Linux/include/llvm/Config/config.h
+++ b/third_party/swiftshader/third_party/llvm-subzero/build/Linux/include/llvm/Config/config.h
@@ -58,7 +58,7 @@
#define HAVE_ERRNO_H 1
/* Define to 1 if you have the <execinfo.h> header file. */
-#define HAVE_EXECINFO_H 1
+/* #define HAVE_EXECINFO_H 1 */
/* Define to 1 if you have the <fcntl.h> header file. */
#define HAVE_FCNTL_H 1
--- a/base/debug/stack_trace.cc
+++ b/base/debug/stack_trace.cc
@@ -311,7 +311,7 @@
std::string StackTrace::ToStringWithPrefix(cstring_view prefix_string) const {
std::stringstream stream;
-#if !defined(__UCLIBC__) && !defined(_AIX)
+#if defined(__GLIBC__) && !defined(_AIX)
OutputToStreamWithPrefix(&stream, prefix_string);
#endif
return stream.str();
@@ -335,7 +335,7 @@
}
std::ostream& operator<<(std::ostream& os, const StackTrace& s) {
-#if !defined(__UCLIBC__) && !defined(_AIX)
+#if defined(__GLIBC__) && !defined(_AIX)
s.OutputToStream(&os);
#else
os << "StackTrace::OutputToStream not implemented.";
--- a/base/debug/stack_trace_unittest.cc
+++ b/base/debug/stack_trace_unittest.cc
@@ -33,7 +33,7 @@
typedef testing::Test StackTraceTest;
#endif
-#if !defined(__UCLIBC__) && !defined(_AIX)
+#if !defined(__UCLIBC__) && !defined(_AIX) && defined(__GLIBC__)
// StackTrace::OutputToStream() is not implemented under uclibc, nor AIX.
// See https://crbug.com/706728

View file

@ -0,0 +1,125 @@
Source: https://git.alpinelinux.org/aports/plain/community/chromium/no-mallinfo.patch
musl does not implement mallinfo()/mallinfo2()
(or rather, malloc-ng, musl's allocator, doesn't)
--
--- a/base/trace_event/malloc_dump_provider.cc
+++ b/base/trace_event/malloc_dump_provider.cc
@@ -185,7 +185,6 @@
#define MALLINFO2_FOUND_IN_LIBC
struct mallinfo2 info = mallinfo2();
#endif
-#endif // defined(__GLIBC__) && defined(__GLIBC_PREREQ)
#if !defined(MALLINFO2_FOUND_IN_LIBC)
struct mallinfo info = mallinfo();
#endif
@@ -205,6 +204,7 @@
sys_alloc_dump->AddScalar(MemoryAllocatorDump::kNameSize,
MemoryAllocatorDump::kUnitsBytes, info.uordblks);
}
+#endif // defined(__GLIBC__) && defined(__GLIBC_PREREQ)
}
#endif
@@ -339,7 +340,7 @@
&allocated_objects_count);
#elif BUILDFLAG(IS_FUCHSIA)
// TODO(fuchsia): Port, see https://crbug.com/706592.
-#else
+#elif defined(__GLIBC__)
ReportMallinfoStats(/*pmd=*/nullptr, &total_virtual_size, &resident_size,
&allocated_objects_size, &allocated_objects_count);
#endif
--- a/base/process/process_metrics_posix.cc
+++ b/base/process/process_metrics_posix.cc
@@ -105,7 +105,7 @@
#endif // !BUILDFLAG(IS_FUCHSIA)
-#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID)
+#if (BUILDFLAG(IS_LINUX) && defined(__GLIBC__)) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID)
namespace {
size_t GetMallocUsageMallinfo() {
@@ -123,7 +123,7 @@
}
} // namespace
-#endif // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) ||
+#endif // (BUILDFLAG(IS_LINUX) && defined(__GLIBC__)) || BUILDFLAG(IS_CHROMEOS) ||
// BUILDFLAG(IS_ANDROID)
size_t ProcessMetrics::GetMallocUsage() {
@@ -131,9 +131,9 @@
malloc_statistics_t stats = {0};
malloc_zone_statistics(nullptr, &stats);
return stats.size_in_use;
-#elif BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID)
+#elif (BUILDFLAG(IS_LINUX) && defined(__GLIBC__)) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID)
return GetMallocUsageMallinfo();
-#elif BUILDFLAG(IS_FUCHSIA)
+#else
// TODO(fuchsia): Not currently exposed. https://crbug.com/735087.
return 0;
#endif
--- ./third_party/tflite/src/tensorflow/lite/profiling/memory_info.cc.orig
+++ ./third_party/tflite/src/tensorflow/lite/profiling/memory_info.cc
@@ -35,7 +35,7 @@
MemoryUsage GetMemoryUsage() {
MemoryUsage result;
-#ifdef __linux__
+#if defined(__linux__) && defined(__GLIBC__)
rusage res;
if (getrusage(RUSAGE_SELF, &res) == 0) {
result.max_rss_kb = res.ru_maxrss;
--- ./third_party/swiftshader/third_party/llvm-subzero/lib/Support/Unix/Process.inc
+++ ./third_party/swiftshader/third_party/llvm-subzero/lib/Support/Unix/Process.inc.orig
@@ -86,11 +86,11 @@
}
size_t Process::GetMallocUsage() {
-#if defined(HAVE_MALLINFO2)
+#if defined(HAVE_MALLINFO2) && defined(__GLIBC__)
struct mallinfo2 mi;
mi = ::mallinfo2();
return mi.uordblks;
-#elif defined(HAVE_MALLINFO)
+#elif defined(HAVE_MALLINFO) && defined(__GLIBC__)
struct mallinfo mi;
mi = ::mallinfo();
return mi.uordblks;
--- ./third_party/swiftshader/third_party/llvm-10.0/configs/linux/include/llvm/Config/config.h.orig 2019-09-30 13:03:42.556880537 -0400
+++ ./third_party/swiftshader/third_party/llvm-10.0/configs/linux/include/llvm/Config/config.h 2019-09-30 13:07:27.989821227 -0400
@@ -122,7 +122,9 @@
/* #undef HAVE_MALLCTL */
/* Define to 1 if you have the `mallinfo' function. */
+#if defined(__GLIBC__)
#define HAVE_MALLINFO 1
+#endif
/* Define to 1 if you have the <malloc.h> header file. */
#define HAVE_MALLOC_H 1
--- a/base/allocator/partition_allocator/src/partition_alloc/shim/allocator_shim_default_dispatch_to_partition_alloc.cc
+++ b/base/allocator/partition_allocator/src/partition_alloc/shim/allocator_shim_default_dispatch_to_partition_alloc.cc
@@ -660,7 +660,7 @@
#endif // !PA_BUILDFLAG(IS_APPLE) && !PA_BUILDFLAG(IS_ANDROID)
-#if PA_BUILDFLAG(IS_LINUX) || PA_BUILDFLAG(IS_CHROMEOS)
+#if (PA_BUILDFLAG(IS_LINUX) && defined(__GLIBC__)) || PA_BUILDFLAG(IS_CHROMEOS)
SHIM_ALWAYS_EXPORT struct mallinfo mallinfo(void) __THROW {
partition_alloc::SimplePartitionStatsDumper allocator_dumper;
Allocator()->DumpStats("malloc", true, &allocator_dumper);
--- a/base/allocator/partition_allocator/src/partition_alloc/shim/allocator_shim_default_dispatch_to_partition_alloc_unittest.cc
+++ b/base/allocator/partition_allocator/src/partition_alloc/shim/allocator_shim_default_dispatch_to_partition_alloc_unittest.cc
@@ -29,7 +29,7 @@
#if PA_BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC)
// Platforms on which we override weak libc symbols.
-#if PA_BUILDFLAG(IS_LINUX) || PA_BUILDFLAG(IS_CHROMEOS)
+#if (PA_BUILDFLAG(IS_LINUX) && defined(__GLIBC__)) || PA_BUILDFLAG(IS_CHROMEOS)
PA_NOINLINE void FreeForTest(void* data) {
free(data);

View file

@ -0,0 +1,15 @@
Source: https://gitlab.alpinelinux.org/alpine/aports/-/blob/master/community/chromium/no-sandbox-settls.patch
this optimisation of CLONE_SETTLS is not valid used like this, and future musl
clone(3) will EINVAL on this use
--
--- a/sandbox/linux/services/credentials.cc
+++ b/sandbox/linux/services/credentials.cc
@@ -89,7 +89,7 @@
int clone_flags = CLONE_FS | LINUX_SIGCHLD;
void* tls = nullptr;
-#if (defined(ARCH_CPU_X86_64) || defined(ARCH_CPU_ARM_FAMILY)) && \
+#if defined(__GLIBC__) && (defined(ARCH_CPU_X86_64) || defined(ARCH_CPU_ARM_FAMILY)) && \
!defined(MEMORY_SANITIZER)
// Use CLONE_VM | CLONE_VFORK as an optimization to avoid copying page tables.
// Since clone writes to the new child's TLS before returning, we must set a

View file

@ -0,0 +1,11 @@
--- a/base/allocator/partition_allocator/src/partition_alloc/partition_root.cc
+++ b/base/allocator/partition_allocator/src/partition_alloc/partition_root.cc
@@ -239,7 +239,7 @@
if (!g_global_init_called.compare_exchange_strong(expected, true))
return;
-#if PA_BUILDFLAG(IS_LINUX) || PA_BUILDFLAG(IS_CHROMEOS)
+#if (PA_BUILDFLAG(IS_LINUX) && defined(__GLIBC__)) || PA_BUILDFLAG(IS_CHROMEOS)
// When fork() is called, only the current thread continues to execute in the
// child process. If the lock is held, but *not* by this thread when fork() is
// called, we have a deadlock.

View file

@ -0,0 +1,27 @@
--- a/third_party/breakpad/breakpad/src/client/linux/handler/exception_handler.cc 2015-12-06 09:59:55.554536646 +0100
+++ b/third_party/breakpad/breakpad/src/client/linux/handler/exception_handler.cc 2015-12-06 10:01:16.818238035 +0100
@@ -477,7 +477,9 @@ bool ExceptionHandler::SimulateSignalDel
siginfo.si_code = SI_USER;
siginfo.si_pid = getpid();
ucontext_t context;
+#if defined(__GLIBC__)
getcontext(&context);
+#endif
return HandleSignal(sig, &siginfo, &context);
}
@@ -647,9 +649,14 @@ bool ExceptionHandler::WriteMinidump() {
sys_prctl(PR_SET_DUMPABLE, 1, 0, 0, 0);
CrashContext context;
+
+#if defined(__GLIBC__)
int getcontext_result = getcontext(&context.context);
if (getcontext_result)
return false;
+#else
+ return false;
+#endif
#if defined(__i386__)
// In CPUFillFromUContext in minidumpwriter.cc the stack pointer is retrieved

View file

@ -0,0 +1,23 @@
Patch-Source: https://webrtc-review.googlesource.com/c/src/+/380500
---
--- a/third_party/webrtc/modules/video_capture/linux/pipewire_session.cc
+++ b/third_party/webrtc/modules/video_capture/linux/pipewire_session.cc
@@ -87,7 +87,7 @@
.param = OnNodeParam,
};
- pw_node_add_listener(proxy_, &node_listener_, &node_events, this);
+ pw_node_add_listener(reinterpret_cast<pw_node*>(proxy_), &node_listener_, &node_events, this);
}
// static
@@ -119,7 +119,7 @@
uint32_t id = info->params[i].id;
if (id == SPA_PARAM_EnumFormat &&
info->params[i].flags & SPA_PARAM_INFO_READ) {
- pw_node_enum_params(that->proxy_, 0, id, 0, UINT32_MAX, nullptr);
+ pw_node_enum_params(reinterpret_cast<pw_node*>(that->proxy_), 0, id, 0, UINT32_MAX, nullptr);
break;
}
}

View file

@ -0,0 +1,19 @@
--- a/BUILD.gn.orig
+++ b/BUILD.gn
@@ -1616,16 +1616,6 @@
}
}
-# TODO(cassew): Add more OS's that don't support x86.
-is_valid_x86_target =
- target_os != "ios" && target_os != "mac" &&
- (target_os != "linux" || use_libfuzzer || !build_with_chromium)
-
-# Note: v8_target_cpu == arm allows using the V8 arm simulator on x86 for fuzzing.
-assert(
- is_valid_x86_target || target_cpu != "x86" || v8_target_cpu == "arm",
- "'target_cpu=x86' is not supported for 'target_os=$target_os'. Consider omitting 'target_cpu' (default) or using 'target_cpu=x64' instead.")
-
group("chromium_builder_perf") {
testonly = true

View file

@ -0,0 +1,39 @@
--- a/third_party/crashpad/crashpad/compat/linux/sys/ptrace.h
+++ b/third_party/crashpad/crashpad/compat/linux/sys/ptrace.h
@@ -17,8 +17,6 @@
#include_next <sys/ptrace.h>
-#include <sys/cdefs.h>
-
// https://sourceware.org/bugzilla/show_bug.cgi?id=22433
#if !defined(PTRACE_GET_THREAD_AREA) && !defined(PT_GET_THREAD_AREA) && \
defined(__GLIBC__)
--- a/third_party/libsync/src/include/sync/sync.h
+++ b/third_party/libsync/src/include/sync/sync.h
@@ -19,12 +19,13 @@
#ifndef __SYS_CORE_SYNC_H
#define __SYS_CORE_SYNC_H
-#include <sys/cdefs.h>
#include <stdint.h>
#include <linux/types.h>
-__BEGIN_DECLS
+#ifdef __cplusplus
+extern "C" {
+#endif
struct sync_legacy_merge_data {
int32_t fd2;
@@ -158,6 +159,8 @@
struct sync_pt_info *itr);
void sync_fence_info_free(struct sync_fence_info_data *info);
-__END_DECLS
+#ifdef __cplusplus
+}
+#endif
#endif /* __SYS_CORE_SYNC_H */

View file

@ -0,0 +1,10 @@
--- a/sandbox/linux/seccomp-bpf-helpers/syscall_sets.cc
+++ b/sandbox/linux/seccomp-bpf-helpers/syscall_sets.cc
@@ -370,6 +370,7 @@
switch (sysno) {
case __NR_exit:
case __NR_exit_group:
+ case __NR_membarrier:
case __NR_wait4:
case __NR_waitid:
#if defined(__i386__)

View file

@ -0,0 +1,11 @@
--- a/base/third_party/symbolize/symbolize.h
+++ b/base/third_party/symbolize/symbolize.h
@@ -58,6 +58,8 @@
#include "config.h"
#include "glog/logging.h"
+#include <sys/types.h>
+
#ifdef HAVE_SYMBOLIZE
#if defined(__ELF__) // defined by gcc

View file

@ -0,0 +1,12 @@
--- a/build/toolchain/linux/unbundle/BUILD.gn.orig
+++ b/build/toolchain/linux/unbundle/BUILD.gn
@@ -35,7 +35,7 @@
extra_ldflags = getenv("BUILD_LDFLAGS")
toolchain_args = {
- current_cpu = current_cpu
- current_os = current_os
+ current_cpu = host_cpu
+ current_os = host_os
}
}

View file

@ -0,0 +1,10 @@
--- a/third_party/webrtc/modules/audio_processing/aec3/clockdrift_detector.h 2020-08-10 20:42:29.000000000 +0200
+++ b/third_party/webrtc/modules/audio_processing/aec3/clockdrift_detector.h 2020-09-04 12:47:07.014833633 +0200
@@ -12,6 +12,7 @@
#define MODULES_AUDIO_PROCESSING_AEC3_CLOCKDRIFT_DETECTOR_H_
#include <array>
+#include <cstddef>
namespace webrtc {

View file

@ -0,0 +1,12 @@
diff --git a/build/npm.gni b/build/npm.gni
index a1987d095..fb33a14c3 100644
--- a/build/npm.gni
+++ b/build/npm.gni
@@ -35,7 +35,6 @@ template("npm_action") {
if (!defined(deps)) {
deps = []
}
- deps += [ ":npm_pre_flight_" + target_name ]
script = "//electron/build/npm-run.py"
args = [

View file

@ -0,0 +1,10 @@
--- electron/script/apply_all_patches.py 2024-02-14 19:35:26.000000000 +0100
+++ - 2024-02-19 12:58:37.818075522 +0100
@@ -22,6 +22,7 @@
patch_data=patch_from_dir(patch_dir),
repo=repo,
threeway=THREEWAY,
+ exclude=['third_party/blink/tools/**', 'test/mjsunit/**', 'content/test/**', 'test/cctest/**', 'test/unit tests/**', 'third_party/blink/web_tests/**', '.gitignore'],
)
def apply_config(config):

View file

@ -0,0 +1,10 @@
--- a/package.json 2022-07-06 17:31:50.000000000 +0200
+++ - 2022-07-08 23:04:43.654812957 +0200
@@ -98,7 +98,6 @@
"precommit": "lint-staged",
"preinstall": "node -e 'process.exit(0)'",
"prepack": "check-for-leaks",
- "prepare": "husky install",
"repl": "node ./script/start.js --interactive",
"start": "node ./script/start.js",
"test": "node ./script/spec-runner.js",

477
srcpkgs/electron35/template Normal file
View file

@ -0,0 +1,477 @@
# Template file for 'electron35'
pkgname=electron35
version=35.7.2
revision=1
_nodever=22.16.0
_chromiumver=134.0.6998.205
archs="x86_64* aarch64*"
create_wrksrc=yes
build_wrksrc="src"
_llvmver=19
hostmakedepends="
$(vopt_if clang "clang${_llvmver} lld${_llvmver} llvm${_llvmver} compiler-rt${_llvmver}")
pkg-config perl gperf bison ninja nodejs hwids which git yarn jq
python3 libepoxy-devel libevent-devel libglib-devel rust rust-bindgen
gn"
makedepends="libpng-devel gtk+3-devel nss-devel pciutils-devel
libXi-devel libgcrypt-devel cups-devel elfutils-devel
libXcomposite-devel speech-dispatcher-devel libXrandr-devel mit-krb5-devel
libXScrnSaver-devel alsa-lib-devel libdrm-devel
libxml2-devel libxslt-devel $(vopt_if pulseaudio pulseaudio-devel) libexif-devel
libXcursor-devel libflac-devel speex-devel libmtp-devel libwebp-devel
libjpeg-turbo-devel libevent-devel json-c-devel minizip-devel jsoncpp-devel
zlib-devel libcap-devel libXdamage-devel fontconfig-devel freetype-devel opus-devel libffi-devel
libva-devel libuv-devel c-ares-devel libnotify-devel
$(vopt_if pipewire pipewire-devel) wayland-devel libcurl-devel libxshmfence-devel
compiler-rt${_llvmver} rust-std"
short_desc="Cross platform application framework based on web technologies"
maintainer="Duncaen <duncaen@voidlinux.org>"
license="BSD-3-Clause"
homepage="https://electronjs.org"
distfiles="https://ayakael.net/api/packages/mirrors/generic/electron/v${version}/electron-v${version}-${_chromiumver}.tar.zst
https://github.com/nodejs/node/archive/v$_nodever.tar.gz>node-$_nodever.tar.gz"
checksum="780f96730b910ae378a2ef292c2645ab8749a5e9a364359d2f9a12a15e4c5c26
00d7c2a8f315f201fe30e2f7ac5a137663ab1c79a5c6873df553aff0409ce291"
if [ "$XBPS_LIBC" = musl ]; then
hostmakedepends+=" musl-legacy-compat"
fi
if [ "$XBPS_TARGET_LIBC" = "musl" ]; then
makedepends+=" musl-legacy-compat"
fi
no_generic_pkgconfig_link=yes
lib32disabled=yes
build_options="clang libcxx debug vaapi pulseaudio sndio pipewire lto drumbrake"
build_options_default="clang libcxx vaapi pulseaudio pipewire"
desc_option_clang="Use clang to build"
desc_option_libcxx="Use bundled libc++"
desc_option_debug="Build with debug symbols"
desc_option_pipewire="Enable support for screen sharing for WebRTC via PipeWire"
desc_option_drumbrake="WebAssembly Interpreter"
if [ "$CROSS_BUILD" ]; then
hostmakedepends+=" libX11-devel libxcb-devel pciutils-devel libXext-devel libglvnd-devel
libjpeg-turbo-devel libXi-devel nss-devel libpng-devel libwebp-devel
libxml2-devel $(vopt_if pulseaudio pulseaudio-devel) libxslt-devel libxkbcommon-devel
$(vopt_if pipewire pipewire-devel) opus-devel pango-devel libva-devel
libcurl-devel libXrandr-devel libXcomposite-devel cups-devel
mit-krb5-devel alsa-lib-devel libXdamage-devel libepoxy-devel libevdev-devel
libavif-devel libaom-devel libdav1d-devel libflac-devel
libdrm-devel libgbm-devel"
fi
if [ ! "$XBPS_WORDSIZE" = "$XBPS_TARGET_WORDSIZE" ]; then
broken="chromium (v8) can only be cross compiled if word size matches"
fi
if [ "$CROSS_BUILD" ]; then
case "${XBPS_TARGET_MACHINE}" in
#aarch64*) ;;
*) nocross="chromium can not be cross compiled for this architecture" ;;
esac
fi
_buildtype=Release
_setup_clang() {
export CC=clang
export CXX=clang++
export AR=llvm-ar
export NM=llvm-nm
export CFLAGS="-Wno-unknown-warning-option -fdebug-prefix-map=$wrksrc=."
export CXXFLAGS="-Wno-unknown-warning-option -fdebug-prefix-map=$wrksrc=."
export LDFLAGS=""
export BUILD_CC=clang
export BUILD_CXX=clang++
export BUILD_AR=llvm-ar
export BUILD_NM=llvm-nm
export BUILD_CFLAGS="-Wno-unknown-warning-option"
export BUILD_CXXFLAGS="-Wno-unknown-warning-option"
if [[ -n "$CROSS_BUILD" ]]; then
CFLAGS+=" --sysroot=${XBPS_CROSS_BASE}"
CXXFLAGS+=" --sysroot=${XBPS_CROSS_BASE}"
LDFLAGS+=" --sysroot=${XBPS_CROSS_BASE}"
if [[ -z "$build_option_libcxx" ]]; then
local gcc_version=$(gcc -dumpversion)
local clang_version=$(clang -dumpversion)
CFLAGS+=" --gcc-toolchain=/usr"
CFLAGS+=" -nostdinc"
CFLAGS+=" -isystem ${XBPS_CROSS_BASE}/usr/include"
CFLAGS+=" -isystem /usr/lib/clang/${clang_version}/include"
CXXFLAGS+=" --gcc-toolchain=/usr"
CXXFLAGS+=" -nostdinc++"
CXXFLAGS+=" -isystem ${XBPS_CROSS_BASE}/usr/include/c++/${gcc_version%.*}"
CXXFLAGS+=" -isystem ${XBPS_CROSS_BASE}/usr/include/c++/${gcc_version%.*}/${XBPS_CROSS_TRIPLET}"
CXXFLAGS+=" -isystem ${XBPS_CROSS_BASE}/usr/include/c++/${gcc_version%.*}/backward"
CXXFLAGS+=" -nostdinc"
CXXFLAGS+=" -isystem ${XBPS_CROSS_BASE}/usr/include"
CXXFLAGS+=" -isystem /usr/lib/clang/${clang_version}/include"
LDFLAGS+=" --gcc-toolchain=/usr"
fi
fi
}
_setup_toolchain() {
if [ "$build_option_clang" ]; then
_setup_clang
fi
}
_apply_patch() {
local args="$1" pname="$(basename $2)"
if [ ! -f ".${pname}_done" ]; then
if [ -f "${2}.args" ]; then
args=$(<"${2}.args")
fi
msg_normal "$pkgver: patching: ${pname}.\n"
patch -N $args -i $2
touch .${pname}_done
fi
}
_git_am() {
local pname="$(basename $1)"
if [ ! -f ".${pname}_done" ]; then
msg_normal "$pkgver: patching: ${pname}.\n"
git -c 'user.name=Electron build' -c 'user.email=electron@ebuild' \
am --exclude "third_party/blink/tools/**" \
--exclude "test/mjsunit/**" --exclude "content/test/**" \
--exclude "test/cctest/**" --exclude "test/unittests/**" \
--exclude "third_party/blink/web_tests/**" \
--exclude "chrome/test/**" \
$1
touch .${pname}_done
fi
}
_get_chromium_arch() {
case "$1" in
x86_64*) echo x64 ;;
i686*) echo x86 ;;
arm*) echo arm ;;
aarch64*) echo arm64 ;;
ppc64*) echo ppc64 ;;
ppc*) echo ppc ;;
mipsel*) echo mipsel ;;
mips*) echo mips ;;
*) msg_error "$pkgver: cannot be compiled for ${XBPS_TARGET_MACHINE}.\n" ;;
esac
}
post_extract() {
mv "electron-v${version}-${_chromiumver}" src
mv "node-${_nodever}" src/third_party/electron_node
}
_git_init() {
repopath="$1"
cd "${wrksrc}/${repopath}"
rm -rf ".git"
git init -q
git config "gc.auto" 0
if [ "$repopath" != "src" ]; then
echo "/${repopath#src/}" >> "$wrksrc/$build_wrksrc/.gitignore"
fi
pwd
ls
git add .
git -c 'user.name=Electron build' \
-c 'user.email=electron@ebuild' \
commit --allow-empty -q -m "init"
}
post_patch() {
cd "$wrksrc"
for x in $FILESDIR/patches/*.patch; do
case "${x##*/}" in
electron*.patch)
_apply_patch "-d src/electron -p1" "$x"
esac
done
for x in $FILESDIR/patches/*; do
case "${x##*/}" in
chromium*.patch)
cd src
_apply_patch -p1 "$x"
cd "$wrksrc"
;;
esac
done
if [ "$XBPS_TARGET_LIBC" = "musl" ]; then
for x in $FILESDIR/musl-patches/*; do
case "${x##*/}" in
chromium*.patch)
cd src
_apply_patch -p1 "$x"
cd "$wrksrc"
;;
electron*.patch)
cd src/electron
_apply_patch -p1 "$x"
cd "$wrksrc"
;;
esac
done
fi
vsed -i 's/OFFICIAL_BUILD/GOOGLE_CHROME_BUILD/' \
src/tools/generate_shim_headers/generate_shim_headers.py
}
pre_configure() {
local system=()
# https://groups.google.com/a/chromium.org/d/topic/chromium-packagers/9JX1N2nf4PU/discussion
touch chrome/test/data/webui/i18n_process_css_test.html
# Use the file at run time instead of effectively compiling it in
sed 's|//third_party/usb_ids/usb.ids|/usr/share/hwdata/usb.ids|g' \
-i services/device/public/cpp/usb/BUILD.gn
mkdir -p third_party/node/linux/node-linux-x64/bin
ln -sf /usr/bin/node third_party/node/linux/node-linux-x64/bin/
rm -f third_party/devtools-frontend/src/third_party/esbuild/esbuild
if false; then
# compile gn early, so it can be used to generate gni stuff
AR="ar" CC=$CC_FOR_BUILD CXX=$CXX_FOR_BUILD LD=$CXX_FOR_BUILD \
CFLAGS=$CFLAGS_FOR_BUILD CXXFLAGS=$CXXFLAGS_FOR_BUILD LDFLAGS=$LDFLAGS_FOR_BUILD \
tools/gn/bootstrap/bootstrap.py ${makejobs} --skip-generate-buildfiles
fi
# reusable system library settings
# libcxx
# snappy System snappy is linked against libstdc++ and not CR libcxx
# ffmpeg
system=(
flac
fontconfig
freetype
libdrm
libjpeg
libpng
libwebp
libxml
libxslt
opus
)
# remove build scripts for system provided dependencies - basically does the
# same as the bundeled script to remove bundeled libs, but this way we don't
# have to list the remaining libs
for LIB in "${system[@]}" libjpeg_turbo; do
msg_normal "Removing buildscripts for system provided $LIB\n"
find "third_party/$LIB" -type f \
\! -path "third_party/$LIB/chromium/*" \
\! -path "third_party/$LIB/google/*" \
\! -path './base/third_party/icu/*' \
\! -path './third_party/harfbuzz-ng/utils/hb_scoped.h' \
\! -regex '.*\.\(gn\|gni\|isolate\)' \
-delete || :
done
# switch to system provided dependencies
build/linux/unbundle/replace_gn_files.py --system-libraries "${system[@]}"
third_party/libaddressinput/chromium/tools/update-strings.py
# Satisfy some scripts that use git describe to figure out the electron version
# cd ${wrksrc}/src/electron
# git tag -f "v${version}"
}
do_configure() {
local target_arch="$(_get_chromium_arch ${XBPS_TARGET_MACHINE})"
local host_arch="$(_get_chromium_arch ${XBPS_MACHINE})"
local conf=()
cd third_party/electron_node
if [ "$CROSS_BUILD" ]; then
conf_args=" --dest-cpu=${target_arch} --cross-compiling"
fi
./configure --prefix=/usr \
--shared-zlib \
--shared-libuv \
--shared-openssl \
--shared-cares \
--openssl-use-def-ca-store \
--without-npm \
--without-bundled-v8 \
${conf_args}
cd "$wrksrc/$build_wrksrc"/electron
yarn install --frozen-lockfile
cd "$wrksrc/$build_wrksrc"
local clang_version="$(clang -dumpversion)"
conf+=(
'import("//electron/build/args/release.gn")'
"override_electron_version=\"${version}\""
)
conf+=(
'enable_nacl=false'
'use_sysroot=false'
'host_pkg_config="/usr/bin/pkg-config"'
"is_clang=$(vopt_if clang true false)"
"use_lld=$(vopt_if clang true false)"
'clang_use_chrome_plugins=false'
'clang_base_path="/usr"'
"clang_version=\"${clang_version%%.*}\""
"use_custom_libcxx=$(vopt_if libcxx true false)" # https://github.com/llvm/llvm-project/issues/61705
'enable_rust=true'
'rust_sysroot_absolute="/usr"'
'rust_bindgen_root="/usr"'
"rustc_version=\"$(rustc --version)\""
# is_debug makes the build a debug build, changes some things.
# might be useful for real debugging vs just debug symbols.
"is_debug=false"
"blink_symbol_level=$(vopt_if debug 1 0)"
"symbol_level=$(vopt_if debug 1 0)"
'icu_use_data_file=true'
'enable_widevine=false'
'enable_hangout_services_extension=true'
'use_system_harfbuzz=false'
'use_system_libffi=true'
'use_qt5=false'
'use_qt6=false'
'use_cups=true'
"use_vaapi=$(vopt_if vaapi true false)"
"use_pulseaudio=$(vopt_if pulseaudio true false)"
"link_pulseaudio=$(vopt_if pulseaudio true false)"
"rtc_use_pipewire=$(vopt_if pipewire true false)"
"v8_enable_drumbrake=$(vopt_if drumbrake true false)"
# Always support proprietary codecs.
# Enable H.264 support in bundled ffmpeg.
'proprietary_codecs=true'
'ffmpeg_branding="Chrome"'
# Make sure that -Werror doesn't get added to CFLAGS by the build system.
# Depending on GCC version the warnings are different and we don't want
# the build to fail because of that.
'treat_warnings_as_errors=false'
'fatal_linker_warnings=false'
# Save space by removing DLOG and DCHECK messages (about 6% reduction).
# 'logging_like_official_build=true'
'disable_fieldtrial_testing_config=true'
'is_official_build=true'
# segfaults with llvm-12.0.1
'is_cfi=false'
'use_cfi_icall=false'
"use_thin_lto=$(vopt_if lto true false)"
'chrome_pgo_phase=0'
)
if [ "$XBPS_TARGET_LIBC" = "musl" ]; then
conf+=( 'is_musl=true' )
fi
if [ "$CROSS_BUILD" ]; then
conf+=(
'custom_toolchain="//build/toolchain/linux/unbundle:default"'
'host_toolchain="//build/toolchain/linux/unbundle:host"'
'v8_snapshot_toolchain="//build/toolchain/linux/unbundle:v8_snapshot_cross"'
)
else
conf+=(
'custom_toolchain="//build/toolchain/linux/unbundle:default"'
'host_toolchain="//build/toolchain/linux/unbundle:default"'
)
fi
conf+=(
"target_cpu=\"$target_arch\""
"host_cpu=\"$host_arch\""
)
_setup_toolchain
if false; then
out/Release/gn gen out/Release --args="${conf[*]}"
else
gn gen out/Release --args="${conf[*]}"
fi
}
do_build() {
# XXX: need for error: the option `Z` is only accepted on the nightly compiler
export RUSTC_BOOTSTRAP=1
export ELECTRON_OUT_DIR="${wrksrc}/${build_wrksrc}/out/${_buildtype}/"
_setup_toolchain
msg_normal "Ninja turtles GO!\n"
CCACHE_SLOPPINESS=include_file_mtime ninja ${makejobs} -C out/$_buildtype \
copy_node_headers version electron chromium_licenses
}
do_install() {
vmkdir /usr/lib/$pkgname
vmkdir /usr/include/$pkgname
for f in out/$_buildtype/*.bin out/$_buildtype/*.pak out/$_buildtype/icudtl.dat; do
vinstall $f 0644 usr/lib/$pkgname
done
vinstall out/$_buildtype/resources/default_app.asar 0644 usr/lib/$pkgname/resources
vcopy out/$_buildtype/locales usr/lib/$pkgname
rm -v ${DESTDIR}/usr/lib/$pkgname/locales/*.pak.info
vinstall out/$_buildtype/electron 0755 usr/lib/$pkgname
vinstall out/$_buildtype/chrome_crashpad_handler 0755 usr/lib/$pkgname
vinstall out/$_buildtype/libEGL.so 0755 usr/lib/$pkgname
vinstall out/$_buildtype/libGLESv2.so 0755 usr/lib/$pkgname
vinstall out/$_buildtype/libvulkan.so.1 0755 usr/lib/$pkgname
vinstall out/$_buildtype/libffmpeg.so 0755 usr/lib/$pkgname
vinstall out/$_buildtype/libvk_swiftshader.so 0755 usr/lib/$pkgname
vinstall out/$_buildtype/vk_swiftshader_icd.json 0644 usr/lib/$pkgname
vinstall out/$_buildtype/version 0644 usr/lib/$pkgname
vinstall out/$_buildtype/LICENSES.chromium.html 0644 usr/lib/$pkgname
vcopy out/$_buildtype/gen/node_headers usr/include/$pkgname
ln -sv /usr/include/$pkgname/node_headers/include/node ${DESTDIR}/usr/include/$pkgname/node
vlicense ${wrksrc}/src/LICENSE chromium.LICENSE
vlicense ${wrksrc}/src/electron/LICENSE electron.LICENSE
vlicense ${wrksrc}/src/third_party/electron_node/LICENSE node.LICENSE
vmkdir /usr/bin
ln -s ../lib/$pkgname/electron "$DESTDIR"/usr/bin/$pkgname
}
electron35-devel_package() {
depends="${sourcepkg}>=${version}_${revision}"
short_desc+=" - development files"
pkg_install() {
vmove usr/include
}
}

View file

@ -0,0 +1,2 @@
site=https://www.electronjs.org/releases/stable?version=${version%%.*}
pattern='tag/v\K[\d\.]+(?=")'