diff --git a/compiler/rustc_codegen_ssa/src/back/linker.rs b/compiler/rustc_codegen_ssa/src/back/linker.rs index 4041bfaa24cf0..807a064ae8b4f 100644 --- a/compiler/rustc_codegen_ssa/src/back/linker.rs +++ b/compiler/rustc_codegen_ssa/src/back/linker.rs @@ -881,8 +881,8 @@ impl<'a> Linker for GccLinker<'a> { if !symbols.is_empty() { writeln!(f, " global:")?; for (sym, _) in symbols { - debug!(" {sym};"); - writeln!(f, " {sym};")?; + debug!(" \"{sym}\";"); + writeln!(f, " \"{sym}\";")?; } } writeln!(f, "\n local:\n *;\n}};")?; diff --git a/tests/run-make/export-quoted-symbols-version-script/lib.rs b/tests/run-make/export-quoted-symbols-version-script/lib.rs new file mode 100644 index 0000000000000..b20d67eb521b5 --- /dev/null +++ b/tests/run-make/export-quoted-symbols-version-script/lib.rs @@ -0,0 +1,4 @@ +#![crate_type = "cdylib"] + +#[unsafe(export_name = "some$foo::bar$thing/path.rs:42")] +pub extern "C" fn exported_symbol_with_version_script_special_characters() {} diff --git a/tests/run-make/export-quoted-symbols-version-script/rmake.rs b/tests/run-make/export-quoted-symbols-version-script/rmake.rs new file mode 100644 index 0000000000000..fea833c97a41b --- /dev/null +++ b/tests/run-make/export-quoted-symbols-version-script/rmake.rs @@ -0,0 +1,19 @@ +//@ only-linux +//@ needs-crate-type: cdylib + +extern crate run_make_support; + +use run_make_support::object::Object; +use run_make_support::{dynamic_lib_name, object, rfs, rustc}; + +const EXPORTED_SYMBOL: &[u8] = b"some$foo::bar$thing/path.rs:42"; + +fn main() { + rustc().input("lib.rs").run(); + + let contents = rfs::read(dynamic_lib_name("lib")); + let object = object::File::parse(contents.as_slice()).unwrap(); + let matching_exports = + object.exports().unwrap().iter().filter(|x| x.name() == EXPORTED_SYMBOL).count(); + assert_eq!(matching_exports, 1); +}