diff options
| author | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2025-04-30 13:02:45 +0300 |
|---|---|---|
| committer | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2025-05-02 16:25:00 +0300 |
| commit | 842858f7650cae36d1b7194e4c758f42b2ca700c (patch) | |
| tree | 5b5336b15ddde4293a08837dad04300c2773bc51 | |
| parent | db074a06fe6649f9455dff8ad3eddd60683036f3 (diff) | |
| download | rust-842858f7650cae36d1b7194e4c758f42b2ca700c.tar.gz rust-842858f7650cae36d1b7194e4c758f42b2ca700c.zip | |
linker: Quote symbol names in .def files
To support weird symbol names, including dots in particular.
| -rw-r--r-- | compiler/rustc_codegen_ssa/src/back/linker.rs | 4 | ||||
| -rw-r--r-- | tests/ui/linking/weird-export-names.rs | 10 |
2 files changed, 13 insertions, 1 deletions
diff --git a/compiler/rustc_codegen_ssa/src/back/linker.rs b/compiler/rustc_codegen_ssa/src/back/linker.rs index a09eec5dd74..e1f903726fb 100644 --- a/compiler/rustc_codegen_ssa/src/back/linker.rs +++ b/compiler/rustc_codegen_ssa/src/back/linker.rs @@ -816,7 +816,9 @@ impl<'a> Linker for GccLinker<'a> { writeln!(f, "EXPORTS")?; for symbol in symbols { debug!(" _{symbol}"); - writeln!(f, " {symbol}")?; + // Quote the name in case it's reserved by linker in some way + // (this accounts for names with dots in particular). + writeln!(f, " \"{symbol}\"")?; } }; if let Err(error) = res { diff --git a/tests/ui/linking/weird-export-names.rs b/tests/ui/linking/weird-export-names.rs new file mode 100644 index 00000000000..8fb2dc6bf5e --- /dev/null +++ b/tests/ui/linking/weird-export-names.rs @@ -0,0 +1,10 @@ +//@ build-pass +//@ needs-crate-type: cdylib + +#![crate_type = "cdylib"] + +#[export_name = "foo.0123"] +pub extern "C" fn foo() {} + +#[export_name = "EXPORTS"] +pub extern "C" fn bar() {} |
