Skip to content

Commit fc28049

Browse files
committed
Add unstable -Zdefault-hidden-visibility cmdline flag for rustc.
The new flag has been described in the Major Change Proposal at rust-lang/compiler-team#656
1 parent 1be1e84 commit fc28049

File tree

5 files changed

+64
-0
lines changed

5 files changed

+64
-0
lines changed

compiler/rustc_interface/src/tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,7 @@ fn test_unstable_options_tracking_hash() {
749749
tracked!(cross_crate_inline_threshold, InliningThreshold::Always);
750750
tracked!(debug_info_for_profiling, true);
751751
tracked!(debug_macros, true);
752+
tracked!(default_hidden_visibility, None);
752753
tracked!(dep_info_omit_d_target, true);
753754
tracked!(dual_proc_macros, true);
754755
tracked!(dwarf_version, Some(5));

compiler/rustc_session/src/options.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1538,6 +1538,8 @@ options! {
15381538
"compress debug info sections (none, zlib, zstd, default: none)"),
15391539
deduplicate_diagnostics: bool = (true, parse_bool, [UNTRACKED],
15401540
"deduplicate identical diagnostics (default: yes)"),
1541+
default_hidden_visibility: Option<bool> = (None, parse_opt_bool, [TRACKED],
1542+
"overrides the `default_hidden_visibility` setting of the target"),
15411543
dep_info_omit_d_target: bool = (false, parse_bool, [TRACKED],
15421544
"in dep-info output, omit targets for tracking dependencies of the dep-info files \
15431545
themselves (default: no)"),

compiler/rustc_session/src/session.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -960,6 +960,21 @@ impl Session {
960960
termize::dimensions().map_or(default_column_width, |(w, _)| w)
961961
}
962962
}
963+
964+
pub fn default_hidden_visibility(&self) -> bool {
965+
// FIXME:
966+
//
967+
// * Combine:
968+
// 1) `self.target.default_hidden_visibility` (or maybe
969+
// `self.target.options.default_hidden_visibility`?)
970+
// and
971+
// 2) `self.opts.unstable_opts.default_hidden_visibility`
972+
//
973+
// * Grep the whole source for `default_hidden_visibility` and use
974+
// `session.default_hidden_visibility()` instead of
975+
// `sess.target.default_hidden_visibility`, etc.
976+
todo!("DO NOT SUBMIT");
977+
}
963978
}
964979

965980
// JUSTIFICATION: defn of the suggested wrapper fns
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# `default-hidden-visibility`
2+
3+
The tracking issue for this feature is: https://github.com/rust-lang/compiler-team/issues/656
4+
5+
------------------------
6+
7+
This flag can be used to override the target's
8+
[`default_hidden_visibility`](https://doc.rust-lang.org/beta/nightly-rustc/rustc_target/spec/struct.TargetOptions.html#structfield.default_hidden_visibility)
9+
setting.
10+
Using `-Zdefault_hidden_visibility=yes` is roughly equivalent to Clang's
11+
[`-fvisibility=hidden`](https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-fvisibility)
12+
cmdline flag.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Verifies that `TargetOptions::default_hidden_visibility` is set when using the related cmdline
2+
// flag. This is a regression test for https://github.com/rust-lang/compiler-team/issues/656.
3+
// See also https://github.com/rust-lang/rust/issues/73295 and
4+
// https://github.com/rust-lang/rust/issues/37530.
5+
//
6+
// revisions:NONE YES
7+
//[YES] compile-flags: -Zdefault-hidden-visibility=yes
8+
//
9+
// FIXME: 3) also cover NO?
10+
11+
// The test scenario is specifically about visibility of symbols in Rust static libraries.
12+
//
13+
// This mimics the relevant part from https://github.com/rust-lang/rust/issues/73295 which
14+
// says:
15+
//
16+
// > We build Rust code into these DSOs in the approved way, which is to aggregate a bunch of Rust
17+
// > libraries (rlibs) into a separate Rust ***staticlib*** for each of the DSOs. (For example,
18+
// > libbase_rust_deps.a and libservices_rust_deps.a). The final C++ linker links exactly one of
19+
// > these staticlibs together with the C++ .a and .o in the final construction of the DSO.
20+
#![crate_type = "staticlib"]
21+
22+
// The test scenario needs to use a public, but non-`#[no_mangle]` Rust symbol.
23+
//
24+
// We want to check the visibility of this symbol:
25+
//
26+
// FIXME: 1) confirm that this test file actually repros the problem at hand (I am not at all
27+
// confident that it does)
28+
// FIXME: 2) fix test expectations below ("internal" below seems unexpected for NONE scenario? no
29+
// idea what should be the expectation for YES scenario)
30+
//
31+
// NONE: @_ZN25default_hidden_visibility15exported_symbol17hc5deee4a42a30cf5E = internal constant
32+
// YES: ???????????
33+
#[used]
34+
pub static exported_symbol: [u8; 6] = *b"foobar";

0 commit comments

Comments
 (0)