rust/compiler
bors 9845f4c47e Auto merge of #100732 - dpaoliello:import_name_type, r=wesleywiser
Implementation of import_name_type

Fixes #96534 by implementing https://github.com/rust-lang/compiler-team/issues/525

Symbols that are exported or imported from a binary on 32bit x86 Windows can be named in four separate ways, corresponding to the [import name types](https://docs.microsoft.com/en-us/windows/win32/debug/pe-format#import-name-type) from the PE-COFF spec. The exporting and importing binaries must use the same name encoding, otherwise mismatches can lead to link failures due to "missing symbols" or to 0xc0000139 (`STATUS_ENTRYPOINT_NOT_FOUND`) errors when the executable/library is loaded. For details, see the comments on the raw-dylib feature's https://github.com/rust-lang/rust/issues/58713. To generate the correct import libraries for these DLLs, therefore, rustc must know the import name type for each `extern` function, and there is currently no way for users to provide this information.

This change adds a new `MetaNameValueStr` key to the `#[link]` attribute called `import_name_type`, and which accepts one of three values: `decorated`, `noprefix`, and `undecorated`.

A single DLL is likely to export all its functions using the same import type name, hence `import_name_type` is a parameter of `#[link]` rather than being its own attribute that is applied per-function. It is possible to have a single DLL that exports different functions using different import name types, but users could express such cases by providing multiple export blocks for the same DLL, each with a different import name type.

Note: there is a fourth import name type defined in the PE-COFF spec, `IMPORT_ORDINAL`. This case is already handled by the `#[link_ordinal]` attribute. While it could be merged into `import_type_name`, that would not make sense as `#[link_ordinal]` provides per-function information (namely the ordinal itself).

Design decisions (these match the MCP linked above):
* For GNU, `decorated` matches the PE Spec and MSVC rather than the default behavior of `dlltool` (i.e., there will be a leading `_` for `stdcall`).
* If `import_name_type` is not present, we will keep our current behavior of matching the environment (MSVC vs GNU) default for decorating.
* Using `import_name_type` on architectures other than 32bit x86 will result in an error.
* Using `import_name_type` with link kinds other than `"raw-dylib"` will result in an error.
2022-08-27 03:19:12 +00:00
..
rustc
rustc_apfloat Add diagnostic translation lints to crates that don't emit them 2022-08-18 19:29:02 +01:00
rustc_arena Rollup merge of #100822 - WaffleLapkin:no_offset_question_mark, r=scottmcm 2022-08-21 16:54:07 +02:00
rustc_ast Rollup merge of #100978 - nnethercote:fix-100948, r=petrochenkov 2022-08-26 09:51:46 +09:00
rustc_ast_lowering Rollup merge of #100724 - JeanCASPAR:migrate-ast_lowering-to-session-diagnostic, r=davidtwco 2022-08-26 15:56:21 -07:00
rustc_ast_passes Rollup merge of #99332 - jyn514:stabilize-label-break-value, r=petrochenkov 2022-08-25 08:50:54 +09:00
rustc_ast_pretty Add diagnostic translation lints to crates that don't emit them 2022-08-18 19:29:02 +01:00
rustc_attr Move LitKind logic to session_diagnostics module 2022-08-22 20:19:20 +02:00
rustc_borrowck diag-mig 2022-08-26 10:32:59 +08:00
rustc_builtin_macros Rollup merge of #100909 - nnethercote:minor-ast-LitKind-improvement, r=petrochenkov 2022-08-23 20:40:09 +05:30
rustc_codegen_cranelift Rustfmt 2022-08-24 17:06:47 +00:00
rustc_codegen_gcc Rollup merge of #100604 - dtolnay:okorerr, r=m-ou-se 2022-08-26 09:51:44 +09:00
rustc_codegen_llvm Implementation of import_name_type 2022-08-26 09:15:35 -07:00
rustc_codegen_ssa Code cleaning 2022-08-25 19:04:00 +02:00
rustc_const_eval Auto merge of #101064 - compiler-errors:rollup-fwm5m5f, r=compiler-errors 2022-08-27 00:38:06 +00:00
rustc_data_structures get rid of RefCell in TransitiveRelation 2022-08-22 18:08:46 +08:00
rustc_driver Code cleaning 2022-08-25 19:04:00 +02:00
rustc_error_codes Stabilize #![feature(label_break_value)] 2022-08-23 21:14:12 -05:00
rustc_error_messages Rollup merge of #100900 - AndyJado:diag-migrate, r=davidtwco 2022-08-26 15:56:30 -07:00
rustc_errors errors: IntoDiagnosticArg for io::Error/paths 2022-08-24 06:50:44 +09:00
rustc_expand Remove the symbol from ast::LitKind::Err. 2022-08-23 16:56:24 +10:00
rustc_feature Implementation of import_name_type 2022-08-26 09:15:35 -07:00
rustc_fs_util Add diagnostic translation lints to crates that don't emit them 2022-08-18 19:29:02 +01:00
rustc_graphviz Add diagnostic translation lints to crates that don't emit them 2022-08-18 19:29:02 +01:00
rustc_hir Add diagnostic translation lints to crates that don't emit them 2022-08-18 19:29:02 +01:00
rustc_hir_pretty Add diagnostic translation lints to crates that don't emit them 2022-08-18 19:29:02 +01:00
rustc_incremental
rustc_index Add diagnostic translation lints to crates that don't emit them 2022-08-18 19:29:02 +01:00
rustc_infer Rollup merge of #99332 - jyn514:stabilize-label-break-value, r=petrochenkov 2022-08-25 08:50:54 +09:00
rustc_interface Rollup merge of #100808 - SkiFire13:migrate_diagnostics_rustc_interface, r=davidtwco 2022-08-25 08:50:58 +09:00
rustc_lexer Add diagnostic translation lints to crates that don't emit them 2022-08-18 19:29:02 +01:00
rustc_lint Rollup merge of #100776 - Rejyr:diagnostic-migration-rustc-lint, r=davidtwco 2022-08-26 15:56:25 -07:00
rustc_lint_defs Tidy 2022-08-22 00:57:21 +09:00
rustc_llvm Auto merge of #100627 - krasimirgg:lto-llvm-16, r=cuviper 2022-08-21 07:19:49 +00:00
rustc_log Add diagnostic translation lints to crates that don't emit them 2022-08-18 19:29:02 +01:00
rustc_macros Auto merge of #100748 - SparrowLii:query_depth, r=cjgillot 2022-08-25 21:27:38 +00:00
rustc_metadata Implementation of import_name_type 2022-08-26 09:15:35 -07:00
rustc_middle Auto merge of #100732 - dpaoliello:import_name_type, r=wesleywiser 2022-08-27 03:19:12 +00:00
rustc_mir_build Auto merge of #100944 - nnethercote:shrink-thir-Expr, r=cjgillot 2022-08-26 10:00:27 +00:00
rustc_mir_dataflow Rollup merge of #100744 - 5225225:migrate-rustc-mir-dataflow, r=davidtwco 2022-08-26 15:56:24 -07:00
rustc_mir_transform make read_immediate error immediately on uninit, so ImmTy can carry initialized Scalar 2022-08-26 13:20:57 -04:00
rustc_monomorphize Minor syntax and formatting update to doc comment 2022-08-19 10:53:18 -07:00
rustc_parse Rollup merge of #100188 - chenyukang:fix-issue-100165, r=estebank 2022-08-25 08:50:56 +09:00
rustc_parse_format Fix rustc_parse_format precision & width spans 2022-08-21 20:21:45 +00:00
rustc_passes Use par_body_owners for liveness 2022-08-23 20:53:02 +09:00
rustc_plugin_impl Migrate rustc_plugin_impl to SessionDiagnostic 2022-08-22 16:35:05 +01:00
rustc_privacy Replace #[lint/warning/error] with #[diag] 2022-08-21 09:17:43 +02:00
rustc_query_impl Auto merge of #100748 - SparrowLii:query_depth, r=cjgillot 2022-08-25 21:27:38 +00:00
rustc_query_system add depth_limit in QueryVTable 2022-08-24 09:42:12 +08:00
rustc_resolve Rollup merge of #100817 - vincenzopalazzo:macros/bool_spelling_sugg, r=davidtwco 2022-08-26 15:56:26 -07:00
rustc_save_analysis save_analysis: Migrate diagnostics 2022-08-24 06:50:16 +09:00
rustc_serialize Adding support for rustc_serialize encode and decode for Box and Vec that use a custom allocator 2022-08-25 20:19:49 +00:00
rustc_session Auto merge of #100732 - dpaoliello:import_name_type, r=wesleywiser 2022-08-27 03:19:12 +00:00
rustc_smir Add diagnostic translation lints to crates that don't emit them 2022-08-18 19:29:02 +01:00
rustc_span Implementation of import_name_type 2022-08-26 09:15:35 -07:00
rustc_symbol_mangling
rustc_target Auto merge of #98051 - davidtwco:split-dwarf-stabilization, r=wesleywiser 2022-08-26 15:47:26 +00:00
rustc_trait_selection Don't catch overflow when running with cargo doc 2022-08-26 21:02:35 +03:00
rustc_traits Add diagnostic translation lints to crates that don't emit them 2022-08-18 19:29:02 +01:00
rustc_transmute Rollup merge of #100604 - dtolnay:okorerr, r=m-ou-se 2022-08-26 09:51:44 +09:00
rustc_ty_utils Migrate rustc_ty_utils to use SessionDiagnostic 2022-08-26 14:36:51 +01:00
rustc_type_ir ADD - diagnostic lints to type_ir 2022-08-18 13:33:03 -04:00
rustc_typeck Rollup merge of #99064 - lyming2007:issue-97687-fix, r=estebank 2022-08-26 09:51:40 +09:00