Skip to content

Commit

Permalink
Use canonical target triple names (x86_64-unknown-theseus) (theseus…
Browse files Browse the repository at this point in the history
…-os#698)

* Previously, the `vendor` was omitted; now it is explicitly `unknown`.

* Now the targets should be ready to be upstreamed as a Rust built-in.
  • Loading branch information
kevinaboos authored Nov 18, 2022
1 parent a8ee62a commit b096c48
Show file tree
Hide file tree
Showing 16 changed files with 85 additions and 85 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/check-clippy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ jobs:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
working-directory: .
run: |
printf "cargo clippy -q -Z build-std=core,alloc -Z build-std-features=compiler-builtins-mem --target cfg/x86_64-theseus.json --workspace --all-features -- -A clippy::all " > cmd.txt;
printf "cargo clippy -q -Z build-std=core,alloc -Z build-std-features=compiler-builtins-mem --target cfg/x86_64-unknown-theseus.json --workspace --all-features -- -A clippy::all " > cmd.txt;
grep -v "#" lints.txt | sed 's/^/-D clippy::/g' | tr -d '\r' | tr '\n' ' ' >> cmd.txt
bash cmd.txt;
5 changes: 2 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ bincode = { git = "https://github.com/bincode-org/bincode" }
wasmparser = { git = "https://github.com/theseus-os/wasm-tools", branch = "no-std-wasmparser" }
backtrace = { path = "ports/backtrace" }
region = { path = "ports/region" }
target-lexicon = { git = "https://github.com/theseus-os/target-lexicon", branch = "theseus" }

### These profiles fix the new rustc behavior of splitting one crate into many object files.
### That messes up our module loading, which is bad!
Expand Down
20 changes: 10 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -504,10 +504,10 @@ clean-old-build:


## This is a special target that enables SIMD personalities.
## It builds everything with the SIMD-enabled x86_64-theseus-sse target,
## and then builds everything again with the regular x86_64-theseus target.
## It builds everything with the SIMD-enabled x86_64-unknown-theseus-sse target,
## and then builds everything again with the regular x86_64-unknown-theseus target.
## The "normal" target must come last ('build_sse', THEN the regular 'build') to ensure that the final nano_core_binary is non-SIMD.
simd_personality_sse : export TARGET := x86_64-theseus
simd_personality_sse : export TARGET := x86_64-unknown-theseus
simd_personality_sse : export BUILD_MODE = release
simd_personality_sse : export override THESEUS_CONFIG += simd_personality simd_personality_sse
simd_personality_sse: clean-old-build build_sse build
Expand All @@ -520,10 +520,10 @@ simd_personality_sse: clean-old-build build_sse build


## This target is like "simd_personality_sse", but uses AVX instead of SSE.
## It builds everything with the SIMD-enabled x86_64-theseus-avx target,
## and then builds everything again with the regular x86_64-theseus target.
## It builds everything with the SIMD-enabled x86_64-unknown-theseus-avx target,
## and then builds everything again with the regular x86_64-unknown-theseus target.
## The "normal" target must come last ('build_avx', THEN the regular 'build') to ensure that the final nano_core_binary is non-SIMD.
simd_personality_avx : export TARGET := x86_64-theseus
simd_personality_avx : export TARGET := x86_64-unknown-theseus
simd_personality_avx : export BUILD_MODE = release
simd_personality_avx : export override THESEUS_CONFIG += simd_personality simd_personality_avx
simd_personality_avx : export override CFLAGS += -DENABLE_AVX
Expand All @@ -536,9 +536,9 @@ simd_personality_avx: clean-old-build build_avx build



### build_sse builds the kernel and applications with the x86_64-theseus-sse target.
### build_sse builds the kernel and applications with the x86_64-unknown-theseus-sse target.
### It can serve as part of the simd_personality_sse target.
build_sse : export override TARGET := x86_64-theseus-sse
build_sse : export override TARGET := x86_64-unknown-theseus-sse
build_sse : export override RUSTFLAGS += -C no-vectorize-loops
build_sse : export override RUSTFLAGS += -C no-vectorize-slp
build_sse : export KERNEL_PREFIX := ksse\#
Expand All @@ -547,9 +547,9 @@ build_sse:
$(MAKE) build


### build_avx builds the kernel and applications with the x86_64-theseus-avx target.
### build_avx builds the kernel and applications with the x86_64-unknown-theseus-avx target.
### It can serve as part of the simd_personality_avx target.
build_avx : export override TARGET := x86_64-theseus-avx
build_avx : export override TARGET := x86_64-unknown-theseus-avx
build_avx : export override RUSTFLAGS += -C no-vectorize-loops
build_avx : export override RUSTFLAGS += -C no-vectorize-slp
build_avx : export KERNEL_PREFIX := kavx\#
Expand Down
2 changes: 1 addition & 1 deletion applications/.old_static_binary_hello/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

PWD := $(shell pwd)
TARGET := x86_64-theseus
TARGET := x86_64-unknown-theseus
RUSTFLAGS := "-C prefer-dynamic -Z pre-link-args=-nostartfiles"


Expand Down
2 changes: 1 addition & 1 deletion book/src/building/rust_builds_out_of_tree.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ The arguments above specify that we wish to
Afterwards, the `build/deps/` directory contains all prebuilt dependencies needed to compile an out-of-tree crate against the existing build of Theseus, with all the properly versioned (correctly hashed) crates and symbols.
This tool also generates a `TheseusBuild.toml` file that describes the parameters of this build of Theseus, such that it can be replicated by `theseus_cargo`. For example:
```toml
target = "x86_64-theseus"
target = "x86_64-unknown-theseus"
rustflags = "--emit=obj -C debuginfo=2 -C code-model=large -C relocation-model=static -D unused-must-use -Z merge-functions=disabled -Z share-generics=no"
cargoflags = "--release"
host_deps = "./host_deps"
Expand Down
6 changes: 3 additions & 3 deletions book/src/subsystems/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,12 @@ Thus, context switching (with preemption) allows for multiple untrusted and unco
The implementation for context switching in Theseus is split across several crates, with each crate corresponding to a particular subset of SIMD instructions being enabled.
The top-level [`context_switch`] crate automatically selects the correct version based on which subset of SIMD functionality is chosen by the target hardware platform's specification.
For example, if SSE2 was enabled, `#[cfg(target_feature = "sse2")]` would be true and the `context_switch_sse2` crate would be used as the context switching implementation.
Currently, one can select this target by using the `x86_64-theseus-sse` target while building Theseus:
Currently, one can select this target by using the `x86_64-unknown-theseus-sse` target while building Theseus:
```sh
make run TARGET=x86_64-theseus-sse
make run TARGET=x86_64-unknown-theseus-sse
```

Theseus supports both SSE2 and AVX, but its default target `x86_64-theseus` disables both.
Theseus supports both SSE2 and AVX, but its default target `x86_64-unknown-theseus` disables both.
This tells the compiler to generate soft floating-point instructions instead of SIMD instructions, meaning that the SIMD register set is not used at all.
Thus, disabling SIMD results in the simplest and fastest version of context switching, as only the basic set of general-purpose CPU registers must be saved and restored; all SIMD registers can be ignored.

Expand Down
12 changes: 6 additions & 6 deletions c_test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ export override LDFLAGS += -static-libgcc
PIE := -fpic -fPIC -fpie -fPIE -pie

TLIBC_DIR := ../tlibc
TLIBC_A := $(TLIBC_DIR)/target/x86_64-theseus/release/libtlibc.a
TLIBC_O := $(TLIBC_DIR)/target/x86_64-theseus/release/tlibc.o
TLIBC_A := $(TLIBC_DIR)/target/x86_64-unknown-theseus/release/libtlibc.a
TLIBC_O := $(TLIBC_DIR)/target/x86_64-unknown-theseus/release/tlibc.o

GLIBC_DIR := $(HOME)/opt/cross/lib/gcc/x86_64-elf/10.2.0/no-red-zone
STARTFILES := $(GLIBC_DIR)/crtbegin.o
ENDFILES := $(GLIBC_DIR)/crtend.o

# LIBGROUP := -Wl,--start-group ../tlibc/target/x86_64-theseus/release/deps/*.o -lgcc -Wl,--end-group
# LIBGROUP := -Wl,--start-group ../tlibc/target/x86_64-unknown-theseus/release/deps/*.o -lgcc -Wl,--end-group
LIBGROUP := -Wl,--start-group $(TLIBC_A) -lgcc -Wl,--end-group
# LIBGROUP := -Wl,--start-group $(TLIBC_O) -lgcc -Wl,--end-group
# LIBGROUP := -L$(TLIBC_DIR)/target/x86_64-theseus/release -ltlibc
# LIBGROUP := -L$(TLIBC_DIR)/target/x86_64-unknown-theseus/release -ltlibc

# PARTIAL_LINK := -Wl,--relocatable

Expand Down Expand Up @@ -73,7 +73,7 @@ export override LDFLAGS += -nostdlib -nostartfiles
$(TLIBC_A) \
$(ENDFILES)

# ../target/x86_64-theseus/release/libnano_core.a \
# ../target/x86_64-unknown-theseus/release/libnano_core.a \
# -static \
Expand Down Expand Up @@ -103,7 +103,7 @@ dummy_pie:
$(PARTIAL_LINK) \
dummy.c \
$(TLIBC_A) \
../target/x86_64-theseus/release/libnano_core.a
../target/x86_64-unknown-theseus/release/libnano_core.a


# -static \
Expand Down
2 changes: 1 addition & 1 deletion cfg/Config.mk
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ SHELL := /bin/bash
ARCH ?= x86_64

## The name of the target JSON file (without the ".json" suffix)
TARGET ?= $(ARCH)-theseus
TARGET ?= $(ARCH)-unknown-theseus

## The top level directory of the Theseus project
ROOT_DIR := $(abspath $(dir $(lastword $(MAKEFILE_LIST)))/..)
Expand Down
32 changes: 24 additions & 8 deletions cfg/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
## Theseus OS target specifications

Theseus OS uses its own target specification to configure how `rustc` compiles its code.
The default target spec is [x86_64-theseus.json], which builds Theseus for the `x86_64` architecture.
The default target spec is [x86_64-unknown-theseus.json], which builds Theseus for the `x86_64` architecture.
If you're unfamiliar with [target triples] or [how Rust handles targets] or how Rust [supports platform cfg via targets], here's a quick breakdown:
* `x86_64`: the architecture.
* A "sub-architecture" can also be provided, but we do not use this on x86,
as it typically only applies to ARM architectures.
* `unknown`: the vendor.
* Theseus doesn't have a specific vendor; the default value is `unknown`.
* `theseus`: the operating system.
* Optionally, the OS parameter can be appended with other items, such as the system environment or ABI.
* Theseus doesn't yet specify an environment or ABI,
but our `llvm-target` item selects `elf`.

We describe the key items in the target spec below; you can read more about the various options
in [`rustc`'s `TargetSpec` type documentation](https://docs.rs/rustc-ap-rustc_target/196.0.0/rustc_target/spec/struct.TargetOptions.html).
in [`rustc`'s `TargetSpec` type documentation](https://docs.rs/rustc-ap-rustc_target/latest/rustc_ap_rustc_target/spec/struct.TargetOptions.html).

* `llvm-target`: all Theseus targets are based on `x86_64-unknown-none-elf`,
which is a minimal target that specifies no underlying OS and
uses the ELF file format for compiled artifacts.
* `features`: `-mmx,-sse,+soft-float`.
This builds Theseus with hardware floating point support disabled in favor of soft floating point.
This is the typical choice for most OS kernels, since using hardware floating point and/or SIMD
Expand Down Expand Up @@ -42,17 +55,20 @@ in [`rustc`'s `TargetSpec` type documentation](https://docs.rs/rustc-ap-rustc_ta
so we may not need it, but it doesn't hurt to explicitly disable it.

### Other target specs
* [x86_64-theseus-sse.json]: similar to the default `x86_64-theseus`, but enables the compiler to
generate instructions that use SSE2 (and higher SSE versions) SIMD features.
* [x86_64-unknown-theseus-sse.json]: similar to the default `x86_64-unknown-theseus`, but enables the compiler to
generate instructions that use SSE2 (and lower SSE versions) SIMD features.
With this, all crates across Theseus can use SSE2 SIMD instructions and registers.
* [x86_64-theseus-avx.json]: similar to above, but enables AVX (version 1) instructions/registers.
* [x86_64-unknown-theseus-avx.json]: similar to above, but enables AVX (version 1) instructions/registers.
With this, all crates across Theseus can use AVX SIMD instructions and registers.
This does not yet enable support for AVX2 or AVX512.


[x86_64-theseus.json]: ./x86_64-theseus.json
[x86_64-theseus-sse.json]: ./x86_64-theseus-sse.json
[x86_64-theseus-avx.json]: ./x86_64-theseus-avx.json
[x86_64-unknown-theseus.json]: ./x86_64-unknown-theseus.json
[x86_64-unknown-theseus-sse.json]: ./x86_64-unknown-theseus-sse.json
[x86_64-unknown-theseus-avx.json]: ./x86_64-unknown-theseus-avx.json
[`code-model`]: https://doc.rust-lang.org/rustc/codegen-options/index.html#code-model
[`relocation-model`]: https://doc.rust-lang.org/rustc/codegen-options/index.html#relocation-model
[`tls-model`]: https://doc.rust-lang.org/beta/unstable-book/compiler-flags/tls-model.html#tls_model
[target triples]: https://clang.llvm.org/docs/CrossCompilation.html#target-triple
[how Rust handles targets]: https://doc.rust-lang.org/rustc/targets/index.html
[supports platform cfg via targets]: https://doc.rust-lang.org/nightly/rustc/platform-support.html
16 changes: 0 additions & 16 deletions cfg/x86_64-theseus-user.json

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
16 changes: 8 additions & 8 deletions libtheseus/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,32 +25,32 @@ $THESEUS_CARGO_PATH/bin/theseus_cargo --input ../build/deps build
# RUST_TARGET_PATH="$THESEUS_BASE_DIR/build/deps" \
# RUSTFLAGS="--emit=obj -C debuginfo=2 -C code-model=large -C relocation-model=static -D unused-must-use -Z merge-functions=disabled -Z share-generics=no --sysroot $THESEUS_BASE_DIR/build/deps/sysroot" \
# cargo build --release --verbose \
# --target x86_64-theseus
# --target x86_64-unknown-theseus


## The "newer" raw cargo command that works without xargo at all. This is good because we can use a pre-built/distributed sysroot directory.
# RUST_TARGET_PATH="$THESEUS_BASE_DIR/build/deps" \
# RUSTFLAGS="--emit=obj -C debuginfo=2 -C code-model=large -C relocation-model=static -D unused-must-use -Z merge-functions=disabled -Z share-generics=no --sysroot $THESEUS_BASE_DIR/build/deps/sysroot" \
# cargo build --release --verbose -vv \
# --target x86_64-theseus
# --target x86_64-unknown-theseus


## The initial normal command that uses `xargo`
# RUST_TARGET_PATH="$THESEUS_BASE_DIR/cfg" \
# RUSTFLAGS="--emit=obj -C debuginfo=2 -C code-model=large -C relocation-model=static -D unused-must-use -Z merge-functions=disabled -Z share-generics=no" \
# xargo build --release --verbose -vv \
# --target x86_64-theseus
# --target x86_64-unknown-theseus



# RUST_TARGET_PATH="$THESEUS_BASE_DIR/cfg" \
# rustc --crate-name libtheseus src/lib.rs --crate-type lib \
# --emit=dep-info,metadata,link \
# -C opt-level=3 -C embed-bitcode=no -C codegen-units=1 -C metadata=43462c60d48a531a -C extra-filename=-43462c60d48a531a \
# --out-dir $THESEUS_BASE_DIR/libtheseus/target/x86_64-theseus/release/deps \
# --target x86_64-theseus \
# -L dependency=$THESEUS_BASE_DIR/target/x86_64-theseus/release/deps \
# --extern rlibc=$THESEUS_BASE_DIR/target/x86_64-theseus/release/deps/librlibc-4eb1a1ba9385f780.rmeta \
# --extern serial_port=$THESEUS_BASE_DIR/target/x86_64-theseus/release/deps/libserial_port-ce2d7a263b9ad06d.rmeta \
# --out-dir $THESEUS_BASE_DIR/libtheseus/target/x86_64-unknown-theseus/release/deps \
# --target x86_64-unknown-theseus \
# -L dependency=$THESEUS_BASE_DIR/target/x86_64-unknown-theseus/release/deps \
# --extern rlibc=$THESEUS_BASE_DIR/target/x86_64-unknown-theseus/release/deps/librlibc-4eb1a1ba9385f780.rmeta \
# --extern serial_port=$THESEUS_BASE_DIR/target/x86_64-unknown-theseus/release/deps/libserial_port-ce2d7a263b9ad06d.rmeta \
# --emit=obj -C debuginfo=2 -C code-model=large -C relocation-model=static -D unused-must-use -Z merge-functions=disabled -Z share-generics=no \
# --sysroot /home/kevin/.xargo
Loading

0 comments on commit b096c48

Please sign in to comment.