Beehaw
  • Communities
  • Create Post
  • search
    Search
  • Login
  • Sign Up
Nemeski ( nemeski@mander.xyz )  to Rust@programming.dev · 1 year ago

Switching to Rust's own mangling scheme on nightly

blog.rust-lang.org

external-link
message-square
6
link
fedilink
36
external-link

Switching to Rust's own mangling scheme on nightly

blog.rust-lang.org

Nemeski ( nemeski@mander.xyz )  to Rust@programming.dev · 1 year ago
message-square
6
link
fedilink
Switching to Rust's own mangling scheme on nightly | Rust Blog
blog.rust-lang.org
external-link
Empowering everyone to build reliable and efficient software.
alert-triangle
You must log in or register to comment.
  • INeedMana ( INeedMana@piefed.zip ) 
    link
    fedilink
    English
    arrow-up
    1
    ·
    1 year ago

    It would be cool if there was an option to tell compiler how to name the object in the end. A strength of C mangling (or rather lack of it) is that you can take the object file and know beforehand the names. With mangling that will always depend on the version of the compiler. In practice, while mangled names are kind of stable, mangled C++ names are not really reliable in the real world

    If we could tell the compiler “in the end name/alias this function as prefix_or_name_of_cargo_my_super_duper_function”, we could then easily call it in an assembler/pure C/etc
    It could even be a separate wrapper. only for exposing stable function names in the object files

    • TehPers ( TehPers@beehaw.org ) 
      link
      fedilink
      English
      arrow-up
      3
      ·
      1 year ago
      #[unsafe(export_name = "my_super_duper_function")]
      pub fn foo() {}
      

      I would recommend reading up some materials on FFI in Rust if you’re interested. Calling functions in Rust from C and in C from Rust (or even languages other than C) is both extremely common and a primary usecase of the language.

      • INeedMana ( INeedMana@piefed.zip ) 
        link
        fedilink
        English
        arrow-up
        1
        ·
        1 year ago

        Wouldn’t that make the body of the function unsafe too?

        I would recommend reading up some materials on FFI in Rust

        Yeah, I’m slowly getting to that

        • TehPers ( TehPers@beehaw.org ) 
          link
          fedilink
          English
          arrow-up
          3
          ·
          1 year ago

          No, the attribute is unsafe. An unsafe function is marked unsafe fn.

          Also, unsafe by itself just means there are invariants that must me manually upheld to avoid unsound behavior. If those invariants are upheld, then it doesn’t matter if it’s unsafe.

    • SavvyWolf ( savvywolf@pawb.social ) 
      link
      fedilink
      English
      arrow-up
      2
      ·
      1 year ago

      https://doc.rust-lang.org/reference/abi.html#the-no_mangle-attribute https://doc.rust-lang.org/nomicon/other-reprs.html#reprc

      Does no_mangle and repr(c) do that?

      • INeedMana ( INeedMana@piefed.zip ) 
        link
        fedilink
        English
        arrow-up
        1
        ·
        1 year ago

        Those are good to know, thanks. But as far as I understand, attribute enforces unsafe, repr is more about the data layout. Right?

        But in there, I’ve found https://github.com/mozilla/cbindgen. Wicked

Rust@programming.dev

rust@programming.dev

Subscribe from Remote Instance

Create a post
You are not logged in. However you can subscribe from another Fediverse account, for example Lemmy or Mastodon. To do this, paste the following into the search field of your instance: !rust@programming.dev

Welcome to the Rust community! This is a place to discuss about the Rust programming language.

Wormhole

!performance@programming.dev

Credits
  • The icon is a modified version of the official rust logo (changing the colors to a gradient and black background)
Visibility: Public
globe

This community can be federated to other instances and be posted/commented in by their users.

  • 32 users / day
  • 63 users / week
  • 142 users / month
  • 751 users / 6 months
  • 118 local subscribers
  • 8.37K subscribers
  • 1.29K Posts
  • 3.8K Comments
  • Modlog
  • mods:
  • snowe ( snowe@programming.dev ) 
  • Ategon ( Ategon@programming.dev ) 
  • EdTheLegendary ( EdTheLegendary@programming.dev ) 
  • torcherist ( torcherist@programming.dev ) 
  • BE: 0.19.21
  • Modlog
  • Legal
  • Instances
  • Docs
  • Code