No_mangle
no_mangle is a Rust attribute that prevents name mangling for an item, preserving its symbol name in compiled output.
Refactoring to Rust
The no_mangle attribute prevents the Rust compiler from applying symbol name mangling to an item.
- How it is used
- Uses unmangled symbols to make Rust functions available to C callers that locate them by name.
- How deep it goes
- Explains symbol naming and export annotations through function signatures, while leaving the mangling algorithm unexplored.
- Examples
- Contrasts a C-callable calculator function with an NGINX request handler and an address-passed callback.
- What you can do after
- Apply it to expose a Rust function by name to C while choosing appropriate visibility, calling conventions, and a collision-resistant name.
Embedded Software with Rust
The Rust no_mangle attribute preserves an item's externally visible symbol name instead of applying name mangling.
- How it is used
- Preserves linker-visible names for bare-metal startup symbols and Rust functions or data exposed to C.
- How deep it goes
- Explains name mangling and the attribute’s unsafe qualification, then distinguishes symbol naming from calling conventions and section placement.
- Examples
- Demonstrates a custom _start entry point, C-callable arithmetic functions, and an exported static constant.
- What you can do after
- Apply it to expose named symbols and verify an exported static-library function with nm.
Rust in Action: Systems programming concepts and techniques
no_mangle is a Rust attribute that suppresses compiler name mangling for an item’s externally visible symbol.
- How it is used
- Controls Rust symbol names when a bare-metal kernel or external component must locate an item predictably.
- How deep it goes
- Explains symbol strings, name-mangling collisions, and boot failure risk, but stops short of linker-level details.
- Examples
- Uses a kernel’s panic handler and _start entry point as concrete no_mangle examples.
- What you can do after
- Apply no_mangle to preserve predictable symbols in a Rust kernel or external-component interface.
Read how Rust in Action: Systems programming concepts and techniques explains no_mangle →
Also covered in
What to know first
- RustRust is a statically typed systems programming language designed for performance, concurrency, and memory safety without requiring garbage collection.
Related concepts
- name manglingaddresses · Name mangling is the transformation of identifiers into altered names to encode distinguishing information or reduce naming collisions.
- foreign function interfaceuses · A foreign function interface is a mechanism that enables code in one programming language to call or interoperate with code or data from another language through compatible conventions.
- interrupt vector tableconfigures · An interrupt vector table is a memory table that provides addresses for processor exception and interrupt handlers.
Questions about no_mangle
What is no_mangle?
no_mangle is a Rust attribute that prevents name mangling for an item, preserving its symbol name in compiled output.
Which Manning books explain no_mangle?
Refactoring to Rust, Embedded Software with Rust and Rust in Action: Systems programming concepts and techniques.
What should I know before learning no_mangle?
Manning books that teach no_mangle usually introduce Rust first.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.


