You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: text/0000-dll-kind.md
+11-9Lines changed: 11 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,5 @@
1
1
- Feature Name: dll_kind
2
-
- Start Date: 2018-06-27
2
+
- Start Date: 2019-01-22
3
3
- RFC PR: (leave this empty)
4
4
- Rust Issue: (leave this empty)
5
5
@@ -11,11 +11,13 @@ Extend the `#[link]` attribute by adding a new kind `kind="dll"` for use on Wind
11
11
# Motivation
12
12
[motivation]: #motivation
13
13
14
-
Traditionally in order to link against a dll the program must actually link against an import library. For example to depend on some symbols from kernel32.dll the program links to kernel32.lib. However this requires that the correct import libraries be available to link against, and for third party libraries that are only distributed as a dll creating an import library can be quite difficult, especially given lib.exe is incapable of creating an import library that links to stdcall symbols.
A real advantage of this feature, however, is the fact that symbols will be *guaranteed*to come from the specified dll. Currently linking is a very finnicky process where if multiple libraries provide the same symbol the linker will choose one of them to provide the symbol and the user has very little control over it. With `kind="dll"` the user is ensured that the symbol will come from the specified dll.
16
+
Traditionally, to link against a [dll], the program must actually link against an import library. For example to depend on some symbols from `kernel32.dll`the program links to `kernel32.lib`. However, this requires that the correct import libraries be available to link against, and for third party libraries that are only distributed as a dll creating an import library can be quite difficult, especially given that `lib.exe`is incapable of creating an import library that links to `stdcall` symbols.
17
17
18
-
Sometimes a crate may know exactly which dll it wants to link against, but which import library it ends up linking against is unknown. In particular the d3dcompiler.lib provided by the Windows SDK can link to several different versions of the d3dcompiler dll depending on which version of the Windows SDK the user has installed. `kind="dll"` would allow `winapi` to link to a specific version of that dll and ensure the symbols are correct for that version.
18
+
A real advantage of this feature, however, is the fact that symbols will be *guaranteed* to come from the specified dll. Currently, linking is a very finnicky process where if multiple libraries provide the same symbol the linker will choose one of them to provide the symbol and the user has little control over it. With `kind="dll"` the user is ensured that the symbol will come from the specified dll.
19
+
20
+
Sometimes, a crate may know exactly which dll it wants to link against, but which import library it ends up linking against is unknown. In particular the `d3dcompiler.lib` provided by the Windows SDK can link to several different versions of the d3dcompiler dll depending on which version of the Windows SDK the user has installed. `kind="dll"` would allow `winapi` to link to a specific version of that dll and ensure the symbols are correct for that version.
19
21
20
22
This would also allow `winapi` to not have to bundle import libraries for the `pc-windows-gnu` targets, saving on bandwidth and disk space for users.
21
23
@@ -24,7 +26,7 @@ This would also allow `winapi` to not have to bundle import libraries for the `p
24
26
25
27
When trying to link to a Windows dll, the `dylib` kind may sometimes be unsuitable, and `kind="dll"` can be used instead. A central requirement of `kind="dll"` is that the dll has a stable ABI. Here are some examples of valid reasons to use `kind="dll"`:
26
28
27
-
* You've had it up to here with trying to create an import library for a dll that has stdcall functions.
29
+
* You've had it up to here with trying to create an import library for a dll that has `stdcall` functions.
28
30
* You're in linking hell with multiple import libraries providing the same symbol but from different dlls.
29
31
* You know exactly which dll you need a symbol from, but you don't know which version of the dll the import library is going to give you.
30
32
* You maintain `winapi`.
@@ -40,7 +42,7 @@ extern "system" {
40
42
}
41
43
```
42
44
43
-
Some symbols are only exported by ordinal from the dll in which case `#[link_ordinal]` may be used:
45
+
Some symbols are only exported by ordinal from the dll in which case `#[link_ordinal(..)]` may be used:
Add a new attribute `#[link_ordinal]` taking a single numerical value, such as `#[link_ordinal(116)]`. It can only be specified on symbols in an extern block using `kind="dll"`.
60
+
Add a new attribute `#[link_ordinal]` taking a single unsuffixed integer value, such as `#[link_ordinal(116)]`. It can only be specified on symbols in an extern block using `kind="dll"`.
59
61
60
-
Add a new value `dll` to the `kind` property of the `link` attribute. When this kind is specified, the `name` must explicitly include the extension. In addition, for all items in the associated extern block Rust will *keep* the symbol mangled, instead of having an unmangled symbol. Rust will emit an idata section that maps from the *mangled* symbol to a symbol in the specified dll. The symbol in the dll that the idata section maps to depends on which attributes are specified on the item in question:
62
+
Add a new value `dll` to the `kind` property of the `link` attribute. When this kind is specified, the `name` must explicitly include the extension. In addition, for all items in the associated extern block, Rust will *keep* the symbol mangled, instead of having an unmangled symbol. Rust will emit an idata section that maps from the *mangled* symbol to a symbol in the specified dll. The symbol in the dll that the idata section maps to depends on which attributes are specified on the item in question:
61
63
62
64
* If `#[link_ordinal]` is specified the idata section will map from the mangled symbol to the ordinal specified in the dll.
63
65
* If `#[link_name]` is specified the idata section will map from the mangled symbol to the name specified in the dll, without any calling convention decorations added. If calling convention decorations are desired they must be specified explicitly in the value of the `#[link_name]` attribute.
@@ -94,7 +96,7 @@ Delphi is a native language that has the ability to import symbols from dlls wit
94
96
# Future possibilities
95
97
[future-possibilities]: #future-possibilities
96
98
97
-
With the features described in this RFC, we would be one step closer towards a fully standalone pure Rust target for Windows that does not rely on any external libraries (aside from the obvious and unavoidable runtime dependence on system libraries), allowing for easy installation and incredibly easy cross compilation.
99
+
With the features described in this RFC, we would be one step closer towards a fully standalone pure Rust target for Windows that does not rely on any external libraries (aside from the obvious and unavoidable runtime dependence on system libraries), allowing for easy installation and easy cross compilation.
98
100
99
101
If that were to happen, we'd no longer need to pretend the pc-windows-gnu toolchain is standalone, and we'd be able to stop bundling MinGW bits entirely in favor of the user's own MinGW installation, thereby resolving a bunch of issues such as [rust-lang/rust#53454](https://github.com/rust-lang/rust/issues/53454).
0 commit comments