Uh oh!
There was an error while loading. Please reload this page.
Implementation of import_name_type - #100732
Conversation
rust-highfive
commented
Aug 18, 2022
r? @TaKO8Ki (rust-highfive has picked a reviewer for you, use r? to override) |
dpaoliello
commented
Aug 18, 2022
This comment has been minimized.
This comment has been minimized.
f647172 to
60d2654Compare
This comment has been minimized.
This comment has been minimized.
60d2654 to
5e5f094Compare
wesleywiser
left a comment
There was a problem hiding this comment.
Overall, this looks pretty good, nice work!
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
9abf76e to
f847388Comparewesleywiser
commented
Aug 24, 2022
Awesome, thanks @dpaoliello! @bors r+ |
bors
commented
Aug 24, 2022
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 Fixesrust-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
commented
Aug 25, 2022
dpaoliello
commented
Aug 25, 2022
@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 |
JohnTitor
commented
Aug 25, 2022
Yeah, @dpaoliello is right, @bors r=wesleywiser |
bors
commented
Aug 25, 2022
bors
commented
Aug 26, 2022
⌛ Testing commit f847388 with merge b771848c3bda7198ca2aa39d18b62bf36e0de759... |
bors
commented
Aug 26, 2022
💔 Test failed - checks-actions |
This comment has been minimized.
This comment has been minimized.
f847388 to
cc49c3eComparedpaoliello
commented
Aug 26, 2022
@wesleywiser build has been fixed, can we please retry? |
wesleywiser
commented
Aug 26, 2022
Sure! @bors r+ |
bors
commented
Aug 26, 2022
bors
commented
Aug 27, 2022
bors
commented
Aug 27, 2022
☀️ Test successful - checks-actions |
rust-timer
commented
Aug 28, 2022
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 eachexternfunction, and there is currently no way for users to provide this information.This change adds a new
MetaNameValueStrkey 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_typeis 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):
decoratedmatches the PE Spec and MSVC rather than the default behavior ofdlltool(i.e., there will be a leading_forstdcall).import_name_typeis not present, we will keep our current behavior of matching the environment (MSVC vs GNU) default for decorating.import_name_typeon architectures other than 32bit x86 will result in an error.import_name_typewith link kinds other than"raw-dylib"will result in an error.