diff options
| author | bors <bors@rust-lang.org> | 2019-12-20 16:24:12 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2019-12-20 16:24:12 +0000 |
| commit | 01a46509a4c2dc430ebebf940a26232fdaeeba81 (patch) | |
| tree | 4e6f0da977dffdce7073fdf1a681986d7b38650b /src/librustc_codegen_utils | |
| parent | 6b561b4917e803c4be4ca44d8e552b680cb9e380 (diff) | |
| parent | 43d1532cd7c2d03e8af3e7179edccd89e989897f (diff) | |
| download | rust-01a46509a4c2dc430ebebf940a26232fdaeeba81.tar.gz rust-01a46509a4c2dc430ebebf940a26232fdaeeba81.zip | |
Auto merge of #67455 - Centril:rollup-mf0yc81, r=Centril
Rollup of 5 pull requests Successful merges: - #64588 (Add a raw "address of" operator) - #67031 (Update tokio crates to latest versions) - #67131 (Merge `TraitItem` & `ImplItem into `AssocItem`) - #67354 (Fix pointing at arg when cause is outside of call) - #67363 (Fix handling of wasm import modules and names) Failed merges: r? @ghost
Diffstat (limited to 'src/librustc_codegen_utils')
| -rw-r--r-- | src/librustc_codegen_utils/symbol_names.rs | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/src/librustc_codegen_utils/symbol_names.rs b/src/librustc_codegen_utils/symbol_names.rs index c52c6cfa83c..922964ee45f 100644 --- a/src/librustc_codegen_utils/symbol_names.rs +++ b/src/librustc_codegen_utils/symbol_names.rs @@ -142,12 +142,32 @@ fn symbol_name(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) -> Symbol { }; let attrs = tcx.codegen_fn_attrs(def_id); + + // Foreign items by default use no mangling for their symbol name. There's a + // few exceptions to this rule though: + // + // * This can be overridden with the `#[link_name]` attribute + // + // * On the wasm32 targets there is a bug (or feature) in LLD [1] where the + // same-named symbol when imported from different wasm modules will get + // hooked up incorectly. As a result foreign symbols, on the wasm target, + // with a wasm import module, get mangled. Additionally our codegen will + // deduplicate symbols based purely on the symbol name, but for wasm this + // isn't quite right because the same-named symbol on wasm can come from + // different modules. For these reasons if `#[link(wasm_import_module)]` + // is present we mangle everything on wasm because the demangled form will + // show up in the `wasm-import-name` custom attribute in LLVM IR. + // + // [1]: https://bugs.llvm.org/show_bug.cgi?id=44316 if is_foreign { - if let Some(name) = attrs.link_name { - return name; + if tcx.sess.target.target.arch != "wasm32" || + !tcx.wasm_import_module_map(def_id.krate).contains_key(&def_id) + { + if let Some(name) = attrs.link_name { + return name; + } + return tcx.item_name(def_id); } - // Don't mangle foreign items. - return tcx.item_name(def_id); } if let Some(name) = attrs.export_name { |
