Skip to content

linkage: Add a note about symbol visibility and unused sections to the paragraph about staticlibs #1361

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

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/linkage.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@ be ignored in favor of only building the artifacts specified by command line.
linking Rust code into an existing non-Rust application
because it will not have dynamic dependencies on other Rust code.

Note that, because the resulting static library contains the code of all the
dependencies, including the standard library, and also exports all public
symbols of them, linking the static library into an executable or shared
library may need special care. In case of a shared library the list of
exported symbols will have to be limited via e.g. a linker or symbol version
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't say that they have to or that special care is needed.
It's more like "if you want to optimize the output in a similar way to rustc".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case of a shared library it seems more than an optimization as you're otherwise risking symbol conflicts, but yes.

How about softening it from the (current) "must" to "should"?

script, exported symbols list (macOS), or module definition file (Windows).
Additionally, unused sections can be removed to remove all code of
dependencies that is not actually used (e.g. `--gc-sections` or `-dead_strip`
for macOS).

* `--crate-type=cdylib`, `#![crate_type = "cdylib"]` - A dynamic system
library will be produced. This is used when compiling
a dynamic library to be loaded from another language. This output type will
Expand Down