The no_mangle attribute keeps Rust from changing an item’s symbol name during compilation. Symbols are strings in the compiled binary, and predictable names matter when code must be found by external components. Rust normally mangles names to prevent collisions between libraries; disabling mangling is necessary here because the boot process may otherwise fail. section 11.2.3 section 11.7
Naming a kernel entry point
A small kernel places #[no_mangle] on its _start function and panic handler. The entry point is also declared pub extern "C" so it follows C calling conventions; no_mangle controls the symbol name, while extern "C" controls how arguments are arranged. section 11.2.3
Listing 11.4 Creating an OS kernel that paints a block of color
1 #![no_std] #1
2 #![no_main] #1
3 #![feature(core_intrinsics)] #2
4
5 use core::intrinsics; #2
6 use core::panic::PanicInfo; #3
7
8 #[panic_handler]
9 #[no_mangle]
10 pub fn panic(_info: &PanicInfo) -> ! {
11 intrinsics::abort(); #4
12 }
13
14 #[no_mangle]
15 pub extern "C" fn _start() -> ! {
16 let framebuffer = 0xb8000 as *mut u8;
17
18 unsafe {
19 framebuffer
20 .offset(1) #5
21 .write_volatile(0x30); #6
22 }
23
24 loop {}
25 }
Inspect the complete kernel listing to see no_mangle alongside no_std, no_main, extern "C", and the bare-metal entry point. section 11.2.3


