From 2b2014823bafe7bfc1dc0aa8f9a08e264532742d Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Thu, 25 Jun 2026 23:27:01 +0200 Subject: [PATCH 01/36] cleanup: remove BUILD.gn support --- .gn | 25 - BUILD.gn | 33 -- src/BUILD.gn | 57 --- src/nonsfi/irt/BUILD.gn | 42 -- src/nonsfi/loader/BUILD.gn | 38 -- src/shared/gio/BUILD.gn | 14 - src/shared/imc/BUILD.gn | 41 -- src/shared/platform/BUILD.gn | 112 ----- src/third_party/gtest/BUILD.gn | 109 ----- src/tools/tls_edit/BUILD.gn | 20 - src/trusted/cpu_features/BUILD.gn | 43 -- src/trusted/debug_stub/BUILD.gn | 58 --- src/trusted/desc/BUILD.gn | 52 --- src/trusted/error_code/BUILD.gn | 11 - src/trusted/fault_injection/BUILD.gn | 17 - src/trusted/interval_multiset/BUILD.gn | 17 - src/trusted/nacl_base/BUILD.gn | 16 - src/trusted/perf_counter/BUILD.gn | 14 - src/trusted/platform_qualify/BUILD.gn | 78 ---- src/trusted/service_runtime/BUILD.gn | 354 --------------- src/trusted/service_runtime/linux/BUILD.gn | 166 ------- .../service_runtime/linux/toolchain/BUILD.gn | 37 -- src/trusted/validator/BUILD.gn | 35 -- src/trusted/validator/driver/BUILD.gn | 37 -- src/trusted/validator_arm/BUILD.gn | 51 --- src/trusted/validator_mips/BUILD.gn | 46 -- src/trusted/validator_ragel/BUILD.gn | 60 --- src/trusted/validator_x86/BUILD.gn | 28 -- src/trusted/win/BUILD.gn | 78 ---- src/untrusted/elf_loader/BUILD.gn | 42 -- src/untrusted/irt/BUILD.gn | 72 --- src/untrusted/nacl/BUILD.gn | 427 ------------------ src/untrusted/pthread/BUILD.gn | 20 - tests/BUILD.gn | 42 -- tests/hello_world/BUILD.gn | 17 - 35 files changed, 2309 deletions(-) delete mode 100644 .gn delete mode 100644 BUILD.gn delete mode 100644 src/BUILD.gn delete mode 100644 src/nonsfi/irt/BUILD.gn delete mode 100644 src/nonsfi/loader/BUILD.gn delete mode 100644 src/shared/gio/BUILD.gn delete mode 100644 src/shared/imc/BUILD.gn delete mode 100644 src/shared/platform/BUILD.gn delete mode 100644 src/third_party/gtest/BUILD.gn delete mode 100644 src/tools/tls_edit/BUILD.gn delete mode 100644 src/trusted/cpu_features/BUILD.gn delete mode 100644 src/trusted/debug_stub/BUILD.gn delete mode 100644 src/trusted/desc/BUILD.gn delete mode 100644 src/trusted/error_code/BUILD.gn delete mode 100644 src/trusted/fault_injection/BUILD.gn delete mode 100644 src/trusted/interval_multiset/BUILD.gn delete mode 100644 src/trusted/nacl_base/BUILD.gn delete mode 100644 src/trusted/perf_counter/BUILD.gn delete mode 100644 src/trusted/platform_qualify/BUILD.gn delete mode 100644 src/trusted/service_runtime/BUILD.gn delete mode 100644 src/trusted/service_runtime/linux/BUILD.gn delete mode 100644 src/trusted/service_runtime/linux/toolchain/BUILD.gn delete mode 100644 src/trusted/validator/BUILD.gn delete mode 100644 src/trusted/validator/driver/BUILD.gn delete mode 100644 src/trusted/validator_arm/BUILD.gn delete mode 100644 src/trusted/validator_mips/BUILD.gn delete mode 100644 src/trusted/validator_ragel/BUILD.gn delete mode 100644 src/trusted/validator_x86/BUILD.gn delete mode 100644 src/trusted/win/BUILD.gn delete mode 100644 src/untrusted/elf_loader/BUILD.gn delete mode 100644 src/untrusted/irt/BUILD.gn delete mode 100644 src/untrusted/nacl/BUILD.gn delete mode 100644 src/untrusted/pthread/BUILD.gn delete mode 100644 tests/BUILD.gn delete mode 100644 tests/hello_world/BUILD.gn diff --git a/.gn b/.gn deleted file mode 100644 index 5c3a24b2a4..0000000000 --- a/.gn +++ /dev/null @@ -1,25 +0,0 @@ -# Copyright (c) 2014 The Native Client Authors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - -# This file is used by the experimental meta-buildsystem in native_client to -# find the root of the source tree and to set startup options. - -# The location of the top of the build (BUILD.gn). -root = "//native_client" - -# The location of the build configuration file. -buildconfig = "//build/config/BUILDCONFIG.gn" - -# The python interpreter to use by default. On Windows, this will look -# for python3.exe and python3.bat. -script_executable = "python3" - -# The secondary source root is a parallel directory tree where -# GN build files are placed when they can not be placed directly -# in the source tree, e.g. for third party source trees. -secondary_source = "//build/secondary/" - -default_args = { - use_custom_libcxx = false -} \ No newline at end of file diff --git a/BUILD.gn b/BUILD.gn deleted file mode 100644 index 27e0e75c38..0000000000 --- a/BUILD.gn +++ /dev/null @@ -1,33 +0,0 @@ -# Copyright (c) 2014 The Native Client Authors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - -# This is the root build file for GN. GN will start processing by loading this -# file, and recursively load all dependencies until all dependencies are either -# resolved or known not to exist (which will cause the build to fail). So if -# you add a new build file, there must be some path of dependencies from this -# file to your new one or GN won't know about it. -# -# All targets in this file file are built by default. -# -# Here we declare the meta targets which pull in the various architecture -# combinations of the real targets. -# - -import("config.gni") - -group("trusted") { - deps = [ - "//native_client/src:trusted_targets", - ] -} - -# -# This is the root untrusted target which will build all trusted components -# -group("untrusted") { - deps = [ - "//native_client/src/:irt_targets($toolchain_irt)", - "//native_client/src/:untrusted_targets($toolchain_untrusted)", - ] -} diff --git a/src/BUILD.gn b/src/BUILD.gn deleted file mode 100644 index e0c7c19da6..0000000000 --- a/src/BUILD.gn +++ /dev/null @@ -1,57 +0,0 @@ -# Copyright (c) 2014 The Native Client Authors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - -group("trusted_targets") { - deps = [ - "//native_client/src/shared/imc:imc", - "//native_client/src/shared/platform:platform", - "//native_client/src/trusted/cpu_features:all_cpu_features", - "//native_client/src/trusted/debug_stub:debug_stub", - "//native_client/src/trusted/desc:nrd_xfer", - "//native_client/src/trusted/desc:nrd_xfer", - "//native_client/src/trusted/error_code", - "//native_client/src/trusted/fault_injection:nacl_fault_inject", - "//native_client/src/trusted/interval_multiset:nacl_interval", - "//native_client/src/trusted/nacl_base:nacl_base", - "//native_client/src/trusted/perf_counter:nacl_perf_counter", - "//native_client/src/trusted/platform_qualify:platform_qual_lib", - "//native_client/src/trusted/service_runtime:env_cleanser", - "//native_client/src/trusted/service_runtime:sel", - "//native_client/src/trusted/service_runtime:sel_ldr", - "//native_client/src/trusted/service_runtime:sel_main", - "//native_client/src/trusted/validator/driver:elf_load", - "//native_client/src/trusted/validator/driver:ncval_new", - "//native_client/src/trusted/validator_ragel:rdfa_validator", - ] - if (is_linux || is_chromeos) { - deps += [ "//native_client/src/nonsfi/loader:nonsfi_loader" ] - } -} - -group("tests") { - testonly = true - deps = [ - "//native_client/tests:large_tests", - "//native_client/tests:medium_tests", - "//native_client/tests:small_tests", - ] -} - -if (is_nacl) { - group("untrusted_targets") { - deps = [ - "//native_client/src/shared/gio:gio", - "//native_client/src/shared/platform:platform", - "//native_client/src/untrusted/elf_loader:elf_loader", - "//native_client/src/untrusted/nacl:imc_syscalls", - "//native_client/tests/hello_world:hello_world", - ] - } - - group("irt_targets") { - deps = [ - "//native_client/src/untrusted/irt:irt_core", - ] - } -} diff --git a/src/nonsfi/irt/BUILD.gn b/src/nonsfi/irt/BUILD.gn deleted file mode 100644 index d8106d5271..0000000000 --- a/src/nonsfi/irt/BUILD.gn +++ /dev/null @@ -1,42 +0,0 @@ -# Copyright 2015 The Native Client Authors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - -static_library("irt_interfaces") { - sources = [ - "../../untrusted/irt/irt_query_list.c", - "irt_interfaces.c", - "irt_random.c", - ] - - deps = [ - "//build/config/nacl:nacl_base", - ] -} - -if (is_nacl) { - static_library("nacl_sys_private") { - cflags = [ "-fgnu-inline-asm" ] - - sources = [ - "../../untrusted/irt/irt_query_list.c", - "../../untrusted/pthread/nc_condvar.c", - "../../untrusted/pthread/nc_mutex.c", - "../../untrusted/pthread/nc_thread.c", - "../../untrusted/pthread/stack_end.c", - "../../untrusted/valgrind/dynamic_annotations.c", - "../linux/directory.c", - "../linux/irt_signal_handling.c", - "../linux/linux_futex.c", - "../linux/linux_pthread_private.c", - "../linux/linux_sys_private.c", - "irt_icache.c", - "irt_interfaces.c", - "irt_random.c", - ] - - deps = [ - "//build/config/nacl:nacl_base", - ] - } -} diff --git a/src/nonsfi/loader/BUILD.gn b/src/nonsfi/loader/BUILD.gn deleted file mode 100644 index 309ef372e7..0000000000 --- a/src/nonsfi/loader/BUILD.gn +++ /dev/null @@ -1,38 +0,0 @@ -# Copyright 2015 The Native Client Authors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - -static_library("elf_loader") { - sources = [ - "elf_loader.c", - ] - - deps = [ - "//build/config/nacl:nacl_base", - "//native_client/src/shared/platform:platform", - ] -} - -if (is_linux || is_nacl || is_chromeos) { - executable("nonsfi_loader") { - sources = [ - "elf_loader_main.c", - ] - - deps = [ - ":elf_loader", - "//native_client/src/nonsfi/irt:irt_interfaces", - "//native_client/src/shared/platform", - ] - if (is_nacl) { - deps += [ - "//native_client/src/nonsfi/irt:nacl_sys_private", - "//native_client/src/untrusted/nacl", - ] - } - # TODO(fabiansommer): Remove with next build deps roll - if (is_linux && current_cpu == "x86") { - ldflags = [ "-static-libstdc++" ] - } - } -} diff --git a/src/shared/gio/BUILD.gn b/src/shared/gio/BUILD.gn deleted file mode 100644 index 02fc134264..0000000000 --- a/src/shared/gio/BUILD.gn +++ /dev/null @@ -1,14 +0,0 @@ -# Copyright (c) 2014 The Native ClientAuthors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - -static_library("gio") { - sources = [ - "gio.c", - "gprintf.c", - ] - - deps = [ - "//build/config/nacl:nacl_base", - ] -} diff --git a/src/shared/imc/BUILD.gn b/src/shared/imc/BUILD.gn deleted file mode 100644 index bc7f7fe3fd..0000000000 --- a/src/shared/imc/BUILD.gn +++ /dev/null @@ -1,41 +0,0 @@ -# Copyright (c) 2014 The Native ClientAuthors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - -static_library("imc") { - sources = [ - "nacl_imc_common.cc", - ] - - if (current_os == "nacl") { - sources += [ "nacl/nacl_imc.cc" ] - } - - if (current_os == "mac") { - sources += [ - "osx/nacl_imc.cc", - "posix/nacl_imc_posix.cc", - ] - } - - if (is_linux || is_chromeos) { - sources += [ - "linux/nacl_imc.cc", - "posix/nacl_imc_posix.cc", - ] - - libs = [ "rt" ] - } - - if (current_os == "win") { - sources += [ - "win/nacl_imc.cc", - "win/nacl_shm.cc", - ] - } - - deps = [ - "//build/config/nacl:nacl_base", - "//native_client/src/shared/platform:platform", - ] -} diff --git a/src/shared/platform/BUILD.gn b/src/shared/platform/BUILD.gn deleted file mode 100644 index 503427fa29..0000000000 --- a/src/shared/platform/BUILD.gn +++ /dev/null @@ -1,112 +0,0 @@ -# Copyright (c) 2014 The Native ClientAuthors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - -# Autogenerated from src/shared/platform/build.scons. - -static_library("platform") { - cflags_c = [ - "-Wno-cast-function-type-mismatch", - "-Wno-unknown-warning-option" - ] - - if (current_os == "nacl") { - sources = [ - "nacl_check.c", - "nacl_log.c", - "posix/condition_variable.c", - "posix/lock.c", - "posix/nacl_error.c", - "posix/nacl_exit.c", - "posix/nacl_thread_id.c", - "posix/nacl_threads.c", - "posix/nacl_timestamp.c", - "nacl_sync_checked.c", - "refcount_base.cc", - ] - } else { - sources = [ - "nacl_check.c", - "nacl_global_secure_random.c", - "nacl_host_desc_common.c", - "nacl_interruptible_condvar.c", - "nacl_interruptible_mutex.c", - "nacl_log.c", - "nacl_secure_random_common.c", - "nacl_sync_checked.c", - "nacl_time_common.c", - "platform_init.c", - "refcount_base.cc", - ] - if (current_os != "win") { - sources += [ - "posix/aligned_malloc.c", - "posix/condition_variable.c", - "posix/lock.c", - "posix/nacl_error.c", - "posix/nacl_exit.c", - "posix/nacl_fast_mutex.c", - "posix/nacl_file_lock.c", - "posix/nacl_find_addrsp.c", - "posix/nacl_host_desc.c", - "posix/nacl_secure_random.c", - "posix/nacl_thread_id.c", - "posix/nacl_threads.c", - "posix/nacl_time.c", - "posix/nacl_timestamp.c", - ] - } - - if (current_os == "win") { - sources += [ - "win/aligned_malloc.c", - "win/condition_variable.cc", - "win/lock.cc", - "win/lock_impl_win.cc", - "win/nacl_clock.c", - "win/nacl_error.c", - "win/nacl_exit.c", - "win/nacl_fast_mutex.c", - "win/nacl_find_addrsp.c", - "win/nacl_host_desc.c", - "win/nacl_host_dir.c", - "win/nacl_secure_random.c", - "win/nacl_semaphore.c", - "win/nacl_sync_win.cc", - "win/nacl_threads.c", - "win/nacl_time.c", - "win/nacl_timestamp.c", - "win/port_win.c", - "win/xlate_system_error.c", - ] - } - - if (current_os == "mac") { - sources += [ - "osx/nacl_clock.c", - "osx/nacl_host_dir.c", - "osx/nacl_semaphore.c", - ] - } - - if (is_linux || is_chromeos) { - sources += [ - "linux/nacl_clock.c", - "linux/nacl_host_dir.c", - "linux/nacl_semaphore.c", - ] - } - - if (current_os == "win") { - cflags_c = [ - "/DUNICODE", - "/D_CRT_RAND_S", - "/D_UNICODE", - ] - } - } - deps = [ - "//build/config/nacl:nacl_base", - "//native_client/src/shared/gio:gio", - ] -} diff --git a/src/third_party/gtest/BUILD.gn b/src/third_party/gtest/BUILD.gn deleted file mode 100644 index f203ba1300..0000000000 --- a/src/third_party/gtest/BUILD.gn +++ /dev/null @@ -1,109 +0,0 @@ -# Copyright 2014 The Chromium Authors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - -# Chromium's GN configuration for gtest now lives at testing/gtest/BUILD.gn. -# -# This configuration is left in the tree because it is pulled by V8 and PDFium, -# and will be removed as soon as the projects switch off of it. -# -# Details at http://crbug.com/630705 and http://crrev.com/2779193002 - -import("//build_overrides/gtest.gni") - -#root = "../.." - -config("gtest_config") { - visibility = [ - ":*", - "//testing/gmock:*", # gmock also shares this config. - ] - - defines = [ - # In order to allow regex matches in gtest to be shared between Windows - # and other systems, we tell gtest to always use it's internal engine. - "GTEST_HAS_POSIX_RE=0", - "GTEST_LANG_CXX11=1", - ] - - # Gtest headers need to be able to find themselves. - include_dirs = [ "../../../../testing/gtest/include", "../../../../testing/gtest/" ] - - cflags = [ "-Wno-deprecated-copy-with-user-provided-copy" ] - if (is_win) { - cflags += [ "/wd4800" ] # Unused variable warning. - } -} - -config("gtest_direct_config") { - visibility = [ ":*" ] - defines = [ "UNIT_TEST" ] -} - -config("gtest_warnings") { - if (is_win && is_clang) { - # The Mutex constructor initializer list in gtest-port.cc is incorrectly - # ordered. See - # https://groups.google.com/d/msg/googletestframework/S5uSV8L2TX8/U1FaTDa6J6sJ. - cflags = [ "-Wno-reorder" ] - } -} - -static_library("gtest") { - testonly = true - sources = [ - "include/gtest/gtest-death-test.h", - "include/gtest/gtest-message.h", - "include/gtest/gtest-param-test.h", - "include/gtest/gtest-printers.h", - "include/gtest/gtest-spi.h", - "include/gtest/gtest-test-part.h", - "include/gtest/gtest-typed-test.h", - "include/gtest/gtest.h", - "include/gtest/gtest_pred_impl.h", - "include/gtest/internal/gtest-death-test-internal.h", - "include/gtest/internal/gtest-filepath.h", - "include/gtest/internal/gtest-internal.h", - "include/gtest/internal/gtest-linked_ptr.h", - "include/gtest/internal/gtest-param-util-generated.h", - "include/gtest/internal/gtest-param-util.h", - "include/gtest/internal/gtest-port.h", - "include/gtest/internal/gtest-string.h", - "include/gtest/internal/gtest-tuple.h", - "include/gtest/internal/gtest-type-util.h", - - #"gtest/src/gtest-all.cc", # Not needed by our build. - "../../../../testing/gtest/src/gtest-death-test.cc", - "../../../../testing/gtest/src/gtest-filepath.cc", - "../../../../testing/gtest/src/gtest-internal-inl.h", - "../../../../testing/gtest/src/gtest-port.cc", - "../../../../testing/gtest/src/gtest-printers.cc", - "../../../../testing/gtest/src/gtest-test-part.cc", - "../../../../testing/gtest/src/gtest-typed-test.cc", - "../../../../testing/gtest/src/gtest.cc", - ] - deps = [] - - include_dirs = [ "." ] - - all_dependent_configs = [ ":gtest_config" ] - public_configs = [ ":gtest_direct_config" ] - - configs -= [ "//build/config/compiler:chromium_code" ] - configs += [ - "//build/config/compiler:no_chromium_code", - - # Must be after no_chromium_code for warning flags to be ordered correctly. - ":gtest_warnings", - ] -} - -source_set("gtest_main") { - testonly = true - sources = [ - "../../../../testing/gtest/src/gtest_main.cc", - ] - deps = [ - ":gtest", - ] -} diff --git a/src/tools/tls_edit/BUILD.gn b/src/tools/tls_edit/BUILD.gn deleted file mode 100644 index fa5c32c9d8..0000000000 --- a/src/tools/tls_edit/BUILD.gn +++ /dev/null @@ -1,20 +0,0 @@ -# Copyright (c) 2014 The Native ClientAuthors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - -executable("tls_edit") { - sources = [ - "tls_edit.c", - ] - deps = [ - "//build/config/nacl:nacl_base", - "//build/win:default_exe_manifest", - "//native_client/src/shared/platform:platform", - "//native_client/src/trusted/validator_ragel:rdfa_validator", - ] - - # TODO(fabiansommer): Remove with next build deps roll - if (is_linux && current_cpu == "x86") { - ldflags = [ "-static-libstdc++" ] - } -} diff --git a/src/trusted/cpu_features/BUILD.gn b/src/trusted/cpu_features/BUILD.gn deleted file mode 100644 index b557a11684..0000000000 --- a/src/trusted/cpu_features/BUILD.gn +++ /dev/null @@ -1,43 +0,0 @@ -# Copyright 2014 The Native Client Authors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - -import("//native_client/src/trusted/asm.gni") - -group("all_cpu_features") { - deps = [ - ":cpu_features", - ] -} - -if (current_toolchain == nacl_asm_toolchain) { - source_set("cpu_features_asm") { - if (current_cpu == "x64" || current_cpu == "x86") { - sources = [ - "arch/x86/cpu_xgetbv.S", - ] - } - deps = [ - "//build/config/nacl:nacl_base", - ] - } -} - -source_set("cpu_features") { - include_dirs = [ "." ] - sources = [ - "arch/arm/cpu_arm.c", - "arch/mips/cpu_mips.c", - ] - - if (current_cpu == "x64" || current_cpu == "x86") { - sources += [ - "arch/x86/cpu_x86.c", - ] - } - - deps = [ - "//build/config/nacl:nacl_base", - ":cpu_features_asm($nacl_asm_toolchain)", - ] -} diff --git a/src/trusted/debug_stub/BUILD.gn b/src/trusted/debug_stub/BUILD.gn deleted file mode 100644 index 44db545b96..0000000000 --- a/src/trusted/debug_stub/BUILD.gn +++ /dev/null @@ -1,58 +0,0 @@ -# Copyright (c) 2014 The Native ClientAuthors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. -import("//build/config/sanitizers/sanitizers.gni") - -static_library("debug_stub") { - sources = [ - "abi.cc", - "debug_stub.cc", - "nacl_debug.cc", - "packet.cc", - "session.cc", - "target.cc", - "thread_common.cc", - "transport_common.cc", - "transport_ipc.cc", - "util.cc", - ] - if (current_os != "win") { - sources += [ - "posix/debug_stub_posix.cc", - "posix/platform_impl.cc", - "posix/thread_impl.cc", - ] - } - if (current_os == "win") { - sources += [ - "win/debug_stub_win.cc", - "win/platform_impl.cc", - "win/thread_impl.cc", - ] - } - deps = [ - "//build/config/nacl:nacl_base", - "//native_client/src/shared/platform:platform", - ] -} - -executable("gdb_rsp_unittest") { - sources = [ - "abi_test.cc", - "packet_test.cc", - "session_test.cc", - "test.cc", - "util_test.cc", - ] - - deps = [ - ":debug_stub", - "//build/config/nacl:nacl_base", - "//build/win:default_exe_manifest", - ] - - # TODO(fabiansommer): Remove with next build deps roll - if (is_linux && current_cpu == "x86") { - ldflags = [ "-static-libstdc++" ] - } -} diff --git a/src/trusted/desc/BUILD.gn b/src/trusted/desc/BUILD.gn deleted file mode 100644 index 6e53f02b00..0000000000 --- a/src/trusted/desc/BUILD.gn +++ /dev/null @@ -1,52 +0,0 @@ -# Copyright (c) 2014 The Native ClientAuthors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - -static_library("nrd_xfer") { - sources = [ - "nacl_desc_base.c", - "nacl_desc_cond.c", - "nacl_desc_custom.c", - "nacl_desc_dir.c", - "nacl_desc_effector_trusted_mem.c", - "nacl_desc_imc.c", - "nacl_desc_imc_shm.c", - "nacl_desc_invalid.c", - "nacl_desc_io.c", - "nacl_desc_mutex.c", - "nacl_desc_null.c", - "nacl_desc_quota.c", - "nacl_desc_quota_interface.c", - "nacl_desc_semaphore.c", - "nacl_desc_sync_socket.c", - "nrd_all_modules.c", - "nrd_xfer.c", - ] - if (current_os != "win") { - sources += [ - "posix/nacl_desc.c", - "posix/nacl_desc_conn_cap.c", - "posix/nacl_desc_imc_bound_desc.c", - "posix/nacl_makeboundsock.c", - ] - } else { - sources += [ - "win/nacl_desc.c", - "nacl_desc_conn_cap.c", - "nacl_desc_imc_bound_desc.c", - "nacl_makeboundsock.c", - ] - } - - if (current_os == "mac") { - sources += [ - "osx/nacl_desc_imc_shm_mach.c", - ] - } - - deps = [ - "//build/config/nacl:nacl_base", - "//native_client/src/shared/imc:imc", - "//native_client/src/trusted/nacl_base:nacl_base", - ] -} diff --git a/src/trusted/error_code/BUILD.gn b/src/trusted/error_code/BUILD.gn deleted file mode 100644 index 1612e3a0c2..0000000000 --- a/src/trusted/error_code/BUILD.gn +++ /dev/null @@ -1,11 +0,0 @@ -# Copyright (c) 2022 The Native Client Authors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - -source_set("error_code") { - sources = [ - "//native_client/src/trusted/service_runtime/nacl_error_code.c", - "//native_client/src/trusted/service_runtime/nacl_error_code.h", - ] - deps = [ "//build/config/nacl:nacl_base" ] -} diff --git a/src/trusted/fault_injection/BUILD.gn b/src/trusted/fault_injection/BUILD.gn deleted file mode 100644 index 092581aad8..0000000000 --- a/src/trusted/fault_injection/BUILD.gn +++ /dev/null @@ -1,17 +0,0 @@ -# Copyright (c) 2014 The Native ClientAuthors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - -# Autogenerated from src/trusted/fault_injection/build.scons. - -static_library("nacl_fault_inject") { - sources = [ - "fault_injection.c", - "test_injection.c", - ] - - deps = [ - "//build/config/nacl:nacl_base", - "//native_client/src/shared/platform:platform", - ] -} diff --git a/src/trusted/interval_multiset/BUILD.gn b/src/trusted/interval_multiset/BUILD.gn deleted file mode 100644 index 8a67493fbd..0000000000 --- a/src/trusted/interval_multiset/BUILD.gn +++ /dev/null @@ -1,17 +0,0 @@ -# Copyright (c) 2014 The Native ClientAuthors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - -# Autogenerated from src/trusted/interval_multiset/build.scons. - -static_library("nacl_interval") { - sources = [ - "nacl_interval_list.c", - "nacl_interval_multiset_delete.c", - "nacl_interval_multiset_factory.c", - "nacl_interval_range_tree.c", - ] - deps = [ - "//build/config/nacl:nacl_base", - ] -} diff --git a/src/trusted/nacl_base/BUILD.gn b/src/trusted/nacl_base/BUILD.gn deleted file mode 100644 index cf2de2857f..0000000000 --- a/src/trusted/nacl_base/BUILD.gn +++ /dev/null @@ -1,16 +0,0 @@ -# Copyright (c) 2014 The Native ClientAuthors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - -# Autogenerated from src/trusted/nacl_base/build.scons. - -static_library("nacl_base") { - sources = [ - "nacl_refcount.c", - ] - - deps = [ - "//build/config/nacl:nacl_base", - "//native_client/src/shared/platform:platform", - ] -} diff --git a/src/trusted/perf_counter/BUILD.gn b/src/trusted/perf_counter/BUILD.gn deleted file mode 100644 index ac63a83d9d..0000000000 --- a/src/trusted/perf_counter/BUILD.gn +++ /dev/null @@ -1,14 +0,0 @@ -# Copyright (c) 2014 The Native ClientAuthors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - -# Autogenerated from src/trusted/perf_counter/build.scons. - -static_library("nacl_perf_counter") { - sources = [ - "nacl_perf_counter.c", - ] - deps = [ - "//build/config/nacl:nacl_base", - ] -} diff --git a/src/trusted/platform_qualify/BUILD.gn b/src/trusted/platform_qualify/BUILD.gn deleted file mode 100644 index 5bebe0be22..0000000000 --- a/src/trusted/platform_qualify/BUILD.gn +++ /dev/null @@ -1,78 +0,0 @@ -# Copyright (c) 2014 The Native ClientAuthors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - -# Autogenerated from src/trusted/platform_qualify/build.scons. - -static_library("platform_qual_lib") { - sources = [] - if (current_os != "win") { - sources += [ "posix/nacl_dep_qualify.c" ] - } - - if (current_cpu != "arm") { - sources += [ "arch/x86/nacl_cpuallowlist.c" ] - } - - if (current_cpu == "x86") { - sources += [ "arch/x86_32/nacl_dep_qualify_arch.c" ] - } - - if (current_cpu == "x64") { - sources += [ "arch/x86_64/nacl_dep_qualify_arch.c" ] - } - - if (current_cpu == "arm") { - sources += [ - "arch/arm/nacl_dep_qualify_arch.c", - "arch/arm/nacl_qualify_fpu.c", - "arch/arm/nacl_qualify_sandbox_instrs.c", - "arch/arm/nacl_qualify_unaligned.c", - ] - } - - if (current_cpu == "mipsel") { - sources += ["arch/mips/nacl_qualify_fpu.c"] - } - - if (current_os == "win") { - sources += [ - "win/nacl_dep_qualify.c", - "win/nacl_os_qualify.c", - ] - } - - if (current_os == "mac") { - sources += [ "osx/nacl_os_qualify.c" ] - } - - if (is_linux || is_chromeos) { - sources += [ "linux/nacl_os_qualify.c" ] - } - - deps = [ - "//build/config/nacl:nacl_base", - "//native_client/src/trusted/cpu_features:cpu_features", - ] -} - -if (current_cpu != "arm" && current_cpu != "mipsel") { - static_library("vcpuid") { - cflags_c = [] - sources = [ - "arch/x86/vcpuid.c", - ] - - if (current_os == "linux") { - cflags_c += [ "-msse3" ] - } - - if (current_os == "mac") { - cflags_c += [ "-mdynamic-no-pic" ] - } - - deps = [ - "//build/config/nacl:nacl_base", - ] - } -} diff --git a/src/trusted/service_runtime/BUILD.gn b/src/trusted/service_runtime/BUILD.gn deleted file mode 100644 index 2d1236b2da..0000000000 --- a/src/trusted/service_runtime/BUILD.gn +++ /dev/null @@ -1,354 +0,0 @@ -# Copyright (c) 2014 The Native Client Authors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - -import("//build/toolchain/toolchain.gni") -import("//native_client/src/trusted/asm.gni") - -if (is_mac) { - import("//build/config/sysroot.gni") -} - -source_set("sel_main") { - sources = [ "sel_main.c" ] - deps = [ - ":sel", - "//build/config/nacl:nacl_base", - "//native_client/src/trusted/debug_stub:debug_stub", - ] -} - -source_set("sel_main_chrome") { - sources = [ "sel_main_chrome.c" ] - deps = [ - ":sel", - "//build/config/nacl:nacl_base", - "//native_client/src/trusted/debug_stub:debug_stub", - ] -} - -source_set("env_cleanser") { - sources = [ "env_cleanser.c" ] - deps = [ "//build/config/nacl:nacl_base" ] -} - -if (current_toolchain == nacl_asm_toolchain) { - source_set("sel_asm") { - if (current_cpu == "x86") { - sources = [ - "arch/x86_32/nacl_switch_32.S", - "arch/x86_32/nacl_switch_all_regs_asm_32.S", - "arch/x86_32/nacl_syscall_32.S", - "arch/x86_32/springboard.S", - "arch/x86_32/tramp_32.S", - ] - } else if (current_cpu == "x64") { - sources = [ - "arch/x86_64/nacl_switch_64.S", - "arch/x86_64/nacl_syscall_64.S", - "arch/x86_64/tramp_64.S", - ] - if (is_win) { - sources += [ - "arch/x86_64/fnstcw.S", - "arch/x86_64/fxsaverstor.S", - "win/exception_patch/exit_fast.S", - "win/exception_patch/intercept.S", - ] - } - } else if (current_cpu == "arm") { - sources = [ - "arch/arm/nacl_switch.S", - "arch/arm/nacl_syscall.S", - "arch/arm/tramp_arm.S", - ] - } else if (current_cpu == "mipsel") { - sources = [ - "arch/mips/nacl_switch.S", - "arch/mips/nacl_syscall.S", - "arch/mips/tramp_mips.S", - ] - } - deps = [ "//build/config/nacl:nacl_base" ] - } -} - -source_set("sel") { - sources = [ - "dyn_array.c", - "elf_util.c", - "filename_util.cc", - "load_file.c", - "nacl_all_modules.c", - "nacl_app_thread.c", - "nacl_copy.c", - "nacl_desc_effector_ldr.c", - "nacl_error_gio.c", - "nacl_error_log_hook.c", - "nacl_globals.c", - "nacl_resource.c", - "nacl_signal_common.c", - "nacl_stack_safety.c", - "nacl_syscall_common.c", - "nacl_syscall_hook.c", - "nacl_syscall_list.c", - "nacl_text.c", - "nacl_valgrind_hooks.c", - "sel_addrspace.c", - "sel_ldr.c", - "sel_ldr_filename.cc", - "sel_ldr_standard.c", - "sel_main_common.c", - "sel_mem.c", - "sel_qualify.c", - "sel_validate_image.c", - "sys_clock.c", - "sys_exception.c", - "sys_fdio.c", - "sys_filename.c", - "sys_futex.c", - "sys_imc.c", - "sys_list_mappings.c", - "sys_memory.c", - "sys_parallel_io.c", - "sys_random.c", - "thread_suspension_common.c", - "thread_suspension_unwind.c", - ] - - if (is_linux || is_chromeos) { - sources += [ "linux/nacl_signal.c" ] - } - - if (is_mac) { - sources += [ - "osx/crash_filter.c", - "osx/mach_exception_handler.c", - "osx/mach_thread_map.c", - "osx/nacl_ldt.c", - "osx/nacl_thread_nice.c", - "osx/thread_suspension.c", - "posix/addrspace_teardown.c", - "posix/sel_memory.c", - "posix/x86/sel_segments.c", - ] - } - - if (is_win) { - sources += [ - "win/addrspace_teardown.c", - "win/debug_exception_handler.c", - "win/debug_exception_handler_standalone.c", - "win/nacl_ldt.c", - "win/nacl_thread_nice.c", - "win/sel_memory.c", - "win/sel_segments.c", - "win/thread_handle_map.c", - ] - } - - if (current_cpu == "arm") { - sources += [ - "arch/arm/nacl_app.c", - "arch/arm/nacl_switch_to_app_arm.c", - "arch/arm/nacl_tls.c", - "arch/arm/sel_addrspace_arm.c", - "arch/arm/sel_ldr_arm.c", - "arch/arm/sel_rt.c", - "linux/nacl_signal_arm.c", - ] - } - - if (current_cpu == "mipsel") { - sources += [ - "arch/mips/nacl_app.c", - "arch/mips/nacl_switch_to_app_mips.c", - "arch/mips/nacl_tls.c", - "arch/mips/sel_addrspace_mips.c", - "arch/mips/sel_ldr_mips.c", - "arch/mips/sel_rt.c", - "linux/nacl_signal_mips.c", - ] - } - - if (is_linux || is_chromeos || is_android) { - sources += [ - "linux/nacl_bootstrap_args.c", - "linux/nacl_thread_nice.c", - "linux/r_debug.c", - "linux/reserved_at_zero.c", - "linux/thread_suspension.c", - "posix/addrspace_teardown.c", - "posix/sel_memory.c", - ] - if (current_cpu == "x86" || current_cpu == "x64") { - sources += [ - "linux/x86/nacl_ldt.c", - "posix/x86/sel_segments.c", - ] - } - if (current_cpu == "arm") { - sources += [ "linux/arm/sel_segments.c" ] - } - if (current_cpu == "mipsel") { - sources += [ "linux/mips/sel_segments.c" ] - } - } - - if (is_posix) { - sources += [ - "posix/nacl_signal_stack.c", - "posix/sel_addrspace_posix.c", - ] - } - - if (is_win) { - sources += [ - "win/nacl_signal_stack.c", - "win/sel_addrspace_win.c", - "win/thread_suspension.c", - "win/vm_hole.c", - ] - } else { - sources += [ "generic/vm_hole.c" ] - } - - if (current_cpu == "x86" || current_cpu == "x64") { - sources += [ "arch/x86/nacl_ldt_x86.c" ] - } - - if (current_cpu == "x86") { - sources += [ - "arch/x86_32/nacl_app_32.c", - "arch/x86_32/nacl_switch_all_regs_32.c", - "arch/x86_32/nacl_switch_to_app_32.c", - "arch/x86_32/nacl_tls_32.c", - "arch/x86_32/sel_addrspace_x86_32.c", - "arch/x86_32/sel_ldr_x86_32.c", - "arch/x86_32/sel_rt_32.c", - ] - if (is_mac) { - sources += [ "osx/nacl_signal_32.c" ] - } - if (is_linux || is_chromeos) { - sources += [ "linux/nacl_signal_32.c" ] - } - if (is_win) { - sources += [ "win/nacl_signal_32.c" ] - } - } - - if (current_cpu == "x64") { - sources += [ - "arch/x86_64/nacl_app_64.c", - "arch/x86_64/nacl_switch_to_app_64.c", - "arch/x86_64/nacl_tls_64.c", - "arch/x86_64/sel_ldr_x86_64.c", - "arch/x86_64/sel_rt_64.c", - ] - if (is_mac) { - sources += [ - "arch/x86_64/sel_addrspace_posix_x86_64.c", - "osx/nacl_signal_64.c", - ] - } - if (is_linux || is_chromeos) { - sources += [ - "arch/x86_64/sel_addrspace_posix_x86_64.c", - "linux/nacl_signal_64.c", - ] - } - if (is_win) { - sources += [ - # We assemble the .asm assembly file with the Microsoft assembler - # because we need to generate x86-64 Windows unwind info, which the - # GNU assembler we use elsewhere does not support. - "arch/x86_64/nacl_switch_unwind_win.asm", - "arch/x86_64/sel_addrspace_win_x86_64.c", - "win/exception_patch/ntdll_patch.c", - "win/nacl_signal_64.c", - ] - } - defines = [ "NACL_X86_64_ZERO_BASED_SANDBOX=0" ] - } - - deps = [ - ":env_cleanser", - ":sel_asm($nacl_asm_toolchain)", - "//build/config/nacl:nacl_base", - "//native_client/src/shared/gio:gio", - "//native_client/src/shared/imc:imc", - "//native_client/src/shared/platform:platform", - "//native_client/src/trusted/desc:nrd_xfer", - "//native_client/src/trusted/error_code", - "//native_client/src/trusted/fault_injection:nacl_fault_inject", - "//native_client/src/trusted/interval_multiset:nacl_interval", - "//native_client/src/trusted/nacl_base:nacl_base", - "//native_client/src/trusted/perf_counter:nacl_perf_counter", - "//native_client/src/trusted/platform_qualify:platform_qual_lib", - "//native_client/src/trusted/validator:validation_cache", - "//native_client/src/trusted/validator:validators", - ] - - if (current_os == "mac") { - deps += [ ":nacl_exc" ] - sources += [ "$target_gen_dir/nacl_exc_server.c" ] - } -} - -if (current_os == "mac") { - import("//build/config/mac/mac_sdk.gni") - - action("nacl_exc") { - script = "osx/run_mig.py" - sources = [ mac_sdk_path + "/usr/include/mach/exc.defs" ] - outputs = [ - "$target_gen_dir/nacl_exc.h", - "$target_gen_dir/nacl_exc_server.c", - ] - args = rebase_path(sources, root_build_dir) + - rebase_path(outputs, root_build_dir) - if (!use_system_xcode) { - import("//build/config/clang/clang.gni") - clang_path = - rebase_path("$clang_base_path/bin/", root_build_dir) + "clang" - mig_path = mac_bin_path + "mig" - migcom_path = mac_bin_path + "../libexec/migcom" - - args += [ - "--clang-path", - clang_path, - "--mig-path", - mig_path, - "--migcom-path", - migcom_path, - ] - } else { - deps = [ "//build/config/mac:sdk_inputs" ] - } - args += [ - "--sdk", - rebase_path(mac_sdk_path, root_build_dir), - ] - } -} - -executable("sel_ldr") { - sources = [ "nacl_test_injection_main.c" ] - deps = [ - ":sel_main", - "//build/win:default_exe_manifest", - ] - if (is_linux || is_chromeos) { - ldflags = [ "-pie" ] - data_deps = [ "linux:bootstrap" ] - } - if (is_linux) { - ldflags += [ - "-static-libstdc++", - # For the chromium build, -static-libstdc++ will be unused. - # This is intentional, so don't warn about it. - "-Wno-unused-command-line-argument", - ] - } -} diff --git a/src/trusted/service_runtime/linux/BUILD.gn b/src/trusted/service_runtime/linux/BUILD.gn deleted file mode 100644 index 29bc499f5b..0000000000 --- a/src/trusted/service_runtime/linux/BUILD.gn +++ /dev/null @@ -1,166 +0,0 @@ -# Copyright (c) 2014 The Native Client Authors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - -# We use a special toolchain to build nacl_helper_bootstrap. This -# seems a bit excessive for compiling one source file. But it is -# the most reasonable way to instantiate the configs with different -# settings such as use_debug_fission=false. - -import("//build/config/nacl/host_toolchain.gni") - -here = get_label_info(".", "dir") -bootstrap_toolchain = here + "/toolchain:nacl_bootstrap_" + current_cpu - -if (default_toolchain == "//build/toolchain/cros:target") { - import("//build/toolchain/cros_toolchain.gni") - bootstrap_toolchain = "//build/toolchain/cros:nacl_bootstrap" -} - -if (current_toolchain == bootstrap_toolchain) { - bootstrap_lib_path = "$target_out_dir/libnacl_bootstrap_lib.a" - bootstrap_raw_path = "$target_out_dir/nacl_bootstrap_raw" - bootstrap_exe_path = "$root_out_dir/nacl_helper_bootstrap" - - linker_script_path = rebase_path("nacl_bootstrap.x") - - if (current_cpu == "x64") { - nacl_reserve_top = "0x0" - linker_emulation = "elf_x86_64" - } - if (current_cpu == "x86") { - nacl_reserve_top = "0x40000000" - linker_emulation = "elf_i386" - } - if (current_cpu == "arm") { - nacl_reserve_top = "0x40002000" - linker_emulation = "armelf_linux_eabi" - } - if (current_cpu == "mipsel") { - nacl_reserve_top = "0x40008000" - linker_emulation = "elf32ltsmip" - } - - static_library("nacl_bootstrap_lib") { - # This code has very specific requirements related to its static - # linking and minimal libc use. It cannot support the normal variety - # of build configs that the rest of the code is built with. So it - # resets the list of configs to empty, and then builds up from scratch - # using only the basics that work here. - configs = [] - configs += [ - "//build/config/compiler:chromium_code", - "//build/config/compiler:clang_revision", - "//build/config/compiler:compiler_cpu_abi", - "//build/config/compiler:compiler_deterministic", - "//build/config/compiler:default_optimization", - "//build/config/compiler:default_symbols", - "//build/config/compiler:runtime_library", - ] - - include_dirs = [ "//" ] - - cflags = [ - "-fno-builtin", - - # These might be the defaults in the compiler configuration, - # but we want them all disabled for this build. - "-fno-stack-protector", - "-fno-pic", - "-fno-PIC", - "-fno-pie", - "-fno-PIE", - # Automatic initialization generates memset calls - "-ftrivial-auto-var-init=uninitialized", - ] - - sources = [ - "nacl_bootstrap.c", - ] - - deps = [ - "//build/config/nacl:nacl_base", - ] - } - - action("nacl_bootstrap_raw") { - deps = [ - ":nacl_bootstrap_lib", - ] - script = "ld_bfd.py" - - sources = [ - bootstrap_lib_path, - linker_script_path, - ] - outputs = [ - bootstrap_raw_path, - ] - args = [ - "--compiler", - nacl_bootstrap_compiler, - "-m", - linker_emulation, - "--build-id", - - # This program is (almost) entirely - # standalone. It has its own startup code, so - # no crt1.o for it. It is statically linked, - # and on x86 it does not use libc at all. - # However, on ARM it needs a few (safe) things - # from libc. - "-static", - - # On x86-64, the default page size with some linkers is 2M - # rather than the real Linux page size of 4K. And on ARM, the - # default page size is 32K. A larger page size is - # incompatible with our custom linker script's special layout. - # NOTE: It's important that this option come before --script! - "-z", - "max-page-size=0x1000", - - # Link with custom linker script for special - # layout. The script uses the symbol RESERVE_TOP. - "--defsym", - "RESERVE_TOP=" + nacl_reserve_top, - "--script=" + rebase_path(linker_script_path, root_build_dir), - "-o", - rebase_path(bootstrap_raw_path, root_build_dir), - - "--whole-archive", - rebase_path(bootstrap_lib_path, root_build_dir), - "--no-whole-archive", - ] - } - - action("munge_nacl_helper_bootstrap") { - deps = [ - ":nacl_bootstrap_raw", - ] - - script = "nacl_bootstrap_munge_phdr.py" - inputs = [ - bootstrap_raw_path, - ] - outputs = [ - bootstrap_exe_path, - ] - args = rebase_path(inputs + outputs, root_build_dir) - } -} else if (is_linux || is_chromeos) { - copy("bootstrap") { - bootstrap = ":munge_nacl_helper_bootstrap($bootstrap_toolchain)" - - bootstrap_out_dir = get_label_info(bootstrap, "root_out_dir") - - deps = [ - bootstrap, - ] - sources = [ - "$bootstrap_out_dir/nacl_helper_bootstrap", - ] - outputs = [ - "$root_out_dir/nacl_helper_bootstrap", - ] - } -} diff --git a/src/trusted/service_runtime/linux/toolchain/BUILD.gn b/src/trusted/service_runtime/linux/toolchain/BUILD.gn deleted file mode 100644 index 7e71490798..0000000000 --- a/src/trusted/service_runtime/linux/toolchain/BUILD.gn +++ /dev/null @@ -1,37 +0,0 @@ -# Copyright (c) 2015 The Native Client Authors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - -import("//build/toolchain/gcc_toolchain.gni") - -# This toolchain's sole purpose is to compile nacl_helper_bootstrap.c. -# That requires a separate toolchain because that's the most reasonable way -# to instantiate the standard configs in a context where use_debug_fission=false -# when the main build is using use_debug_fission=true. See ../BUILD.gn for -# details. - -template("nacl_bootstrap_toolchain") { - clang_toolchain(target_name) { - toolchain_args = { - current_cpu = invoker.toolchain_cpu - current_os = target_os - use_debug_fission = false - } - } -} - -nacl_bootstrap_toolchain("nacl_bootstrap_x64") { - toolchain_cpu = "x64" -} - -nacl_bootstrap_toolchain("nacl_bootstrap_x86") { - toolchain_cpu = "x86" -} - -nacl_bootstrap_toolchain("nacl_bootstrap_arm") { - toolchain_cpu = "arm" -} - -nacl_bootstrap_toolchain("nacl_bootstrap_mipsel") { - toolchain_cpu = "mipsel" -} diff --git a/src/trusted/validator/BUILD.gn b/src/trusted/validator/BUILD.gn deleted file mode 100644 index e9b69c27bf..0000000000 --- a/src/trusted/validator/BUILD.gn +++ /dev/null @@ -1,35 +0,0 @@ -# Copyright (c) 2014 The Native ClientAuthors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - -static_library("validators") { - sources = [ - "validator_init.c", - ] - deps = [ - "//build/config/nacl:nacl_base", - ] - - if (current_cpu == "arm") { - deps += [ "//native_client/src/trusted/validator_arm:ncvalidate_arm_v2" ] - } - if (current_cpu == "mipsel") { - deps += [ "//native_client/src/trusted/validator_mips:ncvalidate_mips" ] - } - if (current_cpu == "x86") { - deps += [ "//native_client/src/trusted/validator_ragel:dfa_validate" ] - } - if (current_cpu == "x64") { - deps += [ "//native_client/src/trusted/validator_ragel:dfa_validate" ] - } -} - -static_library("validation_cache") { - sources = [ - "validation_cache.c", - ] - deps = [ - "//build/config/nacl:nacl_base", - "//native_client/src/shared/platform:platform", - ] -} diff --git a/src/trusted/validator/driver/BUILD.gn b/src/trusted/validator/driver/BUILD.gn deleted file mode 100644 index 4f4c691626..0000000000 --- a/src/trusted/validator/driver/BUILD.gn +++ /dev/null @@ -1,37 +0,0 @@ -# Copyright (c) 2014 The Native ClientAuthors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - -# Autogenerated from src/trusted/validator/driver/build.scons. - -static_library("elf_load") { - sources = [ - "elf_load.cc", - ] - - deps = [ - "//build/config/nacl:nacl_base", - "//native_client/src/shared/platform:platform", - ] -} -executable("ncval_new") { - sources = [ - "ncval.cc", - ] - - deps = [ - ":elf_load", - "//build/config/nacl:nacl_base", - "//build/win:default_exe_manifest", - "//native_client/src/shared/platform:platform", - "//native_client/src/trusted/cpu_features:cpu_features", - "//native_client/src/trusted/validator_arm:arm_validator_core", - "//native_client/src/trusted/validator_arm:arm_validator_reporters", - "//native_client/src/trusted/validator_ragel:rdfa_validator", - ] - - # TODO(fabiansommer): Remove with next build deps roll - if (is_linux && current_cpu == "x86") { - ldflags = [ "-static-libstdc++" ] - } -} diff --git a/src/trusted/validator_arm/BUILD.gn b/src/trusted/validator_arm/BUILD.gn deleted file mode 100644 index d5866fa43a..0000000000 --- a/src/trusted/validator_arm/BUILD.gn +++ /dev/null @@ -1,51 +0,0 @@ -# Copyright (c) 2014 The Native ClientAuthors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - -# Generated from GYP - -config("arm_validator_core_config") { - if (is_clang) { - # arm32_decode_actuals_1.cc's has a few `if (true) return ...; return ...;`. - cflags = [ "-Wno-unreachable-code-return" ] - } -} - -static_library("arm_validator_core") { - sources = [ - "address_set.cc", - "inst_classes.cc", - "model.cc", - "arm_helpers.cc", - "validator.cc", - "gen/arm32_decode.cc", - "gen/arm32_decode_actuals_1.cc", - "gen/arm32_decode_actuals_2.cc", - ] - deps = [ - "//build/config/nacl:nacl_base", - "//native_client/src/trusted/cpu_features:cpu_features", - ] - - configs += [ ":arm_validator_core_config" ] -} - -static_library("ncvalidate_arm_v2") { - sources = [ - "ncvalidate.cc", - ] - deps = [ - "//build/config/nacl:nacl_base", - ":arm_validator_core", - "//native_client/src/trusted/validator:validation_cache", - ] -} - -static_library("arm_validator_reporters") { - sources = [ - "problem_reporter.cc", - ] - deps = [ - "//build/config/nacl:nacl_base", - ] -} diff --git a/src/trusted/validator_mips/BUILD.gn b/src/trusted/validator_mips/BUILD.gn deleted file mode 100644 index c4d127983f..0000000000 --- a/src/trusted/validator_mips/BUILD.gn +++ /dev/null @@ -1,46 +0,0 @@ -# Copyright (c) 2016 The Native ClientAuthors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - - -static_library("mips_validator_core") { - sources = [ - "address_set.cc", - "validator.cc", - "$target_gen_dir/decode.cc", - ] - deps = [ - "//build/config/nacl:nacl_base", - "//native_client/src/trusted/cpu_features:cpu_features", - ":decode_gen" - ] -} - -action("decode_gen") { - script = "dgen/generate_decoder.py" - outputs = [ - "$target_gen_dir/decode.cc", - ] - sources = [ - "mips-opt.table", - ] - inputs = [ - "dgen/generate_decoder.py", - "dgen/dgen_core.py", - "dgen/dgen_input.py", - "dgen/dgen_opt.py", - "dgen/dgen_output.py", - ] - args = rebase_path(sources, root_build_dir) + - rebase_path(outputs, root_build_dir) -} - -static_library("ncvalidate_mips") { - sources = [ - "ncvalidate.cc", - ] - deps = [ - "//build/config/nacl:nacl_base", - ":mips_validator_core", - ] -} diff --git a/src/trusted/validator_ragel/BUILD.gn b/src/trusted/validator_ragel/BUILD.gn deleted file mode 100644 index 1752577304..0000000000 --- a/src/trusted/validator_ragel/BUILD.gn +++ /dev/null @@ -1,60 +0,0 @@ -# Copyright (c) 2014 The Native ClientAuthors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - -# These objects are included in both dfa_validate_x86_xx and rdfa_validator -# libraries, so we have to introduce intermediate scons nodes. -validator32 = "gen/validator_x86_32.c" -validator64 = "gen/validator_x86_64.c" - -config("dfa_validator_config") { - if (is_clang) { - # ragel output (validator_x86_32.c / validator_x86_64.c) has many many - # breaks right after gotos. - cflags = [ "-Wno-unreachable-code-break" ] - } -} - -if (current_cpu == "x86" || current_cpu == "x64") { - static_library("dfa_validate") { - sources = [ - "validator_features_all.c", - "validator_features_validator.c", - "dfa_validate_common.c", - ] - if (current_cpu == "x86") { - sources += [ - validator32, - "dfa_validate_32.c", - ] - } else { - sources += [ - validator64, - "dfa_validate_64.c", - ] - } - deps = [ - "//build/config/nacl:nacl_base", - "//native_client/src/trusted/cpu_features:cpu_features", - "//native_client/src/trusted/validator:validation_cache", - "//native_client/src/trusted/validator_x86:nccopy", - ] - configs += [ ":dfa_validator_config" ] - } -} - -# Low-level platform-independent interface supporting both 32 and 64 bit, -# used in ncval and in validator_benchmark. -static_library("rdfa_validator") { - sources = [ - validator32, - validator64, - "validator_features_all.c", - "validator_features_validator.c", - ] - defines = [ "VALIDATOR_EXPORT=DLLEXPORT" ] - deps = [ - "//build/config/nacl:nacl_base", - ] - configs += [ ":dfa_validator_config" ] -} diff --git a/src/trusted/validator_x86/BUILD.gn b/src/trusted/validator_x86/BUILD.gn deleted file mode 100644 index ebfc56dca7..0000000000 --- a/src/trusted/validator_x86/BUILD.gn +++ /dev/null @@ -1,28 +0,0 @@ -# Copyright (c) 2014 The Native ClientAuthors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - -import("//native_client/src/trusted/asm.gni") - -if (current_cpu == "x86" || current_cpu == "x64") { - if (current_toolchain == nacl_asm_toolchain) { - source_set("nccopy_asm") { - sources = [ - "nccopycode_stores.S", - ] - deps = [ - "//build/config/nacl:nacl_base", - ] - } - } - - source_set("nccopy") { - sources = [ - "nccopycode.c", - ] - deps = [ - "//build/config/nacl:nacl_base", - ":nccopy_asm($nacl_asm_toolchain)", - ] - } -} diff --git a/src/trusted/win/BUILD.gn b/src/trusted/win/BUILD.gn deleted file mode 100644 index 13a88a734c..0000000000 --- a/src/trusted/win/BUILD.gn +++ /dev/null @@ -1,78 +0,0 @@ -# Copyright (c) 2015 The Native Client Authors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - -import("//build/toolchain/toolchain.gni") - -# This is a special toolchain used solely for building GNU/AT&T-syntax -# assembly files on Windows. See src/trusted/asm.gni for more details. - -tool_wrapper_path = - rebase_path("//build/toolchain/win/tool_wrapper.py", root_build_dir) - -template("nacl_win_as_toolchain") { - toolchain(target_name) { - tool("asm") { - # For GCC we can just use the C compiler to compile assembly. - win_as_script = - rebase_path("//native_client/tools/win_as.py", root_build_dir) - clang_cl = rebase_path( - "//third_party/llvm-build/Release+Asserts/bin/clang-cl.exe", - root_build_dir) - if (invoker.toolchain_cpu == "x86") { - env = "environment.x86" - win_as_arch = "Win32" - } else { - env = "environment.x64" - win_as_arch = invoker.toolchain_cpu - } - top_srcdir = rebase_path("//", root_build_dir) - rspfile = "{{output}}.rsp" - rspfile_content = "\"$python_path\" $win_as_script -a $win_as_arch -p $top_srcdir -c $clang_cl -o {{output}} {{source}}" - command = "$python_path $tool_wrapper_path action-wrapper $env $rspfile" - depsformat = "msvc" - description = "GNU ASM {{output}}" - outputs = [ - "{{target_out_dir}}/{{target_output_name}}/{{source_name_part}}.obj", - ] - } - - # These two are really entirely generic, but have to be repeated in - # each toolchain because GN doesn't allow a template to be used here. - # See //build/toolchain/toolchain.gni for details. - tool("stamp") { - command = stamp_command - description = stamp_description - } - tool("copy") { - command = copy_command - description = copy_description - } - - # This is necessary so that certain .gn files with static_libraries (e.g. - # //build/config/sanitizers/BUILD.gn) can be loaded in the context of this - # toolchain. - tool("alink") { - command = "fake" - outputs = [ "fake" ] - } - - toolchain_args = { - current_os = "win" - current_cpu = invoker.toolchain_cpu - - # These values need to be passed through unchanged. - host_toolchain = host_toolchain - target_os = target_os - target_cpu = target_cpu - } - } -} - -nacl_win_as_toolchain("nacl_win_as_x86") { - toolchain_cpu = "x86" -} - -nacl_win_as_toolchain("nacl_win_as_x64") { - toolchain_cpu = "x64" -} diff --git a/src/untrusted/elf_loader/BUILD.gn b/src/untrusted/elf_loader/BUILD.gn deleted file mode 100644 index f922d2324e..0000000000 --- a/src/untrusted/elf_loader/BUILD.gn +++ /dev/null @@ -1,42 +0,0 @@ -# Copyright (c) 2015 The Native Client Authors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - -assert(current_os == "nacl", "This file contains untrusted code only.") - -import("//build/config/nacl/config.gni") - -if (current_cpu != "pnacl" && !is_nacl_glibc) { - executable("elf_loader") { - sources = [ - "elf_loader.c", - ] - - deps = [ - "//build/config/nacl:nacl_base", - ] - } -} - -if (is_nacl_glibc) { - # The elf_loader nexe can only be built with the newlib toolchain, - # but it's needed for things built in the glibc toolchain. To - # keep things simpler for users of it, copy it into the glibc - # $root_out_dir and give it the name used in GYP (and expected by - # the SDK's create_nmf.py): elf_loader_.nexe. - copy("elf_loader") { - here = get_label_info(".", "dir") - newlib_tc = "//build/toolchain/nacl:clang_newlib_" + current_cpu - elf_loader_label = here + ":elf_loader" + "(" + newlib_tc + ")" - newlib_out_dir = get_label_info(elf_loader_label, "root_out_dir") - deps = [ - elf_loader_label, - ] - sources = [ - newlib_out_dir + "/elf_loader.nexe", - ] - outputs = [ - "$root_out_dir/elf_loader_" + current_cpu + ".nexe", - ] - } -} diff --git a/src/untrusted/irt/BUILD.gn b/src/untrusted/irt/BUILD.gn deleted file mode 100644 index 2eeff6af22..0000000000 --- a/src/untrusted/irt/BUILD.gn +++ /dev/null @@ -1,72 +0,0 @@ -# Copyright (c) 2014 The Native ClientAuthors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - -executable("irt_core") { - cflags_c = [ "-std=gnu99" ] - - sources = [ - "irt_core_resource.c", - "irt_entry_core.c", - "irt_pnacl_translator_common.c", - "irt_pnacl_translator_compile.c", - "irt_pnacl_translator_link.c", - ] - deps = [ - "//build/config/nacl:nacl_base", - ":irt_core_lib", - ] - - # TODO(fabiansommer): Remove with next build deps roll - if (is_linux && current_cpu == "x86") { - ldflags = [ "-static-libstdc++" ] - } -} - -static_library("irt_core_lib") { - cflags_c = [ "-std=c99" ] - if (defined(is_nacl_saigo) && is_nacl_saigo) { - cflags_c += [ - "-Wextra", - "-Wno-unused-parameter", - ] - } - - sources = [ - "../../untrusted/pthread/nc_condvar.c", - "../../untrusted/pthread/nc_mutex.c", - "../../untrusted/nacl/sys_private.c", - "../../untrusted/valgrind/dynamic_annotations.c", - "irt_basic.c", - "irt_blockhook.c", - "irt_clock.c", - "irt_code_data_alloc.c", - "irt_cond.c", - "irt_dev_getpid.c", - "irt_dev_list_mappings.c", - "irt_dyncode.c", - "irt_entry.c", - "irt_exception_handling.c", - "irt_fdio.c", - "irt_filename.c", - "irt_futex.c", - "irt_interfaces.c", - "irt_malloc.c", - "irt_memory.c", - "irt_mutex.c", - "irt_private_pthread.c", - "irt_private_tls.c", - "irt_query_list.c", - "irt_random.c", - "irt_sem.c", - "irt_thread.c", - "irt_tls.c", - ] - - deps = [ - "//build/config/nacl:nacl_base", - "//native_client/src/shared/gio:gio", - "//native_client/src/shared/platform:platform", - "//native_client/src/untrusted/nacl:imc_syscalls", - ] -} diff --git a/src/untrusted/nacl/BUILD.gn b/src/untrusted/nacl/BUILD.gn deleted file mode 100644 index ff5dbfdffd..0000000000 --- a/src/untrusted/nacl/BUILD.gn +++ /dev/null @@ -1,427 +0,0 @@ -# Copyright (c) 2014 The Native ClientAuthors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - -assert(current_os == "nacl", "This file contains untrusted code only.") - -static_library("nacl_dyncode_private") { - cflags_c = [] - sources = [ - "dyncode_private.c", - ] - - if (current_cpu == "pnacl") { - cflags_c += [ - "-Wno-self-assign", - ] - } - deps = [ - "//build/config/nacl:nacl_base", - ] -} -static_library("nacl_sys_private") { - cflags_c = [] - sources = [ - "null.c", - "sysbrk.c", - ] - - if (current_cpu == "pnacl") { - cflags_c += [ - "-Wno-self-assign", - ] - } - deps = [ - "//build/config/nacl:nacl_base", - ] -} -static_library("imc_syscalls") { - cflags_c = [] - sources = [ - "imc_accept.c", - "imc_connect.c", - "imc_makeboundsock.c", - "imc_mem_obj_create.c", - "imc_recvmsg.c", - "imc_sendmsg.c", - "imc_socketpair.c", - ] - - if (current_cpu == "pnacl") { - cflags_c += [ - "-Wno-self-assign", - ] - } - deps = [ - "//build/config/nacl:nacl_base", - ] -} -static_library("nacl_exception_private") { - cflags_c = [] - sources = [ - "nacl_exception_private.c", - ] - - if (current_cpu == "pnacl") { - cflags_c += [ - "-Wno-self-assign", - ] - } - deps = [ - "//build/config/nacl:nacl_base", - ] -} -static_library("nacl_list_mappings_private") { - cflags_c = [] - sources = [ - "list_mappings_private.c", - ] - - if (current_cpu == "pnacl") { - cflags_c += [ - "-Wno-self-assign", - ] - } - deps = [ - "//build/config/nacl:nacl_base", - ] -} -static_library("nacl_dyncode") { - cflags_c = [] - sources = [ - "dyncode.c", - ] - - if (current_cpu == "pnacl") { - cflags_c += [ - "-Wno-self-assign", - ] - } - deps = [ - "//build/config/nacl:nacl_base", - ] -} -static_library("nacl") { - cflags_c = [ "-std=c99" ] - sources = [ - "gc_hooks.c", - "nacl_irt.c", - "nacl_irt_init.c", - "nacl_random.c", - "nacl_tls_get.c", - "nacl_tls_init.c", - ] - - if (current_os != "glibc") { - sources += [ - "_exit.c", - "abort.c", - "access.c", - "chdir.c", - "chmod.c", - "clock.c", - "clock_getres.c", - "clock_gettime.c", - "close.c", - "dup.c", - "eaccess.c", - "fchdir.c", - "fchmod.c", - "fdatasync.c", - "fstat.c", - "fsync.c", - "ftruncate.c", - "getcwd.c", - "getcwd_without_malloc.c", - "getdents.c", - "gethostname.c", - "getpagesize.c", - "getpid.c", - "gettimeofday.c", - "htonl.c", - "htons.c", - "isatty.c", - "link.c", - "lock.c", - "lseek.c", - "lstat.c", - "malloc.c", - "mkdir.c", - "mmap.c", - "mprotect.c", - "munmap.c", - "nacl_add_tp.c", - "nacl_ext_supply.c", - "nacl_interface_query.c", - "nacl_irt_fdio.c", - "nacl_irt_filename.c", - "nacl_read_tp.c", - "nanosleep.c", - "ntohl.c", - "ntohs.c", - "open.c", - "pthread_initialize_minimal.c", - "pthread_stubs.c", - "random.c", - "read.c", - "readlink.c", - "rename.c", - "rmdir.c", - "sbrk.c", - "sched_yield.c", - "sigblock.c", - "siggetmask.c", - "sigmask.c", - "sigprocmask.c", - "sigsetmask.c", - "srandom.c", - "stacktrace.c", - "start.c", - "stat.c", - "stubs/_execve.c", - "stubs/accept.c", - "stubs/addmntent.c", - "stubs/bind.c", - "stubs/chown.c", - "stubs/closelog.c", - "stubs/connect.c", - "stubs/endgrent.c", - "stubs/endmntent.c", - "stubs/endpwent.c", - "stubs/environ.c", - "stubs/execvpe.c", - "stubs/fchown.c", - "stubs/fcntl.c", - "stubs/fork.c", - "stubs/freeaddrinfo.c", - "stubs/fstatvfs.c", - "stubs/gai_strerror.c", - "stubs/get_current_dir_name.c", - "stubs/getaddrinfo.c", - "stubs/getdtablesize.c", - "stubs/getegid.c", - "stubs/geteuid.c", - "stubs/getgid.c", - "stubs/getgrent.c", - "stubs/getgrgid.c", - "stubs/getgrgid_r.c", - "stubs/getgrnam.c", - "stubs/getgroups.c", - "stubs/gethostbyaddr.c", - "stubs/gethostbyname.c", - "stubs/getlogin.c", - "stubs/getmntent.c", - "stubs/getnameinfo.c", - "stubs/getpeername.c", - "stubs/getpgrp.c", - "stubs/getppid.c", - "stubs/getpwent.c", - "stubs/getpwnam.c", - "stubs/getpwnam_r.c", - "stubs/getpwuid.c", - "stubs/getpwuid_r.c", - "stubs/getrlimit.c", - "stubs/getrusage.c", - "stubs/getservbyname.c", - "stubs/getservbyport.c", - "stubs/getsockname.c", - "stubs/getsockopt.c", - "stubs/getuid.c", - "stubs/getwd.c", - "stubs/hasmntopt.c", - "stubs/if_freenameindex.c", - "stubs/if_indextoname.c", - "stubs/if_nameindex.c", - "stubs/if_nametoindex.c", - "stubs/inet_ntoa.c", - "stubs/inet_ntop.c", - "stubs/initgroups.c", - "stubs/ioctl.c", - "stubs/issetugid.c", - "stubs/kill.c", - "stubs/lchown.c", - "stubs/listen.c", - "stubs/llseek.c", - "stubs/major.c", - "stubs/makedev.c", - "stubs/minor.c", - "stubs/mkfifo.c", - "stubs/mknod.c", - "stubs/msync.c", - "stubs/openlog.c", - "stubs/pipe.c", - "stubs/poll.c", - "stubs/pselect.c", - "stubs/pthread_sigmask.c", - "stubs/readv.c", - "stubs/recv.c", - "stubs/recvfrom.c", - "stubs/recvmsg.c", - "stubs/sched_get_priority_max.c", - "stubs/sched_get_priority_min.c", - "stubs/sched_setparam.c", - "stubs/sched_setscheduler.c", - "stubs/select.c", - "stubs/send.c", - "stubs/sendmsg.c", - "stubs/sendto.c", - "stubs/setegid.c", - "stubs/seteuid.c", - "stubs/setgid.c", - "stubs/setgrent.c", - "stubs/setgroups.c", - "stubs/setmntent.c", - "stubs/setpgid.c", - "stubs/setpwent.c", - "stubs/setrlimit.c", - "stubs/setsid.c", - "stubs/setsockopt.c", - "stubs/settimeofday.c", - "stubs/setuid.c", - "stubs/shutdown.c", - "stubs/sigaction.c", - "stubs/signal.c", - "stubs/sigsuspend.c", - "stubs/sigvec.c", - "stubs/socket.c", - "stubs/socketpair.c", - "stubs/statvfs.c", - "stubs/syslog.c", - "stubs/tcdrain.c", - "stubs/tcflow.c", - "stubs/tcflush.c", - "stubs/tcgetattr.c", - "stubs/tcsendbreak.c", - "stubs/tcsetattr.c", - "stubs/times.c", - "stubs/ttyname.c", - "stubs/ttyname_r.c", - "stubs/umask.c", - "stubs/vfork.c", - "stubs/wait.c", - "stubs/waitpid.c", - "symlink.c", - "sysconf.c", - "tls.c", - "truncate.c", - "uname.c", - "unlink.c", - "utime.c", - "utimes.c", - "write.c", - ] - } - - if (current_os != "glibc" && current_cpu == "arm") { - sources += [ "aeabi_read_tp.S" ] - } - - if (current_cpu == "pnacl") { - cflags_c += [ - "-Wno-self-assign", - ] - } - - deps = [ - "//build/config/nacl:nacl_base", - ] -} - -source_set("irt_random") { - cflags_c = [] - sources = [ - "../../untrusted/irt/irt_random.c", - ] - - if (current_cpu == "pnacl") { - cflags_c += [ - "-Wno-self-assign", - ] - } - - deps = [ - "//build/config/nacl:nacl_base", - ] -} -static_library("nacl_exception") { - cflags_c = [] - sources = [ - "nacl_exception.c", - ] - - if (current_cpu == "pnacl") { - cflags_c += [ - "-Wno-self-assign", - ] - } - - deps = [ - "//build/config/nacl:nacl_base", - ] -} -static_library("nacl_list_mappings") { - cflags_c = [] - sources = [ - "list_mappings.c", - ] - - if (current_cpu == "pnacl") { - cflags_c += [ - "-Wno-self-assign", - ] - } - - deps = [ - "//build/config/nacl:nacl_base", - ] -} - -if (current_os != "glibc") { - source_set("sys_private") { - cflags_c = [] - sources = [ - "sys_private.c", - ] - - if (current_cpu == "pnacl") { - cflags_c += [ - "-Wno-self-assign", - ] - } - - deps = [ - "//build/config/nacl:nacl_base", - ] - } - source_set("gc_hooks_private") { - cflags_c = [] - sources = [ - "gc_hooks_private.c", - ] - - if (current_cpu == "pnacl") { - cflags_c += [ - "-Wno-self-assign", - ] - } - deps = [ - "//build/config/nacl:nacl_base", - ] - } - source_set("private_blockhook") { - cflags_c = [] - sources = [ - "../../untrusted/irt/irt_blockhook.c", - ] - - if (current_cpu == "pnacl") { - cflags_c += [ - "-Wno-self-assign", - ] - } - - deps = [ - "//build/config/nacl:nacl_base", - ] - } -} diff --git a/src/untrusted/pthread/BUILD.gn b/src/untrusted/pthread/BUILD.gn deleted file mode 100644 index 013f129db6..0000000000 --- a/src/untrusted/pthread/BUILD.gn +++ /dev/null @@ -1,20 +0,0 @@ -# Copyright (c) 2014 The Native ClientAuthors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - -static_library("pthread") { - cflags_c = [ "-std=c99" ] - sources = [ - "nc_thread.c", - "nc_mutex.c", - "nc_condvar.c", - "nc_rwlock.c", - "nc_semaphore.c", - "nc_init_irt.c", - "stack_end.c", - "../valgrind/dynamic_annotations.c", - ] - deps = [ - "//build/config/nacl:nacl_base", - ] -} diff --git a/tests/BUILD.gn b/tests/BUILD.gn deleted file mode 100644 index 15017314e7..0000000000 --- a/tests/BUILD.gn +++ /dev/null @@ -1,42 +0,0 @@ -# Copyright 2016 The Native Client Authors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - -import("//native_client/tests/test.gni") - -source_set("test_utils") { - testonly = true - sources = [ - "test_runner.cc", - ] - deps = [ - "//native_client/src/third_party/gtest", - ] -} - -test("small_tests") { - deps = [ - ":test_utils", - ] - if (is_linux && current_cpu == "x86") { - ldflags = [ "-static-libstdc++" ] - } -} - -test("medium_tests") { - deps = [ - ":test_utils", - ] - if (is_linux && current_cpu == "x86") { - ldflags = [ "-static-libstdc++" ] - } -} - -test("large_tests") { - deps = [ - ":test_utils", - ] - if (is_linux && current_cpu == "x86") { - ldflags = [ "-static-libstdc++" ] - } -} diff --git a/tests/hello_world/BUILD.gn b/tests/hello_world/BUILD.gn deleted file mode 100644 index 7fdd5222d1..0000000000 --- a/tests/hello_world/BUILD.gn +++ /dev/null @@ -1,17 +0,0 @@ -# Copyright (c) 2014 The Native Client Authors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - -executable("hello_world") { - sources = [ - "hello_world.c", - ] - deps = [ - "//build/config/nacl:nacl_base", - ] - - # TODO(fabiansommer): Remove with next build deps roll - if (is_linux && current_cpu == "x86") { - ldflags = [ "-static-libstdc++" ] - } -} From f5888671c005566c6eda38cb6e1669e8dd3402db Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Thu, 25 Jun 2026 23:32:53 +0200 Subject: [PATCH 02/36] cleanup: remove DEPS files --- DEPS | 320 -------------------------- pnacl/support/DEPS | 5 - src/include/DEPS | 5 - src/nonsfi/DEPS | 13 -- src/public/DEPS | 5 - src/shared/DEPS | 5 - src/shared/platform/DEPS | 4 - src/tools/tls_edit/DEPS | 4 - src/trusted/DEPS | 6 - src/untrusted/DEPS | 12 - src/untrusted/minidump_generator/DEPS | 3 - tests/DEPS | 9 - tests/callingconv_ppapi/DEPS | 3 - tools/DEPS | 5 - tools/checkdeps/DEPS | 3 - tools/redirector/DEPS | 3 - 16 files changed, 405 deletions(-) delete mode 100644 DEPS delete mode 100644 pnacl/support/DEPS delete mode 100644 src/include/DEPS delete mode 100644 src/nonsfi/DEPS delete mode 100644 src/public/DEPS delete mode 100644 src/shared/DEPS delete mode 100644 src/shared/platform/DEPS delete mode 100644 src/tools/tls_edit/DEPS delete mode 100644 src/trusted/DEPS delete mode 100644 src/untrusted/DEPS delete mode 100644 src/untrusted/minidump_generator/DEPS delete mode 100644 tests/DEPS delete mode 100644 tests/callingconv_ppapi/DEPS delete mode 100644 tools/DEPS delete mode 100644 tools/checkdeps/DEPS delete mode 100644 tools/redirector/DEPS diff --git a/DEPS b/DEPS deleted file mode 100644 index 9ba6122e8a..0000000000 --- a/DEPS +++ /dev/null @@ -1,320 +0,0 @@ -# DEPS files look like -*- Python -*- - -vars = { - # These revisions are slices of the chromium repository. - # Because they come from separate sub-slices, their hashes do not match at - # equivalent revisions. When updating them, use the roll-dep script - # to move them to equivalent revisions. Additionally, because not all - # directories contain commits at each revision, you will need to select - # revisions at latest revision up to a high watermark from each slice. - # Document the high watermark here: - # chrome_rev: 1214139 - "build_rev": "80d1bcf5591e724463be35b794ffe3261a5b9006", # from cr commit position 1039183 - "buildtools_revision": "cd6bd50a8f5eb44620ab501c26806d3eafe45a66", # from cr commit position 1214139 - "clang_rev": "0fc72d33cae3fefb8ced28631f9a8cf7e54fa873", # from cr commit position 1038345 - - # build_overrides/ is a separate, NaCl-specific repo *forked* from - # chromium/src/build_overrides/. It may need to be updated if - # //build_overrides/build.gni changes in Chromium. - "build_overrides_rev": "3a801f70d2dad1d2b4c935103cc44b6f16144f8d", - - # Three lines of non-changing comments so that - # the commit queue can handle CLs rolling lss - # and whatever else without interference from each other. - "lss_revision": "3f6478ac95edf86cd3da300c2c0d34a438f5dbeb", - - "breakpad_rev": "54fa71efbe50fb2b58096d871575b59e12edba6d", - - # Fetch configuration files required for the 'use_remoteexec' gn arg - 'download_remoteexec_cfg': False, - # RBE instance to use for running remote builds - 'rbe_instance': Str('projects/rbe-chromium-untrusted/instances/default_instance'), - # RBE project to download rewrapper config files for. Only needed if - # different from the project used in 'rbe_instance' - 'rewrapper_cfg_project': Str(''), - # reclient CIPD package version - "reclient_version": "re_client_version:0.117.1.21520c6-gomaip", - - # GN CIPD package version. - "gn_version": "git_revision:b79031308cc878488202beb99883ec1f2efd9a6d", - - # Separately pinned repositories, update with roll-dep individually. - "gtest_rev": "2d3543f81d6d4583332f8b60768ade18e0f96220", - "gyp_rev": "e7079f0e0e14108ab0dba58728ff219637458563", - "mingw_rev": "3cc8b140b883a9fe4986d12cfd46c16a093d3527", # from svn revision 7064 - "lcov_rev": "b37daf5968200da8ff520ce65c4e5bce4047dd15", # from svn revision 149720 - "gnu_binutils_rev": "f4003433b61b25666565690caf3d7a7a1a4ec436", # from svn revision 8151 - "nsis_rev": "21b6ad22daa7bfc04b9f1c1805a34622e2607a93", # from svn revision 7071 - "ragel_rev": "da42bb33f1b67c2d70b38ec1d2edf5263271b635", # from svn revision 9010 - "third_party_rev": "d6b76289219c3183f0be9b5fc0be9daedda20e04", - "validator_snapshots_rev": "ef053694ef9b0d98d9bed0b9bb649963084bfc81", - - # Dummy variables for compatibility with //build. - "build_with_chromium": False, - "cros_boards": Str(""), - "cros_boards_with_qemu_images": Str(""), - - "chromium_git": "https://chromium.googlesource.com", -} - -gclient_gn_args_file = 'build/config/gclient_args.gni' -gclient_gn_args = [ - 'build_with_chromium', - 'checkout_android', # this is provided by gclient - 'cros_boards', - 'cros_boards_with_qemu_images', -] - - -deps = { - "breakpad": - Var("chromium_git") + "/breakpad/breakpad.git@" + - Var("breakpad_rev"), - "buildtools": - Var("chromium_git") + "/chromium/src/buildtools.git@" + - Var("buildtools_revision"), - "build": - Var("chromium_git") + "/chromium/src/build.git@" + - Var("build_rev"), - "build_overrides": - Var("chromium_git") + "/native_client/src/build_overrides.git@" + - Var("build_overrides_rev"), - "testing/gtest": - (Var("chromium_git") + "/external/github.com/google/googletest.git@" + - Var("gtest_rev")), - "third_party": - Var("chromium_git") + "/native_client/src/third_party.git@" + - Var("third_party_rev"), - "validator_snapshots": - (Var("chromium_git") + "/native_client/src/validator_snapshots.git@" + - Var("validator_snapshots_rev")), - "third_party/lcov": - Var("chromium_git") + "/chromium/src/third_party/lcov.git@" + - Var("lcov_rev"), - "third_party/lss": - Var("chromium_git") + "/linux-syscall-support.git@" + - Var("lss_revision"), - 'third_party/ninja': { - 'packages': [ - { - # https://chrome-infra-packages.appspot.com/p/infra/3pp/tools/ninja - 'package': 'infra/3pp/tools/ninja/${{platform}}', - 'version': 'version:2@1.8.2.chromium.3', - } - ], - 'dep_type': 'cipd', - }, - "tools/clang": - Var("chromium_git") + "/chromium/src/tools/clang.git@" + Var("clang_rev"), - "tools/gyp": - Var("chromium_git") + "/external/gyp.git@" + Var("gyp_rev"), - - 'buildtools/linux64': { - 'packages': [ - { - 'package': 'gn/gn/linux-amd64', - 'version': Var('gn_version'), - } - ], - 'dep_type': 'cipd', - 'condition': 'host_os == "linux"', - }, - 'buildtools/mac': { - 'packages': [ - { - 'package': 'gn/gn/mac-amd64', - 'version': Var('gn_version'), - } - ], - 'dep_type': 'cipd', - 'condition': 'host_os == "mac"', - }, - 'buildtools/win': { - 'packages': [ - { - 'package': 'gn/gn/windows-amd64', - 'version': Var('gn_version'), - } - ], - 'dep_type': 'cipd', - 'condition': 'host_os == "win"', - }, - 'buildtools/reclient': { - 'packages': [ - { - 'package': 'infra/rbe/client/${{platform}}', - 'version': Var('reclient_version'), - } - ], - 'dep_type': 'cipd', - }, -} - -deps_os = { - "win": { - # GNU binutils assembler for x86-32. - "third_party/gnu_binutils": - Var("chromium_git") + - "/native_client/deps/third_party/gnu_binutils.git@" + - Var("gnu_binutils_rev"), - # GNU binutils assembler for x86-64. - "third_party/mingw-w64/mingw/bin": - Var("chromium_git") + - "/native_client/deps/third_party/mingw-w64/mingw/bin.git@" + - Var("mingw_rev"), - "third_party/NSIS": - Var("chromium_git") + "/native_client/deps/third_party/NSIS.git@" + - Var("nsis_rev"), - }, - "unix": { - # Ragel for validator_ragel - "third_party/ragel": - Var("chromium_git") + "/native_client/deps/third_party/ragel.git@" + - Var("ragel_rev"), - }, -} - -hooks = [ - ### - ### From here until the similar marker below, these clauses are copied - ### almost verbatim from chromium/src/DEPS. They are modified to drop - ### the src/ prefix on file names but otherwise they should stay identical. - ### - - { - 'name': 'sysroot_arm', - 'pattern': '.', - 'condition': 'checkout_linux', - 'action': ['python3', 'build/linux/sysroot_scripts/install-sysroot.py', - '--arch=arm'], - }, - { - 'name': 'sysroot_arm64', - 'pattern': '.', - 'condition': 'checkout_linux', - 'action': ['python3', 'build/linux/sysroot_scripts/install-sysroot.py', - '--arch=arm64'], - }, - { - # Downloads the current stable linux sysroot to build/linux/ if needed. - # This sysroot updates at about the same rate that the chrome build deps - # change. This script is a no-op except for linux users who are doing - # official chrome builds or cross compiling. - 'name': 'sysroot_x64', - 'pattern': '.', - 'condition': 'checkout_linux', - 'action': ['python3', 'build/linux/sysroot_scripts/install-sysroot.py', - '--arch=x64'], - }, - { - 'name': 'sysroot_x86', - 'pattern': '.', - 'condition': 'checkout_linux', - 'action': ['python3', 'build/linux/sysroot_scripts/install-sysroot.py', - '--arch=x86'], - }, - { - # Update the Windows toolchain if necessary. - 'name': 'win_toolchain', - 'pattern': '.', - 'condition': 'checkout_win', - 'action': ['python3', 'build/vs_toolchain.py', 'update'], - }, - { - # Update the Mac toolchain if necessary. - 'name': 'mac_toolchain', - 'pattern': '.', - 'condition': 'checkout_mac', - 'action': ['python3', 'build/mac_toolchain.py'], - }, - { - # Pull clang if needed or requested via GYP_DEFINES. - # Note: On Win, this should run after win_toolchain, as it may use it. - 'name': 'clang', - 'pattern': '.', - 'action': ['python3', 'tools/clang/scripts/update.py'], - }, - { - # Update LASTCHANGE. - 'name': 'lastchange', - 'pattern': '.', - 'action': ['python3', 'build/util/lastchange.py', - '-o', 'build/util/LASTCHANGE'], - }, - # Pull clang-format binaries using checked-in hashes. - { - 'name': 'clang_format_win', - 'pattern': '.', - 'condition': 'host_os == "win"', - 'action': [ 'download_from_google_storage', - '--no_resume', - '--no_auth', - '--bucket', 'chromium-clang-format', - '-s', 'buildtools/win/clang-format.exe.sha1', - ], - }, - { - 'name': 'clang_format_mac', - 'pattern': '.', - 'condition': 'host_os == "mac"', - 'action': [ 'download_from_google_storage', - '--no_resume', - '--no_auth', - '--bucket', 'chromium-clang-format', - '-s', 'buildtools/mac/clang-format.x64.sha1', - ], - }, - { - 'name': 'clang_format_linux', - 'pattern': '.', - 'condition': 'host_os == "linux"', - 'action': [ 'download_from_google_storage', - '--no_resume', - '--no_auth', - '--bucket', 'chromium-clang-format', - '-s', 'buildtools/linux64/clang-format.sha1', - ], - }, - # Download remote exec cfg files - { - 'name': 'fetch_reclient_cfgs', - 'pattern': '.', - 'condition': 'download_remoteexec_cfg', - 'action': ['python3', - 'src/buildtools/reclient_cfgs/fetch_reclient_cfgs.py', - '--rbe_instance', - Var('rbe_instance'), - '--reproxy_cfg_template', - 'reproxy.cfg.template', - '--rewrapper_cfg_project', - Var('rewrapper_cfg_project'), - '--quiet', - ], - }, - - ### - ### End of clauses copied (almost verbatim) from chromium/src/DEPS. - ### - - # Pull NaCl Toolchain binaries. - { - "pattern": ".", - "action": ["python3", - "native_client/build/package_version/package_version.py", - "sync", "--extract", - ], - }, - # Cleanup any stale package_version files. - { - "pattern": ".", - "action": ["python3", - "native_client/build/package_version/package_version.py", - "cleanup", - ], - }, -] - -include_rules = [ - "+native_client/src/include", - "+gtest", -] diff --git a/pnacl/support/DEPS b/pnacl/support/DEPS deleted file mode 100644 index f9e4bbc539..0000000000 --- a/pnacl/support/DEPS +++ /dev/null @@ -1,5 +0,0 @@ -include_rules = [ - "+native_client/pnacl/support", - "+native_client/src/trusted/service_runtime/include", - "+native_client/src/untrusted", -] diff --git a/src/include/DEPS b/src/include/DEPS deleted file mode 100644 index 31c13896d8..0000000000 --- a/src/include/DEPS +++ /dev/null @@ -1,5 +0,0 @@ -include_rules = [ - "+native_client/src/include", - "+native_client/src/shared/platform/nacl_log.h", - "+native_client/src/trusted/service_runtime/include/bits/wordsize.h", -] diff --git a/src/nonsfi/DEPS b/src/nonsfi/DEPS deleted file mode 100644 index 514bf17a19..0000000000 --- a/src/nonsfi/DEPS +++ /dev/null @@ -1,13 +0,0 @@ -include_rules = [ - "+native_client/src/nonsfi", - "+native_client/src/public", - "+native_client/src/shared/platform", - "+native_client/src/trusted/service_runtime/include", - "+native_client/src/trusted/service_runtime/nacl_config.h", - # TODO(mseaborn): Move irt.h and irt_dev.h to src/public. - "+native_client/src/untrusted/irt/irt.h", - "+native_client/src/untrusted/irt/irt_dev.h", - "+native_client/src/untrusted/irt/irt_interfaces.h", - "+native_client/src/untrusted/nacl", - "+native_client/src/untrusted/pthread/pthread_internal.h", -] diff --git a/src/public/DEPS b/src/public/DEPS deleted file mode 100644 index cac40a5f58..0000000000 --- a/src/public/DEPS +++ /dev/null @@ -1,5 +0,0 @@ -include_rules = [ - "+native_client/src/public", - "+native_client/src/shared/imc/nacl_imc_c.h", - "+native_client/src/trusted/service_runtime/nacl_size_t.h", -] diff --git a/src/shared/DEPS b/src/shared/DEPS deleted file mode 100644 index eaef504342..0000000000 --- a/src/shared/DEPS +++ /dev/null @@ -1,5 +0,0 @@ -include_rules = [ - "+native_client/src/public", - "+native_client/src/shared", - "+native_client/src/trusted", -] diff --git a/src/shared/platform/DEPS b/src/shared/platform/DEPS deleted file mode 100644 index f6a0c202c9..0000000000 --- a/src/shared/platform/DEPS +++ /dev/null @@ -1,4 +0,0 @@ -include_rules = [ - # Allow nacl toolchain headers. - "+nacl", -] diff --git a/src/tools/tls_edit/DEPS b/src/tools/tls_edit/DEPS deleted file mode 100644 index 63774ad1a6..0000000000 --- a/src/tools/tls_edit/DEPS +++ /dev/null @@ -1,4 +0,0 @@ -include_rules = [ - "+native_client/src/shared", - "+native_client/src/trusted", -] diff --git a/src/trusted/DEPS b/src/trusted/DEPS deleted file mode 100644 index 13c7b33cb6..0000000000 --- a/src/trusted/DEPS +++ /dev/null @@ -1,6 +0,0 @@ -include_rules = [ - "+native_client/src/public", - "+native_client/src/shared", - "+native_client/src/trusted", - "+third_party/lss", -] diff --git a/src/untrusted/DEPS b/src/untrusted/DEPS deleted file mode 100644 index b9d27310a6..0000000000 --- a/src/untrusted/DEPS +++ /dev/null @@ -1,12 +0,0 @@ -include_rules = [ - "+native_client/src/public", - "+native_client/src/shared", - "+native_client/src/untrusted", - "+native_client/src/third_party/dlmalloc", - "+native_client/src/third_party/valgrind", - # For nacl/syscall_bindings_trampoline.h and a couple of tests: - "+native_client/src/trusted/service_runtime/include/bits/nacl_syscalls.h", - "+native_client/src/trusted/service_runtime/nacl_config.h", - # For various tests: - "+native_client/src/trusted/service_runtime/include/sys", -] diff --git a/src/untrusted/minidump_generator/DEPS b/src/untrusted/minidump_generator/DEPS deleted file mode 100644 index 7e9979025a..0000000000 --- a/src/untrusted/minidump_generator/DEPS +++ /dev/null @@ -1,3 +0,0 @@ -include_rules = [ - "+breakpad/src", -] diff --git a/tests/DEPS b/tests/DEPS deleted file mode 100644 index 449c648754..0000000000 --- a/tests/DEPS +++ /dev/null @@ -1,9 +0,0 @@ -include_rules = [ - "+native_client/src/nonsfi/linux", - "+native_client/src/public", - "+native_client/src/shared", - "+native_client/src/third_party/valgrind", - "+native_client/src/trusted", - "+native_client/src/untrusted", - "+native_client/tests", -] diff --git a/tests/callingconv_ppapi/DEPS b/tests/callingconv_ppapi/DEPS deleted file mode 100644 index 74feb2d772..0000000000 --- a/tests/callingconv_ppapi/DEPS +++ /dev/null @@ -1,3 +0,0 @@ -include_rules = [ - "+ppapi/c" -] diff --git a/tools/DEPS b/tools/DEPS deleted file mode 100644 index 2d4b2f999e..0000000000 --- a/tools/DEPS +++ /dev/null @@ -1,5 +0,0 @@ -skip_child_includes = [ - "SRC", - "BUILD", - "BACKPORTS", -] diff --git a/tools/checkdeps/DEPS b/tools/checkdeps/DEPS deleted file mode 100644 index 7a57b0bcc8..0000000000 --- a/tools/checkdeps/DEPS +++ /dev/null @@ -1,3 +0,0 @@ -skip_child_includes = [ - "testdata", -] diff --git a/tools/redirector/DEPS b/tools/redirector/DEPS deleted file mode 100644 index 030229b345..0000000000 --- a/tools/redirector/DEPS +++ /dev/null @@ -1,3 +0,0 @@ -include_rules = [ - "+native_client/tools/redirector" -] From 811546083e6730a6859ca50a97005c9010f4d04a Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Thu, 25 Jun 2026 23:28:42 +0200 Subject: [PATCH 03/36] gitignore: ignore toolchain/ symbolic link Ignore toolchain/ symbolic link. This way we can symlink the prebuilt toolchain by Google when we need to build with it for investigation purpose. --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 2427f32cb1..36419ce8c4 100644 --- a/.gitignore +++ b/.gitignore @@ -29,6 +29,7 @@ testserver.log /chromebinaries/ /scons-out/ /toolchain/ +/toolchain /tools/BUILD/ /tools/out/ /tools/perf_expectations/ From 08189c9e1268a639a607762a2453e5e0fd6b2bcf Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Thu, 25 Jun 2026 23:32:19 +0200 Subject: [PATCH 04/36] tools: move files from build/ to tools/build/ Move files from build/ to tools/build/. Keep the build/ directory available as a build folder. --- .gitignore | 4 ++-- SConstruct | 6 +++--- buildbot/buildbot_lib.py | 2 +- buildbot/buildbot_linux-glibc-makefile.sh | 10 +++++----- buildbot/buildbot_mac-glibc-makefile.sh | 10 +++++----- buildbot/buildbot_windows-glibc-makefile.sh | 10 +++++----- site_scons/site_tools/target_platform_windows.py | 2 +- toolchain_build/toolchain_build_pnacl.py | 2 +- {build => tools/build}/build_nexe_tools.py | 0 {build => tools/build}/cygtar.py | 0 {build => tools/build}/filter_windows_lcov.py | 0 {build => tools/build}/get_toolchain_revision.py | 0 {build => tools/build}/link_irt.py | 0 {build => tools/build}/mac/find_sdk.py | 0 {build => tools/build}/mac/strip_from_xcode | 2 +- {build => tools/build}/mac/strip_save_dsym | 0 {build => tools/build}/package_version/archive_info.py | 0 .../build}/package_version/archive_info_test.py | 0 {build => tools/build}/package_version/build.scons | 0 {build => tools/build}/package_version/error.py | 0 {build => tools/build}/package_version/package_info.py | 0 .../build}/package_version/package_info_test.py | 0 .../build}/package_version/package_locations.py | 0 .../build}/package_version/package_version.py | 2 +- .../build}/package_version/package_version_test.py | 0 .../build}/package_version/packages_info.py | 0 .../build}/package_version/packages_info_test.py | 0 .../build}/package_version/revision_info.py | 0 .../build}/package_version/revision_info_test.py | 0 .../package_version/run_package_version_tests.py | 0 .../build}/package_version/standard_packages.json | 0 .../build}/package_version/test_packages.json | 0 {build => tools/build}/toolchain_vs2013.hash | 0 {build => tools/build}/update_pnacl_tool_revisions.py | 0 .../trusted-toolchain-creator.armhf.sh | 2 +- .../trusted-toolchain-creator.mipsel.debian.sh | 2 +- 36 files changed, 27 insertions(+), 27 deletions(-) rename {build => tools/build}/build_nexe_tools.py (100%) rename {build => tools/build}/cygtar.py (100%) rename {build => tools/build}/filter_windows_lcov.py (100%) rename {build => tools/build}/get_toolchain_revision.py (100%) rename {build => tools/build}/link_irt.py (100%) rename {build => tools/build}/mac/find_sdk.py (100%) rename {build => tools/build}/mac/strip_from_xcode (97%) rename {build => tools/build}/mac/strip_save_dsym (100%) rename {build => tools/build}/package_version/archive_info.py (100%) rename {build => tools/build}/package_version/archive_info_test.py (100%) rename {build => tools/build}/package_version/build.scons (100%) rename {build => tools/build}/package_version/error.py (100%) rename {build => tools/build}/package_version/package_info.py (100%) rename {build => tools/build}/package_version/package_info_test.py (100%) rename {build => tools/build}/package_version/package_locations.py (100%) rename {build => tools/build}/package_version/package_version.py (99%) rename {build => tools/build}/package_version/package_version_test.py (100%) rename {build => tools/build}/package_version/packages_info.py (100%) rename {build => tools/build}/package_version/packages_info_test.py (100%) rename {build => tools/build}/package_version/revision_info.py (100%) rename {build => tools/build}/package_version/revision_info_test.py (100%) rename {build => tools/build}/package_version/run_package_version_tests.py (100%) rename {build => tools/build}/package_version/standard_packages.json (100%) rename {build => tools/build}/package_version/test_packages.json (100%) rename {build => tools/build}/toolchain_vs2013.hash (100%) rename {build => tools/build}/update_pnacl_tool_revisions.py (100%) diff --git a/.gitignore b/.gitignore index 36419ce8c4..31086bf186 100644 --- a/.gitignore +++ b/.gitignore @@ -24,8 +24,8 @@ testserver.log /toolchain_build/src/ # Ignore these absolute directories (relative to native_client directory) -/build/Debug/ -/build/Release/ +/tools/build/Debug/ +/tools/build/Release/ /chromebinaries/ /scons-out/ /toolchain/ diff --git a/SConstruct b/SConstruct index 50bb35488c..b933ab7d74 100755 --- a/SConstruct +++ b/SConstruct @@ -2103,7 +2103,7 @@ def MakeBaseTrustedEnv(platform=None): base_env.Append(BUILD_SCONSCRIPTS = [ # KEEP THIS SORTED PLEASE - 'build/package_version/build.scons', + 'tools/build/package_version/build.scons', 'pynacl/build.scons', 'src/nonsfi/irt/build.scons', 'src/nonsfi/loader/build.scons', @@ -2436,7 +2436,7 @@ def MakeMacEnv(platform=None): # This invocation matches the model in //build/config/mac/mac_sdk.gni. mac_sdk_sysroot, mac_sdk_version = subprocess.check_output([ sys.executable, - os.path.join(os.path.pardir, 'build', 'mac', 'find_sdk.py'), + os.path.join(os.path.pardir, 'tools', 'build', 'mac', 'find_sdk.py'), '--print_sdk_path', mac_sdk_min ], encoding='utf-8').splitlines() @@ -2667,7 +2667,7 @@ def SetUpLinuxEnvMips(env): if not which(os.path.join(tc_dir, 'mipsel-linux-gnu-gcc')): print("WARNING: " "MIPS trusted toolchain not found - try running:\n" - " build/package_version/package_version.py --packages" + " tools/build/package_version/package_version.py --packages" " linux_x86/mips_trusted sync -x\n" "Or build it yourself with:\n" " tools/trusted_cross_toolchains/trusted-toolchain-creator" diff --git a/buildbot/buildbot_lib.py b/buildbot/buildbot_lib.py index 46a13dff8f..02458b071f 100644 --- a/buildbot/buildbot_lib.py +++ b/buildbot/buildbot_lib.py @@ -88,7 +88,7 @@ def SetupLinuxEnvironment(context): # Override the trusted compiler for mips, clang does not support mips context['clang'] = False # Ensure the trusted mips toolchain is installed. - cmd = ['build/package_version/package_version.py', '--packages', + cmd = ['tools/build/package_version/package_version.py', '--packages', 'linux_x86/mips_trusted', 'sync', '-x'] Command(context, cmd) diff --git a/buildbot/buildbot_linux-glibc-makefile.sh b/buildbot/buildbot_linux-glibc-makefile.sh index 43d774fa5f..e1b16cbda8 100755 --- a/buildbot/buildbot_linux-glibc-makefile.sh +++ b/buildbot/buildbot_linux-glibc-makefile.sh @@ -202,24 +202,24 @@ done echo @@@STEP_LINK@download@http://gsdview.appspot.com/${GSD_BUCKET}/${UPLOAD_LOC}/@@@ echo @@@BUILD_STEP archive_extract_packages@@@ -python build/package_version/package_version.py \ +python tools/build/package_version/package_version.py \ archive --archive-package=${TOOLCHAINNAME}/nacl_x86_glibc --extract \ --extra-archive gdb_i686_linux.tgz \ tools/toolchain.tar.bz2,${TOOL_TOOLCHAIN}@https://storage.googleapis.com/${GSD_BUCKET}/${UPLOAD_LOC}/toolchain_linux_x86.tar.bz2 \ tools/core_sdk.tar.bz2,${CORE_SDK}@https://storage.googleapis.com/${GSD_BUCKET}/${UPLOAD_LOC}/core_sdk_linux_x86.tar.bz2 -python build/package_version/package_version.py \ +python tools/build/package_version/package_version.py \ archive --archive-package=${TOOLCHAINNAME}/nacl_x86_glibc_raw --extract \ --extra-archive gdb_i686_linux.tgz \ tools/toolchain.tar.bz2,${TOOL_TOOLCHAIN}@https://storage.googleapis.com/${GSD_BUCKET}/${UPLOAD_LOC}/toolchain_linux_x86.tar.bz2 echo @@@BUILD_STEP upload_package_info@@@ -python build/package_version/package_version.py \ +python tools/build/package_version/package_version.py \ --cloud-bucket=${GSD_BUCKET} --annotate \ upload --skip-missing \ --upload-package=${TOOLCHAINNAME}/nacl_x86_glibc --revision=${UPLOAD_REV} -python build/package_version/package_version.py \ +python tools/build/package_version/package_version.py \ --cloud-bucket=${GSD_BUCKET} --annotate \ upload --skip-missing \ --upload-package=${TOOLCHAINNAME}/nacl_x86_glibc_raw --revision=${UPLOAD_REV} @@ -240,7 +240,7 @@ fail() { # Before we start testing, put in dummy mock archives so gyp can still untar # the entire package. -python build/package_version/package_version.py fillemptytars \ +python tools/build/package_version/package_version.py fillemptytars \ --fill-package nacl_x86_glibc # First run 32bit tests, then 64bit tests. Both should succeed. diff --git a/buildbot/buildbot_mac-glibc-makefile.sh b/buildbot/buildbot_mac-glibc-makefile.sh index 090e5d1675..3e2ee56efd 100755 --- a/buildbot/buildbot_mac-glibc-makefile.sh +++ b/buildbot/buildbot_mac-glibc-makefile.sh @@ -133,24 +133,24 @@ done echo @@@STEP_LINK@download@http://gsdview.appspot.com/${GSD_BUCKET}/${UPLOAD_LOC}/@@@ echo @@@BUILD_STEP archive_extract_packages@@@ -python build/package_version/package_version.py \ +python tools/build/package_version/package_version.py \ archive --archive-package=${TOOLCHAINNAME}/nacl_x86_glibc --extract \ --extra-archive gdb_x86_64_apple_darwin.tgz \ tools/toolchain.tar.bz2,${TOOL_TOOLCHAIN}@https://storage.googleapis.com/${GSD_BUCKET}/${UPLOAD_LOC}/toolchain_mac_x86.tar.bz2 \ tools/core_sdk.tar.bz2,${CORE_SDK}@https://storage.googleapis.com/${GSD_BUCKET}/${UPLOAD_LOC}/core_sdk_mac_x86.tar.bz2 -python build/package_version/package_version.py \ +python tools/build/package_version/package_version.py \ archive --archive-package=${TOOLCHAINNAME}/nacl_x86_glibc_raw --extract \ --extra-archive gdb_x86_64_apple_darwin.tgz \ tools/toolchain.tar.bz2,${TOOL_TOOLCHAIN}@https://storage.googleapis.com/${GSD_BUCKET}/${UPLOAD_LOC}/toolchain_mac_x86.tar.bz2 echo @@@BUILD_STEP upload_package_info@@@ -python build/package_version/package_version.py \ +python tools/build/package_version/package_version.py \ --cloud-bucket ${GSD_BUCKET} --annotate \ upload --skip-missing \ --upload-package=${TOOLCHAINNAME}/nacl_x86_glibc --revision=${UPLOAD_REV} -python build/package_version/package_version.py \ +python tools/build/package_version/package_version.py \ --cloud-bucket ${GSD_BUCKET} --annotate \ upload --skip-missing \ --upload-package=${TOOLCHAINNAME}/nacl_x86_glibc_raw --revision=${UPLOAD_REV} @@ -165,7 +165,7 @@ fail() { # Before we start testing, put in dummy mock archives so gyp can still untar # the entire package. -python build/package_version/package_version.py fillemptytars \ +python tools/build/package_version/package_version.py fillemptytars \ --fill-package nacl_x86_glibc export INSIDE_TOOLCHAIN=1 diff --git a/buildbot/buildbot_windows-glibc-makefile.sh b/buildbot/buildbot_windows-glibc-makefile.sh index 941bd07319..438c69a039 100755 --- a/buildbot/buildbot_windows-glibc-makefile.sh +++ b/buildbot/buildbot_windows-glibc-makefile.sh @@ -139,31 +139,31 @@ done echo @@@STEP_LINK@download@http://gsdview.appspot.com/${GSD_BUCKET}/${UPLOAD_LOC}/@@@ echo @@@BUILD_STEP archive_extract_packages@@@ -${NATIVE_PYTHON} build/package_version/package_version.py \ +${NATIVE_PYTHON} tools/build/package_version/package_version.py \ archive --archive-package=${TOOLCHAINNAME}/nacl_x86_glibc --extract \ --extra-archive gdb_i686_w64_mingw32.tgz \ tools/toolchain.tar.bz2,${TOOL_TOOLCHAIN}@https://storage.googleapis.com/${GSD_BUCKET}/${UPLOAD_LOC}/toolchain_win_x86.tar.bz2 \ tools/core_sdk.tar.bz2,${CORE_SDK}@https://storage.googleapis.com/${GSD_BUCKET}/${UPLOAD_LOC}/core_sdk_win_x86.tar.bz2 -${NATIVE_PYTHON} build/package_version/package_version.py \ +${NATIVE_PYTHON} tools/build/package_version/package_version.py \ archive --archive-package=${TOOLCHAINNAME}/nacl_x86_glibc_raw --extract \ --extra-archive gdb_i686_w64_mingw32.tgz \ tools/toolchain.tar.bz2,${TOOL_TOOLCHAIN}@https://storage.googleapis.com/${GSD_BUCKET}/${UPLOAD_LOC}/toolchain_win_x86.tar.bz2 echo @@@BUILD_STEP upload_package_info@@@ -${NATIVE_PYTHON} build/package_version/package_version.py \ +${NATIVE_PYTHON} tools/build/package_version/package_version.py \ --cloud-bucket=${GSD_BUCKET} --annotate \ upload --skip-missing \ --upload-package=${TOOLCHAINNAME}/nacl_x86_glibc --revision=${UPLOAD_REV} -${NATIVE_PYTHON} build/package_version/package_version.py \ +${NATIVE_PYTHON} tools/build/package_version/package_version.py \ --cloud-bucket=${GSD_BUCKET} --annotate \ upload --skip-missing \ --upload-package=${TOOLCHAINNAME}/nacl_x86_glibc_raw --revision=${UPLOAD_REV} # Before we start testing, put in dummy mock archives so gyp can still untar # the entire package. -python3 build/package_version/package_version.py fillemptytars \ +python3 tools/build/package_version/package_version.py fillemptytars \ --fill-package nacl_x86_glibc # sync_backports is obsolete and should probably be removed. diff --git a/site_scons/site_tools/target_platform_windows.py b/site_scons/site_tools/target_platform_windows.py index 6d1954f2a5..e0fff89e51 100755 --- a/site_scons/site_tools/target_platform_windows.py +++ b/site_scons/site_tools/target_platform_windows.py @@ -344,7 +344,7 @@ def RES(*argv, **karg): # NOTE: cygwin is only required for coverage on windows. ('c:\\cygwin\\bin\\bash -c "' 'PATH=/cygdrive/c/cygwin/bin ' - 'build/filter_windows_lcov.py ' + 'tools/build/filter_windows_lcov.py ' "< `cygpath '${COVERAGE_OUTPUT_FILE}.pre.coverage.lcov'` " "> `cygpath '${COVERAGE_OUTPUT_FILE}'` \""), # TODO(bradnelson): eliminate cygwin dependency. diff --git a/toolchain_build/toolchain_build_pnacl.py b/toolchain_build/toolchain_build_pnacl.py index edb622eb80..091c7928bd 100755 --- a/toolchain_build/toolchain_build_pnacl.py +++ b/toolchain_build/toolchain_build_pnacl.py @@ -196,7 +196,7 @@ def MacSdkFlags(): return [] mac_sdk_sysroot, mac_sdk_version = subprocess.check_output([ sys.executable, - os.path.join(os.path.dirname(NACL_DIR), 'build', 'mac', 'find_sdk.py'), + os.path.join(os.path.dirname(NACL_DIR), 'tools', 'build', 'mac', 'find_sdk.py'), '--print_sdk_path', MAC_SDK_MIN, ], encoding='utf-8').splitlines() diff --git a/build/build_nexe_tools.py b/tools/build/build_nexe_tools.py similarity index 100% rename from build/build_nexe_tools.py rename to tools/build/build_nexe_tools.py diff --git a/build/cygtar.py b/tools/build/cygtar.py similarity index 100% rename from build/cygtar.py rename to tools/build/cygtar.py diff --git a/build/filter_windows_lcov.py b/tools/build/filter_windows_lcov.py similarity index 100% rename from build/filter_windows_lcov.py rename to tools/build/filter_windows_lcov.py diff --git a/build/get_toolchain_revision.py b/tools/build/get_toolchain_revision.py similarity index 100% rename from build/get_toolchain_revision.py rename to tools/build/get_toolchain_revision.py diff --git a/build/link_irt.py b/tools/build/link_irt.py similarity index 100% rename from build/link_irt.py rename to tools/build/link_irt.py diff --git a/build/mac/find_sdk.py b/tools/build/mac/find_sdk.py similarity index 100% rename from build/mac/find_sdk.py rename to tools/build/mac/find_sdk.py diff --git a/build/mac/strip_from_xcode b/tools/build/mac/strip_from_xcode similarity index 97% rename from build/mac/strip_from_xcode rename to tools/build/mac/strip_from_xcode index c26b9fb492..33ec72b0e5 100755 --- a/build/mac/strip_from_xcode +++ b/tools/build/mac/strip_from_xcode @@ -12,7 +12,7 @@ # # An example "Strip If Needed" build phase placed after "Link Binary With # Libraries" would do: -# exec "${XCODEPROJ_DEPTH}/build/mac/strip_from_xcode" +# exec "${XCODEPROJ_DEPTH}/tools/build/mac/strip_from_xcode" if [ "${CONFIGURATION}" != "Release" ] ; then # Only strip in release mode. diff --git a/build/mac/strip_save_dsym b/tools/build/mac/strip_save_dsym similarity index 100% rename from build/mac/strip_save_dsym rename to tools/build/mac/strip_save_dsym diff --git a/build/package_version/archive_info.py b/tools/build/package_version/archive_info.py similarity index 100% rename from build/package_version/archive_info.py rename to tools/build/package_version/archive_info.py diff --git a/build/package_version/archive_info_test.py b/tools/build/package_version/archive_info_test.py similarity index 100% rename from build/package_version/archive_info_test.py rename to tools/build/package_version/archive_info_test.py diff --git a/build/package_version/build.scons b/tools/build/package_version/build.scons similarity index 100% rename from build/package_version/build.scons rename to tools/build/package_version/build.scons diff --git a/build/package_version/error.py b/tools/build/package_version/error.py similarity index 100% rename from build/package_version/error.py rename to tools/build/package_version/error.py diff --git a/build/package_version/package_info.py b/tools/build/package_version/package_info.py similarity index 100% rename from build/package_version/package_info.py rename to tools/build/package_version/package_info.py diff --git a/build/package_version/package_info_test.py b/tools/build/package_version/package_info_test.py similarity index 100% rename from build/package_version/package_info_test.py rename to tools/build/package_version/package_info_test.py diff --git a/build/package_version/package_locations.py b/tools/build/package_version/package_locations.py similarity index 100% rename from build/package_version/package_locations.py rename to tools/build/package_version/package_locations.py diff --git a/build/package_version/package_version.py b/tools/build/package_version/package_version.py similarity index 99% rename from build/package_version/package_version.py rename to tools/build/package_version/package_version.py index eba8918762..615b724166 100755 --- a/build/package_version/package_version.py +++ b/tools/build/package_version/package_version.py @@ -24,7 +24,7 @@ Packages File - A file which describes the various package targets for each platform/architecture along with the packages associated with each package target. - [Default file: build/package_version/standard_packages.json]. + [Default file: tools/build/package_version/standard_packages.json]. Package File - A file which contains the list of package archives within a package. [Default file: toolchain/.tars/$PACKAGE_TARGET/$PACKAGE.json] diff --git a/build/package_version/package_version_test.py b/tools/build/package_version/package_version_test.py similarity index 100% rename from build/package_version/package_version_test.py rename to tools/build/package_version/package_version_test.py diff --git a/build/package_version/packages_info.py b/tools/build/package_version/packages_info.py similarity index 100% rename from build/package_version/packages_info.py rename to tools/build/package_version/packages_info.py diff --git a/build/package_version/packages_info_test.py b/tools/build/package_version/packages_info_test.py similarity index 100% rename from build/package_version/packages_info_test.py rename to tools/build/package_version/packages_info_test.py diff --git a/build/package_version/revision_info.py b/tools/build/package_version/revision_info.py similarity index 100% rename from build/package_version/revision_info.py rename to tools/build/package_version/revision_info.py diff --git a/build/package_version/revision_info_test.py b/tools/build/package_version/revision_info_test.py similarity index 100% rename from build/package_version/revision_info_test.py rename to tools/build/package_version/revision_info_test.py diff --git a/build/package_version/run_package_version_tests.py b/tools/build/package_version/run_package_version_tests.py similarity index 100% rename from build/package_version/run_package_version_tests.py rename to tools/build/package_version/run_package_version_tests.py diff --git a/build/package_version/standard_packages.json b/tools/build/package_version/standard_packages.json similarity index 100% rename from build/package_version/standard_packages.json rename to tools/build/package_version/standard_packages.json diff --git a/build/package_version/test_packages.json b/tools/build/package_version/test_packages.json similarity index 100% rename from build/package_version/test_packages.json rename to tools/build/package_version/test_packages.json diff --git a/build/toolchain_vs2013.hash b/tools/build/toolchain_vs2013.hash similarity index 100% rename from build/toolchain_vs2013.hash rename to tools/build/toolchain_vs2013.hash diff --git a/build/update_pnacl_tool_revisions.py b/tools/build/update_pnacl_tool_revisions.py similarity index 100% rename from build/update_pnacl_tool_revisions.py rename to tools/build/update_pnacl_tool_revisions.py diff --git a/tools/trusted_cross_toolchains/trusted-toolchain-creator.armhf.sh b/tools/trusted_cross_toolchains/trusted-toolchain-creator.armhf.sh index fad156e500..2bbea6ba9d 100755 --- a/tools/trusted_cross_toolchains/trusted-toolchain-creator.armhf.sh +++ b/tools/trusted_cross_toolchains/trusted-toolchain-creator.armhf.sh @@ -349,7 +349,7 @@ UploadArchive() { URL=https://storage.googleapis.com/${GS_FILE} set -x gsutil cp -a public-read ${TAR_ARCHIVE} gs://${GS_FILE} - local package_version=build/package_version/package_version.py + local package_version=tools/build/package_version/package_version.py ${package_version} archive --archive-package arm_trusted ${TAR_ARCHIVE}@${URL} ${package_version} upload --upload-package arm_trusted --revision ${REV} ${package_version} setrevision --revision-package arm_trusted --revision \ diff --git a/tools/trusted_cross_toolchains/trusted-toolchain-creator.mipsel.debian.sh b/tools/trusted_cross_toolchains/trusted-toolchain-creator.mipsel.debian.sh index eefd83e4ae..672edeeaa6 100755 --- a/tools/trusted_cross_toolchains/trusted-toolchain-creator.mipsel.debian.sh +++ b/tools/trusted_cross_toolchains/trusted-toolchain-creator.mipsel.debian.sh @@ -555,7 +555,7 @@ UploadArchive() { local URL=https://storage.googleapis.com/${GS_FILE} set -x gsutil cp -a public-read ${TAR_ARCHIVE} gs://${GS_FILE} - local package_version=build/package_version/package_version.py + local package_version=tools/build/package_version/package_version.py ${package_version} archive --archive-package linux_x86/mips_trusted \ ${TAR_ARCHIVE}@${URL} ${package_version} upload --upload-package linux_x86/mips_trusted \ From 8ab33e755aff55aa2a85c56233e04ee1643786ab Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Thu, 25 Jun 2026 23:43:49 +0200 Subject: [PATCH 05/36] gitignore: ignore the build/ directory It is common practice with CMake to build in build/. --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 31086bf186..b372738c83 100644 --- a/.gitignore +++ b/.gitignore @@ -52,3 +52,6 @@ testserver.log # Ignore the hermetic cygwin used on windows toolchain builds. /cygwin/ + +# It is common practice with CMake to build in build/ +/build/ From 6b0137a6908631030cb0a0e4bd14454180ca0028 Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Tue, 8 Apr 2025 09:03:34 +0200 Subject: [PATCH 06/36] win32: do not redefine mode_t with conflicting type on MinGW --- src/include/win/port_win.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/include/win/port_win.h b/src/include/win/port_win.h index 790a8fe3e8..709a190ae8 100644 --- a/src/include/win/port_win.h +++ b/src/include/win/port_win.h @@ -74,7 +74,9 @@ typedef __int64_t int64_t; typedef __uint64_t uint64_t; typedef long off_t; +#if defined(_MSC_VER) typedef int mode_t; +#endif typedef long _off_t; typedef long int __loff_t; typedef unsigned long DWORD; From 0bed0cfe3c4a49587021ebc0f32879ef3508f751 Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Tue, 8 Apr 2025 09:04:53 +0200 Subject: [PATCH 07/36] win32: include stdint for INT64_MAX --- src/include/portability.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/include/portability.h b/src/include/portability.h index d0360ebfa9..ec5ea772eb 100644 --- a/src/include/portability.h +++ b/src/include/portability.h @@ -16,6 +16,7 @@ #ifndef NATIVE_CLIENT_SRC_INCLUDE_PORTABILITY_H_ #define NATIVE_CLIENT_SRC_INCLUDE_PORTABILITY_H_ 1 +#include #include #include "native_client/src/include/build_config.h" From b8b40a38f89644628bbef78f088054e81b97e8bf Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Tue, 8 Apr 2025 09:05:21 +0200 Subject: [PATCH 08/36] win32: use lowercase header file name --- src/shared/platform/win/lock_impl.h | 2 +- src/shared/platform/win/xlate_system_error.c | 2 +- src/trusted/validator/validation_cache.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/shared/platform/win/lock_impl.h b/src/shared/platform/win/lock_impl.h index cb5f98b8d3..9024ea3a06 100644 --- a/src/shared/platform/win/lock_impl.h +++ b/src/shared/platform/win/lock_impl.h @@ -8,7 +8,7 @@ #ifndef NATIVE_CLIENT_SRC_TRUSTED_PLATFORM_WIN_LOCK_IMPL_H_ #define NATIVE_CLIENT_SRC_TRUSTED_PLATFORM_WIN_LOCK_IMPL_H_ -#include +#include #include "native_client/src/include/nacl_macros.h" #include "native_client/src/shared/platform/nacl_sync.h" diff --git a/src/shared/platform/win/xlate_system_error.c b/src/shared/platform/win/xlate_system_error.c index cfaca7c266..b9d51f34fd 100644 --- a/src/shared/platform/win/xlate_system_error.c +++ b/src/shared/platform/win/xlate_system_error.c @@ -9,7 +9,7 @@ */ #include -#include +#include #include "native_client/src/shared/platform/nacl_log.h" #include "native_client/src/shared/platform/win/xlate_system_error.h" diff --git a/src/trusted/validator/validation_cache.c b/src/trusted/validator/validation_cache.c index b9d9536bb7..f8ce53e9ef 100644 --- a/src/trusted/validator/validation_cache.c +++ b/src/trusted/validator/validation_cache.c @@ -21,7 +21,7 @@ #include "native_client/src/trusted/validator/validation_metadata.h" #if NACL_WINDOWS -#include +#include #include #endif From b9cec2e38a407139c9944922fd17988f1ea6f35f Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Tue, 8 Apr 2025 09:26:48 +0200 Subject: [PATCH 09/36] win32: use __inline__ instead of __forceinline__ on MinGW --- src/include/nacl_compiler_annotations.h | 2 +- src/trusted/validator_ragel/bitmap.h | 2 +- src/trusted/validator_ragel/decoding.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/include/nacl_compiler_annotations.h b/src/include/nacl_compiler_annotations.h index c9baad67b7..b8e46d2f26 100644 --- a/src/include/nacl_compiler_annotations.h +++ b/src/include/nacl_compiler_annotations.h @@ -10,7 +10,7 @@ #include "native_client/src/include/build_config.h" /* MSVC supports "inline" only in C++ */ -#if NACL_WINDOWS +#if defined(_MSC_VER) # define INLINE __forceinline #else # define INLINE __inline__ diff --git a/src/trusted/validator_ragel/bitmap.h b/src/trusted/validator_ragel/bitmap.h index dec2a0d2cb..798e392b72 100644 --- a/src/trusted/validator_ragel/bitmap.h +++ b/src/trusted/validator_ragel/bitmap.h @@ -15,7 +15,7 @@ #include "native_client/src/include/nacl_macros.h" #include "native_client/src/include/portability.h" -#if NACL_WINDOWS +#if defined(_MSC_VER) # define FORCEINLINE __forceinline #else # define FORCEINLINE __inline __attribute__ ((always_inline)) diff --git a/src/trusted/validator_ragel/decoding.h b/src/trusted/validator_ragel/decoding.h index 64087b7621..51a781d14e 100644 --- a/src/trusted/validator_ragel/decoding.h +++ b/src/trusted/validator_ragel/decoding.h @@ -19,7 +19,7 @@ #include "native_client/src/include/build_config.h" #include "native_client/src/trusted/validator_ragel/decoder.h" -#if NACL_WINDOWS +#if defined(_MSC_VER) # define FORCEINLINE __forceinline #else # define FORCEINLINE __inline __attribute__ ((always_inline)) From e0c198a678d50666dc77e0ebf110deed1a0ae126 Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Tue, 8 Apr 2025 09:27:54 +0200 Subject: [PATCH 10/36] win32: do not use non-standard i64 integer suffix on MinGW --- src/include/portability.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/include/portability.h b/src/include/portability.h index ec5ea772eb..1344148347 100644 --- a/src/include/portability.h +++ b/src/include/portability.h @@ -60,7 +60,7 @@ #define GG_UINT32_C(x) (x ## U) #define GG_UINT64_C(x) GG_ULONGLONG(x) -#if NACL_WINDOWS +#if NACL_WINDOWS && defined(_MSC_VER) #define GG_LONGLONG(x) x##I64 #define GG_ULONGLONG(x) x##UI64 #else From c602d47482d8267c400afbebff4fb42c0bd02a2e Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Tue, 8 Apr 2025 09:34:32 +0200 Subject: [PATCH 11/36] win32: do not declare PosixSignals enum on MinGW --- src/trusted/service_runtime/nacl_signal.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/trusted/service_runtime/nacl_signal.h b/src/trusted/service_runtime/nacl_signal.h index e3a8fa1732..2301ed407e 100644 --- a/src/trusted/service_runtime/nacl_signal.h +++ b/src/trusted/service_runtime/nacl_signal.h @@ -58,7 +58,7 @@ struct NaClExceptionFrame; #define NACL_ABI_WIFSIGNALED(status) ((((status) + 1) & 0x7f) > 1) #define NACL_ABI_W_EXITCODE(ret, sig) ((((ret) & 0xff) << 8) + ((sig) & 0x7f)) -#if NACL_WINDOWS +#if NACL_WINDOWS && defined(_MSC_VER) enum PosixSignals { SIGINT = 2, SIGQUIT = 3, From a7dc02188aaa12390ea2778cd8fb27438c034b5b Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Tue, 8 Apr 2025 09:37:05 +0200 Subject: [PATCH 12/36] win32: use GCC noinline on MinGW --- src/trusted/service_runtime/sel_ldr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/trusted/service_runtime/sel_ldr.c b/src/trusted/service_runtime/sel_ldr.c index 4dbc7611cb..7bcf97c210 100644 --- a/src/trusted/service_runtime/sel_ldr.c +++ b/src/trusted/service_runtime/sel_ldr.c @@ -912,7 +912,7 @@ void NaClVmIoPendingCheck_mu(struct NaClApp *nap, * We need its symbol in the symbol table so don't inline it. * TODO(dje): add some explanation for the non-GDB person. */ -#if NACL_WINDOWS +#if NACL_WINDOWS && defined(_MSVC_VER) __declspec(dllexport noinline) #endif #ifdef __GNUC__ From 97e64f52c4379cd3cdee98937fb3432e3b1cf66a Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Tue, 8 Apr 2025 11:30:35 +0200 Subject: [PATCH 13/36] win32: use asm intrinsics alternative to __halt() on MinGW --- src/shared/platform/win/nacl_exit.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/shared/platform/win/nacl_exit.c b/src/shared/platform/win/nacl_exit.c index a190175ff5..17c7741d89 100644 --- a/src/shared/platform/win/nacl_exit.c +++ b/src/shared/platform/win/nacl_exit.c @@ -39,7 +39,11 @@ void NaClAbort(void) { * http://code.google.com/p/nativeclient/issues/detail?id=2772). */ while (1) { +#if defined(_MSC_VER) __halt(); +#else + __asm__("hlt"); +#endif } } From 224f152bee3fa0527263c70e1e28b0e147e4b4e0 Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Tue, 8 Apr 2025 12:21:33 +0200 Subject: [PATCH 14/36] win32: use posix intrinsics instead of MSVC asm code on i686 MinGW --- src/trusted/service_runtime/arch/x86_32/sel_rt_32.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/trusted/service_runtime/arch/x86_32/sel_rt_32.c b/src/trusted/service_runtime/arch/x86_32/sel_rt_32.c index 5757b6c904..15d543639e 100644 --- a/src/trusted/service_runtime/arch/x86_32/sel_rt_32.c +++ b/src/trusted/service_runtime/arch/x86_32/sel_rt_32.c @@ -90,7 +90,7 @@ int NaClAppThreadInitArchSpecific(struct NaClAppThread *natp, * Save the system's state of the x87 FPU control word so we can restore * the same state when returning to trusted code. */ -#if NACL_WINDOWS +#if defined(_MSC_VER) { uint16_t sys_fcw; __asm { From 7a0792686924709ac1687c4fc47999d78005d25c Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Tue, 8 Apr 2025 12:29:32 +0200 Subject: [PATCH 15/36] win32: do not use MSVC fast asm in port_win.c on i686 MinGW --- src/shared/platform/win/port_win.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/shared/platform/win/port_win.c b/src/shared/platform/win/port_win.c index 2f303ff10a..d743bd1c49 100644 --- a/src/shared/platform/win/port_win.c +++ b/src/shared/platform/win/port_win.c @@ -12,7 +12,7 @@ #include "native_client/src/include/portability.h" -#if ( DO_NOT_USE_FAST_ASSEMBLER_VERSION_FOR_FFS || defined(_WIN64) ) +#if ( DO_NOT_USE_FAST_ASSEMBLER_VERSION_FOR_FFS || defined(_WIN64) || !defined(_MSC_VER) ) int ffs(int x) { int r = 1; From 58cd85c143fa0bc66cffa1e8667c731d9c8b2780 Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Tue, 9 Dec 2025 18:07:46 +0100 Subject: [PATCH 16/36] win32: silence some MSVC pragma and redefinitions on MinGW --- src/include/portability.h | 2 ++ src/include/portability_io.h | 4 ++++ src/include/portability_string.h | 2 ++ src/include/win/port_win.h | 6 +++++- 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/include/portability.h b/src/include/portability.h index 1344148347..42aab4d5a5 100644 --- a/src/include/portability.h +++ b/src/include/portability.h @@ -31,7 +31,9 @@ #if NACL_WINDOWS /* disable warnings for deprecated functions like getenv, etc. */ +#if defined(_MSC_VER) #pragma warning(disable : 4996) +#endif # include /* TODO: eliminate port_win.h */ # include "native_client/src/include/win/port_win.h" diff --git a/src/include/portability_io.h b/src/include/portability_io.h index 75eedbf12d..8abafd023f 100644 --- a/src/include/portability_io.h +++ b/src/include/portability_io.h @@ -17,7 +17,9 @@ #if NACL_WINDOWS /* disable warnings for deprecated _snprintf */ +#if defined(_MSC_VER) #pragma warning(disable : 4996) +#endif #include #include @@ -43,7 +45,9 @@ /* missing from win stdio.h and fcntl.h */ /* from bits/fcntl.h */ +#if defined(_MSC_VER) #define O_ACCMODE 0003 +#endif #else diff --git a/src/include/portability_string.h b/src/include/portability_string.h index 9b86ead994..1c49954770 100644 --- a/src/include/portability_string.h +++ b/src/include/portability_string.h @@ -53,7 +53,9 @@ size_t strnlen(const char* str, size_t max); #if NACL_WINDOWS /* disable warnings for deprecated strncpy */ +#if defined(_MSC_VER) #pragma warning(disable : 4996) +#endif #define STRDUP _strdup #define STRTOLL _strtoi64 diff --git a/src/include/win/port_win.h b/src/include/win/port_win.h index 709a190ae8..8130db69c2 100644 --- a/src/include/win/port_win.h +++ b/src/include/win/port_win.h @@ -38,6 +38,7 @@ /* TODO: eliminated this file and move its contents to portability*.h */ +#if defined(_MSC_VER) /* wchar_t and unsigned short are not always equivalent*/ #pragma warning(disable : 4255) /* padding added after struct member */ @@ -46,6 +47,7 @@ #pragma warning(disable: 4826) /* conditional expression is constant */ #pragma warning(disable : 4127) +#endif /* TODO: limit this include to files that really need it */ #ifndef NOMINMAX @@ -96,7 +98,7 @@ typedef int32_t ssize_t; * * Only including range values actually used in our codebase. */ -#if _MSC_VER >= 1800 +#if !defined(_MSC_VER) || _MSC_VER >= 1800 #include #else # if !defined(UINT8_MAX) @@ -162,6 +164,8 @@ EXTERN_C_END /* from linux/limits.h, via sys/param.h */ +#if defined(_MSC_VER) #define PATH_MAX 4096 +#endif #endif /* NATIVE_CLIENT_SRC_INCLUDE_WIN_PORT_WIN_H_ */ From 401ee9e0a51b57566449c12dc5e9375fc957cf88 Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Tue, 9 Dec 2025 18:33:56 +0100 Subject: [PATCH 17/36] win32: silence warnings about undefined NACL_USE_TLS and NACL_USE_TSD --- src/trusted/fault_injection/fault_injection.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/trusted/fault_injection/fault_injection.c b/src/trusted/fault_injection/fault_injection.c index 3d71f5f7b2..2fa29c35d9 100644 --- a/src/trusted/fault_injection/fault_injection.c +++ b/src/trusted/fault_injection/fault_injection.c @@ -66,6 +66,8 @@ */ # define NACL_HAS_STRNDUP 0 /* could use TLS if not built into a DLL, otherwise must use TLSALLOC */ +# define NACL_USE_TLS 0 +# define NACL_USE_TSD 0 # define NACL_USE_TLSALLOC 1 # include #endif From 2cd0a475802a6dffe2f3989023f5289041a3bcca Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Tue, 8 Apr 2025 11:02:41 +0200 Subject: [PATCH 18/36] win32: add and use a simplistic macamd64.inc --- include-hax/fake_masm/macamd64.inc | 9 +++++++++ .../arch/x86_64/nacl_switch_unwind_win.asm | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 include-hax/fake_masm/macamd64.inc diff --git a/include-hax/fake_masm/macamd64.inc b/include-hax/fake_masm/macamd64.inc new file mode 100644 index 0000000000..970487f4dc --- /dev/null +++ b/include-hax/fake_masm/macamd64.inc @@ -0,0 +1,9 @@ +push_reg macro Reg + push Reg + .pushreg Reg + endm + +alloc_stack macro Size + sub rsp, Size + .allocstack Size + endm diff --git a/src/trusted/service_runtime/arch/x86_64/nacl_switch_unwind_win.asm b/src/trusted/service_runtime/arch/x86_64/nacl_switch_unwind_win.asm index d5dd93a9a1..6ead09486a 100644 --- a/src/trusted/service_runtime/arch/x86_64/nacl_switch_unwind_win.asm +++ b/src/trusted/service_runtime/arch/x86_64/nacl_switch_unwind_win.asm @@ -2,7 +2,7 @@ ; Use of this source code is governed by a BSD-style license that can be ; found in the LICENSE file. -include ksamd64.inc +include macamd64.inc EXTERN NaClSwitch : QWORD From 8dbb29ab40787c51e3d396156d0c293ba6153f0d Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Tue, 8 Apr 2025 12:25:36 +0200 Subject: [PATCH 19/36] win32: skip some CPU detection on Windows with MinGW like 64-bit MSVC The only known working implementation is for i686 MSVC. - amd64 MSVC was already disabled and marked at not working, - there is no MinGW implementation in the code. --- src/trusted/platform_qualify/arch/x86/vcpuid.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/trusted/platform_qualify/arch/x86/vcpuid.c b/src/trusted/platform_qualify/arch/x86/vcpuid.c index dbefa9b11c..17db404b85 100644 --- a/src/trusted/platform_qualify/arch/x86/vcpuid.c +++ b/src/trusted/platform_qualify/arch/x86/vcpuid.c @@ -38,7 +38,15 @@ const int kMagicConst_ROUNDSS = 0xc0000000; const int kMagicConst_POPCNT = 13; const int kMagicConst_CRC32 = 0xb906c3ea; -#if !(NACL_WINDOWS && (NACL_BUILD_SUBARCH == 64)) +#if (NACL_WINDOWS && defined(_MSC_VER) && (NACL_BUILD_SUBARCH == 64)) +# define NACL_WINDOWS_MSC_64 +#endif + +#if (NACL_WINDOWS && !defined(_MSC_VER)) +# define NACL_WINDOWS_MINGW +#endif + +#if !defined(NACL_WINDOWS_MSC_64) && !defined(NACL_WINDOWS_MINGW) static int asm_HasMMX(void) { volatile int before, after; before = kMagicConst; @@ -386,7 +394,7 @@ static int asm_HasCX8(void) { #endif /* 0 */ #endif /* 64-bit Windows */ -#if NACL_WINDOWS && (NACL_BUILD_SUBARCH == 64) +#if defined(NACL_WINDOWS_MSC_64) || defined(NACL_WINDOWS_MINGW) static int CheckCPUFeatureDetection(NaClCPUFeaturesX86 *cpuf) { /* Unfortunately the asm_ tests will not work on 64-bit Windows */ return 0; From 0223f8bcac4c2c3bbca3ca8fd6e8752d46aba914 Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Wed, 10 Dec 2025 09:16:48 +0100 Subject: [PATCH 20/36] win32: implement CPU detection for MinGW --- .../platform_qualify/arch/x86/vcpuid.c | 43 ++++++++++++++++--- 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/src/trusted/platform_qualify/arch/x86/vcpuid.c b/src/trusted/platform_qualify/arch/x86/vcpuid.c index 17db404b85..a5ec005d4b 100644 --- a/src/trusted/platform_qualify/arch/x86/vcpuid.c +++ b/src/trusted/platform_qualify/arch/x86/vcpuid.c @@ -46,7 +46,7 @@ const int kMagicConst_CRC32 = 0xb906c3ea; # define NACL_WINDOWS_MINGW #endif -#if !defined(NACL_WINDOWS_MSC_64) && !defined(NACL_WINDOWS_MINGW) +#if !defined(NACL_WINDOWS_MSC_64) static int asm_HasMMX(void) { volatile int before, after; before = kMagicConst; @@ -394,20 +394,34 @@ static int asm_HasCX8(void) { #endif /* 0 */ #endif /* 64-bit Windows */ -#if defined(NACL_WINDOWS_MSC_64) || defined(NACL_WINDOWS_MINGW) +#if defined(NACL_WINDOWS_MSC_64) static int CheckCPUFeatureDetection(NaClCPUFeaturesX86 *cpuf) { /* Unfortunately the asm_ tests will not work on 64-bit Windows */ return 0; } #else -#if (NACL_LINUX || NACL_OSX) +#if (NACL_LINUX || NACL_OSX || defined(NACL_WINDOWS_MINGW)) /* Linux/MacOS signal handling code, for trapping illegal instruction faults */ static int sawbadinstruction = 0; -static struct sigaction crash_detect; static int signum; -sigjmp_buf crash_load; +#if defined(NACL_WINDOWS_MINGW) +static PVOID crash_handler; +static jmp_buf crash_load; +#else +static struct sigaction crash_detect; +static sigjmp_buf crash_load; +#endif +#if defined(NACL_WINDOWS_MINGW) +static LONG CALLBACK handler_load(EXCEPTION_POINTERS *ep) +{ + if (ep->ExceptionRecord->ExceptionCode == EXCEPTION_ILLEGAL_INSTRUCTION) { + longjmp(crash_load, SIGILL); + } + return EXCEPTION_CONTINUE_SEARCH; +} +#else void handler_load(int signal_num) { siglongjmp(crash_load, signal_num); } @@ -435,13 +449,18 @@ void all_sigs(struct sigaction *new_action, (void) sigaction(SIGCHLD, &ign, 0); (void) sigaction(SIGTSTP, &ign, 0); } +#endif static void SignalInit(void) { sawbadinstruction = 0; +#if defined(NACL_WINDOWS_MINGW) + crash_handler = AddVectoredExceptionHandler(1, handler_load); +#else crash_detect.sa_handler = handler_load; sigemptyset(&crash_detect.sa_mask); crash_detect.sa_flags = SA_RESETHAND; all_sigs(&crash_detect, 0); +#endif } static void SetSawBadInst(void) { @@ -458,7 +477,13 @@ static int SawBadInst(void) { */ static int DoTest(int (*thetest)(void), const char *s) { SignalInit(); - if (0 != (signum = sigsetjmp(crash_load, 1))) { + +#if defined(NACL_WINDOWS_MINGW) + signum = setjmp(crash_load); +#else + signum = sigsetjmp(crash_load, 1); +#endif + if (0 != signum) { SetSawBadInst(); if (SIGILL == signum) { fprintf(stderr, "%s: illegal instruction\n", s); @@ -470,10 +495,16 @@ static int DoTest(int (*thetest)(void), const char *s) { int hasfeature = thetest(); if (hasfeature && (! SawBadInst())) { printf("[Has %s]\n", s); +#if defined(NACL_WINDOWS_MINGW) + RemoveVectoredExceptionHandler(crash_handler); +#endif return 0; } } printf("no %s\n", s); +#if defined(NACL_WINDOWS_MINGW) + RemoveVectoredExceptionHandler(crash_handler); +#endif return 1; } #elif NACL_WINDOWS From 02ac525c4f88b1cf07e77a87524d5248a3cde70f Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Mon, 7 Apr 2025 20:15:18 +0200 Subject: [PATCH 21/36] cmake: add the Yokai CMake framework --- cmake/Yokai/All.cmake | 36 ++ cmake/Yokai/Architecture.cmake | 208 ++++++++++ cmake/Yokai/Compiler.cmake | 213 ++++++++++ cmake/Yokai/Detection.cmake | 110 ++++++ cmake/Yokai/Detection/Architecture.c | 127 ++++++ cmake/Yokai/Detection/Compiler.c | 150 +++++++ cmake/Yokai/Detection/Compiler.cpp | 1 + cmake/Yokai/Detection/System.c | 68 ++++ cmake/Yokai/Detection/detect | 63 +++ cmake/Yokai/Detection/qprocessordetection.h | 411 ++++++++++++++++++++ cmake/Yokai/Detection/report.h | 47 +++ cmake/Yokai/FileEmbedder.cmake | 44 +++ cmake/Yokai/SourceGenerator.cmake | 180 +++++++++ cmake/Yokai/System.cmake | 143 +++++++ 14 files changed, 1801 insertions(+) create mode 100644 cmake/Yokai/All.cmake create mode 100644 cmake/Yokai/Architecture.cmake create mode 100644 cmake/Yokai/Compiler.cmake create mode 100644 cmake/Yokai/Detection.cmake create mode 100644 cmake/Yokai/Detection/Architecture.c create mode 100644 cmake/Yokai/Detection/Compiler.c create mode 100644 cmake/Yokai/Detection/Compiler.cpp create mode 100644 cmake/Yokai/Detection/System.c create mode 100755 cmake/Yokai/Detection/detect create mode 100644 cmake/Yokai/Detection/qprocessordetection.h create mode 100644 cmake/Yokai/Detection/report.h create mode 100644 cmake/Yokai/FileEmbedder.cmake create mode 100644 cmake/Yokai/SourceGenerator.cmake create mode 100644 cmake/Yokai/System.cmake diff --git a/cmake/Yokai/All.cmake b/cmake/Yokai/All.cmake new file mode 100644 index 0000000000..19b732ea73 --- /dev/null +++ b/cmake/Yokai/All.cmake @@ -0,0 +1,36 @@ +# Daemon BSD Source Code +# Copyright (c) 2025-2026, Daemon Developers +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the Daemon developers nor the +# names of its contributors may be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL DAEMON DEVELOPERS BE LIABLE FOR ANY +# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +################################################################################ +# Collection of reusable CMake helpers written for the Dæmon engine and related +# projects. +################################################################################ + +# Source generation and file embedding. +include("${CMAKE_CURRENT_LIST_DIR}/SourceGenerator.cmake") + +# System, architecture and compiler detection. +include("${CMAKE_CURRENT_LIST_DIR}/Detection.cmake") diff --git a/cmake/Yokai/Architecture.cmake b/cmake/Yokai/Architecture.cmake new file mode 100644 index 0000000000..60616bfd90 --- /dev/null +++ b/cmake/Yokai/Architecture.cmake @@ -0,0 +1,208 @@ +# Daemon BSD Source Code +# Copyright (c) 2022-2026, Daemon Developers +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the Daemon developers nor the +# names of its contributors may be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL DAEMON DEVELOPERS BE LIABLE FOR ANY +# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +################################################################################ +# Architecture detection. +################################################################################ + +# When adding a new architecture, look at all the places YOKAI_HOST_ARCH +# and YOKAI_TARGET_ARCH are used. + +option(USE_ARCH_INTRINSICS "Enable custom code using intrinsics functions or asm declarations" ON) +mark_as_advanced(USE_ARCH_INTRINSICS) + +function(yokai_detect_host_arch) + set(arch_name "unknown") + + string(TOLOWER "${CMAKE_HOST_SYSTEM_PROCESSOR}" processor_lower) + + foreach(name + "amd64" + "arm" + "arm64" + "i686" + "mipsel" + "ppc64" + "riscv64" + ) + if ("${processor_lower}" STREQUAL "${name}") + set(arch_name "${processor_lower}") + endif() + endforeach() + + if ("${arch_name}" STREQUAL "unknown") + set(ARCHES_amd64 "em64t" "x86_64") + set(ARCHES_arm "armv6l" "armv7l") + set(ARCHES_arm64 "armv8l" "aarch64") + set(ARCHES_loong64 "loongarch64") + set(ARCHES_ppc64el "ppc64le") + + foreach(name + "amd64" + "arm" + "arm64" + "loong64" + "ppc64el" + ) + if ("${processor_lower}" IN_LIST ARCHES_${name}) + set(arch_name "${name}") + endif() + endforeach() + endif() + + if ("${arch_name}" STREQUAL "unknown") + if ("${processor_lower}") + message(WARNING "Undocumented host architecture: ${processor_lower}") + else() + message(WARNING "Undocumented host architecture") + endif() + + set(arch_name "${processor_lower}") + endif() + + string(TOUPPER "${arch_name}" arch_name_upper) + + set(YOKAI_HOST_ARCH_NAME "${arch_name}" PARENT_SCOPE) + set(YOKAI_HOST_ARCH_NAME_UPPER "${arch_name_upper}" PARENT_SCOPE) + + # Makes possible to do that in CMake code: + # > if (YOKAI_HOST_ARCH_AMD64) + set("YOKAI_HOST_ARCH_${arch_name_upper}" ON PARENT_SCOPE) + + if ("${arch_name}" STREQUAL "unknown") + message(WARNING "Unknown host architecture: ${processor_lower}") + + set(arch_name "${processor_lower}") + endif() + + set(arm_CHILD + "armel" + "armhf" + ) + + foreach(name + "arm" + ) + if ("${arch_name}" STREQUAL "${name}") + message(STATUS "Parent architecture: ${name}, can be ${${name}_CHILD}") + + foreach(child_name ${${name}_CHILD}) + string(TOUPPER "${child_name}" child_name_upper) + set(YOKAI_HOST_ARCH_${child_name_upper}_PARENT ON PARENT_SCOPE) + endforeach() + endif() + endforeach() +endfunction() + +function(yokai_detect_target_arch) + yokai_run_detection("TARGET" "ARCH" "Architecture.c" "") + + set(YOKAI_TARGET_ARCH_NAME "${arch_name}" PARENT_SCOPE) + set(YOKAI_TARGET_ARCH_NAME_UPPER "${arch_name_upper}" PARENT_SCOPE) + + add_definitions(-DYOKAI_ARCH_${arch_name_upper}) + + # Makes possible to do that in CMake code: + # > if (YOKAI_TARGET_ARCH_AMD64) + set("YOKAI_TARGET_ARCH_${arch_name_upper}" ON PARENT_SCOPE) +endfunction() + +function(yokai_set_arch_intrinsics name) + message(STATUS "Enabling ${name} architecture intrinsics") + string(TOUPPER "${name}" name_upper) + add_definitions(-DYOKAI_USE_ARCH_INTRINSICS_${name_upper}) +endfunction() + +function(yokai_set_intrinsics) + if (USE_ARCH_INTRINSICS) + # Makes possible to do that in C++ code: + # > if defined(YOKAI_USE_ARCH_INTRINSICS) + add_definitions(-DYOKAI_USE_ARCH_INTRINSICS) + + # Makes possible to do that in C++ code: + # > if defined(YOKAI_USE_ARCH_INTRINSICS_AMD64) + yokai_set_arch_intrinsics("${YOKAI_TARGET_ARCH_NAME}") + + set(amd64_PARENT "i686") + set(arm64_PARENT "armhf") + set(ppc64el_PARENT "ppc64") + + if ("${YOKAI_TARGET_ARCH_NAME}_PARENT") + yokai_set_arch_intrinsics("${${YOKAI_TARGET_ARCH_NAME}_PARENT}") + endif() + else() + message(STATUS "Disabling ${YOKAI_TARGET_ARCH_NAME} architecture intrinsics") + endif() +endfunction() + +yokai_detect_host_arch() +yokai_detect_target_arch() + +if (YOKAI_HOST_ARCH_UNKNOWN AND NOT YOKAI_TARGET_ARCH_UNKNOWN) + message(WARNING "Assuming the host architecture is the same as the target: ${YOKAI_TARGET_ARCH_NAME}") + set(YOKAI_HOST_ARCH_NAME "${YOKAI_TARGET_ARCH_NAME}") + set(YOKAI_HOST_ARCH_NAME_UPPER "${YOKAI_TARGET_ARCH_NAME_UPPER}") + set(YOKAI_HOST_ARCH_${YOKAI_HOST_ARCH_NAME_UPPER} ON) + unset(YOKAI_HOST_ARCH_UNKNOWN) +endif() + +if (YOKAI_TARGET_ARCH_UNKNOWN AND NOT YOKAI_HOST_ARCH_UNKNOWN) + message(WARNING "Assuming the target architecture is the same as the host: ${YOKAI_TARGET_ARCH_NAME}") + set(YOKAI_TARGET_ARCH_NAME "${YOKAI_HOST_ARCH_NAME}") + set(YOKAI_TARGET_ARCH_NAME_UPPER "${YOKAI_HOST_ARCH_NAME_UPPER}") + set(YOKAI_TARGET_ARCH_${YOKAI_TARGET_ARCH_NAME_UPPER} ON) + unset(YOKAI_TARGET_ARCH_UNKNOWN) +endif() + +if (YOKAI_HOST_ARCH_UNKNOWN) + message(WARNING "Unknown host architecture") +else() + message(STATUS "Detected host architecture: ${YOKAI_HOST_ARCH_NAME}") +endif() + +if (YOKAI_TARGET_ARCH_UNKNOWN) + message(WARNING "Unknown target architecture") +else() + message(STATUS "Detected target architecture: ${YOKAI_TARGET_ARCH_NAME}") +endif() + +if (NOT "${YOKAI_HOST_ARCH_NAME}" STREQUAL "${YOKAI_TARGET_ARCH_NAME}") + if ("${YOKAI_HOST_ARCH_${YOKAI_TARGET_ARCH_NAME}_PARENT}") + message(STATUS "Assuming no architecture cross-compilation") + else() + message(STATUS "Detected architecture cross-compilation") + set(YOKAI_TARGET_CROSS ON) + endif() +else() + message(STATUS "No architecture cross-compilation detected") +endif() + +if (YOKAI_SOURCE_GENERATOR) + # Add printable strings to the executable. + yokai_add_buildinfo("char*" "YOKAI_ARCH_STRING" "\"${YOKAI_TARGET_ARCH_NAME}\"") +endif() + +yokai_set_intrinsics() diff --git a/cmake/Yokai/Compiler.cmake b/cmake/Yokai/Compiler.cmake new file mode 100644 index 0000000000..5cb422a0b0 --- /dev/null +++ b/cmake/Yokai/Compiler.cmake @@ -0,0 +1,213 @@ +# Daemon BSD Source Code +# Copyright (c) 2024-2026, Daemon Developers +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the Daemon developers nor the +# names of its contributors may be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL DAEMON DEVELOPERS BE LIABLE FOR ANY +# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +################################################################################ +# Compiler detection. +################################################################################ + +# When adding a new compiler, look at all the places YOKAI_C_COMPILER +# and YOKAI_CXX_COMPILER are used. + +function(yokai_detect_compiler lang) + set(C_NAME "C") + set(CXX_NAME "C++") + set(C_EXT ".c") + set(CXX_EXT ".cpp") + + get_filename_component(compiler_basename "${CMAKE_${lang}_COMPILER}" NAME) + + yokai_run_detection("${lang}" "COMPILER" "Compiler${${lang}_EXT}" "GCC;Clang;generic") + + if (compiler_name STREQUAL "Unknown") + if (CMAKE_${lang}_COMPILER_ID) + set(compiler_name "${CMAKE_${lang}_COMPILER_ID}") + # Compiler version is done below. + else() + message(WARNING "Unknown ${${lang}_NAME} compiler") + endif() + endif() + + # AOCC + if (compiler_Clang_version_string) + set(aocc_version_regex ".*CLANG: AOCC_([^ )]+).*") + if (compiler_Clang_version_string MATCHES ${aocc_version_regex}) + set(compiler_name "AOCC") + string(REGEX REPLACE ${aocc_version_regex} "\\1" + compiler_AOCC_version "${compiler_Clang_version_string}") + string(REGEX REPLACE "(.*)-Build.*" "\\1" + compiler_AOCC_version "${compiler_AOCC_version}") + endif() + endif() + + # Zig + if (compiler_Clang_version_string) + set(zig_version_regex ".*[(]https://github.com/ziglang/zig-bootstrap .*[)]") + if (compiler_Clang_version_string MATCHES ${zig_version_regex}) + set(compiler_name "Zig") + endif() + + # Parse “zig version” + execute_process(COMMAND "${CMAKE_${lang}_COMPILER}" version + OUTPUT_VARIABLE CUSTOM_${lang}_ZIG_OUTPUT + RESULT_VARIABLE CUSTOM_${lang}_ZIG_RETURN_CODE + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE) + + if (NOT CUSTOM_${lang}_ZIG_RETURN_CODE) # Success + set(compiler_Zig_version "${CUSTOM_${lang}_ZIG_OUTPUT}") + endif() + endif() + + # Compilers that use the underlying Clang version as their own version. + foreach(name in AppleClang) + if (compiler_name STREQUAL "${name}") + set(compiler_${name}_version "${compiler_Clang_version}") + endif() + endforeach() + + # Compilers that write the version number at the beginning of the VERSION string. + set(string_version_regex "([^ ]+).*") + foreach(name in PNaCl) + if (compiler_name STREQUAL "${name}") + if (compiler_generic_version_string) + if (compiler_generic_version_string MATCHES ${string_version_regex}) + string(REGEX REPLACE ${string_version_regex} "\\1" + compiler_${name}_version "${compiler_generic_version_string}") + endif() + endif() + endif() + endforeach() + + if (compiler_ARMClang_version_string) + # There is no __armclang_patchlevel__ so we should parse __armclang_version__ to get it. + if (compiler_ARMClang_version_string MATCHES ${string_version_regex}) + string(REGEX REPLACE ${string_version_regex} "\\1" + compiler_ARMClang_version "${compiler_ARMClang_version_string}") + endif() + endif() + + if (compiler_ICX_version) + # 20240000 becomes 2024.0.0 + string(REGEX REPLACE "(....)(..)(..)" "\\1.\\2.\\3" + compiler_ICX_version "${compiler_ICX_version}") + string(REGEX REPLACE "\\.0" "." + compiler_ICX_version "${compiler_ICX_version}") + endif() + + if (compiler_${compiler_name}_version) + set(compiler_version "${compiler_${compiler_name}_version}") + elseif (CMAKE_${lang}_COMPILER_VERSION) + set(compiler_version "${CMAKE_${lang}_COMPILER_VERSION}") + else() + set(compiler_version "Unknown") + message(WARNING "Unknown ${${lang}_NAME} compiler version") + endif() + + set(YOKAI_${lang}_COMPILER_BASENAME "${compiler_basename}" PARENT_SCOPE) + set(YOKAI_${lang}_COMPILER_NAME "${compiler_name}" PARENT_SCOPE) + set(YOKAI_${lang}_COMPILER_NAME_UPPER "${compiler_name_upper}" PARENT_SCOPE) + set(YOKAI_${lang}_COMPILER_VERSION "${compiler_version}" PARENT_SCOPE) +endfunction() + +message(STATUS "CMake generator: ${CMAKE_GENERATOR}") + +foreach(lang C;CXX) + set(C_NAME "C") + set(CXX_NAME "C++") + + if (MSVC) + set(YOKAI_${lang}_COMPILER_MSVC_COMPATIBILITY ON) + endif() + + # When MSVC is ON, ${CMAKE_${lang}_COMPILER_ID} can be either MSVC + # or Clang (clang-cl), Only MSVC is true MSVC. + if (MSVC AND "${CMAKE_${lang}_COMPILER_ID}" STREQUAL "MSVC") + set(YOKAI_${lang}_COMPILER_NAME "MSVC") + set(YOKAI_${lang}_COMPILER_NAME_UPPER "MSVC") + + # Let CMake do the job, it does it well, + set(YOKAI_${lang}_COMPILER_VERSION "${CMAKE_${lang}_COMPILER_VERSION}") + + get_filename_component(YOKAI_${lang}_COMPILER_BASENAME "${CMAKE_${lang}_COMPILER}" NAME) + else() + yokai_detect_compiler(${lang}) + + if (YOKAI_${lang}_COMPILER_CLANG_COMPATIBILITY) + if (NOT YOKAI_${lang}_COMPILER_NAME STREQUAL "Clang") + set(YOKAI_${lang}_COMPILER_EXTENDED_VERSION + "${YOKAI_${lang}_COMPILER_VERSION}/Clang_${YOKAI_${lang}_COMPILER_CLANG_VERSION}") + endif() + elseif (YOKAI_${lang}_COMPILER_GCC_COMPATIBILITY) + if (NOT YOKAI_${lang}_COMPILER_NAME STREQUAL "GCC") + # Almost all compilers on Earth pretend to be GCC compatible. + # So we first have to check it's really a GCC variant. + # Parse “ -v” + execute_process(COMMAND "${CMAKE_${lang}_COMPILER}" -v + ERROR_VARIABLE CUSTOM_${lang}_GCC_OUTPUT + RESULT_VARIABLE CUSTOM_${lang}_GCC_RETURN_CODE + OUTPUT_QUIET) + + if (NOT CUSTOM_${lang}_GCC_RETURN_CODE) # Success + # The existence of this string tells us it's a GCC variant. + # The version in this string is the same as __VERSION__, + # the version of the GCC variant, not the version of the upstream + # GCC we are looking for. + if ("${CUSTOM_${lang}_GCC_OUTPUT}" MATCHES "\ngcc version ") + set(YOKAI_${lang}_COMPILER_EXTENDED_VERSION + "${YOKAI_${lang}_COMPILER_VERSION}/GCC_${YOKAI_${lang}_COMPILER_GCC_VERSION}") + endif() + endif() + endif() + endif() + endif() + + if (NOT YOKAI_${lang}_COMPILER_EXTENDED_VERSION) + set(YOKAI_${lang}_COMPILER_EXTENDED_VERSION "${YOKAI_${lang}_COMPILER_VERSION}") + endif() + + set(YOKAI_${lang}_COMPILER_STRING + "${YOKAI_${lang}_COMPILER_NAME}_${YOKAI_${lang}_COMPILER_EXTENDED_VERSION}:${YOKAI_${lang}_COMPILER_BASENAME}") + + if (CMAKE_CXX_COMPILER_ARG1) + set(YOKAI_${lang}_COMPILER_STRING "${YOKAI_${lang}_COMPILER_STRING}:${CMAKE_CXX_COMPILER_ARG1}") + endif() + + message(STATUS "Detected ${${lang}_NAME} compiler: ${YOKAI_${lang}_COMPILER_STRING}") + + # Makes possible to do that in C++ code: + # > if defined(YOKAI_CXX_COMPILER_CLANG) + set(compiler_var_name "YOKAI_${lang}_COMPILER_${YOKAI_${lang}_COMPILER_NAME_UPPER}") + add_definitions(-D${compiler_var_name}) + + # Makes possible to do that in CMake code: + # > if (YOKAI_CXX_COMPILER_CLANG) + set("${compiler_var_name}" ON) + + if (YOKAI_SOURCE_GENERATOR) + # Add printable string to the executable. + yokai_add_buildinfo("char*" "YOKAI_${lang}_COMPILER_STRING" "\"${YOKAI_${lang}_COMPILER_STRING}\"") + endif() +endforeach() diff --git a/cmake/Yokai/Detection.cmake b/cmake/Yokai/Detection.cmake new file mode 100644 index 0000000000..fc9ba8e713 --- /dev/null +++ b/cmake/Yokai/Detection.cmake @@ -0,0 +1,110 @@ +# Daemon BSD Source Code +# Copyright (c) 2025-2026, Daemon Developers +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the Daemon developers nor the +# names of its contributors may be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL DAEMON DEVELOPERS BE LIABLE FOR ANY +# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +################################################################################ +# System, architecture and compiler detection. +################################################################################ + +# Make sure to always call this macro from within a function, not in the global scope. +# As a macro it produces a lot of variables in the parent scope but it is meant to +# only be called by functions so they should never pollute the global scope. +# It's a macro because we need to write a lot of variables in the calling function scope +# and we need to write some variables to the parent scope of the calling function. +macro(yokai_run_detection slug_prefix report_slug file_name compat_list) + string(TOLOWER "${report_slug}" local_slug) + + # Setting -Werror in CXXFLAGS would produce errors instead of warning + # but that should not break the detection, + # so we only print a CMake warning there and use build_log content to + # detect unknown platforms. + # Catching compilation error is still useful, for example to detect + # undefined types, missing header or things like that. + # Setting USE_WERROR to ON doesn't print this warning as the flag + # is set after the detection. + try_compile(build_result + "${CMAKE_BINARY_DIR}" + "${CMAKE_CURRENT_LIST_DIR}/Detection/${file_name}" + # TODO: Force -W#pragma-messages and -Wno-error + # In case there is -Wno-#pragma-messages or -Werror in CFLAGS/CXXFLAGS + CMAKE_FLAGS CMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES} + OUTPUT_VARIABLE build_log + ) + + if (NOT build_result) + message(WARNING "Failed to build ${file_name}.\n" + "Setting -Werror in CFLAGS can produce false positive errors\n" + "${build_log}" + ) + set(${local_slug}_name "Unknown" PARENT_SCOPE) + else() + set(build_log "\n${build_log}\n") + + string(REGEX REPLACE "\n[^\n]*REPORT>[^\n]*\n" "\n" build_log "${build_log}") + + string(REGEX REPLACE ".*\nYOKAI_${report_slug}_NAME=([^\n]*)\n.*" "\\1" + ${local_slug}_name "${build_log}") + + foreach(name ${compat_list};${${local_slug}_name}) + string(TOUPPER "${name}" name_upper) + + set(COMPATIBILITY_REGEX ".*\nYOKAI_${report_slug}_${name}_COMPATIBILITY=([^\n]*)\n.*") + if ("${build_log}" MATCHES ${COMPATIBILITY_REGEX}) + string(REGEX REPLACE ${COMPATIBILITY_REGEX} "\\1" + ${local_slug}_${name}_compatibility "${build_log}") + + set("YOKAI_${slug_prefix}_${report_slug}_${name_upper}_COMPATIBILITY" + "${${local_slug}_${name}_compatibility}" + PARENT_SCOPE) + endif() + + set(VERSION_REGEX ".*\nYOKAI_${report_slug}_${name}_VERSION=([^\n]*)\n.*") + if ("${build_log}" MATCHES ${VERSION_REGEX}) + string(REGEX REPLACE ${VERSION_REGEX} "\\1" + ${local_slug}_${name}_version "${build_log}") + + set("YOKAI_${slug_prefix}_${report_slug}_${name_upper}_VERSION" + "${${local_slug}_${name}_version}" + PARENT_SCOPE) + endif() + + set(VERSION_STRING_REGEX ".*\nYOKAI_${report_slug}_${name}_VERSION_STRING=([^\n]*)\n.*") + if ("${build_log}" MATCHES ${VERSION_STRING_REGEX}) + string(REGEX REPLACE ${VERSION_STRING_REGEX} "\\1" + ${local_slug}_${name}_version_string "${build_log}") + endif() + endforeach() + endif() + + string(TOUPPER "${${local_slug}_name}" ${local_slug}_name_upper) +endmacro() + +# Target detection. +include("${CMAKE_CURRENT_LIST_DIR}/System.cmake") +include("${CMAKE_CURRENT_LIST_DIR}/Architecture.cmake") + +# Compiler detection. +include("${CMAKE_CURRENT_LIST_DIR}/Compiler.cmake") diff --git a/cmake/Yokai/Detection/Architecture.c b/cmake/Yokai/Detection/Architecture.c new file mode 100644 index 0000000000..9d54dae40c --- /dev/null +++ b/cmake/Yokai/Detection/Architecture.c @@ -0,0 +1,127 @@ +/* +=========================================================================== +Daemon BSD Source Code +Copyright (c) 2022-2025, Daemon Developers +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the Daemon developers nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL DAEMON DEVELOPERS BE LIABLE FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +=========================================================================== +*/ + +#define REPORT_SLUG "ARCH" +#include "report.h" + +/* The qprocessordetection.h file doesn't detect endianness for some +platforms including ppc64, but we know how to do it for them. */ + +#include + +/* This source file includes qprocessordetection.h from Qt: + +- https://github.com/qt/qtbase/blob/dev/src/corelib/global/qprocessordetection.h + https://raw.githubusercontent.com/qt/qtbase/dev/src/corelib/global/qprocessordetection.h + +Always update by downloading new version from Qt, do not edit by hand. + +This source file and the qprocessordetection.h header do not contribute to the +produced engine and game binaries in any way that can be subject to copyright. */ + +#include "qprocessordetection.h" + +/* The architecture names are loosely inspired by Debian conventions: + https://wiki.debian.org/ArchitectureSpecificsMemo + +Except we don't have the same technical debt so we don't have +to name i686 as i386 for backward compatibility purpose neither +care of platform name variants that are meant to distinguish +platform variants we cannot support anyway. */ + +/* PNaCl virtual machines. */ +#if defined(__pnacl__) + #pragma message(REPORT_NAME("pnacl")) + +/* Wasm virtual machines, work in progress. */ +#elif defined(Q_PROCESSOR_WASM) + #pragma message(REPORT_NAME("wasm")) + +/* Devices like: + - IBM PC compatibles and derivatives, + - Apple Intel-based mac, + - Steam Deck, Atari VCS consoles… */ + +#elif defined(Q_PROCESSOR_X86_64) + #pragma message(REPORT_NAME("amd64")) + +#elif defined(Q_PROCESSOR_X86_32) + // Assume at least i686. Detecting older revisions would be unlikely to work here + // because the revisions are likely configured by flags, but this file is "compiled" + // without most command-line flags. + #pragma message(REPORT_NAME("i686")) + +/* Devices like: + - Raspberry Pi, + - Apple M1-based mac, + - Android phones and tablets… */ + +#elif defined(Q_PROCESSOR_ARM_64) + #pragma message(REPORT_NAME("arm64")) + +#elif defined(Q_PROCESSOR_ARM_32) && defined(__ARM_PCS_VFP) + #pragma message(REPORT_NAME("armhf")) + +#elif defined(Q_PROCESSOR_ARM_32) && !defined(__ARM_PCS_VFP) + #pragma message(REPORT_NAME("armel")) + +/* Devices like: + - Raptor Computing Systems Talos, Blackbird… */ + +#elif defined(Q_PROCESSOR_POWER_64) && Q_BYTE_ORDER == Q_BIG_ENDIAN + #pragma message(REPORT_NAME("ppc64")) + +#elif defined(Q_PROCESSOR_POWER_64) && Q_BYTE_ORDER == Q_LITTLE_ENDIAN + #pragma message(REPORT_NAME("ppc64el")) + +/* Devices like: + - SiFive HiFive Unmatched, Horse Creek… */ + +#elif defined(Q_PROCESSOR_RISCV_64) + #pragma message(REPORT_NAME("riscv64")) + +/* Devices like: + - Loongson 3A6000, 3A5000… */ +#elif defined(Q_PROCESSOR_LOONGARCH_64) + #pragma message(REPORT_NAME("loong64")) + +/* Remaining native NaCl architecture. */ + +#elif defined(Q_PROCESSOR_MIPS_32) && Q_BYTE_ORDER == Q_LITTLE_ENDIAN + #pragma message(REPORT_NAME("mipsel")) + +#else + #pragma message(REPORT_NAME("unknown")) +#endif + +// Make the compilation succeeds if architecture is supported. +int main(int argc, char** argv) { + return 0; +} diff --git a/cmake/Yokai/Detection/Compiler.c b/cmake/Yokai/Detection/Compiler.c new file mode 100644 index 0000000000..a6c80ab201 --- /dev/null +++ b/cmake/Yokai/Detection/Compiler.c @@ -0,0 +1,150 @@ +/* +=========================================================================== +Daemon BSD Source Code +Copyright (c) 2024-2025, Daemon Developers +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the Daemon developers nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL DAEMON DEVELOPERS BE LIABLE FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +=========================================================================== +*/ + +#define REPORT_SLUG "COMPILER" +#include "report.h" + +// GCC + +#if defined(__GNUC__) + #pragma message(REPORT_COMPATIBILITY("GCC")) +#endif + +#if defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__) + #pragma message(REPORT_VERSION_3("GCC", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__)) +#endif + +// Clang + +#if defined(__clang__) + #pragma message(REPORT_COMPATIBILITY("Clang")) +#endif + +#if defined(__clang_major__) && defined(__clang_minor__) && defined(__clang_patchlevel__) + #pragma message(REPORT_VERSION_3("Clang", __clang_major__, __clang_minor__, __clang_patchlevel__)) +#endif + +#if defined(__clang_version__) + #pragma message(REPORT_VERSION_STRING("Clang", __clang_version__)) +#endif + +// ICC + +#if defined(__INTEL_COMPILER) && defined(__INTEL_COMPILER_UPDATE) + #pragma message(REPORT_VERSION_2("ICC", __INTEL_COMPILER, __INTEL_COMPILER_UPDATE)) +#elif defined(_ICC) + #pragma message(REPORT_VERSION_1("ICC", __ICC)) +#endif + +// ICX + +#if defined(__INTEL_CLANG_COMPILER) + // This requires extra parsing since it's in the form 20240000 for 2024.0.0. + #pragma message(REPORT_VERSION_1("ICX", __INTEL_CLANG_COMPILER)) +#elif defined(__INTEL_LLVM_COMPILER) + // This requires extra parsing since it's in the form 20240000 for 2024.0.0. + #pragma message(REPORT_VERSION_1("ICX", __INTEL_LLVM_COMPILER)) +#endif + +// ArmClang + +#if defined(__armclang_major__) && defined(__armclang_minor__) + // There is no __armclang_patchlevel__, 23.04.1 is reported as 23.04. + #pragma message(REPORT_VERSION_2("ARMClang", __armclang_major__, __armclang_minor__)) +#endif + +#if defined(__armclang_version__) + // This string contains the version patch level and requires extra parsing. + // #define __armclang_major__ 23 + // #define __armclang_minor__ 04 + // #define __armclang_version__ "23.04.1 (build number 14)" + #pragma message(REPORT_VERSION_STRING("ARMClang", __armclang_version__)) +#endif + +// Generic + +#if defined(__VERSION__) + #pragma message(REPORT_VERSION_STRING("generic", __VERSION__)) +#endif + +// Selection + +// There is no Zig specific version definition, we can detect its usage by parsing +// other definitions, and then use the `zig version` command to get the version: +// #define __VERSION__ "Clang 18.1.6 (https://github.com/ziglang/zig-bootstrap 98bc6bf4fc4009888d33941daf6b600d20a42a56)" +// #define __clang_version__ "18.1.6 (https://github.com/ziglang/zig-bootstrap 98bc6bf4fc4009888d33941daf6b600d20a42a56)" + +// There is no Saigo specific version definition, we reuse the clang version instead +// of parsing the version strings: +// #define __VERSION__ "Clang 19.0.0git (https://chromium.googlesource.com/a/native_client/nacl-llvm-project-v10.git e25355fddbdece2ef08747ead05b7f69f3bc6dca)" +// #define __clang_version__ "19.0.0git (https://chromium.googlesource.com/a/native_client/nacl-llvm-project-v10.git e25355fddbdece2ef08747ead05b7f69f3bc6dca)" + +// There is no PNaCl specific version definition, we should parse another definition: +// #define __VERSION__ "4.2.1 Compatible Clang 3.6.0 (https://chromium.googlesource.com/a/native_client/pnacl-clang.git 96b3da27dcefc9d152e51cf54280989b2206d789) (https://chromium.googlesource.com/a/native_client/pnacl-llvm.git d0089f0b008e03cfd141f05c80e3b628c2df75c1)" + +// There is no AOCC specific version definition, we should parse another definition: +// #define __VERSION__ "AMD Clang 14.0.6 (CLANG: AOCC_4.0.0-Build#434 2022_10_28)" +// #define __clang_version__ "14.0.6 (CLANG: AOCC_4.0.0-Build#434 2022_10_28)" + +// There is no usable AppleClang version definitions, +// It reports an old GCC version but reuses the LLVM version as its owns: +// #define __GNUC__ 4.2.1 +// #define __APPLE_CC_ 6000 +// #define __apple_build_version__ 10010046 +// #define __VERSION__ "4.2.1 Compatible Apple LLVM 10.0.1 (clang-1001.0.46.4)" + +#if defined(__INTEL_COMPILER) || defined(__ICC) + #pragma message(REPORT_NAME("ICC")) // Intel +#elif defined(__INTEL_CLANG_COMPILER) || defined(__INTEL_LLVM_COMPILER) + #pragma message(REPORT_NAME("ICX")) // IntelLLVM +#elif defined(__wasi__) + #pragma message(REPORT_NAME("WASI")) +#elif defined(__saigo__) + #pragma message(REPORT_NAME("Saigo")) +#elif defined(__pnacl__) + #pragma message(REPORT_NAME("PNaCl")) +#elif defined(__MINGW64__) || defined(__MINGW32__) + #pragma message(REPORT_NAME("MinGW")) +#elif defined(__armclang_major__) || defined(__armclang_version__) + #pragma message(REPORT_NAME("ARMClang")) +#elif defined(__clang__) && (defined(__APPLE_CC__) || defined(__apple_build_version__)) + #pragma message(REPORT_NAME("AppleClang")) +#elif defined(__clang__) + #pragma message(REPORT_NAME("Clang")) +#elif defined(__GNUC__) + #pragma message(REPORT_NAME("GCC")) // GNU +#else + #pragma message(REPORT_NAME("Unknown")) +#endif + +// Make the compilation succeeds if architecture is supported. +int main(int argc, char** argv) { + return 0; +} diff --git a/cmake/Yokai/Detection/Compiler.cpp b/cmake/Yokai/Detection/Compiler.cpp new file mode 100644 index 0000000000..41c3f576b6 --- /dev/null +++ b/cmake/Yokai/Detection/Compiler.cpp @@ -0,0 +1 @@ +#include "Compiler.c" diff --git a/cmake/Yokai/Detection/System.c b/cmake/Yokai/Detection/System.c new file mode 100644 index 0000000000..a7f3a50ff9 --- /dev/null +++ b/cmake/Yokai/Detection/System.c @@ -0,0 +1,68 @@ +/* +=========================================================================== +Daemon BSD Source Code +Copyright (c) 2025, Daemon Developers +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the Daemon developers nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL DAEMON DEVELOPERS BE LIABLE FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +=========================================================================== +*/ + +#define REPORT_SLUG "SYSTEM" +#include "report.h" + +#if defined(__APPLE__) && defined(__MACH__) +#include +#endif + +#if defined(__linux__) || defined(__linux) || defined(linux) || defined(__gnu_linux__) + #pragma message(REPORT_COMPATIBILITY("Linux")) +#endif + +#if defined(__wasm__) || defined(__wasm) || defined(__wasm32) || defined(__wasi__) + #pragma message(REPORT_NAME("Wasm")) +#elif defined(__pnacl__) || defined(__saigo__) || defined(NACLENTRYALIGN) + #pragma message(REPORT_NAME("NaCl")) +#elif defined(__WINNT__) || defined(__WINNT) || defined(WINNT) \ +|| defined(__WIN64__) || defined(__WIN64) || defined(_WIN64) || defined(WIN64) \ +|| defined(__WIN32__) || defined(__WIN32) || defined(_WIN32) || defined(WIN32) \ +|| defined(__MINGW64__) || defined(__MINGW32__) + #pragma message(REPORT_NAME("Windows")) +#elif defined(__APPLE__) && defined(__MACH__) && (TARGET_OS_MAC && !TARGET_OS_IPHONE) + #pragma message(REPORT_NAME("macOS")) +#elif defined(__FreeBSD__) + #pragma message(REPORT_NAME("FreeBSD")) +#elif defined(__ANDROID__) + #pragma message(REPORT_NAME("Android")) +#elif defined(__gnu_linux__) + #pragma message(REPORT_NAME("Linux")) +#elif defined(__linux__) || defined(__linux) || defined(linux) + #pragma message(REPORT_NAME("Linux") +#else + #pragma message(REPORT_NAME("Unknown")) +#endif + +// Make the compilation succeeds if system is supported. +int main(int argc, char** argv) { + return 0; +} diff --git a/cmake/Yokai/Detection/detect b/cmake/Yokai/Detection/detect new file mode 100755 index 0000000000..56966db068 --- /dev/null +++ b/cmake/Yokai/Detection/detect @@ -0,0 +1,63 @@ +#! /usr/bin/env bash + +# Daemon BSD Source Code +# Copyright (c) 2024, Daemon Developers +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the Daemon developers nor the +# names of its contributors may be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL DAEMON DEVELOPERS BE LIABLE FOR ANY +# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +# Test script not used by the CMake build system. Usage example: +# ./detect cc + +set -ueo pipefail + +script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)" + +if [ -z "${1:-}" ] +then + echo "ERROR: missing compiler" >&2 + false +fi + +for base_name in Compiler System Architecture +do + file_path="${script_dir}/${base_name}.c" + + # PNaCl doesn't work with “-o /dev/null” as it uses the output path as a + # pattern for temporary files and then the parent folder should be writable. + # Zig caches the build if both the source and the output don't change. Since + # the /dev/null file never changes, Zig skips the compilation once done once. + # So we need to use a randomly named path in a writable directory. + temp_file="$(mktemp)" + + "${@}" "${file_path}" -o "${temp_file}" 2>&1 \ + | grep 'REPORT>.*//' \ + | sed -e 's/YOKAI_COMPILER/YOKAI_C_COMPILER/' \ + | sed -e 's/YOKAI_SYSTEM/YOKAI_TARGET_SYSTEM/' \ + | sed -e 's/YOKAI_ARCH/YOKAI_TARGET_ARCH/' \ + | awk -F= '{print toupper($1) "=" $2}' \ + || "${@}" "${file_path}" -o "${temp_file}" + + rm "${temp_file}" +done diff --git a/cmake/Yokai/Detection/qprocessordetection.h b/cmake/Yokai/Detection/qprocessordetection.h new file mode 100644 index 0000000000..7dbd38d316 --- /dev/null +++ b/cmake/Yokai/Detection/qprocessordetection.h @@ -0,0 +1,411 @@ +// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2016 Intel Corporation. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only +// Qt-Security score:significant reason:default + + +#if 0 +#pragma qt_class(QtProcessorDetection) +#pragma qt_sync_skip_header_check +#pragma qt_sync_stop_processing +#endif + +#ifndef QPROCESSORDETECTION_H +#define QPROCESSORDETECTION_H + +/* + This file uses preprocessor #defines to set various Q_PROCESSOR_* #defines + based on the following patterns: + + Q_PROCESSOR_{FAMILY} + Q_PROCESSOR_{FAMILY}_{VARIANT} + Q_PROCESSOR_{FAMILY}_{REVISION} + + The first is always defined. Defines for the various revisions/variants are + optional and usually dependent on how the compiler was invoked. Variants + that are a superset of another should have a define for the superset. + + In addition to the processor family, variants, and revisions, we also set + Q_BYTE_ORDER appropriately for the target processor. For bi-endian + processors, we try to auto-detect the byte order using the __BIG_ENDIAN__, + __LITTLE_ENDIAN__, or __BYTE_ORDER__ preprocessor macros. + + Note: when adding support for new processors, be sure to update + config.tests/arch/arch.cpp to ensure that configure can detect the target + and host architectures. +*/ + +/* Machine byte-order, reuse preprocessor provided macros when available */ +#if defined(__ORDER_BIG_ENDIAN__) +# define Q_BIG_ENDIAN __ORDER_BIG_ENDIAN__ +#else +# define Q_BIG_ENDIAN 4321 +#endif +#if defined(__ORDER_LITTLE_ENDIAN__) +# define Q_LITTLE_ENDIAN __ORDER_LITTLE_ENDIAN__ +#else +# define Q_LITTLE_ENDIAN 1234 +#endif + +/* + Alpha family, no revisions or variants + + Alpha is bi-endian, use endianness auto-detection implemented below. +*/ +#if defined(__alpha__) || defined(_M_ALPHA) +# define Q_PROCESSOR_ALPHA +// Q_BYTE_ORDER not defined, use endianness auto-detection + +/* + ARM family, known revisions: V5, V6, V7, V8 + + ARM is bi-endian, detect using __ARMEL__ or __ARMEB__, falling back to + auto-detection implemented below. +*/ +#elif defined(__arm__) || defined(__TARGET_ARCH_ARM) || defined(_M_ARM) || defined(_M_ARM64) || defined(__aarch64__) || defined(__ARM64__) || defined(_ARM64EC_) +# if defined(__aarch64__) || defined(__ARM64__) || defined(_M_ARM64) || defined(_ARM64EC_) +# define Q_PROCESSOR_ARM_64 +# define Q_PROCESSOR_WORDSIZE 8 +# else +# define Q_PROCESSOR_ARM_32 +# endif +# if defined(__ARM_ARCH) && __ARM_ARCH > 1 +# define Q_PROCESSOR_ARM __ARM_ARCH +# elif defined(__TARGET_ARCH_ARM) && __TARGET_ARCH_ARM > 1 +# define Q_PROCESSOR_ARM __TARGET_ARCH_ARM +# elif defined(_M_ARM) && _M_ARM > 1 +# define Q_PROCESSOR_ARM _M_ARM +# elif defined(__ARM64_ARCH_8__) \ + || defined(__aarch64__) \ + || defined(__ARMv8__) \ + || defined(__ARMv8_A__) \ + || defined(_M_ARM64) \ + || defined (_ARM64EC_) +# define Q_PROCESSOR_ARM 8 +# elif defined(__ARM_ARCH_7__) \ + || defined(__ARM_ARCH_7A__) \ + || defined(__ARM_ARCH_7R__) \ + || defined(__ARM_ARCH_7M__) \ + || defined(__ARM_ARCH_7S__) \ + || defined(_ARM_ARCH_7) \ + || defined(__CORE_CORTEXA__) +# define Q_PROCESSOR_ARM 7 +# elif defined(__ARM_ARCH_6__) \ + || defined(__ARM_ARCH_6J__) \ + || defined(__ARM_ARCH_6T2__) \ + || defined(__ARM_ARCH_6Z__) \ + || defined(__ARM_ARCH_6K__) \ + || defined(__ARM_ARCH_6ZK__) \ + || defined(__ARM_ARCH_6M__) +# define Q_PROCESSOR_ARM 6 +# elif defined(__ARM_ARCH_5TEJ__) \ + || defined(__ARM_ARCH_5TE__) +# define Q_PROCESSOR_ARM 5 +# else +# define Q_PROCESSOR_ARM 0 +# endif +# if Q_PROCESSOR_ARM >= 8 +# define Q_PROCESSOR_ARM_V8 +# endif +# if Q_PROCESSOR_ARM >= 7 +# define Q_PROCESSOR_ARM_V7 +# endif +# if Q_PROCESSOR_ARM >= 6 +# define Q_PROCESSOR_ARM_V6 +# endif +# if Q_PROCESSOR_ARM >= 5 +# define Q_PROCESSOR_ARM_V5 +# else +# error "ARM architecture too old" +# endif +# if defined(_ARM64EC_) +# define Q_PROCESSOR_ARM_64_EC +# endif +# if defined(__ARMEL__) || defined(_M_ARM64) || defined(_ARM64EC_) +# define Q_BYTE_ORDER Q_LITTLE_ENDIAN +# elif defined(__ARMEB__) +# define Q_BYTE_ORDER Q_BIG_ENDIAN +# else +// Q_BYTE_ORDER not defined, use endianness auto-detection +#endif + +/* + AVR32 family, no revisions or variants + + AVR32 is big-endian. +*/ +// #elif defined(__avr32__) +// # define Q_PROCESSOR_AVR32 +// # define Q_BYTE_ORDER Q_BIG_ENDIAN + +/* + Blackfin family, no revisions or variants + + Blackfin is little-endian. +*/ +// #elif defined(__bfin__) +// # define Q_PROCESSOR_BLACKFIN +// # define Q_BYTE_ORDER Q_LITTLE_ENDIAN + +/* + PA-RISC family, no revisions or variants + + PA-RISC is big-endian. +*/ +#elif defined(__hppa__) +# define Q_PROCESSOR_HPPA +# define Q_BYTE_ORDER Q_BIG_ENDIAN + +/* + X86 family, known variants: 32- and 64-bit + + X86 is little-endian. +*/ +#elif defined(__i386) || defined(__i386__) || defined(_M_IX86) +# define Q_PROCESSOR_X86_32 +# define Q_BYTE_ORDER Q_LITTLE_ENDIAN +# define Q_PROCESSOR_WORDSIZE 4 + +/* + * We define Q_PROCESSOR_X86 == 6 for anything above a equivalent or better + * than a Pentium Pro (the processor whose architecture was called P6) or an + * Athlon. + * + * All processors since the Pentium III and the Athlon 4 have SSE support, so + * we use that to detect. That leaves the original Athlon, Pentium Pro and + * Pentium II. + */ + +# if defined(_M_IX86) +# define Q_PROCESSOR_X86 (_M_IX86/100) +# elif defined(__i686__) || defined(__athlon__) || defined(__SSE__) || defined(__pentiumpro__) +# define Q_PROCESSOR_X86 6 +# elif defined(__i586__) || defined(__k6__) || defined(__pentium__) +# define Q_PROCESSOR_X86 5 +# elif defined(__i486__) || defined(__80486__) +# define Q_PROCESSOR_X86 4 +# else +# define Q_PROCESSOR_X86 3 +# endif + +#elif defined(__x86_64) || defined(__x86_64__) || defined(__amd64) || defined(_M_X64) +# define Q_PROCESSOR_X86 6 +# define Q_PROCESSOR_X86_64 +# define Q_BYTE_ORDER Q_LITTLE_ENDIAN +# define Q_PROCESSOR_WORDSIZE 8 + +/* + Itanium (IA-64) family, no revisions or variants + + Itanium is bi-endian, use endianness auto-detection implemented below. +*/ +#elif defined(__ia64) || defined(__ia64__) || defined(_M_IA64) +# define Q_PROCESSOR_IA64 +# define Q_PROCESSOR_WORDSIZE 8 +// Q_BYTE_ORDER not defined, use endianness auto-detection + +/* + LoongArch family, known variants: 32- and 64-bit + + LoongArch is little-endian. +*/ +#elif defined(__loongarch__) +# define Q_PROCESSOR_LOONGARCH +# if __loongarch_grlen == 64 +# define Q_PROCESSOR_LOONGARCH_64 +# else +# define Q_PROCESSOR_LOONGARCH_32 +# endif +# define Q_BYTE_ORDER Q_LITTLE_ENDIAN + +/* + Motorola 68000 family, no revisions or variants + + M68K is big-endian. +*/ +#elif defined(__m68k__) +# define Q_PROCESSOR_M68K +# define Q_BYTE_ORDER Q_BIG_ENDIAN + +/* + MIPS family, known revisions: I, II, III, IV, 32, 64 + + MIPS is bi-endian, use endianness auto-detection implemented below. +*/ +#elif defined(__mips) || defined(__mips__) || defined(_M_MRX000) +# define Q_PROCESSOR_MIPS +# if defined(_MIPS_ARCH_MIPS1) || (defined(__mips) && __mips - 0 >= 1) +# define Q_PROCESSOR_MIPS_I +# endif +# if defined(_MIPS_ARCH_MIPS2) || (defined(__mips) && __mips - 0 >= 2) +# define Q_PROCESSOR_MIPS_II +# endif +# if defined(_MIPS_ARCH_MIPS3) || (defined(__mips) && __mips - 0 >= 3) +# define Q_PROCESSOR_MIPS_III +# endif +# if defined(_MIPS_ARCH_MIPS4) || (defined(__mips) && __mips - 0 >= 4) +# define Q_PROCESSOR_MIPS_IV +# endif +# if defined(_MIPS_ARCH_MIPS5) || (defined(__mips) && __mips - 0 >= 5) +# define Q_PROCESSOR_MIPS_V +# endif +# if defined(_MIPS_ARCH_MIPS32) || defined(__mips32) || (defined(__mips) && __mips - 0 >= 32) +# define Q_PROCESSOR_MIPS_32 +# endif +# if defined(_MIPS_ARCH_MIPS64) || defined(__mips64) +# define Q_PROCESSOR_MIPS_64 +# define Q_PROCESSOR_WORDSIZE 8 +# endif +# if defined(__MIPSEL__) +# define Q_BYTE_ORDER Q_LITTLE_ENDIAN +# elif defined(__MIPSEB__) +# define Q_BYTE_ORDER Q_BIG_ENDIAN +# else +// Q_BYTE_ORDER not defined, use endianness auto-detection +# endif + +/* + Power family, known variants: 32- and 64-bit + + There are many more known variants/revisions that we do not handle/detect. + See http://en.wikipedia.org/wiki/Power_Architecture + and http://en.wikipedia.org/wiki/File:PowerISA-evolution.svg + + Power is bi-endian, use endianness auto-detection implemented below. +*/ +#elif defined(__ppc__) || defined(__ppc) || defined(__powerpc__) \ + || defined(_ARCH_COM) || defined(_ARCH_PWR) || defined(_ARCH_PPC) \ + || defined(_M_MPPC) || defined(_M_PPC) +# define Q_PROCESSOR_POWER +# if defined(__ppc64__) || defined(__powerpc64__) || defined(__64BIT__) +# define Q_PROCESSOR_POWER_64 +# define Q_PROCESSOR_WORDSIZE 8 +# else +# define Q_PROCESSOR_POWER_32 +# endif +// Q_BYTE_ORDER not defined, use endianness auto-detection + +/* + RISC-V family, known variants: 32- and 64-bit + + RISC-V is little-endian. +*/ +#elif defined(__riscv) +# define Q_PROCESSOR_RISCV +# if __riscv_xlen == 64 +# define Q_PROCESSOR_RISCV_64 +# else +# define Q_PROCESSOR_RISCV_32 +# endif +# define Q_BYTE_ORDER Q_LITTLE_ENDIAN + +/* + S390 family, known variant: S390X (64-bit) + + S390 is big-endian. +*/ +#elif defined(__s390__) +# define Q_PROCESSOR_S390 +# if defined(__s390x__) +# define Q_PROCESSOR_S390_X +# endif +# define Q_BYTE_ORDER Q_BIG_ENDIAN + +/* + SuperH family, optional revision: SH-4A + + SuperH is bi-endian, use endianness auto-detection implemented below. +*/ +// #elif defined(__sh__) +// # define Q_PROCESSOR_SH +// # if defined(__sh4a__) +// # define Q_PROCESSOR_SH_4A +// # endif +// Q_BYTE_ORDER not defined, use endianness auto-detection + +/* + SPARC family, optional revision: V9 + + SPARC is big-endian only prior to V9, while V9 is bi-endian with big-endian + as the default byte order. Assume all SPARC systems are big-endian. +*/ +#elif defined(__sparc__) +# define Q_PROCESSOR_SPARC +# if defined(__sparc_v9__) || defined(__sparcv9) +# define Q_PROCESSOR_SPARC_V9 +# endif +# if defined(__sparc64__) +# define Q_PROCESSOR_SPARC_64 +# endif +# define Q_BYTE_ORDER Q_BIG_ENDIAN + +// -- Web Assembly -- +#elif defined(__EMSCRIPTEN__) +# define Q_PROCESSOR_WASM +# define Q_BYTE_ORDER Q_LITTLE_ENDIAN +# define Q_PROCESSOR_WORDSIZE 8 +#ifdef QT_COMPILER_SUPPORTS_SSE2 +# define Q_PROCESSOR_X86 6 // enables SIMD support +# define Q_PROCESSOR_X86_64 // wasm64 +# define Q_PROCESSOR_WASM_64 +#endif + +#endif + +/* + NOTE: + GCC 4.6 added __BYTE_ORDER__, __ORDER_BIG_ENDIAN__, __ORDER_LITTLE_ENDIAN__ + and __ORDER_PDP_ENDIAN__ in SVN r165881. If you are using GCC 4.6 or newer, + this code will properly detect your target byte order; if you are not, and + the __LITTLE_ENDIAN__ or __BIG_ENDIAN__ macros are not defined, then this + code will fail to detect the target byte order. +*/ +// Some processors support either endian format, try to detect which we are using. +#if !defined(Q_BYTE_ORDER) +# if defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == Q_BIG_ENDIAN || __BYTE_ORDER__ == Q_LITTLE_ENDIAN) +// Reuse __BYTE_ORDER__ as-is, since our Q_*_ENDIAN #defines match the preprocessor defaults +# define Q_BYTE_ORDER __BYTE_ORDER__ +# elif defined(__BIG_ENDIAN__) || defined(_big_endian__) || defined(_BIG_ENDIAN) +# define Q_BYTE_ORDER Q_BIG_ENDIAN +# elif defined(__LITTLE_ENDIAN__) || defined(_little_endian__) || defined(_LITTLE_ENDIAN) +# define Q_BYTE_ORDER Q_LITTLE_ENDIAN +# else +# error "Unable to determine byte order!" +# endif +#endif + +/* + Size of a pointer and the machine register size. We detect a 64-bit system by: + * GCC and compatible compilers (Clang, ICC on OS X and Windows) always define + __SIZEOF_POINTER__. This catches all known cases of ILP32 builds on 64-bit + processors. + * Most other Unix compilers define __LP64__ or _LP64 on 64-bit mode + (Long and Pointer 64-bit) + * If Q_PROCESSOR_WORDSIZE was defined above, it's assumed to match the pointer + size. + Otherwise, we assume to be 32-bit and then check in qglobal.cpp that it is right. +*/ + +#if defined __SIZEOF_POINTER__ +# define QT_POINTER_SIZE __SIZEOF_POINTER__ +#elif defined(__LP64__) || defined(_LP64) +# define QT_POINTER_SIZE 8 +#elif defined(Q_PROCESSOR_WORDSIZE) +# define QT_POINTER_SIZE Q_PROCESSOR_WORDSIZE +#else +# define QT_POINTER_SIZE 4 +#endif + +/* + Define Q_PROCESSOR_WORDSIZE to be the size of the machine's word (usually, + the size of the register). On some architectures where a pointer could be + smaller than the register, the macro is defined above. + + Falls back to QT_POINTER_SIZE if not set explicitly for the platform. +*/ +#ifndef Q_PROCESSOR_WORDSIZE +# define Q_PROCESSOR_WORDSIZE QT_POINTER_SIZE +#endif + + +#endif // QPROCESSORDETECTION_H diff --git a/cmake/Yokai/Detection/report.h b/cmake/Yokai/Detection/report.h new file mode 100644 index 0000000000..43a85c7930 --- /dev/null +++ b/cmake/Yokai/Detection/report.h @@ -0,0 +1,47 @@ +/* +=========================================================================== +Daemon BSD Source Code +Copyright (c) 2024-2025, Daemon Developers +All rights reserveid. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the Daemon developers nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL DAEMON DEVELOPERS BE LIABLE FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +=========================================================================== +*/ + +#define STRING(s) #s +#define XSTRING(s) STRING(s) + +#define REPORT(key, value) \ + "REPORT>" +#define REPORT_VERSION_3(name, major, minor, patch) \ + REPORT(name "_VERSION", XSTRING(major) "." XSTRING(minor) "." XSTRING(patch)) +#define REPORT_VERSION_2(name, major, minor) \ + REPORT(name "_VERSION", XSTRING(major) "." XSTRING(minor)) +#define REPORT_VERSION_1(name, major) \ + REPORT(name "_VERSION", XSTRING(major)) +#define REPORT_VERSION_STRING(name, value) \ + REPORT(name "_VERSION_STRING", value) +#define REPORT_COMPATIBILITY(name) \ + REPORT(name "_COMPATIBILITY", "ON") +#define REPORT_NAME(name) \ + REPORT("NAME", name) diff --git a/cmake/Yokai/FileEmbedder.cmake b/cmake/Yokai/FileEmbedder.cmake new file mode 100644 index 0000000000..5410cc906c --- /dev/null +++ b/cmake/Yokai/FileEmbedder.cmake @@ -0,0 +1,44 @@ +# Converts a text file into a C-language char array definition. +# For use in CMake script mode (cmake -P). +# Required definitions on command line: +# INPUT_FILE, OUTPUT_FILE, FILE_FORMAT, VARIABLE_NAME + +# Inspired by: +# https://stackoverflow.com/questions/11813271/embed-resources-eg-shader-code-images-into-executable-library-with-cmake/27206982#27206982 + +file(READ ${INPUT_FILE} contents HEX) + +# Translate the file content. +if ("${FILE_FORMAT}" STREQUAL "TEXT") + # Strip \r for consistency. + string(REGEX REPLACE "(0d)?(..)" "0x\\2," contents "${contents}") +elseif("${FILE_FORMAT}" STREQUAL "BINARY") + string(REGEX REPLACE "(..)" "0x\\1," contents "${contents}") +else() + message(FATAL_ERROR "Unknown file format: ${FILE_FORMAT}") +endif() + +# Add null terminator. +set(contents "${contents}0x00,") + +# Split long lines. +string(REGEX REPLACE + "(0x..,0x..,0x..,0x..,0x..,0x..,0x..,0x..,0x..,0x..,0x..,0x..,0x..,0x..,0x..,)" "\\1\n" + contents "${contents}" +) + +# A bit more of beautification. +string(REGEX REPLACE ",$" ",\n" contents "${contents}") +set(DATA_VARIABLE_NAME "data_${VARIABLE_NAME}") + +file(WRITE ${OUTPUT_FILE} + "constexpr unsigned char ${DATA_VARIABLE_NAME}[] =\n" + "{\n" + "${contents}" + "};\n" + "const embeddedFileMapEntry_t ${VARIABLE_NAME} =\n" + "{\n" + "reinterpret_cast( ${DATA_VARIABLE_NAME} ),\n" + "sizeof( ${DATA_VARIABLE_NAME} ) - 1,\n" + "};\n" +) diff --git a/cmake/Yokai/SourceGenerator.cmake b/cmake/Yokai/SourceGenerator.cmake new file mode 100644 index 0000000000..6797ff7f5a --- /dev/null +++ b/cmake/Yokai/SourceGenerator.cmake @@ -0,0 +1,180 @@ +# Daemon BSD Source Code +# Copyright (c) 2025-2026, Daemon Developers +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the Daemon developers nor the +# names of its contributors may be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL DAEMON DEVELOPERS BE LIABLE FOR ANY +# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +################################################################################ +# Source generation and file embedding. +################################################################################ + +set(YOKAI_SOURCE_GENERATOR "${CMAKE_CURRENT_LIST_FILE}") +get_filename_component(current_list_dir "${CMAKE_CURRENT_LIST_FILE}" DIRECTORY) +set(YOKAI_FILE_EMBEDDER "${current_list_dir}/FileEmbedder.cmake") + +set(YOKAI_GENERATED_SUBDIR "YokaiGeneratedSource") +set(YOKAI_GENERATED_DIR "${CMAKE_CURRENT_BINARY_DIR}/${YOKAI_GENERATED_SUBDIR}") + +set(YOKAI_BUILDINFO_SUBDIR "YokaiBuildInfo") +set(YOKAI_EMBEDDED_SUBDIR "YokaiEmbeddedFiles") + +set(YOKAI_BUILDINFO_DIR "${YOKAI_GENERATED_DIR}/${YOKAI_BUILDINFO_SUBDIR}") +set(YOKAI_EMBEDDED_DIR "${YOKAI_GENERATED_DIR}/${YOKAI_EMBEDDED_SUBDIR}") + +file(MAKE_DIRECTORY "${YOKAI_GENERATED_DIR}") +include_directories("${YOKAI_GENERATED_DIR}") + +file(MAKE_DIRECTORY "${YOKAI_BUILDINFO_DIR}") +file(MAKE_DIRECTORY "${YOKAI_EMBEDDED_DIR}") + +set(YOKAI_GENERATED_HEADER "// Automatically generated, do not modify!\n") +set(YOKAI_GENERATED_CPP_EXT ".cpp") +set(YOKAI_GENERATED_H_EXT ".h") + +set(BUILDINFOLIST) + +foreach(kind CPP H) + set(YOKAI_BUILDINFO_${kind}_TEXT "${YOKAI_GENERATED_HEADER}") +endforeach() + +macro(yokai_add_buildinfo type name value) + string(APPEND YOKAI_BUILDINFO_CPP_TEXT "const ${type} ${name}=${value};\n") + string(APPEND YOKAI_BUILDINFO_H_TEXT "extern const ${type} ${name};\n") +endmacro() + +macro(yokai_write_buildinfo name) + foreach(kind CPP H) + set(buildinfo_file_path "${YOKAI_BUILDINFO_DIR}/${name}${YOKAI_GENERATED_${kind}_EXT}") + + file(GENERATE OUTPUT "${buildinfo_file_path}" CONTENT "${YOKAI_BUILDINFO_${kind}_TEXT}") + list(APPEND BUILDINFOLIST "${buildinfo_file_path}") + endforeach() +endmacro() + +macro(yokai_embed_files basename dir list format targetname) + set(embed_subdir "${YOKAI_EMBEDDED_SUBDIR}/${basename}") + set(embed_dir "${YOKAI_GENERATED_DIR}/${embed_subdir}") + + file(MAKE_DIRECTORY "${embed_dir}") + + foreach(kind CPP H) + set(embed_${kind}_basename "${basename}${YOKAI_GENERATED_${kind}_EXT}") + set(embed_${kind}_src_file "${YOKAI_EMBEDDED_DIR}/${embed_${kind}_basename}") + set(embed_${kind}_file "${YOKAI_EMBEDDED_SUBDIR}/${embed_${kind}_basename}") + set(embed_${kind}_text "${YOKAI_GENERATED_HEADER}") + set_property(SOURCE "${embed_${kind}_src_file}" APPEND PROPERTY OBJECT_DEPENDS "${YOKAI_SOURCE_GENERATOR}") + set_property(TARGET "${targetname}" APPEND PROPERTY SOURCES "${embed_${kind}_src_file}") + endforeach() + + if (NOT YOKAI_EMBEDDED_FILES_HEADER) + set(YOKAI_EMBEDDED_FILES_HEADER "${YOKAI_EMBEDDED_SUBDIR}/YokaiEmbeddedFiles.h") + + string(APPEND embed_header_text + "// Automatically generated, do not modify!\n" + "#ifndef YOKAI_EMBEDDED_FILES_H_\n" + "#define YOKAI_EMBEDDED_FILES_H_\n" + "#include \n" + "#include \n" + "#include \n" + "\n" + "struct embeddedFileMapEntry_t\n" + "{\n" + "\tconst char* data;\n" + "\tsize_t size;\n" + "};\n" + "\n" + "using embeddedFileMap_t = std::unordered_map;\n" + "#endif // YOKAI_EMBEDDED_FILES_H_\n" + ) + + set(embed_header_file "${YOKAI_GENERATED_DIR}/${YOKAI_EMBEDDED_FILES_HEADER}") + file(GENERATE OUTPUT "${embed_header_file}" CONTENT "${embed_header_text}") + endif() + + string(APPEND embed_CPP_text + "#include \"${embed_H_file}\"\n" + "\n" + "namespace ${basename} {\n" + ) + + string(APPEND embed_H_text + "#include \"${YOKAI_EMBEDDED_FILES_HEADER}\"\n" + "\n" + "namespace ${basename} {\n" + ) + + set(embed_map_text "") + + foreach(filename ${list}) + string(REGEX REPLACE "[^A-Za-z0-9]" "_" filename_symbol "${filename}") + + set(inpath "${dir}/${filename}") + set(outpath "${embed_dir}/${filename_symbol}${YOKAI_GENERATED_H_EXT}") + + add_custom_command( + OUTPUT "${outpath}" + COMMAND ${CMAKE_COMMAND} + "-DINPUT_FILE=${inpath}" + "-DOUTPUT_FILE=${outpath}" + "-DFILE_FORMAT=${format}" + "-DVARIABLE_NAME=${filename_symbol}" + -P "${YOKAI_FILE_EMBEDDER}" + MAIN_DEPENDENCY ${inpath} + DEPENDS + "${YOKAI_FILE_EMBEDDER}" + "${YOKAI_SOURCE_GENERATOR}" + ) + + set_property(TARGET "${targetname}" APPEND PROPERTY SOURCES "${outpath}") + + string(APPEND embed_CPP_text + "#include \"${basename}/${filename_symbol}.h\"\n" + ) + + string(APPEND embed_H_text + "extern const embeddedFileMapEntry_t ${filename_symbol};\n" + ) + + string(APPEND embed_map_text + "\t{ \"${filename}\", ${filename_symbol} },\n" + ) + endforeach() + + string(APPEND embed_CPP_text + "\n" + "const embeddedFileMap_t FileMap\n{\n" + "${embed_map_text}" + "};\n" + "}" + ) + + string(APPEND embed_H_text + "extern const embeddedFileMap_t FileMap;\n" + "};\n" + ) + + foreach(kind CPP H) + set(embed_file "${YOKAI_GENERATED_DIR}/${embed_${kind}_file}") + file(GENERATE OUTPUT "${embed_file}" CONTENT "${embed_${kind}_text}") + endforeach() +endmacro() diff --git a/cmake/Yokai/System.cmake b/cmake/Yokai/System.cmake new file mode 100644 index 0000000000..d3ff5f2140 --- /dev/null +++ b/cmake/Yokai/System.cmake @@ -0,0 +1,143 @@ +# Daemon BSD Source Code +# Copyright (c) 2025-2026, Daemon Developers +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the Daemon developers nor the +# names of its contributors may be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL DAEMON DEVELOPERS BE LIABLE FOR ANY +# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +################################################################################ +# System detection. +################################################################################ + +# When adding a new system, look at all the places YOKAI_HOST_SYSTEM +# and YOKAI_TARGET_SYSTEM are used. + +function(yokai_detect_host_system) + set(system_name "Unknown") + + foreach(name + "Linux" + "FreeBSD" + "Android" + "Windows" + ) + if (CMAKE_HOST_SYSTEM_NAME MATCHES "${name}") + set(system_name "${CMAKE_HOST_SYSTEM_NAME}") + endif() + endforeach() + + if ("${system_name}" STREQUAL "Unknown") + set(SYSTEM_Darwin "macOS") + set(SYSTEM_MSYS "Windows") + + foreach(name + "Darwin" + "MSYS" + ) + if ("${CMAKE_HOST_SYSTEM_NAME}" MATCHES "${name}") + set(system_name "${SYSTEM_${name}}") + endif() + endforeach() + endif() + + string(TOUPPER "${system_name}" system_name_upper) + + set(YOKAI_HOST_SYSTEM_NAME "${system_name}" PARENT_SCOPE) + set(YOKAI_HOST_SYSTEM_NAME_UPPER "${system_name_upper}" PARENT_SCOPE) + + # Makes possible to do that in CMake code: + # > if (YOKAI_HOST_SYSTEM_LINUX) + set(YOKAI_HOST_SYSTEM_${system_name_upper} ON PARENT_SCOPE) +endfunction() + +function(yokai_detect_target_system) + yokai_run_detection("TARGET" "SYSTEM" "System.c" "Linux") + + set(YOKAI_TARGET_SYSTEM_NAME "${system_name}" PARENT_SCOPE) + set(YOKAI_TARGET_SYSTEM_NAME_UPPER "${system_name_upper}" PARENT_SCOPE) + + # Makes possible to do that in CMake code: + # > if (YOKAI_TARGET_SYSTEM_LINUX) + set(YOKAI_TARGET_SYSTEM_${system_name_upper} ON PARENT_SCOPE) +endfunction() + +yokai_detect_host_system() +yokai_detect_target_system() + +if (YOKAI_HOST_SYSTEM_UNKNOWN AND NOT YOKAI_TARGET_SYSTEM_UNKNOWN) + message(WARNING "Assuming the host system is the same as the target: ${YOKAI_TARGET_SYSTEM_NAME}") + set(YOKAI_HOST_SYSTEM_NAME "${YOKAI_TARGET_SYSTEM_NAME}") + set(YOKAI_HOST_SYSTEM_NAME_UPPER "${YOKAI_TARGET_SYSTEM_NAME_UPPER}") + set(YOKAI_HOST_SYSTEM_${YOKAI_HOST_SYSTEM_NAME_UPPER} ON) + unset(YOKAI_HOST_SYSTEM_UNKNOWN) +endif() + +if (YOKAI_TARGET_SYSTEM_UNKNOWN AND NOT YOKAI_HOST_SYSTEM_UNKNOWN) + message(WARNING "Assuming the target system is the same as the host: ${YOKAI_TARGET_SYSTEM_NAME}") + set(YOKAI_TARGET_SYSTEM_NAME "${YOKAI_HOST_SYSTEM_NAME}") + set(YOKAI_TARGET_SYSTEM_NAME_UPPER "${YOKAI_HOST_SYSTEM_NAME_UPPER}") + set(YOKAI_TARGET_SYSTEM_${YOKAI_TARGET_SYSTEM_NAME_UPPER} ON) + unset(YOKAI_TARGET_SYSTEM_UNKNOWN) +endif() + +if (YOKAI_HOST_SYSTEM_UNKNOWN) + message(WARNING "Unknown host system") +else() + message(STATUS "Detected host system: ${YOKAI_HOST_SYSTEM_NAME}") +endif() + +if (YOKAI_TARGET_SYSTEM_UNKNOWN) + message(WARNING "Unknown target system") +else() + message(STATUS "Detected target system: ${YOKAI_TARGET_SYSTEM_NAME}") +endif() + +if (NOT "${YOKAI_HOST_SYSTEM_NAME}" STREQUAL "${YOKAI_TARGET_SYSTEM_NAME}") + message(STATUS "Detected system cross-compilation") + set(YOKAI_SYSTEM_CROSS ON) +else() + message(STATUS "No system cross-compilation detected") +endif() + +# This is for systems behaving similarly to a Linux Desktop, +# implementing standards like FHS, XDG, GLVND… +# Makes possible to do that in CMake code: +# > if (YOKAI_HOST_SYSTEM_XDG_COMPATIBILITY) +# > if (YOKAI_TARGET_SYSTEM_XDG_COMPATIBILITY) +foreach(name + "LINUX" + "FREEBSD" +) + foreach(slug + "HOST_SYSTEM" + "TARGET_SYSTEM" + ) + if (YOKAI_${slug}_${name}) + set(YOKAI_${slug}_XDG_COMPATIBILITY ON) + endif() + endforeach() +endforeach() + +if (YOKAI_SOURCE_GENERATOR) + # Add printable string to the executable. + yokai_add_buildinfo("char*" "YOKAI_SYSTEM_STRING" "\"${YOKAI_TARGET_SYSTEM_NAME}\"") +endif() From b2763b081371bb731616a777af9bb3e012f159e4 Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Mon, 7 Apr 2025 20:20:20 +0200 Subject: [PATCH 22/36] cmake: add MinGW CMake toolchains for cross-compilation --- cmake/cross-toolchain-mingw32.cmake | 14 ++++++++++++++ cmake/cross-toolchain-mingw64.cmake | 14 ++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 cmake/cross-toolchain-mingw32.cmake create mode 100644 cmake/cross-toolchain-mingw64.cmake diff --git a/cmake/cross-toolchain-mingw32.cmake b/cmake/cross-toolchain-mingw32.cmake new file mode 100644 index 0000000000..c33340276b --- /dev/null +++ b/cmake/cross-toolchain-mingw32.cmake @@ -0,0 +1,14 @@ +# Target operating system and architecture +set( CMAKE_SYSTEM_NAME Windows ) +set( CMAKE_SYSTEM_PROCESSOR x86 ) + +# C/C++ compilers +set( CMAKE_C_COMPILER i686-w64-mingw32-gcc ) +set( CMAKE_CXX_COMPILER i686-w64-mingw32-g++ ) +set( CMAKE_RC_COMPILER i686-w64-mingw32-windres ) + +# Find programs using host paths and headers/libraries using target paths +# FIXME: not respected when cmake invokes pkg-config +set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER ) +set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY ) +set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY ) diff --git a/cmake/cross-toolchain-mingw64.cmake b/cmake/cross-toolchain-mingw64.cmake new file mode 100644 index 0000000000..24636132bf --- /dev/null +++ b/cmake/cross-toolchain-mingw64.cmake @@ -0,0 +1,14 @@ +# Target operating system and architecture +set( CMAKE_SYSTEM_NAME Windows ) +set( CMAKE_SYSTEM_PROCESSOR x86_64 ) + +# C/C++ compilers +set( CMAKE_C_COMPILER x86_64-w64-mingw32-gcc ) +set( CMAKE_CXX_COMPILER x86_64-w64-mingw32-g++ ) +set( CMAKE_RC_COMPILER x86_64-w64-mingw32-windres ) + +# Find programs using host paths and headers/libraries using target paths +# FIXME: not respected when cmake invokes pkg-config +set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER ) +set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY ) +set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY ) From 12a6d62f9bbbe5dfc7c2306b57f6a993eb7d128f Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Mon, 7 Apr 2025 20:36:51 +0200 Subject: [PATCH 23/36] cmake: add CMake scripts to build sel_ldr and nacl_helper_bootstrap --- CMakeLists.txt | 116 +++++ cmake/NaClFlags.cmake | 302 +++++++++++++ src/shared/gio/CMakeLists.txt | 6 + src/shared/imc/CMakeLists.txt | 18 + src/shared/platform/CMakeLists.txt | 88 ++++ src/trusted/cpu_features/CMakeLists.txt | 14 + src/trusted/debug_stub/CMakeLists.txt | 32 ++ src/trusted/desc/CMakeLists.txt | 56 +++ src/trusted/fault_injection/CMakeLists.txt | 7 + src/trusted/interval_multiset/CMakeLists.txt | 8 + src/trusted/nacl_base/CMakeLists.txt | 2 + src/trusted/perf_counter/CMakeLists.txt | 1 + src/trusted/platform_qualify/CMakeLists.txt | 51 +++ src/trusted/service_runtime/CMakeLists.txt | 401 ++++++++++++++++++ .../service_runtime/linux/CMakeLists.txt | 123 ++++++ src/trusted/validator/CMakeLists.txt | 7 + src/trusted/validator_arm/CMakeLists.txt | 98 +++++ src/trusted/validator_mips/CMakeLists.txt | 21 + src/trusted/validator_ragel/CMakeLists.txt | 34 ++ src/trusted/validator_x86/CMakeLists.txt | 6 + 20 files changed, 1391 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 cmake/NaClFlags.cmake create mode 100644 src/shared/gio/CMakeLists.txt create mode 100644 src/shared/imc/CMakeLists.txt create mode 100644 src/shared/platform/CMakeLists.txt create mode 100644 src/trusted/cpu_features/CMakeLists.txt create mode 100644 src/trusted/debug_stub/CMakeLists.txt create mode 100644 src/trusted/desc/CMakeLists.txt create mode 100644 src/trusted/fault_injection/CMakeLists.txt create mode 100644 src/trusted/interval_multiset/CMakeLists.txt create mode 100644 src/trusted/nacl_base/CMakeLists.txt create mode 100644 src/trusted/perf_counter/CMakeLists.txt create mode 100644 src/trusted/platform_qualify/CMakeLists.txt create mode 100644 src/trusted/service_runtime/CMakeLists.txt create mode 100644 src/trusted/service_runtime/linux/CMakeLists.txt create mode 100644 src/trusted/validator/CMakeLists.txt create mode 100644 src/trusted/validator_arm/CMakeLists.txt create mode 100644 src/trusted/validator_mips/CMakeLists.txt create mode 100644 src/trusted/validator_ragel/CMakeLists.txt create mode 100644 src/trusted/validator_x86/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000000..5e117e3e90 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,116 @@ +cmake_minimum_required(VERSION 3.12) + +if (COMPILER_TARGET) + set(CMAKE_C_COMPILER_TARGET "${COMPILER_TARGET}") + set(CMAKE_CXX_COMPILER_TARGET "${COMPILER_TARGET}") + set(CMAKE_ASM_COMPILER_TARGET "${COMPILER_TARGET}") +endif() + +project(native_client C CXX ASM) + +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}") + +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") + +include(Yokai/Detection) +include(NaClFlags) + +if (NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE RelWithDebInfo) +endif() + +option(BUILD_NACL_LOADER "Build the sel_ldr program." ON) + +if (YOKAI_TARGET_SYSTEM_LINUX_COMPATIBILITY) + option(BUILD_NACL_HELPER_BOOTSTRAP "Build the nacl_helper_bootstrap program on platforms requiring it." ON) +endif() + +# TODO(arbenson): remove this once binutils bug is fixed (see +# src/trusted/service_runtime/arch/x86_64/sel_addrspace_posix_x86_64.c) +if (BUILD_NACL_LOADER AND YOKAI_TARGET_ARCH_AMD64 AND NOT YOKAI_TARGET_SYSTEM_WINDOWS) + option(USE_AMD64_ZERO_BASED_SANDBOX "Allow the zero-based sandbox model to run insecurely." OFF) +endif() + +if (BUILD_NACL_LOADER AND YOKAI_TARGET_SYSTEM_WINDOWS) + option(FORCE_NO_TRUSTED_BUILD "Prevent use of trusted toolchain." OFF) +endif() + +if (BUILD_NACL_LOADER AND YOKAI_TARGET_SYSTEM_WINDOWS) + set(REQUIRE_MASM ON) +endif() + +if (BUILD_NACL_LOADER AND YOKAI_TARGET_SYSTEM_MACOS) + set(REQUIRE_PYTHON ON) +endif() + +if (BUILD_NACL_HELPER_BOOTSTRAP) + set(REQUIRE_PYTHON ON) +endif() + +if (REQUIRE_PYTHON) + if (NOT PYTHON) + find_program(PYTHON NAMES "python3" DOC "Path to the python3 executable." REQUIRED) + endif() +endif() + +if (REQUIRE_MASM) + if (YOKAI_CXX_COMPILER_MINGW AND NOT CMAKE_ASM_MASM_COMPILER) + include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include-hax/fake_masm") + + find_program(JWASM NAMES "jwasm" DOC "Path to the JWasm executable." REQUIRED) + + set(CMAKE_ASM_MASM_COMPILER "${JWASM}") + + if (YOKAI_TARGET_ARCH_I686) + list(APPEND CMAKE_ASM_MASM_FLAGS "-coff") + elseif(YOKAI_TARGET_ARCH_AMD64) + list(APPEND CMAKE_ASM_MASM_FLAGS "-win64") + endif() + endif() + + enable_language(ASM_MASM) +endif() + +include_directories("include-hax") + +if (YOKAI_TARGET_ARCH_I686) + set(VALIDATOR_ARCH_SUFFIX "_x86_32") +elseif (YOKAI_TARGET_ARCH_AMD64) + set(VALIDATOR_ARCH_SUFFIX "_x86_64") +elseif (YOKAI_TARGET_ARCH_ARMHF OR YOKAI_TARGET_ARCH_ARMEL) + set(VALIDATOR_ARCH_SUFFIX "_arm") +elseif (YOKAI_TARGET_ARCH_MIPSEL) + set(VALIDATOR_ARCH_SUFFIX "_mips32") +endif() + +if (BUILD_NACL_LOADER) + add_subdirectory(src/shared/gio) + add_subdirectory(src/shared/imc) + add_subdirectory(src/shared/platform) + add_subdirectory(src/trusted/cpu_features) + add_subdirectory(src/trusted/debug_stub) + add_subdirectory(src/trusted/desc) + add_subdirectory(src/trusted/fault_injection) + add_subdirectory(src/trusted/interval_multiset) + add_subdirectory(src/trusted/nacl_base) + add_subdirectory(src/trusted/perf_counter) + add_subdirectory(src/trusted/platform_qualify) + add_subdirectory(src/trusted/validator) + + if (YOKAI_TARGET_ARCH_I686 OR YOKAI_TARGET_ARCH_AMD64) + add_subdirectory(src/trusted/validator_x86) + add_subdirectory(src/trusted/validator_ragel) + elseif (YOKAI_TARGET_ARCH_ARMHF OR YOKAI_TARGET_ARCH_ARMEL) + add_subdirectory(src/trusted/validator_arm) + elseif (YOKAI_TARGET_ARCH_MIPSEL) + add_subdirectory(src/trusted/validator_mips) + endif() +endif() + +if (BUILD_NACL_LOADER) + add_subdirectory(src/trusted/service_runtime) +endif() + +if (BUILD_NACL_HELPER_BOOTSTRAP) + add_subdirectory(src/trusted/service_runtime/linux) +endif() diff --git a/cmake/NaClFlags.cmake b/cmake/NaClFlags.cmake new file mode 100644 index 0000000000..6091cbc4f6 --- /dev/null +++ b/cmake/NaClFlags.cmake @@ -0,0 +1,302 @@ +macro(set_ASM_flag FLAG) + set(lang ASM) + if (${ARGC} GREATER 1) + set(CMAKE_${lang}_FLAGS_${ARGV1} "${CMAKE_${lang}_FLAGS_${ARGV1}} ${FLAG}") + else() + set(CMAKE_${lang}_FLAGS "${CMAKE_${lang}_FLAGS} ${FLAG}") + endif() +endmacro() + +macro(set_C_flag FLAG) + set(lang C) + if (${ARGC} GREATER 1) + set(CMAKE_${lang}_FLAGS_${ARGV1} "${CMAKE_${lang}_FLAGS_${ARGV1}} ${FLAG}") + else() + set(CMAKE_${lang}_FLAGS "${CMAKE_${lang}_FLAGS} ${FLAG}") + endif() +endmacro() + +macro(set_CXX_flag FLAG) + set(lang CXX) + if (${ARGC} GREATER 1) + set(CMAKE_${lang}_FLAGS_${ARGV1} "${CMAKE_${lang}_FLAGS_${ARGV1}} ${FLAG}") + else() + set(CMAKE_${lang}_FLAGS "${CMAKE_${lang}_FLAGS} ${FLAG}") + endif() +endmacro() + +macro(set_compiler_flag FLAG) + foreach(lang C CXX ASM) + if (${ARGC} GREATER 1) + set(CMAKE_${lang}_FLAGS_${ARGV1} "${CMAKE_${lang}_FLAGS_${ARGV1}} ${FLAG}") + else() + set(CMAKE_${lang}_FLAGS "${CMAKE_${lang}_FLAGS} ${FLAG}") + endif() + endforeach() +endmacro() + +macro(set_EXE_linker_flag FLAG) + set(kind EXE) + if (${ARGC} GREATER 1) + set(CMAKE_${kind}_LINKER_FLAGS_${ARGV1} "${CMAKE_${kind}_LINKER_FLAGS_${ARGV1}} ${FLAG}") + else() + set(CMAKE_${kind}_LINKER_FLAGS "${CMAKE_${kind}_LINKER_FLAGS} ${FLAG}") + endif() +endmacro() + +macro(set_SHARED_linker_flag FLAG) + set(kind SHARED) + if (${ARGC} GREATER 1) + set(CMAKE_${kind}_LINKER_FLAGS_${ARGV1} "${CMAKE_${kind}_LINKER_FLAGS_${ARGV1}} ${FLAG}") + else() + set(CMAKE_${kind}_LINKER_FLAGS "${CMAKE_${kind}_LINKER_FLAGS} ${FLAG}") + endif() +endmacro() + +macro(set_MODULE_linker_flag FLAG) + set(kind MODULE) + if (${ARGC} GREATER 1) + set(CMAKE_${kind}_LINKER_FLAGS_${ARGV1} "${CMAKE_${kind}_LINKER_FLAGS_${ARGV1}} ${FLAG}") + else() + set(CMAKE_${kind}_LINKER_FLAGS "${CMAKE_${kind}_LINKER_FLAGS} ${FLAG}") + endif() +endmacro() + +macro(set_DLL_linker_flag FLAG) + foreach(kind SHARED MODULE) + if (${ARGC} GREATER 1) + set(CMAKE_${kind}_LINKER_FLAGS_${ARGV1} "${CMAKE_${kind}_LINKER_FLAGS_${ARGV1}} ${FLAG}") + else() + set(CMAKE_${kind}_LINKER_FLAGS "${CMAKE_${kind}_LINKER_FLAGS} ${FLAG}") + endif() + endforeach() +endmacro() + +macro(set_linker_flag FLAG) + foreach(kind EXE SHARED MODULE) + if (${ARGC} GREATER 1) + set(CMAKE_${kind}_LINKER_FLAGS_${ARGV1} "${CMAKE_${kind}_LINKER_FLAGS_${ARGV1}} ${FLAG}") + else() + set(CMAKE_${kind}_LINKER_FLAGS "${CMAKE_${kind}_LINKER_FLAGS} ${FLAG}") + endif() + endforeach() +endmacro() + +#TODO: Import from SetUpClang() from (root)/SConstruct. +#TODO: This is mostly ASAN configurations. + +option(USE_WERROR "Tell the compiler to make the build fail when warnings are present." OFF) + +# From MakeUnixLikeEnv() from (root)/SConstruct. +if (NOT YOKAI_CXX_COMPILER_MSVC) + set_C_flag("-std=gnu99") + # -Wdeclaration-after-statement is desirable because MS studio does + # not allow declarations after statements in a block, and since much + # of our code is portable and primarily initially tested on Linux, + # it'd be nice to get the build error earlier rather than later + # (building and testing on Linux is faster). + # TODO(nfullagar): should we consider switching to -std=c99 ? + set_C_flag("-Wdeclaration-after-statement") + # Require defining functions as "foo(void)" rather than + # "foo()" because, in C (but not C++), the latter defines a + # function with unspecified arguments rather than no + # arguments. + set_C_flag("-Wstrict-prototypes") + + # set_compiler_flag("-malign-double") + set_compiler_flag("-Wall") + set_compiler_flag("-pedantic") + set_compiler_flag("-Wextra") + set_compiler_flag("-Wno-long-long") + set_compiler_flag("-Wswitch-enum") + set_compiler_flag("-Wsign-compare") + set_compiler_flag("-Wundef") + set_compiler_flag("-fdiagnostics-show-option") + set_compiler_flag("-fvisibility=hidden") + set_compiler_flag("-fstack-protector") + + # NOTE: pthread is only neeeded for libppNaClPlugin.so and on arm +#TODO: LIBS = ['pthread'] + + add_definitions(-D__STDC_LIMIT_MACROS=1) + add_definitions(-D__STDC_FORMAT_MACROS=1) + + if (NOT YOKAI_TARGET_SYSTEM_ANDROID) + set_CXX_flag("-std=c++98") + endif() + + if (NOT YOKAI_CXX_COMPILER_CLANG_COMPATIBILITY) + set_compiler_flag("--param ssp-buffer-size=4") + endif() + + if (USE_WERROR) + # It was only set on linker flag in (root)SConstruct. + set_linker_flag("-Werror") + endif() +endif() + +# From MakeWindowsEnv() from (root)/SConstruct. +if (YOKAI_TARGET_SYSTEM_WINDOWS) + # Windows /SAFESEH linking requires either an .sxdata section be + # present or that @feat.00 be defined as a local, absolute symbol + # with an odd value. +#TODO: ASCOM = ('$ASPPCOM /E /D__ASSEMBLER__ | ' +#TODO: '$WINASM -defsym @feat.00=1 -o $TARGET'), + add_definitions("-D_WIN32_WINNT=0x0501") + add_definitions("-D__STDC_LIMIT_MACROS=1") + add_definitions("-DNOMINMAX=1") + # WIN32 is used by ppapi + add_definitions("-DWIN32=1") + # WIN32_LEAN_AND_MEAN tells windows.h to omit obsolete and rarely + # used #include files. This allows use of Winsock 2.0 which otherwise + # would conflict with Winsock 1.x included by windows.h. + add_definitions("-DWIN32_LEAN_AND_MEAN=1") + + if (YOKAI_CXX_COMPILER_MSVC) + # TODO(bsy) remove 4355 once cross-repo + # NACL_ALLOW_THIS_IN_INITIALIZER_LIST changes go in. + set_compiler_flag("/EHsc") + set_compiler_flag("/Wx") + set_compiler_flag("/wd4355") + set_compiler_flag("/wd4800") + + if (YOKAI_TARGET_ARCH_I686) + # This linker option allows us to ensure our builds are compatible with + # Chromium, which uses it. +#TODO: disabled until ASCOM is configured. +#TODO: set_linker_flag("safeseh") + endif() + + # We use the GNU assembler (gas) on Windows so that we can use the + # same .S assembly files on all platforms. Microsoft's assembler uses + # a completely different syntax for x86 code. +#FIXME: Use x86_64-w64-mingw32-as.exe or x86_64-w32-mingw32-as.exe on MSVC for .S files. + endif() +endif() + +# From MakeMacEnv() from (root)/SConstruct. +if (YOKAI_TARGET_SYSTEM_MACOS) + # Don't override the macOS version when CMAKE_OSX_DEPLOYMENT_TARGET + # is set explicitely (environemnt, command line, toolchain…). + if (NOT DEFINED CMAKE_OSX_DEPLOYMENT_TARGET) + set(MAC_DEPLOYMENT_TARGET "10.6") + set(MAC_SDK_FLAG "-mmacosx-version-min=${MAC_DEPLOYMENT_TARGET}") + + set_compiler_flag(${MAC_SDK_FLAG}) + set_linker_flag(${MAC_SDK_FLAG}) + endif() + + set_compiler_flag("-fPIC") + set_linker_flag("-fPIC") + set_compiler_flag("-Wno-gnu") + set_linker_flag("-stdlib=libc++") +endif() + +# From SetUpLinuxEnvArm() from (root)/SConstruct. +if (YOKAI_TARGET_SYSTEM_LINUX_COMPATIBILITY AND YOKAI_TARGET_ARCH_ARMHF) + # The -rpath-link argument is needed on Ubuntu/Precise to + # avoid linker warnings about missing ld.linux.so.3. + # TODO(sbc): remove this once we stop supporting Precise + # as a build environment. + # We (Dæmon) don't support Precise. + # set_linker_flag("-fuse-ld=lld") + + if (YOKAI_CXX_COMPILER_CLANG_COMPATIBILITY) + # If ARCH is "armhf", then the target is already set properly by the toolchain. + # set_compiler_flag("--target=arm-linux-gnueabihf") + # set_linker_flag("--target=arm-linux-gnueabihf") + endif() + + set_compiler_flag("-march=armv7-a") + set_compiler_flag("-mtune=generic-armv7-a") + set_compiler_flag("-mfpu=neon") + # If ARCH is "armhf", then the float ABI is already set properly by the toolchain. + # set_compiler_flag("-mfloat-abi=hard") +endif() + +# Partially from SetUpAndroidEnv() from (root)/SConstruct. +if (YOKAI_TARGET_SYSTEM_LINUX_COMPATIBILITY AND YOKAI_TARGET_ARCH_ARMEL) + set_compiler_flag("-march=armv7-a") + set_compiler_flag("-mfpu=vfp") + set_compiler_flag("-mfloat-abi=softfp") +endif() + +#TODO: Import from SetUpAndroidEnv() from (root)/SConstruct. +if (YOKAI_TARGET_SYSTEM_ANDROID) +#TODO: LIBS=['stlport_shared', +#TODO: 'gcc', +#TODO: 'c', +#TODO: 'dl', +#TODO: 'm', +#TODO: ], + +#TODO: env.Append(CCFLAGS=[ +#TODO: '-I%s' % android_stlport_include, +#TODO: CXXFLAGS=['-I%s' % android_stlport_include, +#TODO: '-I%s' % android_ndk_include, + + # (root)/SConstruct was just setting -DANDROID without any value. + # set_compiler_definition("-DANDROID") + # The compiler sets it, we better trust it. + # set_compiler_definition("-D__ANDROID__") + + set_compiler_flag("-ffunction-sections") + set_compiler_flag("-g") + set_compiler_flag("-fstack-protector") + set_compiler_flag("-fno-short-enums") + set_compiler_flag("-finline-limit=64") + set_compiler_flag("-Wa,--noexecstack") + # Due to bogus warnings on uintptr_t formats. + set_compiler_flag("-Wno-format") + + set_CXX_flag("-fno-exceptions") + + # Copied from (root)SConsctruct, break build in Termux, + # produces undefined symbols in std::string. + # set_linker_flag("-nostdlib") + + set_linker_flag("-Wl,--no-undefined") + # Don't export symbols from statically linked libraries. + set_linker_flag("-Wl,--exclude-libs=ALL") + + # crtbegin_dynamic.o should be the last item in ldflags. + # Already done by the toolchain, same for crtend_android.o. + # crtbegin_so.o should be the last item in ldflags. + # Already done by the toolchain, same for crtend_so.o. +endif() + +# From SetUpLinuxEnvMips() from (root)/SConstruct. +if (YOKAI_TARGET_SYSTEM_LINUX_COMPATIBILITY AND YOKAI_TARGET_ARCH_MIPSEL) +#TODO: env.Append(LIBS=['rt', 'dl', 'pthread'] + set_compiler_flag("-march=mips32r2") + # Because of: + # src/trusted/service_runtime/arch/mips/nacl_switch.S: Assembler messages: + # src/trusted/service_runtime/arch/mips/nacl_switch.S:38: Error: float register should be even, was 1 + # src/trusted/service_runtime/arch/mips/nacl_switch.S:72: Error: float register should be even, was 1 + set_compiler_flag("-mfp32") +endif() + +# From MakeGenericLinuxEnv() from (root)/SConstruct. +if (YOKAI_TARGET_SYSTEM_LINUX_COMPATIBILITY) + add_definitions(-D_POSIX_C_SOURCE=199506) + add_definitions(-D_XOPEN_SOURCE=600) + add_definitions(-D_GNU_SOURCE=1) + add_definitions(-D_FORTIFY_SOURCE=2) + + if (NOT YOKAI_TARGET_SYSTEM_ANDROID) + # Disabled in (root)/SConstruct. + add_definitions(-D_LARGEFILE64_SOURCE=1) + # Android complains about not finding -lc++_shared. + set_linker_flag("-static-libstdc++") + endif() + + set_linker_flag("-Wl,-z,relro") + set_linker_flag("-Wl,-z,now") + set_linker_flag("-Wl,-z,noexecstack") + set_compiler_flag("-fPIE") + set_linker_flag("-pie") +endif() + +if (YOKAI_TARGET_ARCH_I686) + set_compiler_flag("-msse2") +endif() diff --git a/src/shared/gio/CMakeLists.txt b/src/shared/gio/CMakeLists.txt new file mode 100644 index 0000000000..ef5fc02ac8 --- /dev/null +++ b/src/shared/gio/CMakeLists.txt @@ -0,0 +1,6 @@ +list(APPEND GIO_INPUTS + "gio.c" + "gprintf.c" +) + +add_library(gio STATIC ${GIO_INPUTS}) diff --git a/src/shared/imc/CMakeLists.txt b/src/shared/imc/CMakeLists.txt new file mode 100644 index 0000000000..530a0b94d8 --- /dev/null +++ b/src/shared/imc/CMakeLists.txt @@ -0,0 +1,18 @@ +list(APPEND NACL_IMC_INPUTS "nacl_imc_common.cc") + +if (YOKAI_TARGET_SYSTEM_WINDOWS) + list(APPEND NACL_IMC_INPUTS + "win/nacl_imc.cc" + "win/nacl_shm.cc" + ) +else() + list(APPEND NACL_IMC_INPUTS "posix/nacl_imc_posix.cc") + + if (YOKAI_TARGET_SYSTEM_LINUX_COMPATIBILITY) + list(APPEND NACL_IMC_INPUTS "linux/nacl_imc.cc") + elseif (YOKAI_TARGET_SYSTEM_MACOS) + list(APPEND NACL_IMC_INPUTS "osx/nacl_imc.cc") + endif() +endif() + +add_library(imc STATIC ${NACL_IMC_INPUTS}) diff --git a/src/shared/platform/CMakeLists.txt b/src/shared/platform/CMakeLists.txt new file mode 100644 index 0000000000..e94c3a9ed2 --- /dev/null +++ b/src/shared/platform/CMakeLists.txt @@ -0,0 +1,88 @@ +if (YOKAI_TARGET_SYSTEM_WINDOWS) + list(APPEND PLATFORM_INPUTS + "win/aligned_malloc.c" + "win/condition_variable.cc" + "win/lock.cc" + "win/nacl_clock.c" + "win/nacl_error.c" + "win/nacl_exit.c" + "win/nacl_fast_mutex.c" + "win/nacl_find_addrsp.c" + "win/nacl_host_desc.c" + "win/nacl_host_dir.c" + "win/lock_impl_win.cc" + "win/nacl_secure_random.c" + "win/nacl_semaphore.c" + "win/nacl_sync_win.cc" + "win/nacl_threads.c" + "win/nacl_timestamp.c" + "win/port_win.c" + "win/xlate_system_error.c" + ) + + if (YOKAI_CXX_COMPILER_MSVC) + list(APPEND PLATFORM_INPUTS "win/nacl_time.c") + else() + list(APPEND PLATFORM_INPUTS "posix/nacl_time.c") + endif() + + if (YOKAI_CXX_COMPILER_MSVC) + list(APPEND PLATFORM_FLAGS "/D_CRT_RAND_S") + list(APPEND PLATFORM_FLAGS "/D_UNICODE") + list(APPEND PLATFORM_FLAGS "/DUNICODE") + endif() +elseif (YOKAI_TARGET_SYSTEM_LINUX_COMPATIBILITY) + list(APPEND PLATFORM_INPUTS + "linux/nacl_clock.c" + "linux/nacl_host_dir.c" + "linux/nacl_semaphore.c" + ) + +#TODO: kernel_version = list(map(int, platform.release().split('.', 2)[:2])) +#TODO: if kernel_version < [3, 0]: +#TODO: cputime_test_enabled = False +elseif (YOKAI_TARGET_SYSTEM_MACOS) + list(APPEND PLATFORM_INPUTS + "osx/nacl_clock.c" + "osx/nacl_host_dir.c" + "osx/nacl_semaphore.c" + ) +endif() + +# It was doing: if env.Bit('posix'): +if (YOKAI_TARGET_SYSTEM_XDG_COMPATIBILITY OR YOKAI_TARGET_SYSTEM_MACOS) + list(APPEND PLATFORM_INPUTS + "posix/aligned_malloc.c" + "posix/condition_variable.c" + "posix/lock.c" + "posix/nacl_error.c" + "posix/nacl_exit.c" + "posix/nacl_fast_mutex.c" + "posix/nacl_file_lock.c" # only used on Linux, but built/tested on Posix + "posix/nacl_find_addrsp.c" + "posix/nacl_host_desc.c" + "posix/nacl_secure_random.c" + "posix/nacl_thread_id.c" + "posix/nacl_threads.c" + "posix/nacl_time.c" + "posix/nacl_timestamp.c" + ) +endif() + +list(APPEND PLATFORM_INPUTS + "nacl_check.c" + "nacl_global_secure_random.c" + "nacl_host_desc_common.c" + "nacl_interruptible_condvar.c" + "nacl_interruptible_mutex.c" + "nacl_log.c" + "nacl_secure_random_common.c" + "nacl_sync_checked.c" + "nacl_time_common.c" + "platform_init.c" + "refcount_base.cc" +) + +add_library(platform STATIC ${PLATFORM_INPUTS}) +string(REPLACE ";" " " PLATFORM_FLAGS_STRING "${PLATFORM_FLAGS}") +set_target_properties(platform PROPERTIES COMPILE_FLAGS "${PLATFORM_FLAGS}") diff --git a/src/trusted/cpu_features/CMakeLists.txt b/src/trusted/cpu_features/CMakeLists.txt new file mode 100644 index 0000000000..69eacd246f --- /dev/null +++ b/src/trusted/cpu_features/CMakeLists.txt @@ -0,0 +1,14 @@ +if (YOKAI_TARGET_ARCH_I686 OR YOKAI_TARGET_ARCH_AMD64) + list(APPEND CPU_FEATURES_INPUTS + "arch/x86/cpu_x86.c" + "arch/x86/cpu_xgetbv.S" + ) +elseif (YOKAI_TARGET_ARCH_ARMHF OR YOKAI_TARGET_ARCH_ARMEL) + # For unkown reasons src/trusted/cpu_features/build.scons was building that on every architecture. + list(APPEND CPU_FEATURES_INPUTS "arch/arm/cpu_arm.c") +elseif (YOKAI_TARGET_ARCH_MIPSEL) + # For unkown reasons src/trusted/cpu_features/build.scons was building that on every architecture. + list(APPEND CPU_FEATURES_INPUTS "arch/mips/cpu_mips.c") +endif() + +add_library(cpu_features STATIC ${CPU_FEATURES_INPUTS}) diff --git a/src/trusted/debug_stub/CMakeLists.txt b/src/trusted/debug_stub/CMakeLists.txt new file mode 100644 index 0000000000..4b59d5c297 --- /dev/null +++ b/src/trusted/debug_stub/CMakeLists.txt @@ -0,0 +1,32 @@ +list(APPEND DEBUG_INPUTS + "abi.cc" + "debug_stub.cc" + "nacl_debug.cc" + "packet.cc" + "session.cc" + "target.cc" + "thread_common.cc" + "transport_common.cc" + "transport_ipc.cc" + "util.cc" +) + +if (YOKAI_TARGET_SYSTEM_WINDOWS) + list(APPEND DEBUG_INPUTS + "win/debug_stub_win.cc" + "win/platform_impl.cc" + "win/thread_impl.cc" + ) +else() + list(APPEND DEBUG_INPUTS + "posix/debug_stub_posix.cc" + "posix/platform_impl.cc" + "posix/thread_impl.cc" + ) +endif() + +add_library(debug_stub STATIC ${DEBUG_INPUTS}) + +if (YOKAI_CXX_COMPILER_MINGW) + target_link_libraries(debug_stub ws2_32) +endif() diff --git a/src/trusted/desc/CMakeLists.txt b/src/trusted/desc/CMakeLists.txt new file mode 100644 index 0000000000..d176b4416d --- /dev/null +++ b/src/trusted/desc/CMakeLists.txt @@ -0,0 +1,56 @@ +add_library(nrd OBJECT "nrd_xfer.c") +list(APPEND NRD_XFER_LIBS nrd) + +if (NOT YOKAI_TARGET_SYSTEM_WINDOWS) + # Use those flags only with the nrd target. + list(APPEND NRD_FLAGS "-fno-strict-aliasing") # This was only a C flag in build.scons + list(APPEND NRD_FLAGS "-Wno-missing-field-initializers") + string(REPLACE ";" " " NRD_FLAGS_STRING "${NRD_FLAGS}") + set_target_properties(nrd PROPERTIES COMPILE_FLAGS "${NRD_FLAGS_STRING}") +endif() + +list(APPEND NRD_LIB_INPUTS + "nacl_desc_base.c" + "nacl_desc_cond.c" + "nacl_desc_custom.c" + "nacl_desc_dir.c" + "nacl_desc_effector_trusted_mem.c" + "nacl_desc_imc.c" + "nacl_desc_imc_shm.c" + "nacl_desc_invalid.c" + "nacl_desc_io.c" + "nacl_desc_mutex.c" + "nacl_desc_null.c" + "nacl_desc_quota.c" + "nacl_desc_quota_interface.c" + "nacl_desc_semaphore.c" + "nacl_desc_sync_socket.c" + "nrd_all_modules.c" +) + +if (YOKAI_TARGET_SYSTEM_WINDOWS) + list(APPEND NRD_LIB_INPUTS "win/nacl_desc.c") +else() + list(APPEND NRD_LIB_INPUTS "posix/nacl_desc.c") +endif() + +if (YOKAI_TARGET_SYSTEM_MACOS) + list(APPEND NRD_LIB_INPUTS "osx/nacl_desc_imc_shm_mach.c") +endif() + +if (YOKAI_TARGET_SYSTEM_WINDOWS) + list(APPEND NRD_LIB_INPUTS + "nacl_desc_conn_cap.c" + "nacl_desc_imc_bound_desc.c" + "nacl_makeboundsock.c" + ) +else() + list(APPEND NRD_LIB_INPUTS + "posix/nacl_desc_conn_cap.c" + "posix/nacl_desc_imc_bound_desc.c" + "posix/nacl_makeboundsock.c" + ) +endif() + +add_library(nrd_xfer STATIC ${NRD_LIB_INPUTS}) +target_link_libraries(nrd_xfer ${NRD_XFER_LIBS} platform nacl_base) diff --git a/src/trusted/fault_injection/CMakeLists.txt b/src/trusted/fault_injection/CMakeLists.txt new file mode 100644 index 0000000000..47b4aeed7a --- /dev/null +++ b/src/trusted/fault_injection/CMakeLists.txt @@ -0,0 +1,7 @@ +list(APPEND NACL_FI_LIB_INPUTS + "fault_injection.c" + "test_injection.c" +) + +add_library(nacl_fault_inject STATIC ${NACL_FI_LIB_INPUTS}) +target_link_libraries(nacl_fault_inject platform) diff --git a/src/trusted/interval_multiset/CMakeLists.txt b/src/trusted/interval_multiset/CMakeLists.txt new file mode 100644 index 0000000000..ef47d5ee77 --- /dev/null +++ b/src/trusted/interval_multiset/CMakeLists.txt @@ -0,0 +1,8 @@ +list(APPEND NACL_INTERVAL_LIB_INPUTS + "nacl_interval_multiset_delete.c" + "nacl_interval_multiset_factory.c" + "nacl_interval_list.c" + "nacl_interval_range_tree.c" +) + +add_library(nacl_interval STATIC ${NACL_INTERVAL_LIB_INPUTS}) diff --git a/src/trusted/nacl_base/CMakeLists.txt b/src/trusted/nacl_base/CMakeLists.txt new file mode 100644 index 0000000000..39d43c9dba --- /dev/null +++ b/src/trusted/nacl_base/CMakeLists.txt @@ -0,0 +1,2 @@ +add_library(nacl_base STATIC "nacl_refcount.c") +target_link_libraries(nacl_base platform) diff --git a/src/trusted/perf_counter/CMakeLists.txt b/src/trusted/perf_counter/CMakeLists.txt new file mode 100644 index 0000000000..9cb0c68241 --- /dev/null +++ b/src/trusted/perf_counter/CMakeLists.txt @@ -0,0 +1 @@ +add_library(nacl_perf_counter STATIC "nacl_perf_counter.c") diff --git a/src/trusted/platform_qualify/CMakeLists.txt b/src/trusted/platform_qualify/CMakeLists.txt new file mode 100644 index 0000000000..50edf53521 --- /dev/null +++ b/src/trusted/platform_qualify/CMakeLists.txt @@ -0,0 +1,51 @@ +if (YOKAI_TARGET_SYSTEM_WINDOWS) + list(APPEND PQL_INPUTS + "win/nacl_os_qualify.c" + "win/nacl_dep_qualify.c" + ) +elseif (YOKAI_TARGET_SYSTEM_LINUX_COMPATIBILITY OR YOKAI_TARGET_SYSTEM_MACOS) + list(APPEND PQL_INPUTS "posix/nacl_dep_qualify.c") + + if (YOKAI_TARGET_SYSTEM_LINUX_COMPATIBILITY) + list(APPEND PQL_INPUTS "linux/nacl_os_qualify.c") + elseif (YOKAI_TARGET_SYSTEM_MACOS) + list(APPEND PQL_INPUTS "osx/nacl_os_qualify.c") + endif() +endif() + +if (YOKAI_TARGET_ARCH_I686 OR YOKAI_TARGET_ARCH_AMD64) + list(APPEND PQL_INPUTS "arch/x86/nacl_cpuallowlist.c") + + if (YOKAI_TARGET_SYSTEM_MACOS) + list(APPEND VCPUID_FLAGS "-mdynamic-no-pic") +# TODO: vcpuid_env.FilterOut(CCFLAGS = ['-fPIC']) + list(APPEND VCPUID_FLAGS "-fno-PIC") + elseif (YOKAI_TARGET_SYSTEM_LINUX_COMPATIBILITY) + list(APPEND VCPUID_FLAGS "-msse3") + endif() + + add_library(vcpuid OBJECT "arch/x86/vcpuid.c") + list(APPEND VCPUID_LIBS vcpuid) + + if (YOKAI_TARGET_ARCH_I686) + list(APPEND PQL_INPUTS "arch/x86_32/nacl_dep_qualify_arch.c") + elseif (YOKAI_TARGET_ARCH_AMD64) + list(APPEND PQL_INPUTS "arch/x86_64/nacl_dep_qualify_arch.c") + endif() +elseif (YOKAI_TARGET_ARCH_ARMHF OR YOKAI_TARGET_ARCH_ARMEL) + list(APPEND PQL_INPUTS + # Compile ARM primitives for checking XN functionality + "arch/arm/nacl_dep_qualify_arch.c" + # Compile ARM primitives for checking VFP/vector features. + "arch/arm/nacl_qualify_fpu.c" + # Compile ARM primitives for checking sandboxing features. + "arch/arm/nacl_qualify_sandbox_instrs.c" + # Compile ARM primitives for checking alignment features. + "arch/arm/nacl_qualify_unaligned.c" + ) +elseif (YOKAI_TARGET_ARCH_MIPSEL) + list(APPEND PQL_INPUTS "arch/mips/nacl_qualify_fpu.c") +endif() + +add_library(platform_qual_lib STATIC ${PQL_INPUTS}) +target_link_libraries(platform_qual_lib ${VCPUID_LIBS}) diff --git a/src/trusted/service_runtime/CMakeLists.txt b/src/trusted/service_runtime/CMakeLists.txt new file mode 100644 index 0000000000..77c9969d9c --- /dev/null +++ b/src/trusted/service_runtime/CMakeLists.txt @@ -0,0 +1,401 @@ +# Copyright (c) 2012 The Native Client Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +set(GENERATED_ROOT "${CMAKE_BINARY_DIR}/gen") +set(GENERATED "${GENERATED_ROOT}/native_client/src/trusted/service_runtime") + +# ---------------------------------------------------------- +# TODO(robertm): this library is too big and needs to be split up +# for easier unit testing +list(APPEND LDR_INPUTS + "dyn_array.c" + "elf_util.c" + "filename_util.cc" + "load_file.c" + "nacl_all_modules.c" + "nacl_app_thread.c" + "nacl_copy.c" + "nacl_desc_effector_ldr.c" + "nacl_error_gio.c" + "nacl_error_log_hook.c" + "nacl_globals.c" + "nacl_resource.c" + "nacl_signal_common.c" + "nacl_stack_safety.c" + "nacl_syscall_common.c" + "nacl_syscall_hook.c" + "nacl_syscall_list.c" + "nacl_text.c" + "nacl_valgrind_hooks.c" + "sel_addrspace.c" + "sel_ldr.c" + "sel_ldr_filename.cc" + "sel_ldr_standard.c" + "sel_main_common.c" + "sel_mem.c" + "sel_qualify.c" + "sel_validate_image.c" + "sys_clock.c" + "sys_exception.c" + "sys_fdio.c" + "sys_filename.c" + "sys_futex.c" + "sys_imc.c" + "sys_list_mappings.c" + "sys_memory.c" + "sys_parallel_io.c" + "sys_random.c" + "thread_suspension_common.c" + "thread_suspension_unwind.c" +) + +if (YOKAI_TARGET_ARCH_I686) + list(APPEND LDR_INPUTS + "arch/x86/nacl_ldt_x86.c" + "arch/x86_32/nacl_app_32.c" + "arch/x86_32/nacl_switch_32.S" + "arch/x86_32/nacl_switch_all_regs_32.c" + "arch/x86_32/nacl_switch_all_regs_asm_32.S" + "arch/x86_32/nacl_switch_to_app_32.c" + "arch/x86_32/nacl_syscall_32.S" + "arch/x86_32/nacl_tls_32.c" + "arch/x86_32/sel_addrspace_x86_32.c" + "arch/x86_32/sel_ldr_x86_32.c" + "arch/x86_32/sel_rt_32.c" + "arch/x86_32/springboard.S" + "arch/x86_32/tramp_32.S" + ) +elseif (YOKAI_TARGET_ARCH_AMD64) + list(APPEND LDR_INPUTS + "arch/x86/nacl_ldt_x86.c" + "arch/x86_64/nacl_app_64.c" + "arch/x86_64/nacl_switch_64.S" + "arch/x86_64/nacl_switch_to_app_64.c" + "arch/x86_64/nacl_syscall_64.S" + "arch/x86_64/nacl_tls_64.c" + "arch/x86_64/sel_ldr_x86_64.c" + "arch/x86_64/sel_rt_64.c" + "arch/x86_64/tramp_64.S" + ) + + if (YOKAI_TARGET_SYSTEM_WINDOWS) + # We assemble the .asm assembly file with the Microsoft assembler + # because we need to generate x86-64 Windows unwind info, which + # the GNU assembler we use elsewhere does not support. + + list(APPEND LDR_INPUTS + "arch/x86_64/sel_addrspace_win_x86_64.c" + "arch/x86_64/fnstcw.S" + "arch/x86_64/fxsaverstor.S" + ) + + if (NOT FORCE_NO_TRUSTED_BUILD) + # This use of win64_asm_env causes an invocation of MSVC, even if sel_ldr + # would not otherwise be actually built. So don't include it if we aren't + # actually building sel_ldr + add_library(nacl_switch_unwind_win OBJECT "arch/x86_64/nacl_switch_unwind_win.asm") + list(APPEND LDR_LIBS nacl_switch_unwind_win) + endif() + else() + list(APPEND LDR_INPUTS "arch/x86_64/sel_addrspace_posix_x86_64.c") + + if (USE_AMD64_ZERO_BASED_SANDBOX) + add_definitions(-DNACL_X86_64_ZERO_BASED_SANDBOX=1) + else() + add_definitions(-DNACL_X86_64_ZERO_BASED_SANDBOX=0) + endif() + endif() +elseif (YOKAI_TARGET_ARCH_ARMHF OR YOKAI_TARGET_ARCH_ARMEL) + list(APPEND LDR_INPUTS + "arch/arm/nacl_app.c" + "arch/arm/nacl_switch_to_app_arm.c" + "arch/arm/sel_rt.c" + "arch/arm/nacl_tls.c" + "arch/arm/sel_ldr_arm.c" + "arch/arm/sel_addrspace_arm.c" + "arch/arm/nacl_switch.S" + "arch/arm/nacl_syscall.S" + "arch/arm/tramp_arm.S" + ) +elseif (YOKAI_TARGET_ARCH_MIPSEL) + list(APPEND LDR_INPUTS + "arch/mips/nacl_app.c" + "arch/mips/nacl_switch_to_app_mips.c" + "arch/mips/sel_rt.c" + "arch/mips/nacl_tls.c" + "arch/mips/sel_ldr_mips.c" + "arch/mips/sel_addrspace_mips.c" + "arch/mips/nacl_switch.S" + "arch/mips/nacl_syscall.S" + "arch/mips/tramp_mips.S" + ) +endif() + +if (YOKAI_TARGET_SYSTEM_WINDOWS) + list(APPEND LDR_INPUTS + "win/addrspace_teardown.c" + "win/nacl_ldt.c" + "win/nacl_thread_nice.c" + "win/sel_memory.c" + ) + + if (YOKAI_CXX_COMPILER_MSVC) + list(APPEND LDR_INPUTS "win/sel_segments.c") + else() + list(APPEND LDR_INPUTS "posix/x86/sel_segments.c") + endif() +elseif (YOKAI_TARGET_SYSTEM_MACOS) + # Rely on the c preprocessor to discover where the mach interface definitions + # are located. + set(GENERATED_NACL_EXC_C "${GENERATED}/nacl_exc.c") + set(GENERATED_NACL_EXC_H "${GENERATED}/nacl_exc.h") + set(GENERATED_NACL_EXC_SERVER_C "${GENERATED}/nacl_exc_server.c") + set(GENERATED_NACL_EXC_DEFS "${GENERATED}/exc.defs") + + file(WRITE "${GENERATED_NACL_EXC_C}" "#include ") + + # It works with clang but not with default cc (which is clang). + execute_process( + COMMAND "clang" "${CMAKE_C_COMPILER_FLAGS}" -E "${GENERATED_NACL_EXC_C}" + OUTPUT_FILE "${GENERATED_NACL_EXC_DEFS}" + ) + + include_directories("${GENERATED_ROOT}") + + execute_process( + COMMAND "${PYTHON}" + "${CMAKE_CURRENT_LIST_DIR}/osx/run_mig.py" + "${GENERATED_NACL_EXC_DEFS}" + "${GENERATED_NACL_EXC_H}" + "${GENERATED_NACL_EXC_SERVER_C}" + ) + + list(APPEND LDR_INPUTS + "${GENERATED_NACL_EXC_SERVER_C}" + "osx/crash_filter.c" + "osx/mach_exception_handler.c" + "osx/mach_thread_map.c" + "osx/nacl_ldt.c" + "osx/nacl_thread_nice.c" + "posix/addrspace_teardown.c" + "posix/sel_memory.c" + "posix/x86/sel_segments.c" + ) +elseif (YOKAI_TARGET_SYSTEM_LINUX_COMPATIBILITY) + list(APPEND LDR_INPUTS + "linux/nacl_bootstrap_args.c" + "linux/nacl_thread_nice.c" + "linux/r_debug.c" + "linux/reserved_at_zero.c" + "posix/addrspace_teardown.c" + "posix/sel_memory.c" + ) + + if (YOKAI_TARGET_ARCH_I686 OR YOKAI_TARGET_ARCH_AMD64) + list(APPEND LDR_INPUTS + "linux/x86/nacl_ldt.c" + "posix/x86/sel_segments.c" + ) + elseif (YOKAI_TARGET_ARCH_ARMHF OR YOKAI_TARGET_ARCH_ARMEL) + list(APPEND LDR_INPUTS "linux/arm/sel_segments.c") + elseif (YOKAI_TARGET_ARCH_MIPSEL) + list(APPEND LDR_INPUTS "linux/mips/sel_segments.c") + endif() +endif() + +# ------------------------------------------------------------- +# Add OS and architecture specific signal handling files. +# +if (YOKAI_TARGET_SYSTEM_WINDOWS) + list(APPEND LDR_INPUTS + "win/debug_exception_handler.c" + "win/debug_exception_handler_standalone.c" + "win/nacl_signal_stack.c" + "win/thread_handle_map.c" + "win/thread_suspension.c" + "win/sel_addrspace_win.c" + ) + + if (YOKAI_TARGET_ARCH_I686) + list(APPEND LDR_INPUTS "win/nacl_signal_32.c") + elseif (YOKAI_TARGET_ARCH_AMD64) + list(APPEND LDR_INPUTS + "win/exception_patch/exit_fast.S" + "win/exception_patch/intercept.S" + "win/exception_patch/ntdll_patch.c" + "win/nacl_signal_64.c" + ) + else() + message(FATAL_ERROR "Unsupported target") + endif() +endif() + +if (YOKAI_TARGET_SYSTEM_LINUX_COMPATIBILITY) + list(APPEND LDR_INPUTS + "linux/thread_suspension.c" + "posix/nacl_signal_stack.c" + "posix/sel_addrspace_posix.c" + ) + + if (YOKAI_TARGET_ARCH_ARMHF OR YOKAI_TARGET_ARCH_ARMEL) + list(APPEND LDR_INPUTS "linux/nacl_signal_arm.c") + elseif (YOKAI_TARGET_ARCH_MIPSEL) + list(APPEND LDR_INPUTS "linux/nacl_signal_mips.c") + elseif (YOKAI_TARGET_ARCH_I686) + list(APPEND LDR_INPUTS "linux/nacl_signal_32.c") + elseif (YOKAI_TARGET_ARCH_AMD64) + list(APPEND LDR_INPUTS "linux/nacl_signal_64.c") + else() + message(FATAL_ERROR "Unsupported target") + endif() + + add_library(nacl_signal STATIC "linux/nacl_signal.c") + list(APPEND LDR_LIBS nacl_signal) + if (YOKAI_TARGET_ARCH_I686) + # nacl_signal.c needs to be compiled without the stack protector + # on i386. + # See https://code.google.com/p/nativeclient/issues/detail?id=3581. +#TODO: nacl_signal_env.FilterOut(CCFLAGS=['-fstack-protector', '-fstack-protector-all']) + set_target_properties(nacl_signal PROPERTIES COMPILE_FLAGS "-fno-stack-protector") + endif() +endif() + +if (YOKAI_TARGET_SYSTEM_MACOS) + list(APPEND LDR_INPUTS + "osx/thread_suspension.c" + "posix/nacl_signal_stack.c" + "posix/sel_addrspace_posix.c" + ) + + if (YOKAI_TARGET_ARCH_I686) + list(APPEND LDR_INPUTS "osx/nacl_signal_32.c") + elseif (YOKAI_TARGET_ARCH_AMD64) + list(APPEND LDR_INPUTS "osx/nacl_signal_64.c") + else() + message(FATAL_ERROR "Unsupported target") + endif() +endif() + +if (YOKAI_TARGET_SYSTEM_WINDOWS) + list(APPEND LDR_INPUTS "win/vm_hole.c") +else() + list(APPEND LDR_INPUTS "generic/vm_hole.c") +endif() + +#TODO: syscall_gen_flags = '-a ${ARCHITECTURE} -s ${TARGET_SUBARCH}' + +#TODO: env.Append(SYSCALL_GEN_FLAGS=syscall_gen_flags) + +add_library(sel OBJECT ${LDR_INPUTS}) +list(APPEND LDR_LIBS sel) + +add_library(sel_main OBJECT "sel_main.c") +list(APPEND LDR_LIBS sel_main) + +# add_library(sel_main_chrome OBJECT "sel_main_chrome.c") + +add_library(env_cleanser OBJECT "env_cleanser.c") +list(APPEND LDR_LIBS env_cleanser) + +add_library(nacl_error_code OBJECT "nacl_error_code.c") +list(APPEND LDR_LIBS nacl_error_code) + +list(APPEND LDR_LIBS debug_stub) # not listed in src/trusted/service_runtime/build.scons +list(APPEND LDR_LIBS nrd_xfer) +list(APPEND LDR_LIBS nacl_perf_counter) +list(APPEND LDR_LIBS nacl_base) +list(APPEND LDR_LIBS imc) +list(APPEND LDR_LIBS nacl_fault_inject) +list(APPEND LDR_LIBS nacl_interval) +list(APPEND LDR_LIBS platform) +list(APPEND LDR_LIBS gio) # not listed in src/trusted/service_runtime/build.scons +list(APPEND LDR_LIBS platform_qual_lib) +list(APPEND LDR_LIBS validators) + +if (YOKAI_TARGET_ARCH_I686 OR YOKAI_TARGET_ARCH_AMD64) + list(APPEND LDR_LIBS dfa_validate_caller) +elseif (YOKAI_TARGET_ARCH_ARMHF OR YOKAI_TARGET_ARCH_ARMEL) + list(APPEND LDR_LIBS ncvalidate_arm_v2) + list(APPEND LDR_LIBS arm_validator_reporters) +elseif (YOKAI_TARGET_ARCH_MIPSEL) + list(APPEND LDR_LIBS ncvalidate_mips) +endif() + +if (YOKAI_TARGET_ARCH_I686 OR YOKAI_TARGET_ARCH_AMD64) + list(APPEND LDR_LIBS nccopy) # not listed in src/trusted/service_runtime/build.scons +endif() + +list(APPEND LDR_LIBS cpu_features) # not listed in src/trusted/service_runtime/build.scons + +if (YOKAI_TARGET_SYSTEM_WINDOWS) + set(MMAP_TEST_CHECK_CC "win/mmap_test_check.cc") +elseif (YOKAI_TARGET_SYSTEM_MACOS) + set(MMAP_TEST_CHECK_CC "osx/mmap_test_check.cc") +elseif (YOKAI_TARGET_SYSTEM_LINUX_COMPATIBILITY) + set(MMAP_TEST_CHECK_CC "linux/mmap_test_check.cc") +else() + message(FATAL_ERROR "Unsupported host OS") +endif() + +add_library(sel_test STATIC "${MMAP_TEST_CHECK_CC}") +list(APPEND LDR_LIBS sel_test) + +# NOTE(robertm): these extra libs were orignially only added to the +# sel_ldr binary +# TODO(robertm): see who really needs them and remove +if (YOKAI_TARGET_SYSTEM_WINDOWS) +# FIXME: Unused for now. + set(LIBS + ws2_32 + kernel32 + advapi32 + winmm + # TODO(gregoryd): ntdll.lib is required for sem_get_value implementation but + # it is available in Windows DDK only. The DDK is not + # in third_party, but we might need to add it if we want to use it. + # ntdll + ) +endif() + +if (NOT COVERAGE_ENABLED OR NOT YOKAI_TARGET_SYSTEM_WINDOWS) +#TODO: sel_main_objs = [env.ComponentObject('nacl_test_injection_main.c')] + add_library(nacl_test_injection_main OBJECT "nacl_test_injection_main.c") + list(APPEND LDR_LIBS nacl_test_injection_main) + + if (YOKAI_TARGET_SYSTEM_LINUX_COMPATIBILITY) + # FIXME: librt was added by src/shared/imc/build.scons for Linux but not Android. + # FIXME: libdl was added by (root)/SConstruct for Linux on armhf and Android on armel. + # get_plugin_dirname.cc has a dependency on dladdr + list(APPEND LDR_LIBS "-ldl") + list(APPEND LDR_LIBS "-lrt") + list(APPEND LDR_LIBS "-pthread") + endif() + + add_executable(sel_ldr) + target_link_libraries(sel_ldr ${LDR_LIBS}) + + if (YOKAI_TARGET_SYSTEM_MACOS) + # This target exists only to check that the service_runtime code + # can successfully be linked into a Mac OS X dynamic library. Our + # assembly code needs to be PIC-friendly and linkable in this + # context, because it is linked into a dynamic library inside + # Chromium, and OS X is strict about TEXTRELs. Without this, the + # standalone build won't catch some mistakes that can break the + # Chromium build. Linking a dylib here works because -fPIC is the + # default for all C code on OS X. +#TODO: dylib_env = env.Clone() +#TODO: dylib_env.Append(LINKFLAGS=['-bundle']) +#TODO: dylib_env.ComponentProgram('dummy_sel_ldr.dylib', sel_main_objs, EXTRA_LIBS=['sel_main']) + endif() + + # NOTE: we do not have segments on ARM +endif() + +if (YOKAI_TARGET_SYSTEM_LINUX_COMPATIBILITY AND YOKAI_TARGET_ARCH_AMD64) +#TODO: sel_ldr_seccomp_node = env.ComponentProgram('sel_ldr_seccomp', +#TODO: ['sel_ldr_seccomp_main.c'], +#TODO: EXTRA_LIBS=['sel_main', +#TODO: 'seccomp_bpf']) +#TODO: env.SDKInstallBin('sel_ldr_seccomp', sel_ldr_seccomp_node) +endif() diff --git a/src/trusted/service_runtime/linux/CMakeLists.txt b/src/trusted/service_runtime/linux/CMakeLists.txt new file mode 100644 index 0000000000..f155e5b1ff --- /dev/null +++ b/src/trusted/service_runtime/linux/CMakeLists.txt @@ -0,0 +1,123 @@ +#TODO: bootstrap_env.FilterOut(CCFLAGS=['-fstack-protector', '-fPIC', '-fPIE', '-pedantic', '$COVERAGE_CCFLAGS'], +list(APPEND BOOTSTRAP_FLAGS "-fno-pic") +list(APPEND BOOTSTRAP_FLAGS "-fno-PIC") +list(APPEND BOOTSTRAP_FLAGS "-fno-pie") +# Assumed to be what is expected, as -fno-pie was passed twice in src/trusted/service_runtime/build.scons. +list(APPEND BOOTSTRAP_FLAGS "-fno-PIE") +list(APPEND BOOTSTRAP_FLAGS "-fno-stack-protector") +# Was only a C flag in src/trusted/service_runtime/build.scons. +list(APPEND BOOTSTRAP_FLAGS "-Wdeclaration-after-statement") + +if (ANDROID) + # It is is known to break the Android build, making bits/fortify/unistd.h + # unable to find SSIZE_MAX (this may be an NDK bug). + remove_definitions(-D_FORTIFY_SOURCE=2) +endif() + +# Using optimizations when building with GCC breaks the program on armhf. +if (NOT YOKAI_CXX_COMPILER_CLANG_COMPATIBILITY) + list(APPEND BOOTSTRAP_FLAGS "-O0") +endif() + +# The src/trusted/service_runtime/build.scons file was only setting them on +# Clang but GCC accepts them as well. +if (ON) # YOKAI_CXX_COMPILER_CLANG_COMPATIBILITY) + list(APPEND BOOTSTRAP_FLAGS "-ffreestanding") + # TODO(bbudge) Remove -Qunused-arguments when Clang supports -fno-pic. + # list(APPEND BOOTSTRAP_FLAGS "-Qunused-arguments") + list(APPEND BOOTSTRAP_FLAGS "-Wno-builtin-macro-redefined") + + # FIXME: It doesn't work; CMake puts it in flags that is passed after the + # definitions and then it unsets it after overwriting it, not before. + # add_definitions("-U__STDC_HOSTED__") + + add_definitions("-D__STDC_HOSTED__=1") +endif() + +set(COMPILER_OVERRIDE "${CMAKE_CXX_COMPILER}") + +if (YOKAI_TARGET_ARCH_AMD64) + set(LD_EMUL "elf_x86_64") + + if (USE_AMD64_ZERO_BASED_SANDBOX) + # For the zero-based 64-bit sandbox, we want to reserve 44GB of address + # space: 4GB for the program plus 40GB of guard pages. Due to a binutils + # bug (see http://sourceware.org/bugzilla/show_bug.cgi?id=13400), the + # amount of address space that the linker can pre-reserve is capped + # at 4GB. For proper reservation, GNU ld version 2.22 or higher + # needs to be used. + # + # Without the bug fix, trying to reserve 44GB will result in + # pre-reserving the entire capped space of 4GB. This tricks the run-time + # into thinking that we can mmap up to 44GB. This is unsafe as it can + # overwrite the run-time program itself and/or other programs. Because + # of this, we only reserve 4GB. + # + # TODO(arbenson): remove these comments and reserve 44GB once the + # necessary ld version becomes standard. + set(RESERVE_TOP "0x100000000") + # The reserve_top value gets interpreted as a pointer in + # linux/nacl_bootstrap.c. By default, mcmodel is set to small, + # which restricts code and data to the first 2GB. With + # mcmodel set to small or medium, the reserve_top value is + # truncated, which produces an error. With mcmodel set to large, + # there is no restriction on the code and data, so we can + # safely set reserve_top to 0x100000000. + list(APPEND BOOTSTRAP_FLAGS "-mcmodel=large") + else() + set(RESERVE_TOP "0x0") + endif() +elseif (YOKAI_TARGET_ARCH_I686) + set(LD_EMUL "elf_i386") + set(RESERVE_TOP "0x40000000") +elseif (YOKAI_TARGET_ARCH_ARMHF OR YOKAI_TARGET_ARCH_ARMEL) + set(LD_EMUL "armelf_linux_eabi") + set(RESERVE_TOP "0x40002000") + + if (YOKAI_CXX_COMPILER_CLANG_COMPATIBILITY) + if (YOKAI_TARGET_SYSTEM_ANDROID) + if (YOKAI_TARGET_ARCH_ARMEL) + set(COMPILER_OVERRIDE "arm-linux-androideabi-g++") + endif() + elseif (YOKAI_TARGET_SYSTEM_LINUX_COMPATIBILITY) + if (YOKAI_TARGET_ARCH_ARMHF) + set(COMPILER_OVERRIDE "arm-linux-gnueabihf-g++") + elseif (YOKAI_TARGET_ARCH_ARMEL) + set(COMPILER_OVERRIDE "arm-linux-gnueabi-g++") + endif() + endif() + endif() +elseif (YOKAI_TARGET_ARCH_MIPSEL) + set(LD_EMUL "elf32ltsmip") + set(RESERVE_TOP "0x40008000") +endif() + +string(REPLACE ";" " " BOOTSTRAP_FLAGS_STRING "${BOOTSTRAP_FLAGS}") + +add_library(nacl_bootstrap OBJECT "nacl_bootstrap.c") +set_target_properties(nacl_bootstrap PROPERTIES COMPILE_FLAGS ${BOOTSTRAP_FLAGS_STRING}) + +add_custom_target(nacl_bootstrap_raw + COMMAND env "${PYTHON}" + "${CMAKE_CURRENT_LIST_DIR}/ld_bfd.py" + --compiler "${COMPILER_OVERRIDE}" + -m "${LD_EMUL}" + --build-id + -static + -z "max-page-size=0x1000" + --defsym RESERVE_TOP="${RESERVE_TOP}" + --script "${CMAKE_CURRENT_LIST_DIR}/nacl_bootstrap.x" + -o "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/nacl_bootstrap_raw" + "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/nacl_bootstrap.dir/nacl_bootstrap.c.o" + DEPENDS nacl_bootstrap + BYPRODUCTS "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/nacl_bootstrap_raw" +) + +add_custom_target(nacl_helper_bootstrap ALL + COMMAND "${PYTHON}" + "${CMAKE_CURRENT_LIST_DIR}/nacl_bootstrap_munge_phdr.py" + "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/nacl_bootstrap_raw" + "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/nacl_helper_bootstrap" + DEPENDS nacl_bootstrap_raw + BYPRODUCTS "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/nacl_helper_bootstrap" +) diff --git a/src/trusted/validator/CMakeLists.txt b/src/trusted/validator/CMakeLists.txt new file mode 100644 index 0000000000..6b94e27a22 --- /dev/null +++ b/src/trusted/validator/CMakeLists.txt @@ -0,0 +1,7 @@ +# set(NCFILEUTILS "ncfileutils${VALIDATOR_ARCH_SUFFIX}") +# add_library(${NCFILEUTILS} OBJECT "ncfileutil.c") + +add_library(validation_cache OBJECT "validation_cache.c") + +add_library(validators STATIC "validator_init.c") +target_link_libraries(validators validation_cache) diff --git a/src/trusted/validator_arm/CMakeLists.txt b/src/trusted/validator_arm/CMakeLists.txt new file mode 100644 index 0000000000..348a994660 --- /dev/null +++ b/src/trusted/validator_arm/CMakeLists.txt @@ -0,0 +1,98 @@ +# Android compiler cannot compile NDK C++ headers with these. + +if (YOKAI_TARGET_SYSTEM_LINUX_COMPATIBILITY AND NOT YOKAI_TARGET_SYSTEM_ANDROID) + # TODO(cbiffle): give everyone else these warnings too. + # TODO(karl): Why does -fno-rtti cause linking issues. + # CXXFLAGS='-Weffc++ -Woverloaded-virtual -fno-rtti -fomit-frame-pointer', + list(APPEND VALIDATOR_FLAGS -Weffc) + list(APPEND VALIDATOR_FLAGS -Woverloaded-virtual) + list(APPEND VALIDATOR_FLAGS -fomit-frame-pointer) +endif() + +list(APPEND GEN_TEST_LIST + # Generated table file names. + "gen/arm32_decode_advanced_simd_data_processing_instructions_tests.cc" + "gen/arm32_decode_advanced_simd_element_or_structure_load_store_instructions_tests.cc" + "gen/arm32_decode_ARMv7_tests.cc" + "gen/arm32_decode_branch_branch_with_link_and_block_data_transfer_tests.cc" + "gen/arm32_decode_coprocessor_instructions_and_supervisor_call_tests.cc" + "gen/arm32_decode_data_processing_and_miscellaneous_instructions_tests.cc" + "gen/arm32_decode_data_processing_immediate_tests.cc" + "gen/arm32_decode_data_processing_register_shifted_register_tests.cc" + "gen/arm32_decode_data_processing_register_tests.cc" + "gen/arm32_decode_extension_register_load_store_instructions_tests.cc" + "gen/arm32_decode_extra_load_store_instructions_tests.cc" + "gen/arm32_decode_floating_point_data_processing_instructions_tests.cc" + "gen/arm32_decode_halfword_multiply_and_multiply_accumulate_tests.cc" + "gen/arm32_decode_load_store_word_and_unsigned_byte_tests.cc" + "gen/arm32_decode_media_instructions_tests.cc" + "gen/arm32_decode_memory_hints_advanced_simd_instructions_and_miscellaneous_instructions_tests.cc" + "gen/arm32_decode_miscellaneous_instructions_tests.cc" + "gen/arm32_decode_msr_immediate_and_hints_tests.cc" + "gen/arm32_decode_multiply_and_multiply_accumulate_tests.cc" + "gen/arm32_decode_other_floating_point_data_processing_instructions_tests.cc" + "gen/arm32_decode_packing_unpacking_saturation_and_reversal_tests.cc" + "gen/arm32_decode_parallel_addition_and_subtraction_signed_tests.cc" + "gen/arm32_decode_parallel_addition_and_subtraction_unsigned_tests.cc" + "gen/arm32_decode_saturating_addition_and_subtraction_tests.cc" + "gen/arm32_decode_signed_multiply_signed_and_unsigned_divide_tests.cc" + "gen/arm32_decode_simd_dp_1imm_tests.cc" + "gen/arm32_decode_simd_dp_2misc_tests.cc" + "gen/arm32_decode_simd_dp_2scalar_tests.cc" + "gen/arm32_decode_simd_dp_2shift_tests.cc" + "gen/arm32_decode_simd_dp_3diff_tests.cc" + "gen/arm32_decode_simd_dp_3same_tests.cc" + "gen/arm32_decode_synchronization_primitives_tests.cc" + "gen/arm32_decode_transfer_between_arm_core_and_extension_register_8_16_and_32_bit_tests.cc" + "gen/arm32_decode_transfer_between_arm_core_and_extension_registers_64_bit_tests.cc" + "gen/arm32_decode_unconditional_instructions_tests.cc" +) + +list(APPEND GEN_ACTUAL_LIST + "gen/arm32_decode_actuals_1.cc" + "gen/arm32_decode_actuals_1.h" + "gen/arm32_decode_actuals_2.cc" + "gen/arm32_decode_actuals_2.h" +) + +list(APPEND GEN_BASELINE_LIST + "gen/arm32_decode_baselines_1.cc" + "gen/arm32_decode_baselines_1.h" + "gen/arm32_decode_baselines_2.cc" + "gen/arm32_decode_baselines_2.h" + "gen/arm32_decode_baselines_3.cc" + "gen/arm32_decode_baselines_3.h" +) + +list(APPEND GEN_OTHER_LIST + "gen/arm32_decode.cc" + "gen/arm32_decode.h" + "gen/arm32_decode_actuals.h" + "gen/arm32_decode_baselines.h" +# "gen/arm32_decode_named.cc" # Why? + "gen/arm32_decode_named_classes.h" + "gen/arm32_decode_named_bases.h" + "gen/arm32_decode_named_decoder.h" + ${GEN_ACTUAL_LIST} + ${GEN_BASELINE_LIST} +) + +list(APPEND VALIDATOR_INPUTS + "address_set.cc" + "inst_classes.cc" + "model.cc" + "arm_helpers.cc" + "validator.cc" +) + +string(REPLACE ";" " " VALIDATOR_FLAGS_STRING "${VALIDATOR_FLAGS}") + +add_library(arm_validator_core OBJECT ${VALIDATOR_INPUTS} ${GEN_OTHER_LIST}) +set_target_properties(arm_validator_core PROPERTIES FLAGS "${VALIDATOR_FLAGS_STRING}") + +add_library(ncvalidate_arm_v2 STATIC "ncvalidate.cc") +target_link_libraries(ncvalidate_arm_v2 arm_validator_core) # We don't support OPTIONAL_COVERAGE_LIBS. +set_target_properties(ncvalidate_arm_v2 PROPERTIES FLAGS "${VALIDATOR_FLAGS_STRING}") + +add_library(arm_validator_reporters STATIC "problem_reporter.cc") +set_target_properties(arm_validator_reporters PROPERTIES FLAGS "${VALIDATOR_FLAGS_STRING}") diff --git a/src/trusted/validator_mips/CMakeLists.txt b/src/trusted/validator_mips/CMakeLists.txt new file mode 100644 index 0000000000..29fcb2f2e2 --- /dev/null +++ b/src/trusted/validator_mips/CMakeLists.txt @@ -0,0 +1,21 @@ +if (YOKAI_TARGET_SYSTEM_LINUX_COMPATIBILITY AND NOT YOKAI_TARGET_SYSTEM_ANDROID) + list(APPEND VALIDATOR_FLAGS -Weffc) + list(APPEND VALIDATOR_FLAGS -Woverloaded-virtual) + list(APPEND VALIDATOR_FLAGS -fno-rtti) + list(APPEND VALIDATOR_FLAGS -fomit-frame-pointer) +endif() + +list(APPEND VALIDATOR_INPUTS + "address_set.cc" + "validator.cc" + "gen/decode.cc" +) + +string(REPLACE ";" " " VALIDATOR_FLAGS_STRING "${VALIDATOR_FLAGS}") + +add_library(mips_validator_core OBJECT ${VALIDATOR_INPUTS}) +set_target_properties(mips_validator_core PROPERTIES FLAGS "${VALIDATOR_FLAGS_STRING}") + +add_library(ncvalidate_mips STATIC "ncvalidate.cc") +target_link_libraries(ncvalidate_mips mips_validator_core) # We don't support OPTIONAL_COVERAGE_LIBS. +set_target_properties(ncvalidate_mips PROPERTIES FLAGS "${VALIDATOR_FLAGS_STRING}") diff --git a/src/trusted/validator_ragel/CMakeLists.txt b/src/trusted/validator_ragel/CMakeLists.txt new file mode 100644 index 0000000000..8507a0c8d1 --- /dev/null +++ b/src/trusted/validator_ragel/CMakeLists.txt @@ -0,0 +1,34 @@ +add_definitions("-DVALIDATOR_EXPORT=DLLEXPORT") + +# src/trusted/validator_ragel/build.scons built both for both bitness +# because it was needed for the rdfa_validator library which looks to +# only be used for running some benchmark. +if (YOKAI_TARGET_ARCH_I686) + set(VALIDATOR_LIB validator32) + add_library(${VALIDATOR_LIB} OBJECT "gen/validator_x86_32.c") +elseif (YOKAI_TARGET_ARCH_AMD64) + set(VALIDATOR_LIB validator64) + add_library(${VALIDATOR_LIB} OBJECT "gen/validator_x86_64.c") +endif() + +add_library(validator_features_all OBJECT "validator_features_all.c") +list(APPEND FEATURES_LIBS validator_features_all) +add_library(validator_features_validator OBJECT "validator_features_validator.c") +list(APPEND FEATURES_LIBS validator_features_validator) + +if (YOKAI_TARGET_ARCH_I686) + set(DFA_VALIDATE_CALLER_INPUTS + "dfa_validate_32.c" + "dfa_validate_common.c" + ) +elseif (YOKAI_TARGET_ARCH_AMD64) + set(DFA_VALIDATE_CALLER_INPUTS + "dfa_validate_64.c" + "dfa_validate_common.c" + ) +endif() + +add_library(dfa_validate_caller${VALIDATOR_ARCH_SUFFIX} STATIC ${DFA_VALIDATE_CALLER_INPUTS}) +target_link_libraries(dfa_validate_caller${VALIDATOR_ARCH_SUFFIX} ${FEATURES_LIBS} ${VALIDATOR_LIB}) + +add_library(dfa_validate_caller ALIAS dfa_validate_caller${VALIDATOR_ARCH_SUFFIX}) diff --git a/src/trusted/validator_x86/CMakeLists.txt b/src/trusted/validator_x86/CMakeLists.txt new file mode 100644 index 0000000000..add762847c --- /dev/null +++ b/src/trusted/validator_x86/CMakeLists.txt @@ -0,0 +1,6 @@ +list(APPEND NCCOPY_INPUTS + "nccopycode.c" + "nccopycode_stores.S" +) + +add_library(nccopy STATIC ${NCCOPY_INPUTS}) From f3d4d4a4f101d89ff7484e4f97c961afd0d4cbad Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Mon, 13 Oct 2025 08:35:46 +0200 Subject: [PATCH 24/36] cmake: fix building nacl_helper_bootstrap with zero-based 64-bit sandbox with Clang --- src/trusted/service_runtime/linux/CMakeLists.txt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/trusted/service_runtime/linux/CMakeLists.txt b/src/trusted/service_runtime/linux/CMakeLists.txt index f155e5b1ff..75680efa89 100644 --- a/src/trusted/service_runtime/linux/CMakeLists.txt +++ b/src/trusted/service_runtime/linux/CMakeLists.txt @@ -63,7 +63,11 @@ if (YOKAI_TARGET_ARCH_AMD64) # truncated, which produces an error. With mcmodel set to large, # there is no restriction on the code and data, so we can # safely set reserve_top to 0x100000000. - list(APPEND BOOTSTRAP_FLAGS "-mcmodel=large") + if (DAEMON_CXX_COMPILER_Clang_COMPATIBILITY) + list(APPEND BOOTSTRAP_FLAGS "-mcmodel=medium") + else() + list(APPEND BOOTSTRAP_FLAGS "-mcmodel=large") + endif() else() set(RESERVE_TOP "0x0") endif() From 92805b2e4d0c6bbf26b067fe08a673cdec96c01c Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Mon, 13 Oct 2025 08:54:31 +0200 Subject: [PATCH 25/36] cmake: use size optimization for nacl_helper_bootstrap, with toplevel-reorder disabled on armhf The -ftoplevel-reorder option breaks the build for armhf. --- src/trusted/service_runtime/linux/CMakeLists.txt | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/trusted/service_runtime/linux/CMakeLists.txt b/src/trusted/service_runtime/linux/CMakeLists.txt index 75680efa89..5f68292014 100644 --- a/src/trusted/service_runtime/linux/CMakeLists.txt +++ b/src/trusted/service_runtime/linux/CMakeLists.txt @@ -14,9 +14,12 @@ if (ANDROID) remove_definitions(-D_FORTIFY_SOURCE=2) endif() -# Using optimizations when building with GCC breaks the program on armhf. -if (NOT YOKAI_CXX_COMPILER_CLANG_COMPATIBILITY) - list(APPEND BOOTSTRAP_FLAGS "-O0") +list(APPEND BOOTSTRAP_FLAGS "-Os") + +# Using this optimization when building with GCC breaks the program on armhf: +# > Illegal instruction +if (NOT YOKAI_CXX_COMPILER_CLANG_COMPATIBILITY AND (YOKAI_TARGET_ARCH_ARMHF OR YOKAI_TARGET_ARCH_ARMEL)) + list(APPEND BOOTSTRAP_FLAGS -fno-toplevel-reorder) endif() # The src/trusted/service_runtime/build.scons file was only setting them on From 64f68e4c9f4d23d6b5a3b711ca36eb6f76420e03 Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Thu, 18 Dec 2025 17:58:46 +0100 Subject: [PATCH 26/36] cmake: discard extra sections linking nacl_helper_bootstrap See d281e6a3f08a13a7c7ba6ffd7160b2267a3c8765 --- src/trusted/service_runtime/linux/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/trusted/service_runtime/linux/CMakeLists.txt b/src/trusted/service_runtime/linux/CMakeLists.txt index 5f68292014..b4b8e58d56 100644 --- a/src/trusted/service_runtime/linux/CMakeLists.txt +++ b/src/trusted/service_runtime/linux/CMakeLists.txt @@ -113,6 +113,7 @@ add_custom_target(nacl_bootstrap_raw -static -z "max-page-size=0x1000" --defsym RESERVE_TOP="${RESERVE_TOP}" + --orphan-handling=discard --script "${CMAKE_CURRENT_LIST_DIR}/nacl_bootstrap.x" -o "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/nacl_bootstrap_raw" "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/nacl_bootstrap.dir/nacl_bootstrap.c.o" From 965f9a28e44ce0e9c4b9d876a7c534cbd41bab1f Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Fri, 26 Jun 2026 00:43:42 +0200 Subject: [PATCH 27/36] cmake: add install target --- src/trusted/service_runtime/CMakeLists.txt | 1 + src/trusted/service_runtime/linux/CMakeLists.txt | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/src/trusted/service_runtime/CMakeLists.txt b/src/trusted/service_runtime/CMakeLists.txt index 77c9969d9c..f7f2dc4afd 100644 --- a/src/trusted/service_runtime/CMakeLists.txt +++ b/src/trusted/service_runtime/CMakeLists.txt @@ -374,6 +374,7 @@ if (NOT COVERAGE_ENABLED OR NOT YOKAI_TARGET_SYSTEM_WINDOWS) add_executable(sel_ldr) target_link_libraries(sel_ldr ${LDR_LIBS}) + install(TARGETS sel_ldr DESTINATION bin) if (YOKAI_TARGET_SYSTEM_MACOS) # This target exists only to check that the service_runtime code diff --git a/src/trusted/service_runtime/linux/CMakeLists.txt b/src/trusted/service_runtime/linux/CMakeLists.txt index b4b8e58d56..e8195c78cd 100644 --- a/src/trusted/service_runtime/linux/CMakeLists.txt +++ b/src/trusted/service_runtime/linux/CMakeLists.txt @@ -129,3 +129,8 @@ add_custom_target(nacl_helper_bootstrap ALL DEPENDS nacl_bootstrap_raw BYPRODUCTS "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/nacl_helper_bootstrap" ) + +install(PROGRAMS + "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/nacl_helper_bootstrap" + DESTINATION bin +) From 10c0aae4e941e2745dbaafddb45568f6d0f0cd77 Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Fri, 26 Jun 2026 23:35:24 +0200 Subject: [PATCH 28/36] cmake: use path sanitization --- cmake/NaClFlags.cmake | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/cmake/NaClFlags.cmake b/cmake/NaClFlags.cmake index 6091cbc4f6..f40ec2914f 100644 --- a/cmake/NaClFlags.cmake +++ b/cmake/NaClFlags.cmake @@ -82,6 +82,27 @@ macro(set_linker_flag FLAG) endforeach() endmacro() +option(USE_PATH_SANITIZATION "Tell the compiler to remove build-specific paths from generated binaries." ON) + +if (USE_PATH_SANITIZATION) + if (YOKAI_CXX_COMPILER_MSVC) + set(path_sanitization_flags + "/FC-" + "/pathmap:${CMAKE_CURRENT_SOURCE_DIR}=." + ) + else() + set(path_sanitization_flags + "-ffile-prefix-map=${CMAKE_CURRENT_SOURCE_DIR}=." + "-fmacro-prefix-map=${CMAKE_CURRENT_SOURCE_DIR}=." + "-fdebug-prefix-map=${CMAKE_CURRENT_SOURCE_DIR}=." + ) + endif() + + foreach(path_sanitization_flag ${path_sanitization_flags}) + set_compiler_flag("${path_sanitization_flag}") + endforeach() +endif() + #TODO: Import from SetUpClang() from (root)/SConstruct. #TODO: This is mostly ASAN configurations. From 3085d995bc9a77ac1e3a3c88c74d3f428e701948 Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Thu, 10 Apr 2025 03:18:00 +0200 Subject: [PATCH 29/36] bootstrap: force alignement to make possible to build nacl_helper_bootstrap with a different page size --- src/trusted/service_runtime/linux/nacl_bootstrap.x | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/trusted/service_runtime/linux/nacl_bootstrap.x b/src/trusted/service_runtime/linux/nacl_bootstrap.x index 93051f1058..442effce20 100644 --- a/src/trusted/service_runtime/linux/nacl_bootstrap.x +++ b/src/trusted/service_runtime/linux/nacl_bootstrap.x @@ -108,9 +108,9 @@ SECTIONS { * It just maps it from the file, i.e. way off the end of the file, * which is perfect for reserving the address space. */ - . = ALIGN(CONSTANT(COMMONPAGESIZE)); + . = ALIGN(CONSTANT(MAXPAGESIZE)); RESERVE_START = .; - .reserve : { + .reserve : ALIGN(CONSTANT(MAXPAGESIZE)) { . += (RESERVE_TOP > RESERVE_START) ? (RESERVE_TOP - RESERVE_START) : 0; } :reserve From 1204c38c89dc120d5be56ce9c2c9bf64ee5417a5 Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Thu, 10 Apr 2025 03:18:00 +0200 Subject: [PATCH 30/36] scons: build arm sel_ldr and nacl_helper_bootstrap with 64K page size Build arm sel_ldr and nacl_helper_bootstrap with 64K page size alignment. Makes it compatible with 16k page size kernels. SCons plumbing. --- SConstruct | 6 +++++- src/trusted/service_runtime/build.scons | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/SConstruct b/SConstruct index b933ab7d74..dbfe995d15 100755 --- a/SConstruct +++ b/SConstruct @@ -2698,6 +2698,8 @@ def MakeGenericLinuxEnv(platform=None): LINK = '$CXX', ) + linux_env.SetDefault(MAX_PAGE_SIZE='0x1000') + # Prepend so we can disable warnings via Append linux_env.Prepend( CPPDEFINES = [['_POSIX_C_SOURCE', '199506'], @@ -2717,6 +2719,7 @@ def MakeGenericLinuxEnv(platform=None): LINKFLAGS = ['-m64'] + sysroot_flags, ) elif linux_env.Bit('build_arm'): + linux_env.Replace(MAX_PAGE_SIZE='0x10000') SetUpLinuxEnvArm(linux_env) elif linux_env.Bit('build_mips32'): SetUpLinuxEnvMips(linux_env) @@ -2742,7 +2745,8 @@ def MakeGenericLinuxEnv(platform=None): linux_env.Prepend(SHLINKFLAGS=['$COMMON_LINKFLAGS']) linux_env.Prepend(COMMON_LINKFLAGS=['-Wl,-z,relro', '-Wl,-z,now', - '-Wl,-z,noexecstack']) + '-Wl,-z,noexecstack', + '-Wl,-z,max-page-size=${MAX_PAGE_SIZE}']) linux_env.Prepend(LINKFLAGS=['-pie']) # The ARM toolchain has a linker that doesn't handle the code its # compiler generates under -fPIE. diff --git a/src/trusted/service_runtime/build.scons b/src/trusted/service_runtime/build.scons index ab6c0d3cd0..3aae8f55a6 100644 --- a/src/trusted/service_runtime/build.scons +++ b/src/trusted/service_runtime/build.scons @@ -427,7 +427,7 @@ if (env.Bit('linux') and not env.Bit('built_elsewhere')): 'nacl_bootstrap_raw', [bootstrap_obj], ("env CXX='${CXX}' ${PYTHON} %s %s " + - '-m %s --build-id -static -z max-page-size=0x1000 ' + + '-m %s --build-id -static -z max-page-size=${MAX_PAGE_SIZE} ' + '--orphan-handling=discard ' + '--defsym RESERVE_TOP=%s --script %s -o ${TARGET} ${SOURCES}') % (bootstrap_env.File('linux/ld_bfd.py'), compiler_override, ld_emul, From 882d4e458ed9e576b32812679ba5cf41b635fa0b Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Thu, 10 Apr 2025 03:18:00 +0200 Subject: [PATCH 31/36] cmake: build arm sel_ldr and nacl_helper_bootstrap with 64K page size Build arm sel_ldr and nacl_helper_bootstrap with 64K page size alignment. Makes it compatible with 16k page size kernels. CMake plumbing. --- cmake/NaClFlags.cmake | 14 ++++++++++++++ src/trusted/service_runtime/linux/CMakeLists.txt | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/cmake/NaClFlags.cmake b/cmake/NaClFlags.cmake index f40ec2914f..c7c4d41afc 100644 --- a/cmake/NaClFlags.cmake +++ b/cmake/NaClFlags.cmake @@ -103,6 +103,20 @@ if (USE_PATH_SANITIZATION) endforeach() endif() +if (YOKAI_TARGET_SYSTEM_LINUX_COMPATIBILITY) + if (YOKAI_TARGET_ARCH_ARMHF) + option(USE_ARMHF_LARGE_PAGESIZE "Build armhf binaries with large page size." ON) + endif() + + if (USE_ARMHF_LARGE_PAGESIZE) + set(MAX_PAGE_SIZE 0x10000) + else() + set(MAX_PAGE_SIZE 0x1000) + endif() + + set_linker_flag("-Wl,-z,max-page-size=${MAX_PAGE_SIZE}") +endif() + #TODO: Import from SetUpClang() from (root)/SConstruct. #TODO: This is mostly ASAN configurations. diff --git a/src/trusted/service_runtime/linux/CMakeLists.txt b/src/trusted/service_runtime/linux/CMakeLists.txt index e8195c78cd..020b51b6af 100644 --- a/src/trusted/service_runtime/linux/CMakeLists.txt +++ b/src/trusted/service_runtime/linux/CMakeLists.txt @@ -111,7 +111,7 @@ add_custom_target(nacl_bootstrap_raw -m "${LD_EMUL}" --build-id -static - -z "max-page-size=0x1000" + -z "max-page-size=${MAX_PAGE_SIZE}" --defsym RESERVE_TOP="${RESERVE_TOP}" --orphan-handling=discard --script "${CMAKE_CURRENT_LIST_DIR}/nacl_bootstrap.x" From beca906f9175f46f88e7219c274b70fe52419ffd Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Tue, 7 Jul 2026 10:12:30 +0200 Subject: [PATCH 32/36] win32: disable DEP qualifications outside of MSVC --- src/trusted/platform_qualify/win/nacl_dep_qualify.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/trusted/platform_qualify/win/nacl_dep_qualify.c b/src/trusted/platform_qualify/win/nacl_dep_qualify.c index e687fdafeb..f394225fb2 100644 --- a/src/trusted/platform_qualify/win/nacl_dep_qualify.c +++ b/src/trusted/platform_qualify/win/nacl_dep_qualify.c @@ -19,6 +19,7 @@ int NaClAttemptToExecuteDataAtAddr(uint8_t *thunk_buffer, size_t size) { +#if defined(_MSC_VER) int got_fault = 0; nacl_void_thunk thunk = NaClGenerateThunk(thunk_buffer, size); __try { @@ -28,12 +29,16 @@ int NaClAttemptToExecuteDataAtAddr(uint8_t *thunk_buffer, size_t size) { got_fault = 1; } return got_fault; +#else + return 1; +#endif } /* * Returns 1 if Data Execution Prevention is present and working. */ int NaClAttemptToExecuteData(void) { +#if defined(_MSC_VER) int result; uint8_t *thunk_buffer = malloc(64); if (NULL == thunk_buffer) { @@ -42,4 +47,7 @@ int NaClAttemptToExecuteData(void) { result = NaClAttemptToExecuteDataAtAddr(thunk_buffer, 64); free(thunk_buffer); return result; +#else + return 1; +#endif } From 6db3cdbecd872f9e7318a5d42c5ebfa60fd704e1 Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Tue, 7 Jul 2026 12:34:27 +0200 Subject: [PATCH 33/36] posix: g_prereserved_sandbox_size only exists on Linux, not on macOS --- src/trusted/service_runtime/posix/addrspace_teardown.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/trusted/service_runtime/posix/addrspace_teardown.c b/src/trusted/service_runtime/posix/addrspace_teardown.c index 08f0483265..20e72412a4 100644 --- a/src/trusted/service_runtime/posix/addrspace_teardown.c +++ b/src/trusted/service_runtime/posix/addrspace_teardown.c @@ -18,10 +18,12 @@ void NaClAddrSpaceFree(struct NaClApp *nap) { uintptr_t addrsp_size = (uintptr_t) 1U << nap->addr_bits; size_t full_size = (NACL_ADDRSPACE_LOWER_GUARD_SIZE + addrsp_size + NACL_ADDRSPACE_UPPER_GUARD_SIZE); +#if NACL_LINUX if (g_prereserved_sandbox_size > 0) { NaClLog(LOG_WARNING, "NaClAddrSpaceFree: can't unmap when memory is prereserved by bootstrap helper\n"); return; } +#endif if (munmap(base, full_size) != 0) { NaClLog(LOG_FATAL, "NaClAddrSpaceFree: munmap() failed, errno %d\n", errno); From dc56f6e6d0c340dac7611bd2a2edd5d2bbc06e94 Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Tue, 7 Jul 2026 14:38:22 +0200 Subject: [PATCH 34/36] cmake: standardize found executable path variable name --- CMakeLists.txt | 6 +++--- src/trusted/service_runtime/CMakeLists.txt | 2 +- src/trusted/service_runtime/linux/CMakeLists.txt | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5e117e3e90..f8b4a03bf2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -49,7 +49,7 @@ endif() if (REQUIRE_PYTHON) if (NOT PYTHON) - find_program(PYTHON NAMES "python3" DOC "Path to the python3 executable." REQUIRED) + find_program(PATH_PYTHON NAMES "python3" DOC "Path to the python3 executable." REQUIRED) endif() endif() @@ -57,9 +57,9 @@ if (REQUIRE_MASM) if (YOKAI_CXX_COMPILER_MINGW AND NOT CMAKE_ASM_MASM_COMPILER) include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include-hax/fake_masm") - find_program(JWASM NAMES "jwasm" DOC "Path to the JWasm executable." REQUIRED) + find_program(PATH_JWASM NAMES "jwasm" DOC "Path to the JWasm executable." REQUIRED) - set(CMAKE_ASM_MASM_COMPILER "${JWASM}") + set(CMAKE_ASM_MASM_COMPILER "${PATH_JWASM}") if (YOKAI_TARGET_ARCH_I686) list(APPEND CMAKE_ASM_MASM_FLAGS "-coff") diff --git a/src/trusted/service_runtime/CMakeLists.txt b/src/trusted/service_runtime/CMakeLists.txt index f7f2dc4afd..7247b09e96 100644 --- a/src/trusted/service_runtime/CMakeLists.txt +++ b/src/trusted/service_runtime/CMakeLists.txt @@ -164,7 +164,7 @@ elseif (YOKAI_TARGET_SYSTEM_MACOS) include_directories("${GENERATED_ROOT}") execute_process( - COMMAND "${PYTHON}" + COMMAND "${PATH_PYTHON}" "${CMAKE_CURRENT_LIST_DIR}/osx/run_mig.py" "${GENERATED_NACL_EXC_DEFS}" "${GENERATED_NACL_EXC_H}" diff --git a/src/trusted/service_runtime/linux/CMakeLists.txt b/src/trusted/service_runtime/linux/CMakeLists.txt index 020b51b6af..a0db360d90 100644 --- a/src/trusted/service_runtime/linux/CMakeLists.txt +++ b/src/trusted/service_runtime/linux/CMakeLists.txt @@ -105,7 +105,7 @@ add_library(nacl_bootstrap OBJECT "nacl_bootstrap.c") set_target_properties(nacl_bootstrap PROPERTIES COMPILE_FLAGS ${BOOTSTRAP_FLAGS_STRING}) add_custom_target(nacl_bootstrap_raw - COMMAND env "${PYTHON}" + COMMAND env "${PATH_PYTHON}" "${CMAKE_CURRENT_LIST_DIR}/ld_bfd.py" --compiler "${COMPILER_OVERRIDE}" -m "${LD_EMUL}" @@ -122,7 +122,7 @@ add_custom_target(nacl_bootstrap_raw ) add_custom_target(nacl_helper_bootstrap ALL - COMMAND "${PYTHON}" + COMMAND "${PATH_PYTHON}" "${CMAKE_CURRENT_LIST_DIR}/nacl_bootstrap_munge_phdr.py" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/nacl_bootstrap_raw" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/nacl_helper_bootstrap" From 8a85cf52d9f33cc9c3a184d71568fb28f344378d Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Tue, 7 Jul 2026 14:40:48 +0200 Subject: [PATCH 35/36] cmake: configure jwasm anytime on mingw, even if explicitly provided --- CMakeLists.txt | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f8b4a03bf2..0b1ca7de87 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -54,12 +54,14 @@ if (REQUIRE_PYTHON) endif() if (REQUIRE_MASM) - if (YOKAI_CXX_COMPILER_MINGW AND NOT CMAKE_ASM_MASM_COMPILER) - include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include-hax/fake_masm") + if (YOKAI_CXX_COMPILER_MINGW) + if (NOT CMAKE_ASM_MASM_COMPILER) + find_program(PATH_JWASM NAMES "jwasm" DOC "Path to the JWasm executable." REQUIRED) - find_program(PATH_JWASM NAMES "jwasm" DOC "Path to the JWasm executable." REQUIRED) + set(CMAKE_ASM_MASM_COMPILER "${PATH_JWASM}") + endif() - set(CMAKE_ASM_MASM_COMPILER "${PATH_JWASM}") + include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include-hax/fake_masm") if (YOKAI_TARGET_ARCH_I686) list(APPEND CMAKE_ASM_MASM_FLAGS "-coff") From d949bc3daeaa60e8302d75e391f88663f95c9e19 Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Tue, 7 Jul 2026 13:32:11 +0200 Subject: [PATCH 36/36] WIP: CI --- .azure-pipeline.yml | 115 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 .azure-pipeline.yml diff --git a/.azure-pipeline.yml b/.azure-pipeline.yml new file mode 100644 index 0000000000..5c9c468dcf --- /dev/null +++ b/.azure-pipeline.yml @@ -0,0 +1,115 @@ +# Documentation: https://wiki.unvanquished.net/wiki/Continuous_integration + +trigger: + branches: + include: + - master + +pr: + branches: + include: + - '*' + paths: + include: + - .azure-pipelines.yml + - src/ + - include-hax/ + - cmake/ + - CMakeLists.txt + +strategy: + matrix: + Linux amd64 GCC: + VM_IMAGE: 'ubuntu-22.04' + APT_PACKAGES: ninja-build g++-10 + C_COMPILER: gcc-10 + CXX_COMPILER: g++-10 + Linux i686 GCC: + VM_IMAGE: 'ubuntu-22.04' + APT_PACKAGES: ninja-build g++-i686-linux-gnu + C_COMPILER: i686-linux-gnu-gcc + CXX_COMPILER: i686-linux-gnu-g++ + COMPILER_FLAGS: -mfpmath=sse -msse + Linux armhf GCC: + # There is an IO bug in qemu-arm from ubuntu-22.04. + VM_IMAGE: 'ubuntu-24.04' + APT_PACKAGES: ninja-build g++-arm-linux-gnueabihf qemu-user + C_COMPILER: arm-linux-gnueabihf-gcc + CXX_COMPILER: arm-linux-gnueabihf-g++ + EXE_RUNNER: qemu-arm -L /usr/arm-linux-gnueabihf + Linux amd64 Clang: + VM_IMAGE: 'ubuntu-22.04' + APT_PACKAGES: ninja-build + C_COMPILER: clang + CXX_COMPILER: clang++ + Windows amd64 MinGW: + VM_IMAGE: 'ubuntu-22.04' + APT_PACKAGES: ninja-build g++-mingw-w64-x86-64 mingw-w64-x86-64-dev gcc-mingw-w64-x86-64-posix-runtime wine + SETUP_COMMANDS: sudo update-alternatives --set x86_64-w64-mingw32-g++ /usr/bin/x86_64-w64-mingw32-g++-posix + TOOLCHAIN_FILE: cmake/cross-toolchain-mingw64.cmake + EXE_RUNNER: wine + EXE_EXT: .exe + WITH_JWASM: true + Windows i686 MinGW: + VM_IMAGE: 'ubuntu-22.04' + APT_ARCHITECTURE: i386 + APT_PACKAGES: ninja-build g++-mingw-w64-i686 mingw-w64-i686-dev gcc-mingw-w64-i686-posix-runtime wine wine32 + SETUP_COMMANDS: sudo update-alternatives --set i686-w64-mingw32-g++ /usr/bin/i686-w64-mingw32-g++-posix + TOOLCHAIN_FILE: cmake/cross-toolchain-mingw32.cmake + COMPILER_FLAGS: -mfpmath=sse -msse + EXE_RUNNER: wine + EXE_EXT: .exe + WITH_JWASM: true + macOS amd64 AppleClang: + VM_IMAGE: 'macOS-14' + CMAKE_GENERATOR: Unix Makefiles + NPROC_COMMAND: sysctl -n hw.logicalcpu + +pool: + vmImage: $(VM_IMAGE) + +steps: +- bash: | + set -xue + if [ -n "${APT_ARCHITECTURE:-}" ]; then + sudo dpkg --add-architecture "${APT_ARCHITECTURE}" + fi + if [ -n "${APT_PACKAGES:-}" ]; then + sudo apt-get update && sudo apt-get -y -q --no-install-recommends install ${APT_PACKAGES} + fi + if [ -n "${SETUP_COMMANDS:-}" ]; then + $(SETUP_COMMANDS) + fi + displayName: 'Setup' +- bash: | + set -xue + export CMAKE_BUILD_PARALLEL_LEVEL="$(${NPROC_COMMAND:-nproc})" + echo "${CMAKE_BUILD_PARALLEL_LEVEL}" + cmake_args=(-G"${CMAKE_GENERATOR:-Ninja}") + if "${WITH_JWASM:-false}"; then + git clone https://github.com/JWasm/JWasm.git build/jwasm + cmake -Sbuild/jwasm -Bbuild/jwasm/build + cmake --build build/jwasm/build --config Release + # No EXE_EXT, this is a native tool. + cmake_args+=(-DCMAKE_ASM_MASM_COMPILER="$(realpath build/jwasm/build/jwasm)") + fi + if [ -n "${TOOLCHAIN_FILE:-}" ]; then + cmake_args+=(-DCMAKE_TOOLCHAIN_FILE="${TOOLCHAIN_FILE}") + fi + if [ -n "${C_COMPILER:-}" ]; then + cmake_args+=(-DCMAKE_C_COMPILER="${C_COMPILER}") + fi + if [ -n "${CXX_COMPILER:-}" ]; then + cmake_args+=(-DCMAKE_CXX_COMPILER="${CXX_COMPILER}") + fi + if [ -n "${COMPILER_FLAGS:-}" ]; then + cmake_args+=(-DCMAKE_C_FLAGS="${COMPILER_FLAGS}" -DCMAKE_CXX_FLAGS="${COMPILER_FLAGS}") + fi + cmake -S. -Bbuild "${cmake_args[@]}" + cmake --build build --config Release + displayName: 'Build' +- bash: | + set -xue + # TODO + true + displayName: 'Test'