Skip to content

Commit

Permalink
Update the Rust toolchain to 2021-03-25.
Browse files Browse the repository at this point in the history
This includes rust-lang/rust#82141, which is needed in order to add ARM support to libtock_runtime. It also allows us to use the unsafe_op_in_unsafe_fn lint.
  • Loading branch information
jrvanwhy committed Mar 30, 2021
1 parent 5e85312 commit 33bc502
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 67 deletions.
24 changes: 7 additions & 17 deletions core/src/entry_point/start_item_arm.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
use core::hint;

/// Tock programs' entry point. Called by the kernel at program start. Sets up
/// the stack then calls rust_start() for the remainder of setup.
#[doc(hidden)]
#[no_mangle]
#[naked]
#[link_section = ".start"]
pub unsafe extern "C" fn _start(
app_start: usize,
mem_start: usize,
_memory_len: usize,
app_heap_break: usize,
) -> ! {
llvm_asm!("
pub unsafe extern "C" fn _start() -> ! {
asm!(
"
// Because ROPI-RWPI support in LLVM/rustc is incomplete, Rust
// applications must be statically linked. An offset between the
// location the program is linked at and its actual location in flash
Expand Down Expand Up @@ -102,12 +96,8 @@ pub unsafe extern "C" fn _start(
mov r2, r8
// Call rust_start
bl rust_start"
: // No output operands
: "{r0}"(app_start), "{r1}"(mem_start), "{r3}"(app_heap_break) // Input operands
: "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r8", "r12",
"cc", "memory" // Clobbers
: "volatile" // Options
);
hint::unreachable_unchecked()
bl rust_start",
// No clobbers because we don't return.
options(noreturn),
)
}
26 changes: 10 additions & 16 deletions core/src/entry_point/start_item_riscv32.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use core::hint;

/// Tock programs' entry point. Called by the kernel at program start. Sets up
/// the stack then calls rust_start() for the remainder of setup.
#[doc(hidden)]
Expand All @@ -14,12 +12,12 @@ use core::hint;
// Due to Rust issue: https://github.com/rust-lang/rust/issues/42779 we can't have
// args to the function
pub unsafe extern "C" fn _start() -> ! {
llvm_asm!(
// Compute the stack top.
//
// struct hdr* myhdr = (struct hdr*) app_start;
// uint32_t stacktop = (((uint32_t) mem_start + myhdr->stack_size + 7) & 0xfffffff8);
"lw t0, 36(a0) // t0 = myhdr->stack_size
asm!(
// Compute the stack top.
//
// struct hdr* myhdr = (struct hdr*) app_start;
// uint32_t stacktop = (((uint32_t) mem_start + myhdr->stack_size + 7) & 0xfffffff8);
"lw t0, 36(a0) // t0 = myhdr->stack_size
addi t0, t0, 7 // t0 = myhdr->stack_size + 7
add t0, t0, a1 // t0 = mem_start + myhdr->stack_size + 7
li t1, 7 // t1 = 7
Expand Down Expand Up @@ -89,14 +87,10 @@ pub unsafe extern "C" fn _start() -> ! {
mv s0, sp // Set the frame pointer to sp.
mv a1, s1 // second arg is stacktop
mv a2, t1 // third arg is app_heap_break that we told the kernel
jal rust_start"
: // No output operands
:
: "memory", "x10", "x11", "x12", "x13", "x14", "x15", "x16", "x17",
"x5", "x6", "x7", "x28", "x29", "x30", "x31", "x1" // Clobbers
: "volatile" // Options
);
hint::unreachable_unchecked();
jal rust_start",
// No clobbers needed for a noreturn asm! block.
options(noreturn),
)
}

/// Ensure an abort symbol exists.
Expand Down
2 changes: 1 addition & 1 deletion core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(lang_items, llvm_asm, naked_functions)]
#![feature(asm, lang_items, llvm_asm, naked_functions)]
#![cfg_attr(any(target_arch = "arm", target_arch = "riscv32"), no_std)]
#![cfg_attr(feature = "alloc", feature(alloc_error_handler))]

Expand Down
35 changes: 11 additions & 24 deletions layout_generic.ld
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,15 @@ SECTIONS {
/* Section for just the app crt0 header.
* This must be first so that the app can find it.
*/
.crt0_header :
/* Runtime setup logic. The crt0_header symbol is used by the entry point
* assembly. We have to include start here rather than .text because
* otherwise elf2tab fails to recognize that the process binary's flash
* region should start at the beginning of .start.
*/
.start :
{
_beginning = .; /* Start of the app in flash. */
crt0_header = .;
/**
* Populate the header expected by `crt0`:
*
Expand Down Expand Up @@ -68,14 +74,15 @@ SECTIONS {
* between the header and subsequent .data section. It's unclear why,
* but LLD is aligning sections to a multiple of 32 bytes. */
. = ALIGN(32);

*(.start)
} > FLASH =0xFF

/* Text section, Code! */
.text :
{
. = ALIGN(4);
_text = .;
KEEP (*(.start))
*(.text*)
*(.rodata*)
KEEP (*(.syscalls))
Expand Down Expand Up @@ -140,30 +147,10 @@ SECTIONS {
{
} > FLASH

/* ARM Exception support
*
* This contains compiler-generated support for unwinding the stack,
* consisting of key-value pairs of function addresses and information on
* how to unwind stack frames.
* https://wiki.linaro.org/KenWerner/Sandbox/libunwind?action=AttachFile&do=get&target=libunwind-LDS.pdf
*
* .ARM.exidx is sorted, so has to go in its own output section.
*
* __NOTE__: It's at the end because we currently don't actually serialize
* it to the binary in elf2tbf. If it was before the RAM sections, it would
* through off our calculations of the header.
*/
PROVIDE_HIDDEN (__exidx_start = .);
.ARM.exidx :
{
/* (C++) Index entries for section unwinding */
*(.ARM.exidx* .gnu.linkonce.armexidx.*)
} > FLASH
PROVIDE_HIDDEN (__exidx_end = .);

/* Sections we do not need. */
/DISCARD/ :
{
*(.eh_frame)
*(.ARM.exidx .eh_frame)
}
}

Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[toolchain]
# See https://rust-lang.github.io/rustup-components-history/ for a list of
# recently nightlies and what components are available for them.
channel = "nightly-2020-08-20"
channel = "nightly-2021-03-25"
components = ["clippy", "miri", "rustfmt"]
targets = ["thumbv7em-none-eabi",
"riscv32imac-unknown-none-elf",
Expand Down
20 changes: 12 additions & 8 deletions tools/print_sizes/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,25 +117,29 @@ fn main() {
.expect("No examples found");
let section_width = 7;

// TODO: We do not currently print out .rodata's size. Currently, the linker
// script embeds .rodata in .text, so we don't see it as a separate section
// here. We should modify the linker script to put .rodata in its own
// section. Until that is done, .rodata's size will be counted as part of
// .text, so we'll just print .text's size for now.
println!(
"{0:1$} {2:3$} {4:>7$} {5:>7$} {6:>7$}",
"Example", name_width, "Architecture", arch_width, ".bss", ".data", ".text", section_width
"{0:1$} {2:3$} {4:>8$} {5:>8$} {6:>8$} {7:>8$}",
"Example",
name_width,
"Architecture",
arch_width,
".bss",
".data",
".text",
".rodata",
section_width
);
for data in example_data {
println!(
"{0:1$} {2:3$} {4:7$} {5:7$} {6:7$}",
"{0:1$} {2:3$} {4:8$} {5:8$} {6:8$} {7:8$}",
data.name,
name_width,
data.arch,
arch_width,
data.sizes.bss,
data.sizes.data,
data.sizes.text,
data.sizes.rodata,
section_width
);
}
Expand Down

0 comments on commit 33bc502

Please sign in to comment.