Skip to content
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

Compile with unaligned-scalar-mem feature #29

Merged
merged 1 commit into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@
xtask = "run --package xtask --"

[target.riscv32imc-unknown-none-elf]
rustflags = ["-C", "panic=abort"]
rustflags = [
"-C panic=abort",
"-C target-feature=+relax,+unaligned-scalar-mem",
"-C force-frame-pointers=no"
]
12 changes: 7 additions & 5 deletions xtask/src/apps_build.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Licensed under the Apache-2.0 license

use crate::runtime_build::{objcopy, target_binary, OBJCOPY_FLAGS};
use crate::runtime_build::{objcopy, target_binary, OBJCOPY_FLAGS, RUSTFLAGS_COMMON};
use crate::tbf::TbfHeader;
use crate::{DynError, PROJECT_ROOT, TARGET};
use std::process::Command;
Expand Down Expand Up @@ -114,12 +114,14 @@ INCLUDE runtime/apps/app_layout.ld",
),
)?;

let ld_flag = format!("-C link-arg=-T{}", layout_ld.display());
let mut rustc_flags = Vec::from(RUSTFLAGS_COMMON);
rustc_flags.push(ld_flag.as_str());
let rustc_flags = rustc_flags.join(" ");

let status = Command::new("cargo")
.current_dir(&*PROJECT_ROOT)
.env(
"RUSTFLAGS",
format!("-C link-arg=-T{}", layout_ld.display()),
)
.env("RUSTFLAGS", rustc_flags)
.env("LIBTOCK_LINKER_FLASH", format!("0x{:x}", offset))
.env("LIBTOCK_LINKER_FLASH_LENGTH", "128K")
.env("LIBTOCK_LINKER_RAM", "0x50000000")
Expand Down
7 changes: 6 additions & 1 deletion xtask/src/rom.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
// Licensed under the Apache-2.0 license

use crate::runtime_build::RUSTFLAGS_COMMON;
use crate::{runtime_build::objcopy, DynError, PROJECT_ROOT, TARGET};
use std::process::Command;

pub fn rom_build() -> Result<(), DynError> {
let mut rustc_flags = Vec::from(RUSTFLAGS_COMMON);
rustc_flags.push("-C link-arg=-Trom/layout.ld");
let rustc_flags = rustc_flags.join(" ");

let status = Command::new("cargo")
.current_dir(&*PROJECT_ROOT)
.env("RUSTFLAGS", "-C link-arg=-Trom/layout.ld")
.env("RUSTFLAGS", rustc_flags)
.args(["b", "-p", "rom", "--release", "--target", TARGET])
.status()?;
if !status.success() {
Expand Down
22 changes: 13 additions & 9 deletions xtask/src/runtime_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ const RAM_START: usize = 0x5000_0000;
const RAM_SIZE: usize = 128 * 1024;
const BSS_SIZE: usize = 5000; // this is approximate. Increase it is there are "sram" errors when linking

// TODO: Add +b/+zb* features when the emulator supports the extra bit manipulation instructions
// This saves several hundred bytes of instruction space, and the VeeR core supports them.
pub const RUSTFLAGS_COMMON: [&str; 2] = [
"-C target-feature=+relax,+unaligned-scalar-mem",
"-C force-frame-pointers=no",
];

pub fn target_binary(name: &str) -> PathBuf {
PROJECT_ROOT
.join("target")
Expand Down Expand Up @@ -133,21 +140,18 @@ INCLUDE runtime/kernel_layout.ld
// - `-C symbol-mangling-version=v0`: Opt-in to Rust v0 symbol mangling scheme.
// See https://github.com/rust-lang/rust/issues/60705 and
// https://github.com/tock/tock/issues/3529.
let rustc_flags = [
format!("-C link-arg=-T{}", ld_file_path.display()).as_str(),
let ld_arg = format!("-C link-arg=-T{}", ld_file_path.display());
let mut rustc_flags = Vec::from(RUSTFLAGS_COMMON);
rustc_flags.extend_from_slice(&[
ld_arg.as_str(),
"-C linker=rust-lld",
"-C linker-flavor=ld.lld",
"-C relocation-model=static",
"-C link-arg=-nmagic", // don't page align sections, link against static libs
"-C link-arg=-icf=all", // identical code folding
"-C symbol-mangling-version=v0",
// RISC-V-specific flags.
"-C force-frame-pointers=no",
// Ensure relocations generated is eligible for linker relaxation.
// This provide huge space savings.
"-C target-feature=+relax",
]
.join(" ");
]);
let rustc_flags = rustc_flags.join(" ");

// RUSTC_FLAGS_TOCK by default extends RUSTC_FLAGS with options that are global
// to all Tock boards.
Expand Down
Loading