-
Notifications
You must be signed in to change notification settings - Fork 69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add import_name_type parameter to #[link] #525
Comments
This issue is not meant to be used for technical discussion. There is a Zulip stream for that. Use this issue to leave procedural comments, such as volunteering to review, indicating that you second the proposal (or third, etc), or raising a concern that you would like to be addressed. cc @rust-lang/compiler @rust-lang/compiler-contributors |
@rustbot second |
@rustbot label -final-comment-period +major-change-accepted |
…leywiser Implementation of import_name_type Fixes rust-lang#96534 by implementing rust-lang/compiler-team#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 rust-lang#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.
…ywiser Implementation of import_name_type Fixes rust-lang#96534 by implementing rust-lang/compiler-team#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 rust-lang#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.
Proposal
(This is another attempt at #495)
Add a new parameter,
import_name_type
, to the#[link]
attribute to be used with#[link(kind = "raw-dylib")]
when importing functions on i686-pc-windows-* targets.Symbols that are exported or imported from a binary on i686 Windows can be named in four separate ways, corresponding to the import name types 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 rust-lang/rust#58713. To generate the correct import libraries for these DLLs, therefore, rustc must know the import name type for eachextern
function, and there is currently no way for users to provide this information.I propose adding a new
MetaNameValueStr
key to the#[link]
attribute. This key would be calledimport_name_type
, and it would accept one of three values:decorated
,noprefix
, andundecorated
.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 intoimport_type_name
, that would not make sense as#[link_ordinal]
provides per-function information (namely the ordinal itself).Open points of discussion:
decorated
mean forstdcall
on GNU?dlltool
doesn't include a leading_
, should that be our behavior? Or should we add the_
to match MSVC? (I suggest: match MSVC - this gives us compatibility with the Win32 DLLs)import_name_type
is not present on an extern block? Should the compiler signal an error, use the system default, or fully decorate? (I suggest: system default - this matches the behavior when not usingraw-dylib
)import_name_type
is provided in situations where it is not required, or should it silently ignore the extra parameter? These cases include the following:unsupported_calling_conventions
rust#87678).#[link]
attribute where kind is not"raw-dylib"
(I suggest: error - this is a user error and will not do what they intended).#[link]
attribute on an extern block with a calling convention that doesn't decorate names (I suggest: error - this is a user error and will not do what they intended. NOTE:kind = "raw-dylib"
already raises errors for unsupported calling conventions).I have a prototype of this feature implemented via dpaoliello/rust@e86a32c
Mentors or Reviewers
Reviewer: @wesleywiser
Process
The main points of the Major Change Process are as follows:
@rustbot second
.-C flag
, then full team check-off is required.@rfcbot fcp merge
on either the MCP or the PR.You can read more about Major Change Proposals on forge.
Comments
This issue is not meant to be used for technical discussion. There is a Zulip stream for that. Use this issue to leave procedural comments, such as volunteering to review, indicating that you second the proposal (or third, etc), or raising a concern that you would like to be addressed.
The text was updated successfully, but these errors were encountered: