Skip to content

Commit 2d5eea8

Browse files
committed
Remove support for "interposable" visibility - it would be a no-op.
1 parent 3b92c0b commit 2d5eea8

File tree

1 file changed

+38
-84
lines changed

1 file changed

+38
-84
lines changed

text/0000-export-visibility.md

Lines changed: 38 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -162,32 +162,6 @@ The `#[export_visibility = ...]` attribute uses the
162162
syntax to specify the desired visibility. The following sections describe
163163
string values that may be used.
164164

165-
### Interposable visibility
166-
167-
`#[export_visibility = "interposable"]` will cause symbols to be emitted with
168-
"default" visibility. On platforms that support it, this makes it so that
169-
symbols can be interposed, which means that they can be overridden by symbols
170-
with the same name from the executable or by other shared objects earlier in the
171-
load order.
172-
173-
> **Note**:
174-
> See [interposable-vs-llvm] section below for discussion about an open
175-
> question that asks about interactions between `interposable` visibility
176-
> and LLVM optimization passes.
177-
178-
> **Note**:
179-
> See [interposable-vs-dllexport] section below for discussion whether
180-
> this visibility should also inject `dllexport` when targeting Windows
181-
> platform.
182-
183-
> **TODO**: This section (as well as `protected` and `hidden` sections below) is based on
184-
> https://doc.rust-lang.org/beta/unstable-book/compiler-flags/default-visibility.html#interposable
185-
> In the long-term we should deduplicated these docs/definitions (for example
186-
> description of `hidden` in this RFC is a bit expanded and brings up additional
187-
> benefits of hiding symbols). "long-term" probably means: 1) once this or the
188-
> other feature have been stabilized and/or 2) once we are confident with names,
189-
> behavior, etc of all the visibility levels.
190-
191165
### Protected visibility
192166

193167
<!-- This section is based on
@@ -285,17 +259,8 @@ and
285259
[`#[export_name = ...]`](https://doc.rust-lang.org/reference/abi.html#the-export_name-attribute)
286260
attributes provides a similar level of details.)
287261

288-
A few additional notes attempt to clarify the intended behavior of the proposed
289-
behavior beyond what is described in the guide-level explanation above:
290-
291-
* The `#[export_visibility = ...]` attribute may only be applied to item
292-
definitions with an "extern" indicator as checked by
293-
[`fn contains_extern_indicator`](https://github.com/rust-lang/rust/blob/3bc767e1a215c4bf8f099b32e84edb85780591b1/compiler/rustc_middle/src/middle/codegen_fn_attrs.rs#L174-L184).
294-
Therefore it may only be applied to items to which
295-
`#[no_mangle]`, `#[export_name = ...]`, and similar already-existing
296-
attributes may be already applied.
297-
* The proposal in this RFC has been prototyped in
298-
https://github.com/anforowicz/rust/tree/export-visibility
262+
The proposal in this RFC has been prototyped in
263+
https://github.com/anforowicz/rust/tree/export-visibility
299264

300265
# Drawbacks
301266
[drawbacks]: #drawbacks
@@ -305,6 +270,41 @@ See "Open questions" section.
305270
# Rationale and alternatives
306271
[rationale-and-alternatives]: #rationale-and-alternatives
307272

273+
## Context: why the new attribute cannot increase visibility
274+
275+
The `#[export_visibility = ...]` attribute may only be applied to item
276+
definitions with an "extern" indicator as checked by [`fn
277+
contains_extern_indicator`](https://github.com/rust-lang/rust/blob/3bc767e1a215c4bf8f099b32e84edb85780591b1/compiler/rustc_middle/src/middle/codegen_fn_attrs.rs#L174-L184).
278+
Therefore it may only be applied to items to which `#[no_mangle]`,
279+
`#[export_name = ...]`, and similar already-existing attributes may be already
280+
applied.
281+
282+
Based on the above, the `#[export_visibility = ...]` attribute may never
283+
_increase_ visibility of a symbol. This is because:
284+
285+
* `#[no_mangle]`, `#[export_name = ...]` and similar attributes force the
286+
_maximum_ possible visiblity. See
287+
https://github.com/rust-lang/rust/blob/8111a2d6da405e9684a8a83c2c9d69036bf23f12/compiler/rustc_monomorphize/src/partitioning.rs#L930-L937
288+
* One known exception is `#[rustc_std_internal_symbol]` - see
289+
https://github.com/rust-lang/rust/blob/8111a2d6da405e9684a8a83c2c9d69036bf23f12/compiler/rustc_codegen_ssa/src/back/symbol_export.rs#L527-L542. This exception is avoided by disallowing using `#[export_visibility = ...]` with `#[rustc_std_internal_symbol]`.
290+
291+
## Rationale for not supporting `interposable` visibility
292+
293+
The "why the new attribute cannot increase visibility" section above means that
294+
`#[export_visibility = "interposable"]` would be a no-op. Because of this, the
295+
`"interposable"` visibility value is not supported by the
296+
`#[export_visibility = ...]` attribute.
297+
298+
> Side-note: The "interposable" visibility is sometimes called
299+
> "default" [linker] visibility (see [the LLVM documentation
300+
> here](https://llvm.org/docs/LangRef.html#visibility-styles)),
301+
> or "public" or "exported" visibility.
302+
303+
Lack of support for the `"interposable"` visibility means that this RFC avoids
304+
potential open questions about interaction with `__declspec(dllexport)` and/or
305+
whether `rustc` would have to enable the [the LLVM SemanticInterposition
306+
feature](https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-fsemantic-interposition).
307+
308308
## Alternative: `#[rust_symbol_export_level]`
309309

310310
The `#[export_visibility = ...]` proposed in this RFC supports directly
@@ -339,8 +339,7 @@ Other notes:
339339
- No `dylib` trouble (see [hidden-vs-dylibs])
340340
- No need to define behavior of specific visibilities - this question
341341
is punted to `-Zdefault-visibility=...`.
342-
See also [cross-platform-behavior], [interposable-vs-dllexport]
343-
and [interposable-vs-llvm].
342+
See also [cross-platform-behavior].
344343
* Cons:
345344
- Doesn't give the same level of control as C++ attributes
346345
* Open questions:
@@ -678,51 +677,6 @@ hiding symbols coming from Rust standard library:
678677
would still require rebuilding it with `-Zdefault-visibility=hidden`
679678
as described in the "do nothing" alternative above.
680679

681-
## Windows and `__declspec(dllexport)`
682-
[interposable-vs-dllexport]: #windows-and-__declspecdllexport
683-
684-
We need to decide whether `#[export_visibility = "interposable"]` should also
685-
result in `__declspec((dllexport))` being added to a symbol. See for example
686-
[this Stack Overflow question and answer](https://stackoverflow.com/a/25746044/24042981).
687-
688-
Potential answers:
689-
690-
* Don't stabilize for now (or don't support at all)
691-
`#[export_visibility = "interposable"]` but still support other visibilities
692-
* `#[export_visibility = "interposable"]` should only control visibility
693-
* `#[export_visibility = "interposable"]` should control visibility
694-
and also use `__declspec(dllexport)`
695-
696-
## Interposability vs LLVM optimization passes
697-
[interposable-vs-llvm]: #interposability-vs-llvm-optimization-passes
698-
699-
This RFC proposes to use `interposable` to map to
700-
[`SymbolVisibility::Interposable`](https://github.com/rust-lang/rust/blob/81a964c23ea4fe9ab52b4449bb166bf280035797/compiler/rustc_target/src/spec/mod.rs#L842)
701-
which is then mapped to
702-
[`llvm::Visibility::Default`](https://github.com/rust-lang/rust/blob/81a964c23ea4fe9ab52b4449bb166bf280035797/compiler/rustc_codegen_llvm/src/llvm/ffi.rs#L167). This mimics how `interposable` is implemented and supported
703-
in
704-
[`-Zdefault-visibility=...`](https://doc.rust-lang.org/beta/unstable-book/compiler-flags/default-visibility.html).
705-
706-
One problem here is that `llvm::Visibility::Default` is not sufficient to
707-
achieve actual interposability. https://crbug.com/418073233 has one example of
708-
undefined behavior, but even if DSO-local global data structures were not an
709-
issue, then LLVM-level assumptions could still lead to undefined behavior.
710-
This is because the LLVM optimization passes assume that a symbol with normal
711-
external linkage (not weak, odr, etc) the definition it can see is the
712-
definition that will be actually used. To avoid these LLVM assumptions `rustc`
713-
would have to enable
714-
[the SemanticInterposition feature](https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-fsemantic-interposition).
715-
716-
Special thanks to @jyknight for pointing out this concern.
717-
718-
Potential answers:
719-
720-
* Don't stabilize for now (or don't support at all)
721-
`#[export_visibility = "interposable"]` but still support other visibilities
722-
* Rename `interposable` to `public` or `default`.
723-
(It is quite unfortunate that `default` is an overloaded term and
724-
may be potentially confused with the `inherit` behavior.)
725-
726680
# Future possibilities
727681
[future-possibilities]: #future-possibilities
728682

0 commit comments

Comments
 (0)