Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
RFC: Allow symbol re-export in cdylib crate from linked staticlib #3556
base: master
Are you sure you want to change the base?
RFC: Allow symbol re-export in cdylib crate from linked staticlib #3556
Changes from 2 commits
970682f
52786db
59e918b
9dca3a8
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In light of #3325, have you considered whether the attribute should be
unsafe
or not?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The motivating issue there suggests that allowing rust crates to export symbols at all is unsafe, so (assuming that RFC gets merged) whatever attribute this RFC ends up using would presumably also be unsafe.
If that RFC gets merged first then I'd update this one as needed, or if this goes first then I assume there will be a pass over attributes to see if they should be unsafe.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll note that linking can be done in many other ways, the
#[link]
attribute doesn't have to be on the sameextern
block. So it may not always be possible / feasible to check which library the symbol comes from, and whether that library is static!There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I see this as a best-effort warning - if the
extern
block has nolink
attribute at all then there's not much we can do as that is a valid setup. But if you do have a link attribute on an extern block and that library is not explicitly static then possibly there's something wrong (there could also not be, e.g. if the function is actually from another lib rather than the one annotated on the extern block, but that seems unusual?)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
#[no_mangle]
explicitly documents that it does two things; disable name mangling and publicly exports the symbol, similar to the#[used]
attribute.Symbol name mangling is already disabled within an
extern
block, so why not use#[used]
for this instead? I don't think it's as clear as#[re_export]
, so that one is still my favourite, but I think it has slightly closer semantics than#[no_mangle]
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#[used]
doesn't cause a symbol to be exported. It merely prevents it from being dropped entirely by the linker when there are no uses.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On Mach-O, I'm unsure about exporting individual symbols (maybe
-exported_symbols_list
would work?), but I do know that you can re-export an entire library using the-reexport_library
linker flag.