Skip to content

Commit 223ae46

Browse files
committed
[x86] Initial support for Rust on x86_64
The starting json file and flags were taken from an x86_64 linux build, and may need further tweaks. But, this is able to build and run the initial hook from the rust code. Change-Id: If421f08fa70eb479343f7ac646c231f811ba99d0 Signed-off-by: David Brown <davidb@davidb.org>
1 parent 54039a9 commit 223ae46

5 files changed

Lines changed: 53 additions & 1 deletion

File tree

arch/x86/64/x86_64-llvm.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"arch": "x86_64",
3+
"rustc-abi": "x86-softfloat",
4+
"data-layout": "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128",
5+
"features": "-mmx,+soft-float,-retpoline-external-thunk,-retpoline-indirect-branches,-retpoline-indirect-calls,+harden-sls-ijmp,+harden-sls-ret",
6+
"llvm-target": "x86_64-linux-gnu",
7+
"supported-sanitizers": ["kcfi","kernel-address"],
8+
"target-pointer-width": 64,
9+
"emit-debug-gdb-scripts": false,
10+
"frame-pointer": "may-omit",
11+
"stack-probes": {"kind": "none"}
12+
}

lib/rust_support/Cargo.toml.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Rust meta crate
22

3+
cargo-features = ["panic-immediate-abort"]
4+
35
# This crate brings in the other dependencies needed so that cargo builds all of the Rust code that
46
# we need.
57

@@ -22,9 +24,11 @@ debug-assertions = true
2224
overflow-checks = true
2325
debug = true
2426
codegen-units = 1
27+
panic = "immediate-abort"
2528

2629
[profile.dev]
2730
opt-level = 2
2831
codegen-units = 1
32+
panic = "immediate-abort"
2933

3034
@DEPCRATES@

lib/rust_support/rules.mk

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,19 @@ ifeq ($(RUST_TARGET_PATH),)
4646
RUST_TARGET_PATH := $(RUST_TARGET)
4747
endif
4848

49+
ifndef RUST_CFLAGS
50+
RUST_CFLAGS :=
51+
endif
52+
4953
define TOML_ESC
5054
$(subst \,\\,$(subst ",\",$1))
5155
endef
5256

57+
# Expand a make "list" (space separated) into a quoted version appropriate for inserting into TOML.
58+
define TOML_ARRAY
59+
[$(foreach w,$(1),\"$(w)\",)]
60+
endef
61+
5362
CARGO_CONFIG := $(MODULE_BUILDDIR)/.cargo/config.toml
5463

5564
# TODO: Allow debug/release builds
@@ -97,6 +106,9 @@ $(CARGO_CONFIG): $(CARGO_CONFIG).phony
97106
echo "[env]"; \
98107
echo 'GLOBAL_INCLUDES = { value = "$(call TOML_ESC,$(GLOBAL_INCLUDES))", force = true }'; \
99108
echo; \
109+
echo "[target.'cfg(all())']"; \
110+
echo "rustflags = $(call TOML_ARRAY,$(RUST_CFLAGS))"; \
111+
echo; \
100112
echo "[unstable]"; \
101113
echo 'build-std = ["core", "alloc"]'; \
102114
} > "$$tmp"; \

platform/pc/rules.mk

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,22 @@ LK_HEAP_IMPLEMENTATION ?= dlmalloc
3535
GLOBAL_DEFINES += \
3636
PLATFORM_HAS_DYNAMIC_TIMER=1
3737

38-
include make/module.mk
38+
# TODO: This probably needs to be different for 32 and 64 bit.
39+
RUST_TARGET := x86_64-llvm
40+
RUST_TARGET_PATH := $(abspath $(BUILDROOT))/arch/x86/64/x86_64-llvm.json
41+
42+
RUST_CFLAGS := \
43+
-Ctarget-feature=-sse,-sse2,-sse3,-ssse3,-sse4.1,-sse4.2,-avx,-avx2 \
44+
-Ctarget-cpu=x86-64 \
45+
-Ztune-cpu=generic \
46+
-Cno-redzone=y \
47+
-Copt-level=2 \
48+
-Cdebug-assertions=n \
49+
-Coverflow-checks=y \
50+
-Ccode-model=kernel \
51+
-Cforce-frame-pointers=y
52+
# -Zdwarf-version=5 -Cdebuginfo=2
53+
# -Zfunction-return=thunk-extern
54+
# -Zpatchable-function-entry=16,16
3955

56+
include make/module.mk

project/pc-x86-64-test.mk

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,10 @@ include project/target/pc.mk
77
include project/virtual/fs.mk
88
include project/virtual/minip.mk
99
include project/virtual/test.mk
10+
11+
USE_RUST ?= 0
12+
13+
ifeq ($(call TOBOOL,$(USE_RUST)),true)
14+
$(info "Including rust support")
15+
include project/virtual/rust.mk
16+
endif

0 commit comments

Comments
 (0)