Side effect of marking all the methods to #[no_mangle]

Hello all. we use Rust to write component for iOS/macOS/Android and Windows. As the image shows that it’s hard to read mangled symbols from Apple’s Instruments which collects performance data even if built with debug = true. What’s the side effect of marking all the methods to #[no_mangle] even though they will not be exported as FFI? Like this:

pub struct MyType {
    /// some fields

impl MyType {
    pub fn new() -> MyType { }

    pub fn read_some_field(&self) -> SomeFieldType { }

    pub fn write_some_field(&mut self, new_value: SomeFieldType)  { }

AFAIK (I haven’t tested it) you can’t have multiple methods named new. I would not recommend to mark them all with no_mangle, but instead use the c++ name mangeling (or as a pendant to c++filt).
Your Profiler should have an option available.

After a second look, most of the names are demangled, but the hash in the end which rust uses vor versioning afaik. Can you use rustfilt instead? Is that possible in your program?

Thank you! Never heard about it before. Will try it ASAP. However even without no_mangle Rust forbidden function name overloading. Therefore there’s no way to share the same name among methods inside a struct or mod in current version of Rust.

Edit: I think it’s still inconvenient for Instruments of Apple after reading the docs of rustfilt. Because rustfilt is an offline tool rather than telling rustc to build things as if there is no namespace or module just like C symbols.

Yes, this is correct! Using the code below gives the error

mod foo {
    fn run() {

mod bar {
    fn run() {
error: symbol `run` is already defined
  --> src/
10 | /     fn run() {
11 | |         println!("bar::run");
12 | |     }
   | |_____^

error: aborting due to previous error

Please update this thread if using rustfilt worked for you (and how you did it)

1 Like

I have written some code seconds ago like you did and got the same error.:rofl: Sorry for misunderstanding. Since no_mangle isn’t a suitable solution. The question will be how to tell rustc not to add those …$… symbols or how to use rustfilt to demangle symbols for generated .dSYMs file or .so with debug info automatically.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.