-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
How to generate one instruction only when asm! is used in naked functions? #96037
Comments
It could/should work with |
Triage: is this still an issue? I'm not sure what eGON.BT0 seems to be some ARM chip: https://linux-sunxi.org/Main_Page |
Ok, turns out this is a MIPS architecture actually. Minimal reproduction: #![no_std]
#![feature(naked_functions, asm_experimental_arch, start)]
use core::arch::asm;
#[naked]
#[link_section = ".head.text"]
#[export_name = "head_jump"]
pub unsafe extern "C" fn head_jump() {
asm!("j {}", sym main, options(noreturn))
}
#[start]
fn start(_: isize, _: *const *const u8) -> isize {
0
}
fn main() {}
#[panic_handler]
fn panic(_: &core::panic::PanicInfo) -> ! {
loop {}
} I'm trying to get access to a linker/version of objdump that actually supports this architecture, I think |
@jyn514 : I'm using RISC-V compiling target. It's riscv64imac-unknown-none-elf. |
Hmm, I'm still having trouble reproducing this. I'm compiling with
What am I missing? |
@jyn514 : It looks like that we should provide a linker script to include ".head.text" into output file, or I'll try put it into ".text" instead to see what will happen. |
Godbolt repro: https://godbolt.org/z/d9oebcjhW This happens because of rust/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp Lines 451 to 457 in c469197
Given that TrapUnreachable significantly limits the impact of returning-from-noreturn (and similar "entering unreachable code") UB, and that |
Since #128004 naked functions much now use head_jump:
j example::main::h71184965de29500a
example::main::h71184965de29500a:
ret |
There's a usage sceneario in Rust for embedded rom bootloader. Some chips use eGON.BT0 format on boot, it has one jump instruction on head and the following should be boot tables.
j main
It's ideal to write this instruction
j main
using Rust naked function as follows, in this way we do not require further tools to help with filling this instruction.The
options(noreturn)
is required in current naked function or it won't compile. I expect this function to generate one instructionj main
only, however it generates anunimp
which is unexpected:I didn't expect this
unimp
instruction, for it will overlap bootloader magic, making this Rust image not bootable. What should I do?I looked into RFC 2972, in section Naked Function Definition it shows:
Should we expect that there would be additional instructions after what we have in
asm!
macro?Note: I try to remove the
option(noreturn)
, it shows following compile error:The text was updated successfully, but these errors were encountered: