Skip to content

[mk][pr] Port zircon core to mk #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 76 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
7b9b2ab
[mk][top] Port listnode from fuchsia
bherrera Feb 14, 2025
0c73476
[mk][top] Move to c++
bherrera Feb 15, 2025
87a2d58
[mk][kernel|arch] Migrate to C++ comp/linkage
bherrera Feb 17, 2025
3cb8d73
[mk][build] Add fuchsia cpp flags
bherrera Feb 15, 2025
690371d
[mk][repo] Move lib/fbl_ulib to ulib/fbl
bherrera Feb 15, 2025
e5f16b4
[mk][lib][fit] Add missing rules.mk
bherrera Feb 17, 2025
dc5c490
[mk][arch][x86] Updade arch defines
bherrera Feb 17, 2025
f6e9bd9
[mk] Add debuglog lib from fuchsia 1b726b4acdaf27dfc2b629dda07f54ede2…
bherrera Feb 14, 2025
9a95e80
[mk] Add result.h from zx ulib from fuchsia 1b726b4acdaf27dfc2b629dda…
bherrera Feb 14, 2025
190b5a9
[mk] Add concurrent ulib from fuchsia 1b726b4acdaf27dfc2b629dda07f54e…
bherrera Feb 14, 2025
f6c239f
[mk] Add kconcurrent lib from fuchsia 1b726b4acdaf27dfc2b629dda07f54e…
bherrera Feb 14, 2025
44f26bd
[mk] Add arch lib from fuchsia 1b726b4acdaf27dfc2b629dda07f54ede215063a
bherrera Feb 14, 2025
326700d
[mk] Add lazy_init lib from fuchsia 1b726b4acdaf27dfc2b629dda07f54ede…
bherrera Feb 14, 2025
253ec10
[mk] Add src/performance/lib/fxt from fuchsia 1b726b4acdaf27dfc2b629d…
bherrera Feb 15, 2025
1859363
[mk] Add lockdep ulib from fuchsia 1b726b4acdaf27dfc2b629dda07f54ede2…
bherrera Feb 15, 2025
fab0cb6
[mk] Add affine ulib from fuchsia 1b726b4acdaf27dfc2b629dda07f54ede21…
bherrera Feb 15, 2025
015797b
[mk] Add lockdep lib from fuchsia 1b726b4acdaf27dfc2b629dda07f54ede21…
bherrera Feb 15, 2025
246c4b7
[mk] Add lockup_detector lib from fuchsia 1b726b4acdaf27dfc2b629dda07…
bherrera Feb 15, 2025
3054a9b
[mk] Add ffl ulib from fuchsia 1b726b4acdaf27dfc2b629dda07f54ede215063a
bherrera Feb 15, 2025
17a4aa8
[mk] Add hwreg ulib from fuchsia 1b726b4acdaf27dfc2b629dda07f54ede215…
bherrera Feb 15, 2025
b69386d
[mk] Add mmio-ptr ulib from fuchsia 1b726b4acdaf27dfc2b629dda07f54ede…
bherrera Feb 15, 2025
664aced
[mk] Add wake-vector lib from fuchsia 1b726b4acdaf27dfc2b629dda07f54e…
bherrera Feb 17, 2025
452c425
[mk] Add counters lib from fuchsia 1b726b4acdaf27dfc2b629dda07f54ede2…
bherrera Feb 17, 2025
40e32a8
[mk] Add ktrace lib from fuchsia 1b726b4acdaf27dfc2b629dda07f54ede215…
bherrera Feb 17, 2025
4783684
[mk] Add power-management lib from fuchsia 1b726b4acdaf27dfc2b629dda0…
bherrera Feb 17, 2025
1d922cc
[mk] Add backtrace lib from fuchsia 1b726b4acdaf27dfc2b629dda07f54ede…
bherrera Feb 17, 2025
3265994
[mk] Add stall lib from fuchsia 1b726b4acdaf27dfc2b629dda07f54ede215063a
bherrera Feb 17, 2025
0fd3b11
[mk] Add mock-function ulib from fuchsia 1b726b4acdaf27dfc2b629dda07f…
bherrera Feb 20, 2025
cb2ba99
[mk][top] Use same init categories
bherrera Feb 17, 2025
ab3ac57
[mk][project] Disable some test (for now)
bherrera Feb 17, 2025
1bb8f89
[mk][platform] Migrate to C++ comp/linkage
bherrera Feb 17, 2025
41af1ab
[mk][migration] Add lk_|Lk prefix to avoid symbol clash during migration
bherrera Feb 17, 2025
dd8cb55
[mk][gn] Fix GN build
bherrera Feb 20, 2025
54c45c5
[mk][build][gn] Fix public header target
bherrera Feb 20, 2025
0f4ae3a
[mk][build][gn] Remove invocation of sdk targets
bherrera Feb 20, 2025
61c2874
[mk][build][gn] Supress checking for output dir leaks
bherrera Feb 20, 2025
5ba951d
[mk][build][gn] Add missing script to build for host
bherrera Feb 20, 2025
de9c68d
[mk][build] IMPORTANT: Deprecated makefiles build (only using GN/Ninja)
bherrera Feb 20, 2025
1cf9f4f
[mk][arch] Small asm improvements
bherrera Feb 20, 2025
3281afa
[mk][build] Add missing linux config dir
bherrera Feb 20, 2025
2a5eaa0
[mk][zircon-internal] Move from lib to ulib
bherrera Feb 20, 2025
1642a31
[mk][init] Move lk/init.h from top to lib init
bherrera Feb 20, 2025
083d42f
[mk][top] Move lk/main.h to mk/include/lk/main.h
bherrera Feb 20, 2025
d9052ee
[mk][repo] Fix clangd workspace path
bherrera Feb 20, 2025
e8a9170
[mk][build] Set output dir to build-$HOST_ARCH
bherrera Feb 20, 2025
615bc5d
[mk][fxt] Fix to mk build
bherrera Feb 20, 2025
21ab25f
[mk][ktrace] Fix for mk build
bherrera Feb 20, 2025
1fc5a55
[mk] Enable to build some libs
bherrera Feb 20, 2025
61e15c3
[mk][minip][nit] Fix ident
bherrera Feb 20, 2025
ec2946f
[mk][transition] Disable some c libs
bherrera Feb 20, 2025
35bbf37
[mk][top] Migrate init.c to init.cc
bherrera Feb 20, 2025
3671d45
[mk][arch][x86] Build cpuid
bherrera Feb 20, 2025
1590407
[mk][cbuf] Migrate to C++ comp/linkage
bherrera Feb 20, 2025
a727eb0
[mk][zx] Add missing BUILD.gn
bherrera Feb 20, 2025
ebccb1c
[mk] Add zbi-format lib from fuchsia 1b726b4acdaf27dfc2b629dda07f54ed…
bherrera Feb 20, 2025
7cb61a1
[mk] Add user_copy lib from fuchsia 1b726b4acdaf27dfc2b629dda07f54ede…
bherrera Feb 20, 2025
7125d0a
[mk][lazy_init] Move from lib to ulib
bherrera Feb 20, 2025
acc1035
[mk][libc] Move to C++ impl
bherrera Feb 20, 2025
c39aea0
[mk][vm] Port vm from fuchsia
bherrera Feb 20, 2025
80a0185
[mk] Add virtual_alloc lib from fuchsia 1b726b4acdaf27dfc2b629dda07f5…
bherrera Feb 20, 2025
26adc90
[mk][build] REWORD build.gn
bherrera Feb 20, 2025
d8ee857
[mk][concurrent] Fix to build with mk
bherrera Feb 20, 2025
8007151
[mk] Add third_party/boringssl from fuchsia 1b726b4acdaf27dfc2b629dda…
bherrera Feb 21, 2025
5bc2125
[mk][third_party] Move third_party libs to mk/third_party
bherrera Feb 21, 2025
c95abe0
[mk] Add third_party/zstd from fuchsia 1b726b4acdaf27dfc2b629dda07f54…
bherrera Feb 21, 2025
f0655a5
[mk] Add src/lib/llvm-profdata from fuchsia 1b726b4acdaf27dfc2b629dda…
bherrera Feb 21, 2025
8463072
[mk] Add src/lib/zbitl from fuchsia 1b726b4acdaf27dfc2b629dda07f54ede…
bherrera Feb 21, 2025
674970b
[mk] Add mk/third_party/lib/jitterentropy from fuchsia 1b726b4acdaf27…
bherrera Feb 21, 2025
f59f6f7
[mk] Add mk/third_party/ulib/lz4 from fuchsia 1b726b4acdaf27dfc2b629d…
bherrera Feb 21, 2025
4d289db
[mk][build] Add some build missing files
bherrera Feb 21, 2025
d24ef5c
[mk][scripts] Add grep-sed script
bherrera Feb 21, 2025
99f50a4
[mk] Add src/lib/elfldltl from fuchsia 1b726b4acdaf27dfc2b629dda07f54…
bherrera Feb 22, 2025
173cc80
[mk] Add src/lib/symbolizer-markup from fuchsia 1b726b4acdaf27dfc2b62…
bherrera Feb 22, 2025
cc80f89
[mk] Add src/lib/trivial-allocator from fuchsia 1b726b4acdaf27dfc2b62…
bherrera Feb 22, 2025
712e955
[mk] BIG BANG
bherrera Feb 24, 2025
8d28fa3
[mk][ci] Fix to update jiri
bherrera Feb 24, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
6 changes: 2 additions & 4 deletions .github/workflows/build-gn-clang.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ jobs:
run: |
export PATH=$PWD/.jiri_root/bin:$PATH
jiri import -name=integration mk https://github.com/misttech/mk-integration
jiri fetch-packages
jiri update

- name: Build
run: |
./prebuilt/third_party/gn/linux-x64/gn gen build-x64
./prebuilt/third_party/ninja/linux-x64/ninja -C build-x64
run: make gen && make all
10 changes: 9 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,12 @@ tables_generator_tests_*.txt

# Local test coverage file.
lcov.info
.coverage
.coverage

# Third party repos.
/third_party/*
!/third_party/BUILD.gn
!/third_party/boringssl/
/third_party/boringssl/src
!/third_party/zstd/
/third_party/zstd/src
1 change: 1 addition & 0 deletions .gn
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ exec_script_whitelist = [
"//build/toolchain/default_concurrent_jobs.gni",
"//build/toolchain/mk/mk_toolchain.gni",
"//build/config/clang/clang_toolchain_info.gni",
"//mk/arch/x86/phys/BUILD.gn",
]

check_system_includes = true
Expand Down
6 changes: 5 additions & 1 deletion BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ assert(
### Top-level targets.
###
group("default") {
deps = [ "//mk:kernel" ]
#testonly = true
deps = [
"//mk:kernel",
"//mk/arch/x86/phys/boot-shim",
]
}

# A GN pool matching the special Ninja 'console' pool. Any action() that
Expand Down
8 changes: 4 additions & 4 deletions build/config/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,7 @@ config("Wno-conversion") {

# To trim this list:
# $ scripts/gn/trim_visibility.py --target="//build/config:Wno-conversion"
visibility = []
#visibility = [ "//mk/third_party/ulib/cksum:*" ]
}

config("Wno-extra-semi") {
Expand All @@ -806,7 +806,7 @@ config("Wno-extra-semi") {

config("Wno-implicit-fallthrough") {
cflags = [ "-Wno-implicit-fallthrough" ]
visibility = []
#visibility = []
}

# Config to suppress Wno-unused-but-set-parameter warning in the third party code
Expand Down Expand Up @@ -837,11 +837,11 @@ config("Wno-defaulted-function-deleted") {

config("Wno-missing-prototypes") {
cflags_c = [ "-Wno-missing-prototypes" ]
visibility = []
#visibility = []
}

config("Wno-missing-declarations") {
visibility = []
#visibility = []

cflags = [ "-Wno-missing-declarations" ]
}
Expand Down
14 changes: 8 additions & 6 deletions build/config/BUILDCONFIG.gn
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ if (defined(toolchain_variant.is_basic) && toolchain_variant.is_basic) {
# Some library targets may be built as different type depending on the target
# platform. This variable specifies the default library type for each target.
if (is_mk) {
#default_library_type = "shared_library"
default_library_type = "shared_library"
} else {
default_library_type = "static_library"
}

Expand Down Expand Up @@ -445,6 +446,7 @@ if (kernel_toolchain == false) {
"//build/config:relative_paths",
"//build/config:symbol_visibility_hidden",
"//build/config:thread_safety_annotations",

#"//build/config:werror",
"//build/config:no-template-backtrace-limit",
"//build/config/kernel:compiler",
Expand Down Expand Up @@ -1127,16 +1129,16 @@ foreach(_target_type,
(defined(hermetic_action_ignored_prefixes) &&
filter_exclude(hermetic_action_ignored_prefixes,
_ignored_prefixes_allowlist) != [])) {
deps += [ "//build:non_hermetic_deps" ]
#deps += [ "//build:non_hermetic_deps" ]
}
}
if (!hermetic_toolchain || !hermetic_deps) {
# Touching this file will force all non-hermetic actions to rerun.
# This is useful for ensuring incremental build correctness, even in
# the presence of non-hermetic actions.
inputs += [ "$root_build_dir/force_nonhermetic_rebuild" ]
deps +=
[ "//build/tracer:nonhermetic_rebuild_sentinel($host_toolchain)" ]
#deps +=
# [ "//build/tracer:nonhermetic_rebuild_sentinel($host_toolchain)" ]
}

if (!should_trace) {
Expand Down Expand Up @@ -1260,7 +1262,7 @@ foreach(_target_type,

# To suppress checking for output dir leaks, in the invoker:
# no_output_dir_leaks = false
no_output_dir_leaks = true
no_output_dir_leaks = false
if (defined(invoker.no_output_dir_leaks)) {
no_output_dir_leaks = invoker.no_output_dir_leaks
} else if (string_replace("##${current_toolchain}",
Expand All @@ -1272,7 +1274,7 @@ foreach(_target_type,
}

if (!no_output_dir_leaks) {
deps += [ "//build:output_dir_leaking_allowlist" ]
#deps += [ "//build:output_dir_leaking_allowlist" ]
}

# Prevent the build output dir path from leaking into the
Expand Down
59 changes: 59 additions & 0 deletions build/config/kernel/hermetic-code-blob.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/* Copyright 2023 The Fuchsia 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 sets the entry point in the ELF file and avoids a warning about not
* setting an explicit entry point, but it has no effect. The assertion below
* ensures that the entry point is always at the beginning of the blob.
*/
ENTRY(HERMETIC_ENTRY)

/*
* This is a linker script to produce a single hermetic leaf function binary blob.
* It's used with --oformat binary to directly produce the raw blob to be patched in.
* It requires the global symbol HERMETIC_ENTRY be set to the function's entry point,
* and requires that this entry point be the first instruction in the code.
* No non-code sections are allowed unless HERMETIC_RODATA_OK is defined.
* No allocated sections other than .text* and .rodata* are ever allowed.
*/
SECTIONS {
. = 0;

/*
* The .text* sections become the actual binary blob.
* The entry point must be first, so it can be put into .text.entry.
*/
.text : { *(.text.entry) *(.text*) }
ASSERT(HERMETIC_ENTRY == 0,
"hermetic code blob requires entry point at beginning of code")

.rodata : { *(.rodata*) }
ASSERT(DEFINED(HERMETIC_RODATA_OK) || SIZEOF(.rodata) == 0,
"RODATA not allowed in this hermetic code blob")

/*
* These clauses detect any relocation records that haven't been applied by the hermetic link.
* No references outside the hermetic blob are allowed.
*/
.relr.auth.dyn : { *(.relr.auth.dyn) }
.relr : { *(.relr.*) }
.rela : { *(.rela.*) }
.rel : { *(.rel.*) }
ASSERT(SIZEOF(.relr.auth.dyn) + SIZEOF(.relr) + SIZEOF(.rela) + SIZEOF(.rel) == 0,
"hermetic code blob cannot use dynamic relocations")

/*
* There's no way to make use of DWARF CFI for an hermetic code blob.
*/
/DISCARD/ : { *(.eh_frame*) }

/*
* This should detect any section not called .text*, such as .data et al.
* These are not allowed.
*/
.other : { INPUT_SECTION_FLAGS(SHF_ALLOC) *(*) }
ASSERT(SIZEOF(.other) == 0,
"unexpected SHF_ALLOC sections not .text* or .rodata*")
}
118 changes: 118 additions & 0 deletions build/config/linux/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
# Copyright 2017 The Fuchsia Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import("//build/config/clang/clang.gni")
import("//build/config/sysroot.gni")

config("compiler") {
configs = [
":sysroot",
":target",
":clang_defaults",
]

rustflags = [
"-Clinker=$rebased_clang_prefix/clang++",
"-Cdefault-linker-libraries",
]
}

config("default-pie") {
if (!toolchain_variant.is_pic_default) {
# Rust links are always PIE on Linux. C/C++ static library code that is
# linked into Rust programs must be compiled as PIE too. Since there's no
# good way to distinguish code going into Rust links from other code, just
# do it for everything.
cflags = [ "-fPIE" ]
asmflags = cflags

# Since we're compiling as PIE, link as PIE too.
# This makes `#ifdef __PIE__` checks comport with link-time behavior.
ldflags = cflags + [ "-pie" ]

rustflags = []
foreach(flag, ldflags) {
rustflags += [ "-Clink-arg=$flag" ]
}
}
}

config("implicit-host-libs") {
ldflags = [
# Use static C++ standard library.
"-static-libstdc++",

# Set rpath to find dynamically linked libraries placed next to executables
# in the host build directory.
"-Wl,-rpath=\$ORIGIN/",
]

rustflags = []
foreach(flag, ldflags) {
rustflags += [ "-Clink-arg=$flag" ]
}
}

config("sysroot") {
cflags = [ "--sysroot=" + rebase_path(sysroot, root_build_dir) ]
ldflags = cflags
asmflags = cflags

rustflags = []
foreach(flag, ldflags) {
rustflags += [ "-Clink-arg=$flag" ]
}
}

config("target") {
cflags = [ "--target=$current_target_tuple" ]
asmflags = cflags
ldflags = cflags

rustflags = []
foreach(flag, ldflags) {
rustflags += [ "-Clink-arg=$flag" ]
}
}

# These flags are enabled by default in Fuchsia's Clang toolchain, but we set
# them explicitly to support other Clang toolchains and Clang-based tools.
config("clang_defaults") {
cflags_cc = [
# Use libc++ as the C++ standard library.
"-stdlib=libc++",
]
ldflags = [
# Use libc++ as the C++ standard library.
"-stdlib=libc++",

"--start-no-unused-arguments",

# Use libunwind as the unwinder.
"-unwindlib=libunwind",

# Use compiler-rt as the compiler runtime.
"-rtlib=compiler-rt",

"--end-no-unused-arguments",

# Use lld as the linker.
"-fuse-ld=lld",

# Generate build ID for all binaries.
"-Wl,--build-id",
]

rustflags = []
foreach(flag, ldflags) {
rustflags += [ "-Clink-arg=$flag" ]
}

# On RISC-V the linker uses base address that's below the base allowed by
# Zircon (0x200000). See b/311221240. Specify the base address to
# workaround this issue.
if (current_cpu == "riscv64") {
ldflags += [ "-Wl,--image-base=0x200000" ]
}
}
54 changes: 54 additions & 0 deletions build/config/profile/config.gni
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Copyright 2021 The Fuchsia Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import("//build/config/clang/clang.gni")
import("//build/config/sysroot.gni")

declare_args() {
# List of paths to source files to be instrumented by `profile` variants.
profile_source_files = [
# https://fxbug.dev/42061298: profile all checked-in sources.
# (don't profile generated sources under out/)
"//*",
]

# List of paths to source files to NOT instrument by `profile` variants.
# These take precedence over `profile_source_files`.
dont_profile_source_files = [
# Do not instrument system headers that are under //prebuilt.
"//prebuilt/*",
# https://fxbug.dev/42061298: don't profile //third_party.
# https://fxbug.dev/42067345: uncomment the below when issue is fixed.
# Also, change the expression to not reject //third_party/cobalt/*
#"//third_party/*",
]

# When clang_prefix is provided, it might be installed somewhere other than //prebuilt.
# This ensures that we don't profile source files that are under clang_prefix directory.
if (clang_prefix != default_clang_prefix) {
clang_dir = get_path_info(clang_prefix, "dir")
dont_profile_source_files += [ "$clang_dir/*" ]
}

# When target_sysroot is provided, it might be installed somewhere other than //prebuilt.
# This ensures that we don't profile source files that are under target_sysroot directory.
if (target_sysroot != "") {
dont_profile_source_files += [ "$target_sysroot/*" ]
}

# List of paths to files in Clang's `-fprofile-list` format describing files
# and functions to be instrumented by `profile` variants.
profile_source_files_list_files = []

# Profile data path that is used by PGO.
pgo_profile_path = ""
}

# This helps build code discern whether all code is being instrumented by
# default or not. If it's true, then additional -fprofile-list=... switches
# may be required to ensure particular code (e.g. in tests) gets instrumented.
#
# Type: bool
selective_profiling = profile_source_files + dont_profile_source_files +
profile_source_files_list_files != []
Loading
Loading