Skip to content

Commit bbf4b66

Browse files
committed
Stabilize -Z symbol-mangling-version as -C symbol-mangling-version
This allows selecting `v0` symbol-mangling without an unstable option. Selecting `legacy` still requires -Z unstable-options. Continue supporting -Z symbol-mangling-version for compatibility for now, but show a deprecation warning for it.
1 parent c145692 commit bbf4b66

File tree

5 files changed

+42
-12
lines changed

5 files changed

+42
-12
lines changed

Diff for: compiler/rustc_interface/src/tests.rs

+1
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,7 @@ fn test_codegen_options_tracking_hash() {
594594
tracked!(relocation_model, Some(RelocModel::Pic));
595595
tracked!(soft_float, true);
596596
tracked!(split_debuginfo, Some(SplitDebuginfo::Packed));
597+
tracked!(symbol_mangling_version, Some(SymbolManglingVersion::V0));
597598
tracked!(target_cpu, Some(String::from("abc")));
598599
tracked!(target_feature, String::from("all the features, all of them"));
599600
}

Diff for: compiler/rustc_metadata/src/rmeta/encoder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
721721
no_builtins: tcx.sess.contains_name(&attrs, sym::no_builtins),
722722
panic_runtime: tcx.sess.contains_name(&attrs, sym::panic_runtime),
723723
profiler_runtime: tcx.sess.contains_name(&attrs, sym::profiler_runtime),
724-
symbol_mangling_version: tcx.sess.opts.debugging_opts.get_symbol_mangling_version(),
724+
symbol_mangling_version: tcx.sess.opts.get_symbol_mangling_version(),
725725

726726
crate_deps,
727727
dylib_dependency_formats,

Diff for: compiler/rustc_session/src/config.rs

+36-10
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,10 @@ impl Options {
781781
},
782782
}
783783
}
784+
785+
pub fn get_symbol_mangling_version(&self) -> SymbolManglingVersion {
786+
self.cg.symbol_mangling_version.unwrap_or(SymbolManglingVersion::Legacy)
787+
}
784788
}
785789

786790
impl DebuggingOptions {
@@ -794,10 +798,6 @@ impl DebuggingOptions {
794798
deduplicate_diagnostics: self.deduplicate_diagnostics,
795799
}
796800
}
797-
798-
pub fn get_symbol_mangling_version(&self) -> SymbolManglingVersion {
799-
self.symbol_mangling_version.unwrap_or(SymbolManglingVersion::Legacy)
800-
}
801801
}
802802

803803
// The type of entry function, so users can have their own entry functions
@@ -2116,6 +2116,34 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
21162116
);
21172117
}
21182118

2119+
// Handle both `-Z symbol-mangling-version` and `-C symbol-mangling-version`; the latter takes
2120+
// precedence.
2121+
match (cg.symbol_mangling_version, debugging_opts.symbol_mangling_version) {
2122+
(Some(smv_c), Some(smv_z)) if smv_c != smv_z => {
2123+
early_error(
2124+
error_format,
2125+
"incompatible values passed for `-C symbol-mangling-version` \
2126+
and `-Z symbol-mangling-version`",
2127+
);
2128+
}
2129+
(Some(SymbolManglingVersion::V0), _) => {}
2130+
(Some(_), _) if !debugging_opts.unstable_options => {
2131+
early_error(
2132+
error_format,
2133+
"`-C symbol-mangling-version=legacy` requires `-Z unstable-options`",
2134+
);
2135+
}
2136+
(None, None) => {}
2137+
(None, smv) => {
2138+
early_warn(
2139+
error_format,
2140+
"`-Z symbol-mangling-version` is deprecated; use `-C symbol-mangling-version`",
2141+
);
2142+
cg.symbol_mangling_version = smv;
2143+
}
2144+
_ => {}
2145+
}
2146+
21192147
if debugging_opts.instrument_coverage.is_some()
21202148
&& debugging_opts.instrument_coverage != Some(InstrumentCoverage::Off)
21212149
{
@@ -2127,19 +2155,17 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
21272155
);
21282156
}
21292157

2130-
// `-Z instrument-coverage` implies `-Z symbol-mangling-version=v0` - to ensure consistent
2158+
// `-Z instrument-coverage` implies `-C symbol-mangling-version=v0` - to ensure consistent
21312159
// and reversible name mangling. Note, LLVM coverage tools can analyze coverage over
21322160
// multiple runs, including some changes to source code; so mangled names must be consistent
21332161
// across compilations.
2134-
match debugging_opts.symbol_mangling_version {
2135-
None => {
2136-
debugging_opts.symbol_mangling_version = Some(SymbolManglingVersion::V0);
2137-
}
2162+
match cg.symbol_mangling_version {
2163+
None => cg.symbol_mangling_version = Some(SymbolManglingVersion::V0),
21382164
Some(SymbolManglingVersion::Legacy) => {
21392165
early_warn(
21402166
error_format,
21412167
"-Z instrument-coverage requires symbol mangling version `v0`, \
2142-
but `-Z symbol-mangling-version=legacy` was specified",
2168+
but `-C symbol-mangling-version=legacy` was specified",
21432169
);
21442170
}
21452171
Some(SymbolManglingVersion::V0) => {}

Diff for: compiler/rustc_session/src/options.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1083,6 +1083,9 @@ options! {
10831083
"how to handle split-debuginfo, a platform-specific option"),
10841084
strip: Strip = (Strip::None, parse_strip, [UNTRACKED],
10851085
"tell the linker which information to strip (`none` (default), `debuginfo` or `symbols`)"),
1086+
symbol_mangling_version: Option<SymbolManglingVersion> = (None,
1087+
parse_symbol_mangling_version, [TRACKED],
1088+
"which mangling version to use for symbol names ('legacy' (default) or 'v0')"),
10861089
target_cpu: Option<String> = (None, parse_opt_string, [TRACKED],
10871090
"select target processor (`rustc --print target-cpus` for details)"),
10881091
target_feature: String = (String::new(), parse_target_feature, [TRACKED],

Diff for: compiler/rustc_symbol_mangling/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ fn compute_symbol_name<'tcx>(
245245
// 2. we favor `instantiating_crate` where possible (i.e. when `Some`)
246246
let mangling_version_crate = instantiating_crate.unwrap_or(def_id.krate);
247247
let mangling_version = if mangling_version_crate == LOCAL_CRATE {
248-
tcx.sess.opts.debugging_opts.get_symbol_mangling_version()
248+
tcx.sess.opts.get_symbol_mangling_version()
249249
} else {
250250
tcx.symbol_mangling_version(mangling_version_crate)
251251
};

0 commit comments

Comments
 (0)