Skip to content

Commit

Permalink
Build partition_alloc
Browse files Browse the repository at this point in the history
  • Loading branch information
niranjanyardi committed Dec 14, 2024
1 parent e967f94 commit a61fe7b
Show file tree
Hide file tree
Showing 13 changed files with 177 additions and 24 deletions.
21 changes: 20 additions & 1 deletion base/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -1087,6 +1087,25 @@ component("base") {
"//third_party/abseil-cpp:absl",
]

if (is_cobalt && is_starboard && current_toolchain == cobalt_toolchain) {
import("//cobalt/build/configs/modular_variables.gni")
if (use_custom_libc) {
if (is_starboard && current_toolchain == cobalt_toolchain) {
deps -= [ "//base/allocator/partition_allocator:raw_ptr" ]

# TODO: b/330221826 Change to |public_configs| with matching dependencies.
# all_dependent_configs += [ ":starboard_config" ]
}
}
}

if (is_cobalt && is_starboard && current_toolchain == cobalt_toolchain) {
import("//cobalt/build/configs/modular_variables.gni")
if (use_custom_libc) {
deps += [ "//starboard:starboard_group" ]
}
}

if (build_rust_base_conversions) {
# Base provides conversions between CXX types and base types (e.g.
# StringPiece).
Expand Down Expand Up @@ -1627,7 +1646,7 @@ component("base") {
]
}

if (is_posix) {
if (is_posix && !is_cobalt) {
sources += [
"base_paths_posix.h",
"memory/madv_free_discardable_memory_allocator_posix.cc",
Expand Down
11 changes: 9 additions & 2 deletions base/allocator/partition_allocator/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -214,15 +214,15 @@ component("partition_alloc") {
"partition_alloc_base/time/time_win.cc",
"partition_tls_win.cc",
]
} else if (is_posix) {
} else if (is_posix && !is_cobalt) {
sources += [
"page_allocator_internals_posix.cc",
"page_allocator_internals_posix.h",
"partition_alloc_base/files/file_util.h",
"partition_alloc_base/files/file_util_posix.cc",
"partition_alloc_base/posix/safe_strerror.cc",
"partition_alloc_base/posix/safe_strerror.h",
"partition_alloc_base/rand_util_posix.cc",
# "partition_alloc_base/rand_util_posix.cc",
"partition_alloc_base/threading/platform_thread_internal_posix.h",
"partition_alloc_base/threading/platform_thread_posix.cc",
"partition_alloc_base/time/time_conversion_posix.cc",
Expand Down Expand Up @@ -320,6 +320,13 @@ component("partition_alloc") {
# tagging.cc requires __arm_mte_set_* functions.
deps += [ "//third_party/android_ndk:cpu_features" ]
}

if (is_cobalt && is_starboard && current_toolchain == cobalt_toolchain) {
import("//cobalt/build/configs/modular_variables.gni")
if (use_custom_libc) {
deps += [ "//starboard:starboard_group" ]
}
}
if (is_fuchsia) {
public_deps += [
"//third_party/fuchsia-sdk/sdk/pkg/fit",
Expand Down
4 changes: 2 additions & 2 deletions base/allocator/partition_allocator/partition_alloc_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ static_assert(sizeof(void*) != 8, "");
#endif

#if BUILDFLAG(HAS_64_BIT_POINTERS) && \
(BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_ANDROID))
(BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_ANDROID)) && !BUILDFLAG(IS_STARBOARD)
#include <linux/version.h>
// TODO(bikineev): Enable for ChromeOS.
#define PA_CONFIG_STARSCAN_UFFD_WRITE_PROTECTOR_SUPPORTED() \
Expand Down Expand Up @@ -104,7 +104,7 @@ static_assert(sizeof(void*) != 8, "");
// POSIX is not only UNIX, e.g. macOS and other OSes. We do use Linux-specific
// features such as futex(2).
#define PA_CONFIG_HAS_LINUX_KERNEL() \
(BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID))
(BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID)) && !BUILDFLAG(IS_STARBOARD)

// On some platforms, we implement locking by spinning in userspace, then going
// into the kernel only if there is contention. This requires platform support,
Expand Down
33 changes: 31 additions & 2 deletions build/config/c++/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,34 @@ config("runtime_library") {
"-isystem" + rebase_path("$libcxx_prefix/include", root_build_dir),
"-isystem" + rebase_path("$libcxxabi_prefix/include", root_build_dir),
]
if (is_cobalt && is_starboard && current_toolchain == cobalt_toolchain) {
import("//cobalt/build/configs/modular_variables.gni")
if (use_custom_libc) {
# if (is_cobalt) {
# import("//cobalt/build/configs/modular_variables.gni")
# if (is_starboard && current_toolchain == cobalt_toolchain &&
# use_custom_libc) {
# deps = [
# "//third_party/llvm-project/compiler-rt:compiler_rt",
# "//third_party/musl:c",
# ]
# all_dependent_configs = [ "//starboard/build/config/modular/x64" ]
# }
# }
cflags_cc += [
"-isystem" +
rebase_path("//third_party/musl/include", root_build_dir),
"-isystem" +
rebase_path("//third_party/musl/arch/generic", root_build_dir),
]
cflags_c = [
"-isystem" +
rebase_path("//third_party/musl/include", root_build_dir),
"-isystem" +
rebase_path("//third_party/musl/arch/generic", root_build_dir),
]
}
}

cflags_objcc = cflags_cc

Expand All @@ -87,10 +115,11 @@ config("runtime_library") {
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83931); -nodefaultlibs
# removes all of the default libraries, so add back the ones that we need.
libs += [
"c",
# "c",
"gcc_s",
"m",
"rt",

# "rt",
]
}
}
Expand Down
23 changes: 23 additions & 0 deletions buildtools/third_party/libc++/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ target(_libcxx_target_type, "libc++") {
"//build/config:common_deps",
"//third_party/catapult/devil:devil",
]
if (is_cobalt && is_starboard && current_toolchain == cobalt_toolchain) {
import("//cobalt/build/configs/modular_variables.gni")
if (use_custom_libc) {
visibility += [ "//starboard:starboard_group" ]
}
}

if (is_linux) {
# This target packages libc++.so, so must have an explicit dependency on
# libc++.
Expand Down Expand Up @@ -115,6 +122,12 @@ target(_libcxx_target_type, "libc++") {
"trunk/src/verbose_abort.cpp",
]

if (is_cobalt && is_starboard && current_toolchain == cobalt_toolchain) {
import("//cobalt/build/configs/modular_variables.gni")
if (use_custom_libc) {
sources-= [ "trunk/src/atomic.cpp",]
}}

if (enable_iterator_debugging) {
sources += [
"trunk/src/debug.cpp",
Expand Down Expand Up @@ -210,4 +223,14 @@ target(_libcxx_target_type, "libc++") {
deps = [ "//buildtools/third_party/libc++abi" ]
}
}
if (is_cobalt) {
import("//cobalt/build/configs/modular_variables.gni")
if (is_starboard && current_toolchain == cobalt_toolchain &&
use_custom_libc) {
deps += [
"//third_party/llvm-project/compiler-rt:compiler_rt",
"//third_party/musl:c",
]
}
}
}
14 changes: 14 additions & 0 deletions buildtools/third_party/libc++abi/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ source_set("libc++abi") {
} else {
visibility = [ "//buildtools/third_party/libc++" ]
}
if (is_cobalt && is_starboard && current_toolchain == cobalt_toolchain) {
import("//cobalt/build/configs/modular_variables.gni")
if (use_custom_libc) {
visibility += [ "//starboard:starboard_group" ]
}
}

# Fuchsia builds don't link against any libraries that provide stack
# unwinding symbols, unlike Linux does with glibc (same applies for Android).
Expand All @@ -21,6 +27,14 @@ source_set("libc++abi") {
deps = [ "//buildtools/third_party/libunwind" ]
}

if (is_cobalt) {
import("//cobalt/build/configs/modular_variables.gni")
if (is_starboard && current_toolchain == cobalt_toolchain &&
use_custom_libc) {
deps = [ "//third_party/musl:c" ]
}
}

sources = [
"trunk/src/abort_message.cpp",
"trunk/src/cxa_aux_runtime.cpp",
Expand Down
9 changes: 7 additions & 2 deletions cobalt/build/configs/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import("//cobalt/build/configs/modular_variables.gni")
import("//starboard/build/buildflags.gni")

config("cobalt_config") {
Expand All @@ -21,8 +22,12 @@ config("cobalt_config") {
]
if (current_toolchain == starboard_toolchain) {
configs += [ "//${starboard_path}/platform_configuration" ]
} else if (current_toolchain == cobalt_toolchain) {
# TODO(nyardi) : Add modular/cobalt toolchain configs as needed"
} else if (current_toolchain == cobalt_toolchain && is_starboard &&
use_custom_libc) {
configs += [
"//starboard/build/config/modular/x64",
"//starboard/build/config:starboard",
]
} else {
# No configs to add for any other toolchain
}
Expand Down
5 changes: 5 additions & 0 deletions cobalt/build/configs/linux-x64x11/args.gn
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,8 @@ media_use_ffmpeg = false
# Overriding flag from components/nacl/features.gni
# NACL platform is deprecated in 2022 : https://sites.google.com/a/google.com/sandboxing-mitigations/reviews/nacl
enable_nacl = false

use_custom_libcxx = true

use_partition_alloc = false
enable_pkeys = false
63 changes: 62 additions & 1 deletion starboard/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,68 @@ if (!is_cobalt) {
}
} else {
group("starboard_group") {
deps = [ "//starboard($starboard_toolchain)" ]
deps = []
public_deps = [
":starboard_headers_only",
"//starboard/client_porting/eztime",
]

if (sb_is_modular && current_toolchain == cobalt_toolchain) {
public_deps += [
"//buildtools/third_party/libc++",
"//buildtools/third_party/libc++abi",
"//third_party/llvm-project/compiler-rt:compiler_rt",
"//third_party/musl:c",
]

if (!sb_is_evergreen) {
# For modular builds, we need to wrap any POSIX APIs that may not be ABI
# equivalent across the Cobalt toolchain and the platform toolchain. For
# non-Evergreen builds, this is done via the below wrapper implementations
# of the API functions, which will simply call a renamed version of the
# function that will be implemented in the Starboard shared library. The
# same behavior is achieved in Evergreen via exported_symbols.cc remapping
# the functions to the same renamed version. In both cases, implementation
# of these renamed functions will handle translating data types across the
# ABI boundary and be compiled into the Starboard shared library in
# //starboard/build/config/starboard_target_type.gni.
deps += [ "//starboard/shared/modular:cobalt_layer_posix_abi_wrappers" ]
}

if (sb_is_evergreen) {
public_deps += [ "//starboard/elf_loader:sabi_string" ]
} else {
data_deps = [ ":starboard($starboard_toolchain)" ]
}

# TODO: b/295702296 Fix libunwind for modular builds.
if (sb_is_evergreen) {
public_deps += [ "//third_party/llvm-project/libunwind:unwind" ]
}
} else {
public_deps += [
":starboard($starboard_toolchain)",
"//starboard/common",
]

if (enable_evergreen_code) {
if (!sb_is_modular || sb_is_evergreen) {
if (sb_is_evergreen_compatible &&
current_toolchain == starboard_toolchain) {
public_deps += [ "//starboard/crashpad_wrapper" ]
} else {
public_deps += [ "//starboard/crashpad_wrapper:wrapper_stub" ]
}
}
}

if (final_executable_type == "shared_library" &&
current_toolchain != default_toolchain) {
set_defaults("executable") {
sources = [ "//starboard/shared/starboard/shared_main_adapter.cc" ]
}
}
}
}
}

Expand Down
10 changes: 1 addition & 9 deletions starboard/build/config/modular/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,11 @@ config("modular") {
"-ffunction-sections",
"-fdata-sections",
"-nostdlibinc",
"-isystem" + rebase_path("//third_party/llvm-project/libcxxabi/include",
root_build_dir),
"-isystem" + rebase_path("//third_party/llvm-project/libunwind/include",
root_build_dir),
"-isystem" + rebase_path("//third_party/llvm-project/libcxx/include",
root_build_dir),
"-isystem" + rebase_path("//third_party/musl/include", root_build_dir),
"-isystem" + rebase_path("//third_party/musl/arch/generic", root_build_dir),
]

cflags += [ "-fPIC" ]

cflags_cc = [ "-nostdinc++" ]
# cflags_cc = [ "-nostdinc++" ]

defines = [
# Ensure that the Starboardized __external_threading file is included.
Expand Down
3 changes: 1 addition & 2 deletions third_party/abseil-cpp/absl/base/internal/direct_mmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@

#include <sys/mman.h>

#ifdef __linux__

#if defined(__linux__) && !defined(STARBOARD)
#include <sys/types.h>
#ifdef __BIONIC__
#include <sys/syscall.h>
Expand Down
1 change: 0 additions & 1 deletion third_party/llvm-project/compiler-rt/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,4 @@ static_library("compiler_rt") {
}

configs += [ ":compiler_rt_config" ]
configs -= [ "//starboard/build/config:default_cpp_standard" ]
}
4 changes: 2 additions & 2 deletions third_party/musl/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ if (target_cpu == "x64") {

config("external_settings") {
include_dirs = [
"musl/include",
"include",
"arch/$musl_arch",
"arch/generic",
]
Expand Down Expand Up @@ -518,7 +518,7 @@ static_library("c_internal") {
}

deps = [
"//starboard:starboard_headers_only",
"//starboard:starboard_headers_only",
"//starboard/client_porting/eztime",
"//starboard/common:common_headers_only",
]
Expand Down

0 comments on commit a61fe7b

Please sign in to comment.