Add import_name_type
parameter to #[link]
#495
Labels
major-change
A proposal to make a major change to rustc
T-compiler
Add this label so rfcbot knows to poll the compiler team
Proposal
I propose the addition of a new parameter,
import_name_type
, to the#[link]
attribute, to be used with#[link(kind = "raw-dylib")]
when importing stdcall functions on i686-pc-windows-* targets.When creating a Windows DLL on i686 that exports stdcall functions, it is possible to export the symbols from the DLL in one of four different ways, corresponding to the import name types from the PE-COFF spec. Each import name type encodes the symbol names in the DLL's export table in a different way, and the symbols in the import library must match in order to get a usable image. Mismatches lead either to link failures when creating the image or to "undefined symbol" errors upon attempting to load the image. For details, see the comments on the raw-dylib feature's tracking PR. To generate the correct import libraries for these DLLs, therefore, rustc has to know the import name type for each function in the extern block, 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:"name"
,"noprefix"
, and"undecorate"
. (These names are taken from the PE-COFF spec.)It is in theory possible to have a single DLL that exports some names with one type and other names with a different type, although I strongly suspect this to be quite rare in practice. Under this proposal, users could express such cases by providing multiple
export
blocks for the 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 implemented on master; it is handled by the#[link_ordinal]
attribute. This case differs from the other three in that it requires additional information specific to each function, so moving this functionality into the#[link]
attribute seems like a poor choice. I am proposing no changes to the#[link_ordinal]
attribute.Open points of discussion:
import_name_type
is not present on anextern "stdcall"
orextern "system"
block? Should the compiler signal an error, or should it default to one of the three values? If we choose to have a default, which of the three options should we choose? As one data point, the Windows API (such as kernel32.dll) requires "undecorate," but I don't have any hard data on which of the three is most common in the wild.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:#[link]
attribute wherekind
is not"raw-dylib"
#[link]
attribute on anextern
block with a calling convention other that"stdcall"
or"system"
extern "stdcall"
block is marked with the#[link_ordinal]
attribute, then specifyingimport_name_type
is unnecessary but harmless.I'm currently focusing on stdcall functions, although I suspect that this would also apply to fastcall and vectorcall. However, there are currently outstanding problems with code generation for the latter two calling conventions that are unrelated to raw-dylib, so they would seem to be less pressing.
Mentors or Reviewers
@wesleywiser is willing to review this proposal.
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: