Auto merge of #90128 - joshtriplett:stabilize-symbol-mangling-version, r=wesleywiser

Stabilize -Z symbol-mangling-version=v0 as -C symbol-mangling-version=v0

This allows selecting `v0` symbol-mangling without an unstable option. Selecting `legacy` still requires -Z unstable-options.

This does not change the default symbol-mangling-version. See https://github.com/rust-lang/rust/pull/89917 for a pull request changing the default. Rationale, from #89917:

Rust's current mangling scheme depends on compiler internals; loses information about generic parameters (and other things) which makes for a worse experience when using external tools that need to interact with Rust symbol names; is inconsistent; and can contain . characters which aren't universally supported. Therefore, Rust has defined its own symbol mangling scheme which is defined in terms of the Rust language, not the compiler implementation; encodes information about generic parameters in a reversible way; has a consistent definition; and generates symbols that only use the characters A-Z, a-z, 0-9, and _.

Support for the new Rust symbol mangling scheme has been added to upstream tools that will need to interact with Rust symbols (e.g. debuggers).

This pull request allows enabling the new v0 symbol-mangling-version.

See #89917 for references to the implementation of v0, and for references to the tool changes to decode Rust symbols.
This commit is contained in:
bors 2022-01-02 15:49:23 +00:00
commit 8f3238f898
28 changed files with 76 additions and 46 deletions

View file

@ -38,7 +38,7 @@ if [[ "$HOST_TRIPLE" != "$TARGET_TRIPLE" ]]; then
fi
fi
export RUSTFLAGS="$linker -Cpanic=abort -Zsymbol-mangling-version=v0 -Cdebuginfo=2 -Clto=off -Zpanic-abort-tests -Zcodegen-backend=$(pwd)/target/${CHANNEL:-debug}/librustc_codegen_gcc.$dylib_ext --sysroot $(pwd)/build_sysroot/sysroot"
export RUSTFLAGS="$linker -Cpanic=abort -Csymbol-mangling-version=v0 -Cdebuginfo=2 -Clto=off -Zpanic-abort-tests -Zcodegen-backend=$(pwd)/target/${CHANNEL:-debug}/librustc_codegen_gcc.$dylib_ext --sysroot $(pwd)/build_sysroot/sysroot"
# FIXME(antoyo): remove once the atomic shim is gone
if [[ `uname` == 'Darwin' ]]; then

View file

@ -183,7 +183,7 @@ EOF
git checkout src/test/ui/type-alias-impl-trait/auxiliary/cross_crate_ice2.rs
rm src/test/ui/llvm-asm/llvm-asm-in-out-operand.rs || true # TODO(antoyo): Enable back this test if I ever implement the llvm_asm! macro.
RUSTC_ARGS="-Zpanic-abort-tests -Zsymbol-mangling-version=v0 -Zcodegen-backend="$(pwd)"/../target/"$CHANNEL"/librustc_codegen_gcc."$dylib_ext" --sysroot "$(pwd)"/../build_sysroot/sysroot -Cpanic=abort"
RUSTC_ARGS="-Zpanic-abort-tests -Csymbol-mangling-version=v0 -Zcodegen-backend="$(pwd)"/../target/"$CHANNEL"/librustc_codegen_gcc."$dylib_ext" --sysroot "$(pwd)"/../build_sysroot/sysroot -Cpanic=abort"
echo "[TEST] rustc test suite"
COMPILETEST_FORCE_STAGE0=1 ./x.py test --run always --stage 0 src/test/ui/ --rustc-args "$RUSTC_ARGS"

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],
@ -1227,7 +1230,7 @@ options! {
instrument_coverage: Option<InstrumentCoverage> = (None, parse_instrument_coverage, [TRACKED],
"instrument the generated code to support LLVM source-based code coverage \
reports (note, the compiler build config must include `profiler = true`); \
implies `-Z symbol-mangling-version=v0`. Optional values are:
implies `-C symbol-mangling-version=v0`. Optional values are:
`=all` (implicit value)
`=except-unused-generics`
`=except-unused-functions`

View file

@ -237,7 +237,7 @@ fn compute_symbol_name<'tcx>(
// Pick the crate responsible for the symbol mangling version, which has to:
// 1. be stable for each instance, whether it's being defined or imported
// 2. obey each crate's own `-Z symbol-mangling-version`, as much as possible
// 2. obey each crate's own `-C symbol-mangling-version`, as much as possible
// We solve these as follows:
// 1. because symbol names depend on both `def_id` and `instantiating_crate`,
// both their `CrateNum`s are stable for any given instance, so we can pick
@ -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)
};

View file

@ -27,7 +27,7 @@ When running a coverage-instrumented program, the counter values are written to
[`llvm.instrprof.increment`]: https://llvm.org/docs/LangRef.html#llvm-instrprof-increment-intrinsic
[llvm code coverage mapping format]: https://llvm.org/docs/CoverageMappingFormat.html
> **Note**: `-Z instrument-coverage` also automatically enables `-Z symbol-mangling-version=v0` (tracking issue [#60705]). The `v0` symbol mangler is strongly recommended, but be aware that this demangler is also experimental. The `v0` demangler can be overridden by explicitly adding `-Z symbol-mangling-version=legacy`.
> **Note**: `-Z instrument-coverage` also automatically enables `-C symbol-mangling-version=v0` (tracking issue [#60705]). The `v0` symbol mangler is strongly recommended, but be aware that this demangler is also experimental. The `v0` demangler can be overridden by explicitly adding `-Z unstable-options -C symbol-mangling-version=legacy`.
[#60705]: https://github.com/rust-lang/rust/issues/60705

View file

@ -1,7 +1,7 @@
// Checks that closures, constructors, and shims except
// for a drop glue receive inline hint by default.
//
// compile-flags: -Cno-prepopulate-passes -Zsymbol-mangling-version=v0
// compile-flags: -Cno-prepopulate-passes -Csymbol-mangling-version=v0
#![crate_type = "lib"]
pub fn f() {

View file

@ -8,8 +8,8 @@
# and will probably get removed once `legacy` is gone.
all:
$(RUSTC) a.rs --cfg x -C prefer-dynamic -Z symbol-mangling-version=legacy
$(RUSTC) b.rs -C prefer-dynamic -Z symbol-mangling-version=legacy
$(RUSTC) a.rs --cfg x -C prefer-dynamic -Z unstable-options -C symbol-mangling-version=legacy
$(RUSTC) b.rs -C prefer-dynamic -Z unstable-options -C symbol-mangling-version=legacy
$(call RUN,b)
$(RUSTC) a.rs --cfg y -C prefer-dynamic -Z symbol-mangling-version=legacy
$(RUSTC) a.rs --cfg y -C prefer-dynamic -Z unstable-options -C symbol-mangling-version=legacy
$(call FAIL,b)

View file

@ -11,7 +11,7 @@
-include ../../run-make-fulldeps/tools.mk
COMMON_ARGS=-Cprefer-dynamic -Zshare-generics=yes -Ccodegen-units=1 -Zsymbol-mangling-version=v0
COMMON_ARGS=-Cprefer-dynamic -Zshare-generics=yes -Ccodegen-units=1 -Csymbol-mangling-version=v0
all:
$(RUSTC) instance_provider_a.rs $(COMMON_ARGS) --crate-type=rlib

View file

@ -1,5 +1,5 @@
// run-pass
// compile-flags: -Zsymbol-mangling-version=v0
// compile-flags: -Csymbol-mangling-version=v0
pub fn f<T: ?Sized>() {}
pub trait Frob<T: ?Sized> {}

View file

@ -14,8 +14,8 @@
// NOTE(eddyb) output differs between symbol mangling schemes
// revisions: legacy v0
// [legacy] compile-flags: -Zsymbol-mangling-version=legacy
// [v0] compile-flags: -Zsymbol-mangling-version=v0
// [legacy] compile-flags: -Zunstable-options -Csymbol-mangling-version=legacy
// [v0] compile-flags: -Csymbol-mangling-version=v0
fn main() {
panic!()

View file

@ -1,5 +1,5 @@
// build-pass
// compile-flags:-Zpolymorphize=on -Zsymbol-mangling-version=v0
// compile-flags:-Zpolymorphize=on -Csymbol-mangling-version=v0
fn foo(f: impl Fn()) {
let x = |_: ()| ();

View file

@ -1,5 +1,5 @@
// build-pass
// compile-flags:-Zpolymorphize=on -Zsymbol-mangling-version=v0
// compile-flags:-Zpolymorphize=on -Csymbol-mangling-version=v0
fn foo(f: impl Fn()) {
// Mutate an upvar from `x` so that it implements `FnMut`.

View file

@ -1,5 +1,5 @@
// build-pass
// compile-flags:-Zpolymorphize=on -Zsymbol-mangling-version=v0
// compile-flags:-Zpolymorphize=on -Csymbol-mangling-version=v0
fn foo(f: impl Fn()) {
// Move a non-copy type into `x` so that it implements `FnOnce`.

View file

@ -1,5 +1,5 @@
// build-pass
// compile-flags:-Zpolymorphize=on -Zsymbol-mangling-version=v0
// compile-flags:-Zpolymorphize=on -Csymbol-mangling-version=v0
fn y_uses_f(f: impl Fn()) {
let x = |_: ()| ();

View file

@ -1,5 +1,5 @@
// build-pass
// compile-flags: -Zpolymorphize=on -Zsymbol-mangling-version=v0
// compile-flags: -Zpolymorphize=on -Csymbol-mangling-version=v0
pub(crate) struct Foo<'a, I, E>(I, &'a E);

View file

@ -1,7 +1,7 @@
// build-fail
// revisions: legacy v0
//[legacy]compile-flags: -Z symbol-mangling-version=legacy
//[v0]compile-flags: -Z symbol-mangling-version=v0
//[legacy]compile-flags: -Z unstable-options -C symbol-mangling-version=legacy
//[v0]compile-flags: -C symbol-mangling-version=v0
#![feature(rustc_attrs)]

View file

@ -1,5 +1,5 @@
// build-fail
// compile-flags: -Z symbol-mangling-version=v0 --crate-name=c
// compile-flags: -C symbol-mangling-version=v0 --crate-name=c
// normalize-stderr-test: "c\[.*?\]" -> "c[HASH]"
#![feature(rustc_attrs)]

View file

@ -1,5 +1,5 @@
// build-fail
// compile-flags: -Z symbol-mangling-version=v0 --crate-name=c
// compile-flags: -C symbol-mangling-version=v0 --crate-name=c
// normalize-stderr-test: "c\[.*?\]" -> "c[HASH]"
#![feature(adt_const_params, rustc_attrs)]
#![allow(incomplete_features)]

View file

@ -1,5 +1,5 @@
// build-fail
// compile-flags: -Z symbol-mangling-version=v0 --crate-name=c
// compile-flags: -C symbol-mangling-version=v0 --crate-name=c
// NOTE(eddyb) we need `core` for `core::option::Option`, normalize away its
// disambiguator hash, which can/should change (including between stage{1,2}).

View file

@ -1,7 +1,7 @@
// check-pass
// revisions: legacy v0
//[legacy]compile-flags: -Z symbol-mangling-version=legacy --crate-type=lib
//[v0]compile-flags: -Z symbol-mangling-version=v0 --crate-type=lib
//[legacy]compile-flags: -Z unstable-options -C symbol-mangling-version=legacy --crate-type=lib
//[v0]compile-flags: -C symbol-mangling-version=v0 --crate-type=lib
// `char`
pub struct Char<const F: char>;

View file

@ -1,7 +1,7 @@
// build-fail
// revisions: legacy v0
//[legacy]compile-flags: -Z symbol-mangling-version=legacy
//[v0]compile-flags: -Z symbol-mangling-version=v0
//[legacy]compile-flags: -Z unstable-options -C symbol-mangling-version=legacy
//[v0]compile-flags: -C symbol-mangling-version=v0
//[legacy]normalize-stderr-test: "h[\w]{16}E?\)" -> "<SYMBOL_HASH>)"
#![feature(auto_traits, rustc_attrs)]

View file

@ -1,7 +1,7 @@
// build-fail
// revisions: legacy v0
//[legacy]compile-flags: -Z symbol-mangling-version=legacy
//[v0]compile-flags: -Z symbol-mangling-version=v0
//[legacy]compile-flags: -Z unstable-options -C symbol-mangling-version=legacy
//[v0]compile-flags: -C symbol-mangling-version=v0
#![feature(rustc_attrs)]

View file

@ -1,7 +1,7 @@
// build-fail
// revisions: legacy v0
//[legacy]compile-flags: -Z symbol-mangling-version=legacy
//[v0]compile-flags: -Z symbol-mangling-version=v0
//[legacy]compile-flags: -Z unstable-options -C symbol-mangling-version=legacy
//[v0]compile-flags: -C symbol-mangling-version=v0
//[legacy]normalize-stderr-test: "h[\w{16}]+" -> "SYMBOL_HASH"
#![feature(rustc_attrs)]

View file

@ -1,7 +1,7 @@
// check-pass
// revisions: legacy v0
//[legacy]compile-flags: -Z symbol-mangling-version=legacy --crate-type=lib
//[v0]compile-flags: -Z symbol-mangling-version=v0 --crate-type=lib
//[legacy]compile-flags: -Z unstable-options -C symbol-mangling-version=legacy --crate-type=lib
//[v0]compile-flags: -C symbol-mangling-version=v0 --crate-type=lib
pub struct Bar<const F: bool>;

View file

@ -2,7 +2,7 @@
// build-fail
// revisions: v0
//[v0]compile-flags: -Z symbol-mangling-version=v0
//[v0]compile-flags: -C symbol-mangling-version=v0
//[v0]normalize-stderr-test: "core\[.*?\]" -> "core[HASH]"
#![feature(rustc_attrs)]