-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Implementation of import_name_type #100732
Conversation
r? @TaKO8Ki (rust-highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
f647172
to
60d2654
Compare
This comment has been minimized.
This comment has been minimized.
60d2654
to
5e5f094
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, this looks pretty good, nice work!
9abf76e
to
f847388
Compare
Awesome, thanks @dpaoliello! @bors r+ |
Thanks for working on this! This looks good to me, with my lang team hat on.
As a potential improvement for the future, I do think it might make sense to allow this attribute on a per-function basis as an override. That is not a blocker in any way, though. |
…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.
@Dylan-DPC - I don't believe that failure is related to this change: the code that I added should only be enabled if someone actually uses the |
Yeah, @dpaoliello is right, @bors r=wesleywiser |
⌛ Testing commit f847388 with merge b771848c3bda7198ca2aa39d18b62bf36e0de759... |
💔 Test failed - checks-actions |
This comment has been minimized.
This comment has been minimized.
f847388
to
cc49c3e
Compare
@wesleywiser build has been fixed, can we please retry? |
Sure! @bors r+ |
☀️ Test successful - checks-actions |
Finished benchmarking commit (9845f4c): comparison URL. Overall result: ❌ regressions - no action needed@rustbot label: -perf-regression Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Footnotes |
Fixes #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 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 #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.This change adds a new
MetaNameValueStr
key to the#[link]
attribute calledimport_name_type
, and which accepts 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).Design decisions (these match the MCP linked above):
decorated
matches the PE Spec and MSVC rather than the default behavior ofdlltool
(i.e., there will be a leading_
forstdcall
).import_name_type
is not present, we will keep our current behavior of matching the environment (MSVC vs GNU) default for decorating.import_name_type
on architectures other than 32bit x86 will result in an error.import_name_type
with link kinds other than"raw-dylib"
will result in an error.