Write::write_fmt doesn't work properly on bare metal
Asked Answered
S

1

6

On x86_64 architectures, the write! macro works as expected with string arguments, but not with integers. When an integer argument is used, I get a strange loop (e.g. write!(writer, "Hello {}!", 123) produces infinite "Hello Hello Hello..."). On aarch64, the write! macro does not work at all.

I build libcore using the following command:

rustc -C opt-level=3 -Z no-landing-pads -C no-stack-check \
  --crate-type rlib --target {arch}-unknown-linux-gnu lib.rs

where {arch} is respectively x86_64 or aarch64.

My code is built using the same code generation options. The libcore version corresponds to my compiler. The problematic code is here. Can you suggest a possible cause of the problem?

IMPORTANT UPDATES:

Here is more distilled code. The libcore is built within the project so everything is under control. The loop above comes from machine rebooting. The code perfectly works on aarch64 but strangely crashes inside Write::write_fmt on x86_64. Carefully checked my startup assembly - doesn't seem to have errors there.

Snapshot answered 4/6, 2015 at 9:4 Comment(3)
Does write_str work fine?Vally
Please include the relevant code directly in the question - that way it won't go away before the answer.Fabria
I'm not sure about an exact location of the problem. I can assume that the cause is in improper bootstrapping assembly. Should I provide the assembly lines?Snapshot
V
0
write!(writer, "format {}", "1").unwrap();

I don't think this will help you with you problem, but when I had a similar problem write! would only print the str arguments. If you can find a #![no_std] function that converts i32 to str then this might help you with what you're trying to do.

Vories answered 2/1, 2021 at 15:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.