Skip to content
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

Avoid using \u{1} prefixes in symbol names where possible #2935

Open
bjorn3 opened this issue Sep 19, 2024 · 5 comments
Open

Avoid using \u{1} prefixes in symbol names where possible #2935

bjorn3 opened this issue Sep 19, 2024 · 5 comments

Comments

@bjorn3
Copy link
Member

bjorn3 commented Sep 19, 2024

This prefix disables name mangling in LLVM, but other codegen backends don't support this. We also don't guarantee that it will remain working. As discussed in https://rust-lang.zulipchat.com/#narrow/stream/238009-t-compiler.2Fmeetings/topic/.5Bweekly.5D.202024-09-19/near/471499857 we may choose to add a #[link_name("foo", verbatim)] flag or similar to get the same effect and then deny all usage of \u{1} over an edition boundary.

@bjorn3
Copy link
Member Author

bjorn3 commented Sep 19, 2024

See also rust-lang/rustc_codegen_cranelift#1520 for an example where this causes linking to fail with cg_clif as the \u{1} prefix gets passed straight to the linker.

@pvdrz
Copy link
Contributor

pvdrz commented Sep 19, 2024

hey Bjorn :)

I'm all-in if we could replace this hacky solution for something less brittle. Is there something we could do before the #[link_name("foo", verbatim)] is actually implemented?

@bjorn3
Copy link
Member Author

bjorn3 commented Sep 19, 2024

Most of the time it should be possible to reverse the symbol mangling in rust-bindgen back to whatever would have been written in C before passing it to #[link_name] and thus avoid \u{1} most of the time. For the remaining cases where the symbol name doesn't match something that regular C mangling would produce, keeping usage of \u{1} until #[link_name("foo", verbatim)] is implemented is the best you can do I think.

@emilio
Copy link
Contributor

emilio commented Sep 25, 2024

Most of the time it should be possible to reverse the symbol mangling in rust-bindgen back to whatever would have been written in C

That's true for C, but not so easy for C++, right?

@bjorn3
Copy link
Member Author

bjorn3 commented Sep 25, 2024

Outside of Windows it is possible to unmangle C++ names into something that cam be written in C (except for ABI tags as those need a dot, but that works fine with #[linkage_name] without \x01 already anyway). And for Windows C++ it is fine by me to keep using \x01 for now if necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants