Skip to content

Commit 96d9828

Browse files
committed
New alternative: #[rust_symbol_export_level].
1 parent 2b930a6 commit 96d9828

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

text/0000-export-visibility.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,48 @@ See "Open questions" section.
305305
# Rationale and alternatives
306306
[rationale-and-alternatives]: #rationale-and-alternatives
307307

308+
## Alternative: `#[rust_symbol_export_level]`
309+
310+
The `#[export_visibility = ...]` proposed in this RFC supports directly
311+
controlling an exact visibility level of a symbol. One alternative is
312+
to control the visibility indirectly, levereging the fact that `#[no_mangle]`
313+
and `#[export_name = ...]` symbols are currently public only because:
314+
315+
* Such symbols are treated as `SymbolExportLevel::C`:
316+
https://github.com/rust-lang/rust/blob/3048886e59c94470e726ecaaf2add7242510ac11/compiler/rustc_codegen_ssa/src/back/symbol_export.rs#L593-L605
317+
* `SymbolExportLevel::C` translates into public visibility, but
318+
visibility of `SymbolExportLevel::Rust` may be controlled via
319+
`-Zdefault-visibility=...`:
320+
https://github.com/rust-lang/rust/blob/3048886e59c94470e726ecaaf2add7242510ac11/compiler/rustc_monomorphize/src/partitioning.rs#L941-L948
321+
322+
Special thanks to @bjorn3 for proposing this alternative in
323+
https://github.com/rust-lang/rfcs/pull/3834#issuecomment-2978073435
324+
325+
This alternative has been prototyped in
326+
https://github.com/rust-lang/rust/commit/9dd4d3f6b2beecb85ff4220502a8c7f61edca839
327+
and tested to verify that it also addresses https://crbug.com/418073233
328+
(with similar test/repro steps as in #comment12 of that bug, but using
329+
https://crrev.com/c/6580611/3).
330+
331+
Other notes:
332+
333+
* Pros:
334+
- It is simpler
335+
(`#[rust_symbol_export_level]` vs `#[export_visibility = "<some value>"]`)
336+
both for users and for implementation.
337+
- It avoids some problems and open questions associated with
338+
`#[export_visibility = ...]`:
339+
- No `dylib` trouble (see [hidden-vs-dylibs])
340+
- No need to define behavior of specific visibilities - this question
341+
is punted to `-Zdefault-visibility=...`.
342+
See also [cross-platform-behavior], [interposable-vs-dllexport]
343+
and [interposable-vs-llvm].
344+
* Cons:
345+
- Doesn't give the same level of control as C++ attributes
346+
* Open questions:
347+
- The name of the attribute proposed in this alternative is subject to
348+
change if a better name is proposed.
349+
308350
## Alternative: version scripts
309351

310352
Using
@@ -505,6 +547,7 @@ answering the `dylib`-vs-`hidden`-visibility problem:
505547
code ends up calling a hidden symbol from the other crate.
506548

507549
## Cross-platform behavior
550+
[cross-platform-behavior]: #cross-platform-behavior
508551

509552
We don't really know
510553
whether the `hidden` / `protected` / `interposable` visibilities

0 commit comments

Comments
 (0)