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

Make sure .heap is 4-byte aligned #253

Merged
merged 2 commits into from
Jan 7, 2025
Merged

Conversation

ia0
Copy link
Contributor

@ia0 ia0 commented Dec 30, 2024

Note sure why the . = ALIGN(${ARCH_WIDTH}); before __ebss = .; doesn't also align .heap.

[package]
name = "foo"
version = "0.1.0"
edition = "2024"

[dependencies]
critical-section = "1.2.0"
embedded-alloc = "0.6.0"
riscv = { version = "0.12.1", features = ["critical-section-single-hart"] }

[dependencies.riscv-rt]
git = "https://github.com/rust-embedded/riscv.git"
rev = "fe6da179b437f23545a5db13ead28dc9855523a4"
MEMORY {
  FLASH (RX) : ORIGIN = 0x20000000, LENGTH = 0x80000
  RAM    (W) : ORIGIN = 0x10000000, LENGTH = 0x20000
}

REGION_ALIAS("REGION_TEXT", FLASH);
REGION_ALIAS("REGION_RODATA", FLASH);
REGION_ALIAS("REGION_DATA", RAM);
REGION_ALIAS("REGION_BSS", RAM);
REGION_ALIAS("REGION_HEAP", RAM);
REGION_ALIAS("REGION_STACK", RAM);
_heap_size = 0x10000;
#![no_std]
#![no_main]

extern crate alloc;

use embedded_alloc::TlsfHeap as Heap;
use {critical_section as _, riscv as _};

#[global_allocator]
static ALLOCATOR: Heap = Heap::empty();

#[panic_handler]
fn panic(info: &core::panic::PanicInfo) -> ! {
    for &byte in alloc::format!("{info}").as_bytes() {
        unsafe { (0x40000000 as *mut u8).write_volatile(byte) };
    }
    loop {}
}

#[riscv_rt::entry]
fn main() -> ! {
    panic!()
}
% RUSTFLAGS='-C link-arg=-Tmemory.x -C link-arg=-Tlink.x' cargo build --release --target=riscv32imc-unknown-none-elf
   Compiling foo v0.1.0 (/tmp/foo)
error: linking with `rust-lld` failed: exit status: 1
  |
  = note: [...]
  = note: rust-lld: error: 
          BUG(riscv-rt): start of .heap is not 4-byte aligned
          
          rust-lld: error: 
          BUG(riscv-rt): start of .heap is not 4-byte aligned
          

error: could not compile `foo` (bin "foo") due to 1 previous error

@ia0 ia0 requested a review from a team as a code owner December 30, 2024 11:09
romancardenas
romancardenas previously approved these changes Jan 7, 2025
Copy link
Contributor

@romancardenas romancardenas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks!

@romancardenas
Copy link
Contributor

@ia0 can you add a brief note in CHANGELOG.md?

auto-merge was automatically disabled January 7, 2025 09:11

Head branch was pushed to by a user without write access

@ia0
Copy link
Contributor Author

ia0 commented Jan 7, 2025

@ia0 can you add a brief note in CHANGELOG.md?

Sure, done.

@romancardenas
Copy link
Contributor

If you rebase from master, the CI should pass

@romancardenas romancardenas added this pull request to the merge queue Jan 7, 2025
Merged via the queue into rust-embedded:master with commit bc21d25 Jan 7, 2025
119 checks passed
@ia0 ia0 deleted the fix branch January 7, 2025 22:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants