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.
This commit is contained in:
Josh Triplett 2021-10-21 14:02:59 +02:00
parent c145692254
commit bbf4b6699e
5 changed files with 42 additions and 12 deletions

View File

@ -594,6 +594,7 @@ fn test_codegen_options_tracking_hash() {
tracked!(relocation_model, Some(RelocModel::Pic));
tracked!(soft_float, true);
tracked!(split_debuginfo, Some(SplitDebuginfo::Packed));
tracked!(symbol_mangling_version, Some(SymbolManglingVersion::V0));
tracked!(target_cpu, Some(String::from("abc")));
tracked!(target_feature, String::from("all the features, all of them"));
}

View File

@ -721,7 +721,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
no_builtins: tcx.sess.contains_name(&attrs, sym::no_builtins),
panic_runtime: tcx.sess.contains_name(&attrs, sym::panic_runtime),
profiler_runtime: tcx.sess.contains_name(&attrs, sym::profiler_runtime),
symbol_mangling_version: tcx.sess.opts.debugging_opts.get_symbol_mangling_version(),
symbol_mangling_version: tcx.sess.opts.get_symbol_mangling_version(),
crate_deps,
dylib_dependency_formats,

View File

@ -781,6 +781,10 @@ impl Options {
},
}
}
pub fn get_symbol_mangling_version(&self) -> SymbolManglingVersion {
self.cg.symbol_mangling_version.unwrap_or(SymbolManglingVersion::Legacy)
}
}
impl DebuggingOptions {
@ -794,10 +798,6 @@ impl DebuggingOptions {
deduplicate_diagnostics: self.deduplicate_diagnostics,
}
}
pub fn get_symbol_mangling_version(&self) -> SymbolManglingVersion {
self.symbol_mangling_version.unwrap_or(SymbolManglingVersion::Legacy)
}
}
// 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 {
);
}
// Handle both `-Z symbol-mangling-version` and `-C symbol-mangling-version`; the latter takes
// precedence.
match (cg.symbol_mangling_version, debugging_opts.symbol_mangling_version) {
(Some(smv_c), Some(smv_z)) if smv_c != smv_z => {
early_error(
error_format,
"incompatible values passed for `-C symbol-mangling-version` \
and `-Z symbol-mangling-version`",
);
}
(Some(SymbolManglingVersion::V0), _) => {}
(Some(_), _) if !debugging_opts.unstable_options => {
early_error(
error_format,
"`-C symbol-mangling-version=legacy` requires `-Z unstable-options`",
);
}
(None, None) => {}
(None, smv) => {
early_warn(
error_format,
"`-Z symbol-mangling-version` is deprecated; use `-C symbol-mangling-version`",
);
cg.symbol_mangling_version = smv;
}
_ => {}
}
if debugging_opts.instrument_coverage.is_some()
&& debugging_opts.instrument_coverage != Some(InstrumentCoverage::Off)
{
@ -2127,19 +2155,17 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
);
}
// `-Z instrument-coverage` implies `-Z symbol-mangling-version=v0` - to ensure consistent
// `-Z instrument-coverage` implies `-C symbol-mangling-version=v0` - to ensure consistent
// and reversible name mangling. Note, LLVM coverage tools can analyze coverage over
// multiple runs, including some changes to source code; so mangled names must be consistent
// across compilations.
match debugging_opts.symbol_mangling_version {
None => {
debugging_opts.symbol_mangling_version = Some(SymbolManglingVersion::V0);
}
match cg.symbol_mangling_version {
None => cg.symbol_mangling_version = Some(SymbolManglingVersion::V0),
Some(SymbolManglingVersion::Legacy) => {
early_warn(
error_format,
"-Z instrument-coverage requires symbol mangling version `v0`, \
but `-Z symbol-mangling-version=legacy` was specified",
but `-C symbol-mangling-version=legacy` was specified",
);
}
Some(SymbolManglingVersion::V0) => {}

View File

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

View File

@ -245,7 +245,7 @@ fn compute_symbol_name<'tcx>(
// 2. we favor `instantiating_crate` where possible (i.e. when `Some`)
let mangling_version_crate = instantiating_crate.unwrap_or(def_id.krate);
let mangling_version = if mangling_version_crate == LOCAL_CRATE {
tcx.sess.opts.debugging_opts.get_symbol_mangling_version()
tcx.sess.opts.get_symbol_mangling_version()
} else {
tcx.symbol_mangling_version(mangling_version_crate)
};