Skip to content

Commit 9dca3a8

Browse files
committed
Future possibility for passthrough re-export of symbols
Allows 'correct' re-export of symbols that need C++ types
1 parent 59e918b commit 9dca3a8

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

text/3556-re-export-symbols.md

+18-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,24 @@ For a number of reasons, Rust as a project has opted to avoid exposing too many
143143
# Future possibilities
144144
[future-possibilities]: #future-possibilities
145145

146-
This RFC makes it possible to re-export all symbols from a linked staticlib by iterating over all the symbols in a build script and writing them into an extern block that gets `include!`d into the cdylib crate. A more ergonomic re-export of all symbols from a staticlib included via `+whole-archive` may be desirable. It's not clear to the RFC author if this should always be the behavior of `+whole-archive` when pulling a staticlib into a cdylib, or if an additional flag is appropriate - the [original RFC](https://rust-lang.github.io/rfcs/2951-native-link-modifiers.html) that introduced `+whole-archive` is not fully illuminating for this case.
146+
## Re-exporting everything from a linked staticlib
147+
148+
This RFC makes it possible to re-export all symbols from a linked staticlib by iterating over all the symbols in a build script and writing them into an extern block that gets `include!`d into the cdylib crate. A more ergonomic re-export of all symbols from a staticlib included via `+whole-archive` may be desirable.
149+
150+
It's not clear to the RFC author if this should always be the behavior of `+whole-archive` when pulling a staticlib into a cdylib, or if an additional flag is appropriate - the [original RFC](https://rust-lang.github.io/rfcs/2951-native-link-modifiers.html) that introduced `+whole-archive` is not fully illuminating for this case.
151+
152+
## Re-exporting types not representable by Rust
153+
154+
One limitation of this RFC is the lack of support for types not easily representable in Rust, e.g. C++'s `std::vector`. Users in this situation will have two options after this RFC:
155+
156+
1. manually writing an 'appropriate' FFI declaration for the type - e.g. given a particular platform, a type of the same size and alignment may be considered 'compatible'
157+
2. relying on the lack of type information in symbols - many binary formats, including ELF, do not have any type information as part of the symbol itself, so re-exporting can be correctly performed with completely incorrect type information (as linkers will ignore any type information coming from Rust)
158+
159+
Unfortunately, each of these have drawbacks - 1 requires that the Rust developer pay careful attention to the size (and other relevant meta information, like alignment) of the type in case it changes between versions. 2 works for many compiled formats, but not all (e.g. asm.js associates function symbols with information about their return types and arguments) and a mismatch could cause miscompilations.
160+
161+
Future work could consider true 'passthrough' re-exports, where you just tell Rust the name of a symbol and it figures how to pass all the relevant detail through itself, without needing to worry about `fn` vs `static` or type information.
162+
163+
## Additional linking scenarios
147164

148165
Scenarios out of scope of this RFC include:
149166

0 commit comments

Comments
 (0)