-
Notifications
You must be signed in to change notification settings - Fork 707
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
Undesired link_name attributes generated #1221
Comments
Right, so this is somewhat annoying, because fixing this would need to assume knowledge about the backend mangling on the target. The only reason those Indeed we used to have a fair amount of bugs with C++ related to that. So as much as this is only cosmetic, I don't think there's any particular reason to fix this, is there? |
See all the I think we could consider doing this as a best-effort thing, like: If we really know that the backend needs the extra underscore, just remove it, otherwise fall back to |
In my case, I typically build a bindings file once and commit it, rather than building it on the target machine. (This is the case for a lot of bindings...) Also in my case, my bindings are for C APIs rather than C++ ... I understand the need for this for C++ APIs, but what is the need for C? |
Sorry for the lag replying to this. You can use the If there's anything else we can do on our side (maybe renaming that option? We've done more breaking changes for the next release so it should be fine) please let me know, or submit a PR :) |
I'm still getting the
|
It's expected that you get that if the symbol name is different from the name you're exposing. The Do you need the link name to go away? If so, why? How would that link? |
Right, |
That wouldn't work on MacOS where we'd need an underscore. So the |
I'm sorry, I don't quite understand. You're saying |
Yes, that's right, see f2b30c8. Basically rustc passes Prepending |
I ran into the same issue today with rust-mbedtls + pregenerating the bindings to be reused on Windows/macOS/Linux. As a temporary workaround, I did a search & replace in the generated bindings to remove the \u{1} prefix and it worked. |
@awakecoding as I understand, it's not an issue, and you can leave the |
@jethrogb I found this issue because leaving \u{1} caused issues for me on macOS. I modified rust-mbedtls to link against a prebuilt mbedtls library provided by conan, but any static library would cause the same problem. Removing \u{1} made it work for Windows/macOS/Linux. |
@awakecoding what's your clang version? Some old libclangs returned bogus mangled names. In any case, this should not be an issue if you run bindgen once per platform (at build time or such). If you know you don't have or use non-C symbols, you can use the |
@emilio I think it was libclang 6.0.0 on Linux. However, in my case, my intent is to generate the bindings once for all platforms, since the mbedtls API is identical on all platforms (at least if you build it with exactly the same options everywhere). I will try distrust-clang-mangling. |
Sorry to comment on an old issue, but it seems to describe my issue exactly. Currently I am working on a crate for bindings to Matlab. I distribute the generated bindings with the crate instead of letting the user generate them. This seems to break on MacOS because of the prefixed Is there any option to generate the |
I recently had an issue with mangling on macos and it was the fact that it added I don't have a macos to test but it would be interesting to see if prepending |
Sadly I also don't have MacOS to test this. Currently I try to get CI with Github Actions up to test on MacOS. The thing which confuses me is, why does the |
the thing is that we already ask clang to mangle the names. So this |
So, as far as I understand now, when I write
My problem with this is now that I do want the platform dependent mangling while using
But since bindgen, as far as I know, cannot generate this code for me I have to resort to do at least the |
Well yeah. To be more preceise
Well the issue is that
Yeah this |
That doesn't surprise me at all, as I generate the bindings once, currently on windows, and distribute them so users don't have to install LLVM themselves. I know the function names stay the same between all platforms and I can rely on the mangling done by rustc to generate the correct symbol name.
|
So, in principle you could run bindgen with each |
I guess in principle that would work, but since I do have to do some cleanup after the code generation that would triple this work. Also it seems somewhat roundabout to codegen for three different targets only to get the mangling correct when that mangling would happen anyway with normal compilation. |
According to the discussion in rust-lang/rust-bindgen#1221 (comment), the \u{1} is a hint to LLVM to avoid name-mangling but this might be required on some platforms to link against the right name, e.g. on macOS.
According to the discussion in rust-lang/rust-bindgen#1221 (comment), the \u{1} is a hint to LLVM to avoid name-mangling but this might be required on some platforms to link against the right name, e.g. on macOS.
…ssl_flush_output functions According to the discussion in rust-lang/rust-bindgen#1221 (comment), the \u{1} is a hint to LLVM to avoid name-mangling but this might be required on some platforms to link against the right name, e.g. on macOS.
…ssl_flush_output functions According to the discussion in rust-lang/rust-bindgen#1221 (comment), the \u{1} is a hint to LLVM to avoid name-mangling but this might be required on some platforms to link against the right name, e.g. on macOS.
…ssl_flush_output functions According to the discussion in rust-lang/rust-bindgen#1221 (comment), the \u{1} is a hint to LLVM to avoid name-mangling but this might be required on some platforms to link against the right name, e.g. on macOS.
* Allow name-mangling for the mbedtls_free, mbedtls_calloc and mbedtls_ssl_flush_output functions According to the discussion in rust-lang/rust-bindgen#1221 (comment), the \u{1} is a hint to LLVM to avoid name-mangling but this might be required on some platforms to link against the right name, e.g. on macOS. * Add macOS test in CI * tests: add missing nextest config * build: bump ver --------- Co-authored-by: Tobias Naumann <[email protected]>
Input C/C++ Header
Bindgen Invocation
Actual Results
I would like the output to not contain the
link_name
attribute as it shouldn't be necessary here.I'm on macOS, so all symbols get the
_
prefix ...The text was updated successfully, but these errors were encountered: