Skip to content
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

codegen: do not set attributes on foreign function imports #128247

Closed
wants to merge 3 commits into from

Conversation

RalfJung
Copy link
Member

@RalfJung RalfJung commented Jul 26, 2024

Currently we are setting all the usual attributes when translating an FFI import, like

    extern {
        pub fn myfun(x: NonZeroI32) -> &'static mut ();
    }

into LLVM. However, if the same function is imported multiple times as different items in Rust, that all becomes a single LLVM declaration. The attributes set on any one of them may then apply to calls done via other imported items. For instance, the import above, even if it is never called, can introduce UB if there is another part of the program that also imports myfun, calls it via that import, and passes 0 or myfun returns NULL.

To fix that, this PR changes the function declarations we emit to all look like declare @fn(). The one exception are Rust's own allocator functions, which have a bunch of attributes that LLVM currently only honors in the declaration, not the call site -- though with llvm/llvm-project@1953629 we can maybe avoid that in the future.

The hope is that this fixes #46188. The only cases I can still think of where we emit different declarations with the same name and one of them "wins" are:

  • Rust's native allocation functions. Even then, the "wrong" declarations will just have no argument and return value so I don't think this should cause problems.
  • Two extern static with the same name but different type, or an extern static with the same name as an imported function. Again I doubt the "type of the static" will lead LLVM to deduce things about the function or vice versa, so probably the worst that can happen is LLVM crashes. (And of course if this static actually ends up resolving to a function, that's UB unless the static has size 0. And conversely, if it resolves to a static instead of code then calling the function is UB.)

Fixes rust-lang/miri#3581 by making this not UB.

Cc @nikic

try-job: x86_64-msvc
try-job: i686-msvc

@rustbot
Copy link
Collaborator

rustbot commented Jul 26, 2024

r? @BoxyUwU

rustbot has assigned @BoxyUwU.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 26, 2024
@nikic
Copy link
Contributor

nikic commented Jul 26, 2024

I thought the lang team decision was that this is basically not a bug but a feature (unsafe extern blocks)?

@RalfJung
Copy link
Member Author

RalfJung commented Jul 27, 2024

No, I don't think unsafe extern blocks are related to this at all. Unsafe extern blocks are about splitting the proof obligation for calling extern functions in two parts:

  • ABI concerns
  • behavior of the callee

The unsafe on extern can be used to discharge the first obligation separately from the second, and by declaring a safe fn inside that block I can discharge the second obligation once-and-for-all if the callee is indeed safe for all valid argument values.

The last comments you made in #46188 led us to believe that the trouble with attributes "leaking" from one extern function import to another is just a codegen bug we can fix. Based on this comment, the double-declaration issue was removed from the motivation for unsafe extern blocks since it was believed that double declarations can be fixed in rustc. Now the question is, how do we fix it, specifically for the case where not just the attributes are different but the signatures differ in arbitrary ways? Or did we misunderstand your comments?

This seems like something an IR should be able to express: two different imports of the same function, with two different signatures, and then using some runtime condition to decide which one to call. It is something Rust can express, and as long as the call actually made is fine there's no good reason this should be UB. So if our codegen backends cannot express, we have to figure out what to do.

Doesn't LLVM have an attribute a la link_name, where one can do something like:

declare ptr @malloc_2(i64, i64) #0
attributes #0 = { "link_name" = "malloc" }

Or, can we maybe somehow import just the name (declare @malloc), and then provide all the information for call ABI etc at the call site?

@RalfJung
Copy link
Member Author

RalfJung commented Jul 27, 2024

Concretely, I mean code like this:

extern "C" {
    #[link_name = "myfunc"]
    fn myfunc_1(x: i32, y: i32);
    
    #[link_name = "myfunc"]
    fn myfunc_2(xy: i64);
}

pub fn call_myfunc(version: i32) {
    match version {
        1 => unsafe { myfunc_1(0, 0) },
        2 => unsafe { myfunc_2(0) },
        _ => panic!(),
    }
}

Currently, this compiles to

; Function Attrs: nounwind nonlazybind uwtable
declare void @myfunc(i32, i32) unnamed_addr #3

and the calls become

bb2:                                              ; preds = %start
  call void @myfunc(i32 0, i32 0) #5, !dbg !19
  br label %bb4, !dbg !19

bb3:                                              ; preds = %start
  call void @myfunc(i64 0) #5, !dbg !20
  br label %bb4, !dbg !20

I am surprised LLVM doesn't complain that we're calling the function with the wrong number of arguments...

It would be quite unfortunate to have to declare this UB, even if call_myfunc is only ever called with the right version that matches the signature of myfunc that was actually linked in. Dead code cannot cause UB so we'd be back to having to somehow say that just importing a function with the wrong signature is UB, or something like that.

Cc @rust-lang/opsem

@RalfJung RalfJung marked this pull request as draft July 27, 2024 18:05
@RalfJung RalfJung added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 27, 2024
@BoxyUwU
Copy link
Member

BoxyUwU commented Jul 30, 2024

r? @nikic
idk anything about codegen :3

@rustbot rustbot assigned nikic and unassigned BoxyUwU Jul 30, 2024
@nikic
Copy link
Contributor

nikic commented Aug 8, 2024

No, I don't think unsafe extern blocks are related to this at all. Unsafe extern blocks are about splitting the proof obligation for calling extern functions in two parts:

  • ABI concerns
  • behavior of the callee

The unsafe on extern can be used to discharge the first obligation separately from the second, and by declaring a safe fn inside that block I can discharge the second obligation once-and-for-all if the callee is indeed safe for all valid argument values.

The last comments you made in #46188 led us to believe that the trouble with attributes "leaking" from one extern function import to another is just a codegen bug we can fix. Based on this comment, the double-declaration issue was removed from the motivation for unsafe extern blocks since it was believed that double declarations can be fixed in rustc. Now the question is, how do we fix it, specifically for the case where not just the attributes are different but the signatures differ in arbitrary ways? Or did we misunderstand your comments?

I think the lang team understood my comment correctly: This codegen bug should not be the motivation for unsafe extern blocks. But now that we do have unsafe extern blocks, this is now a feature and not a bug.

The normative part of the RFC says this:

If the function signature declared in Rust is incompatible with the function signature as declared in the foreign code, the behavior of the resulting program may be undefined.

That is, UB occurs at the point of declaration, not at the point of use.

In your words, I consider things like "used &'static mut () instead of *mut ()" part of the "ABI concerns" that need to be discharged by whoever wrote the unsafe extern block. I don't really get why you would consider making malloc return -> bool to be part of "unsafe extern" obligations, but -> &'static mut () to not be part of them.

@RalfJung
Copy link
Member Author

RalfJung commented Aug 8, 2024

The normative part of the RFC says this:

This says "may be UB", i.e. no decision has been made yet. I don't think anyone involved interpreted this as "#46188 is not a bug", in fact I interpreted it (based on your comment) as the exact opposite: #46188 can and should be fixed (but that "may" not work and then we'll see).
In my understanding, this merely describes what the codegen backend does: originally it said "this is UB", but based on your comment it got changed to "there may be UB" (due to factors outside our control).

But we have not nearly explored the design space around making unused function declarations cause UB that this can be interpreted as saying "yeah we're okay with that". When #46188 was opened, I was devastated that this kind of UB would leak through from C via LLVM to Rust, since it sounded like just something that LLVM fundamentally makes UB. But as you pointed out, that is not the case, and if this UB does not inevitably leak through then I want to push back as hard as possible against any attempt to make this UB. Having unused declarations cause UB is about as excusable as having UB due to a missing newline at the end of the file, IMO.

In your words, I consider things like "used &'static mut () instead of *mut ()" part of the "ABI concerns" that need to be discharged by whoever wrote the unsafe extern block. I don't really get why you would consider making malloc return -> bool to be part of "unsafe extern" obligations, but -> &'static mut () to not be part of them.

I am not entirely following -- I am not making a difference between attributes and the rest of the signature, that's the entire point for why this PR took a (to me) unexpected turn. My main point is that dead code should not be able to cause UB. It's really bad when dead code can do that, given that UB is supposed to be a contract about what happens during the execution of the program, but dead code does not get executed.

@nikic
Copy link
Contributor

nikic commented Aug 8, 2024

The normative part of the RFC says this:

This says "may be UB", i.e. no decision has been made yet. I don't think anyone involved interpreted this as "#46188 is not a bug", in fact I interpreted it (based on your comment) as the exact opposite: #46188 can and should be fixed (but that "may" not work and then we'll see). In my understanding, this merely describes what the codegen backend does: originally it said "this is UB", but based on your comment it got changed to "there may be UB" (due to factors outside our control).

Okay, I see. So the RFC leaves open the possibility that this is UB, but doesn't decide on it yet.


So to return the the technical part...

It seems like we will generate LLVM IR that has

; Function Attrs: nounwind nonlazybind uwtable
declare noundef nonnull align 1 ptr @malloc(i64 noundef, i64 noundef) unnamed_addr #5

and then we fill up the extra arguments with 0?!?

  %0 = tail call noundef ptr @malloc(i64 noundef 1384596541119774447, i64 0) #9

I have no idea how that even happens, but it seems like nonsense.

Wow, this is terrible. This is done by the cursed transformConstExprCastCall() transform in InstCombine, which is a piece of code I plan to either remove entirely or at least significantly de-fang. I was aware that it can do some stupid stuff, but actually adding new arguments and filling them with zero -- and for a declaration at that -- certainly takes the cake.

The good news is that using void @fn() as the declaration avoids that problem. For declarations at least, this will suppress any transforms of that kind. I believe this is also what Clang sometimes uses for functions where it does not know the prototype, so I think this should be pretty safe overall, and not run the same risks that something more exotic like calling a [0 x i8] global might.

I think the combination of call-site only attributes + void @fn() should give the semantics you want.


A possible problem with using void @fn() though, is that this also means that TLI (TargetLibraryInfo) in LLVM will no longer recognize it as a known library call. LLVM has various optimizations for known library calls, and these are guarded by the declaration having the correct signature. If we no longer specify the proper signature, then we also don't get those optimizations.

For example, with this approach LLVM will no longer be able to perform allocation optimizations for malloc used from Rust. I don't know if that would be considered an actual problem or not.

@RalfJung
Copy link
Member Author

RalfJung commented Aug 9, 2024

Wow, this is terrible. This is done by the cursed transformConstExprCastCall() transform in InstCombine, which is a piece of code I plan to either remove entirely or at least significantly de-fang. I was aware that it can do some stupid stuff, but actually adding new arguments and filling them with zero -- and for a declaration at that -- certainly takes the cake.

Happy to hear that we agree on that. 😂

I think the combination of call-site only attributes + void @fn() should give the semantics you want.

That sounds like a suggestion worth trying, thanks.

For example, with this approach LLVM will no longer be able to perform allocation optimizations for malloc used from Rust. I don't know if that would be considered an actual problem or not.

For our own native Rust allocation functions, they carry a bunch of attributes that hopefully we can add at the call site so I assume they will still get the special treatment. (Or we can exempt them from the signature erasure.)

More broadly speaking, I wonder if LLVM could be taught to consider the caller signature when recognizing such library calls?

@nikic
Copy link
Contributor

nikic commented Aug 9, 2024

Wow, this is terrible. This is done by the cursed transformConstExprCastCall() transform in InstCombine, which is a piece of code I plan to either remove entirely or at least significantly de-fang. I was aware that it can do some stupid stuff, but actually adding new arguments and filling them with zero -- and for a declaration at that -- certainly takes the cake.

Happy to hear that we agree on that. 😂

I've put up llvm/llvm-project#102596 to at least stop doing this for declarations.

I think the combination of call-site only attributes + void @fn() should give the semantics you want.

That sounds like a suggestion worth trying, thanks.

For example, with this approach LLVM will no longer be able to perform allocation optimizations for malloc used from Rust. I don't know if that would be considered an actual problem or not.

For our own native Rust allocation functions, they carry a bunch of attributes that hopefully we can add at the call site so I assume they will still get the special treatment. (Or we can exempt them from the signature erasure.)

In theory, yes. In practice, after a cursory review, I found a bunch of cases where this is not actually the case :(

https://github.com/llvm/llvm-project/blob/ccb2b011e577e861254f61df9c59494e9e122b38/llvm/lib/Analysis/MemoryBuiltins.cpp#L243 The allocsize attribute is currently only queried on the function declaration, not the call-site.

https://github.com/llvm/llvm-project/blob/ccb2b011e577e861254f61df9c59494e9e122b38/llvm/lib/Analysis/MemoryBuiltins.cpp#L561 The free allockind is queried at the call-site ... but only after a check that the callee is known (which is not the case for signature mismatch).

https://github.com/llvm/llvm-project/blob/ccb2b011e577e861254f61df9c59494e9e122b38/llvm/lib/Analysis/MemoryBuiltins.cpp#L515 Same for the alloc-family attribute.

This is easy to fix, but probably your suggestion of exempting them from the signature erase makes the most sense in the interest of robustness.

More broadly speaking, I wonder if LLVM could be taught to consider the caller signature when recognizing such library calls?

To some degree -- however, a lot of optimizations are ultimately based on inferring attributes on the function declaration. Like, there are no specific optimizations for removing a dead strlen() call, it's just a consequence of it being read-only (and nounwind, and willreturn, etc). In theory those optimizations could be done at the call-site instead, but I don't really think that LLVM should do this, as the current declaration-site inference is cleaner.

A possible alternative here would be to instead query LLVM's TLI from Rust -- if it says the signature is valid, use it, otherwise use the dummy signature. In that case LLVM gives us the guarantee that the signature is correct. (Of course, it might not be if someone provides a broken libc, but I think we'd call that UB at some different layer...)

@nikic
Copy link
Contributor

nikic commented Aug 9, 2024

This is easy to fix, but probably your suggestion of exempting them from the signature erase makes the most sense in the interest of robustness.

Should be fixed upstream by llvm/llvm-project@1953629.

@rust-log-analyzer

This comment has been minimized.

@RalfJung
Copy link
Member Author

I have updated the PR to always declare FFI imports as void @fn(). This at least seems to not immediately explode any more. ;)

However, updating all the codegen tests will be a bunch of work since the checks need to be moved from the declaration to the call site. I have updated some of them, so the effect becomes clear, but these are still failing:

    [codegen] tests/codegen/align-byval.rs#x86_64-windows
    [codegen] tests/codegen/align-byval.rs#m68k
    [codegen] tests/codegen/align-byval.rs#wasm
    [codegen] tests/codegen/align-byval.rs#x86_64-linux
    [codegen] tests/codegen/align-byval.rs#i686-windows
    [codegen] tests/codegen/align-byval-vector.rs#x86-linux
    [codegen] tests/codegen/align-byval-vector.rs#x86-darwin
    [codegen] tests/codegen/align-byval.rs#i686-linux
    [codegen] tests/codegen/powerpc64le-struct-align-128.rs
    [codegen] tests/codegen/aarch64-struct-align-128.rs#linux
    [codegen] tests/codegen/aarch64-struct-align-128.rs#darwin
    [codegen] tests/codegen/aarch64-struct-align-128.rs#win

I'll wait with updating them until it is clear we actually want to go ahead and do this. Marking as ready for review accordingly.

@RalfJung RalfJung marked this pull request as ready for review August 18, 2024 19:44
@RalfJung RalfJung added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Aug 18, 2024
@rust-log-analyzer

This comment has been minimized.

@nikic
Copy link
Contributor

nikic commented Sep 4, 2024

Filed an upstream issue: llvm/llvm-project#107195 But this one is probably not straightforward to fix.

@DianQK
Copy link
Member

DianQK commented Sep 4, 2024

This seems to be caused by -Cllvm-args=-lint-abort-on-error which was added in #128970.

@DianQK is it important to have that flag in this test, in combination with an extern function call? That unfortunately leads to a spurious UB error... For the reasons explained above, we are declaring the function with 0 arguments no matter how many it actually has. That should not be UB if the function actually has the number of arguments given at the call site.

Removing it is fine with me.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (2a65736): comparison URL.

Overall result: ❌✅ regressions and improvements - ACTION NEEDED

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf.

Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please fix the regressions and do another perf run. If the next run shows neutral or positive results, the label will be automatically removed.

@bors rollup=never
@rustbot label: -S-waiting-on-perf +perf-regression

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
1.7% [1.6%, 1.7%] 4
Regressions ❌
(secondary)
1.1% [1.1%, 1.1%] 1
Improvements ✅
(primary)
-0.3% [-0.3%, -0.2%] 24
Improvements ✅
(secondary)
-0.5% [-5.5%, -0.2%] 33
All ❌✅ (primary) 0.0% [-0.3%, 1.7%] 28

Max RSS (memory usage)

Results (secondary -2.2%)

This 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.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.2% [-2.5%, -2.0%] 2
All ❌✅ (primary) - - 0

Cycles

Results (primary 1.7%, secondary -1.3%)

This 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.

mean range count
Regressions ❌
(primary)
1.7% [1.7%, 1.8%] 4
Regressions ❌
(secondary)
1.0% [1.0%, 1.0%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-3.6% [-3.6%, -3.6%] 1
All ❌✅ (primary) 1.7% [1.7%, 1.8%] 4

Binary size

Results (primary 0.4%, secondary 0.3%)

This 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.

mean range count
Regressions ❌
(primary)
0.4% [0.0%, 0.8%] 20
Regressions ❌
(secondary)
0.3% [0.1%, 0.6%] 75
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.4% [0.0%, 0.8%] 20

Bootstrap: 751.345s -> 752.545s (0.16%)
Artifact size: 340.69 MiB -> 341.25 MiB (0.16%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Sep 4, 2024
@RalfJung
Copy link
Member Author

RalfJung commented Sep 4, 2024

Well that did help reduce the regressions -- it's actually a net speedup now over all benchmarks, and the mean is neutral for primary benchmarks.

Binary size is still affected, though. Is that a blocker?
We could make it so that just the nounwind attribute is still emitted for declarations. That at least reduces the ways a declaration can cause UB.

@RalfJung

This comment was marked as resolved.

@RalfJung RalfJung force-pushed the import-attribute-clash branch 2 times, most recently from 7642197 to 450c764 Compare September 10, 2024 13:47
@bors
Copy link
Contributor

bors commented Sep 11, 2024

☔ The latest upstream changes (presumably #129403) made this pull request unmergeable. Please resolve the merge conflicts.

@RalfJung
Copy link
Member Author

@bors try

bors added a commit to rust-lang-ci/rust that referenced this pull request Sep 11, 2024
…try>

codegen: do not set attributes on foreign function imports

Currently we are setting all the usual attributes when translating an FFI import, like
```rust
    extern {
        pub fn myfun(x: NonZeroI32) -> &'static mut ();
    }
```
into LLVM. However, if the same function is imported multiple times as different items in Rust, that all becomes a single LLVM declaration. The attributes set on any one of them may then apply to calls done via other imported items. For instance, the import above, *even if it is never called*, can introduce UB if there is another part of the program that also imports `myfun`, calls it via that import, and passes 0 or `myfun` returns NULL.

To fix that, this PR changes the function declarations we emit to all look like `declare `@fn()`.` The one exception are Rust's own allocator functions, which have a bunch of attributes that LLVM currently only honors in the declaration, not the call site -- though with llvm/llvm-project@1953629 we can maybe avoid that in the future.

The hope is that this fixes rust-lang#46188. The only cases I can still think of where we emit different declarations with the same name and one of them "wins" are:
- Rust's native allocation functions. Even then, the "wrong" declarations will just have no argument and return value so I don't think this should cause problems.
- Two `extern static` with the same name but different type, or an `extern static` with the same name as an imported function. Again I doubt the "type of the static" will lead LLVM to deduce things about the function or vice versa, so probably the worst that can happen is LLVM crashes. (And of course if this static actually ends up resolving to a function, that's UB unless the static has size 0. And conversely, if it resolves to a static instead of code then calling the function is UB.)

Fixes rust-lang/miri#3581 by making this not UB.

Cc `@nikic`

try-job: x86_64-msvc
try-job: i686-msvc
@bors
Copy link
Contributor

bors commented Sep 11, 2024

⌛ Trying commit a78c911 with merge 345a972...

@rust-log-analyzer
Copy link
Collaborator

The job i686-msvc failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
[command]C:\Windows\system32\cmd.exe /D /S /C C:\a\_temp\setup-msys2\msys2.cmd -c "'paccache' '-r' '-f' '-u' '-k0'"
==> no candidate packages found for pruning
[command]C:\Windows\system32\cmd.exe /D /S /C C:\a\_temp\setup-msys2\msys2.cmd -c "'paccache' '-r' '-f' '-k1'"
==> no candidate packages found for pruning
[command]"C:\Program Files\Git\usr\bin\tar.exe" --posix -cf cache.tzst --exclude cache.tzst -P -C C:/a/rust/rust --files-from manifest.txt --force-local --use-compress-program "zstd -T0"
Cache saved successfully
Cache saved as ID 29 using key msys2-pkgs-upd:false-conf:e8555627-files:305123cd29efffaad88eb14e88ff433b93ed4169
[command]C:\Windows\system32\cmd.exe /D /S /C C:\a\_temp\setup-msys2\msys2.cmd -c "'pacman' '--noconfirm' '-Scc'"

---
Updating files:  99% (49032/49527)
Updating files:  99% (49066/49527)
Updating files: 100% (49527/49527)
Updating files: 100% (49527/49527), done.
branch 'try' set up to track 'origin/try'.
Switched to a new branch 'try'
[command]"C:\Program Files\Git\bin\git.exe" log -1 --format='%H'
'345a97245018695ac35925988ceec6c4a280d433'
##[group]Run src/ci/scripts/setup-environment.sh
src/ci/scripts/setup-environment.sh
---
file:.git/config remote.origin.url=https://github.com/rust-lang-ci/rust
file:.git/config remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
file:.git/config gc.auto=0
file:.git/config http.https://github.com/.extraheader=AUTHORIZATION: basic ***
file:.git/config branch.try.remote=origin
file:.git/config branch.try.merge=refs/heads/try
file:.git/config submodule.library/backtrace.url=https://github.com/rust-lang/backtrace-rs.git
file:.git/config submodule.library/stdarch.active=true
file:.git/config submodule.library/stdarch.url=https://github.com/rust-lang/stdarch.git
file:.git/config submodule.src/doc/book.active=true
---
[RUSTC-TIMING] alloc test:false 6.928
[RUSTC-TIMING] hashbrown test:false 1.583
error: linking with `link.exe` failed: exit code: 1120
  |
  = note: "C:\\Program Files\\Microsoft Visual Studio\\2022\\Enterprise\\VC\\Tools\\MSVC\\14.41.34120\\bin\\HostX64\\x86\\link.exe" "/DEF:C:\\a\\_temp\\msys64\\tmp\\rustcLo27Fv\\lib.def" "/NOLOGO" "/LARGEADDRESSAWARE" "/SAFESEH" "C:\\a\\_temp\\msys64\\tmp\\rustcLo27Fv\\symbols.o" "C:\\a\\rust\\rust\\build\\i686-pc-windows-msvc\\stage1-std\\i686-pc-windows-msvc\\release\\deps\\std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o" "C:\\a\\rust\\rust\\build\\i686-pc-windows-msvc\\stage1-std\\i686-pc-windows-msvc\\release\\deps\\std-3cf90c7c7c73bbaa.8vs6a4j3qyhmzxme1uzm2s06o.rcgu.rmeta" "C:\\a\\rust\\rust\\build\\i686-pc-windows-msvc\\stage1-std\\i686-pc-windows-msvc\\release\\deps\\std-3cf90c7c7c73bbaa.4y0h4al3c98tzqagar6uhsx8n.rcgu.o" "kernel32.lib" "kernel32.lib" "C:\\a\\rust\\rust\\build\\i686-pc-windows-msvc\\stage1-std\\i686-pc-windows-msvc\\release\\deps\\libpanic_unwind-01e67e98ed22372e.rlib" "C:\\a\\rust\\rust\\build\\i686-pc-windows-msvc\\stage1-std\\i686-pc-windows-msvc\\release\\deps\\libwindows_targets-4291a0c00630f550.rlib" "C:\\a\\rust\\rust\\build\\i686-pc-windows-msvc\\stage1-std\\i686-pc-windows-msvc\\release\\deps\\librustc_demangle-c1c2899d0c269dcf.rlib" "C:\\a\\rust\\rust\\build\\i686-pc-windows-msvc\\stage1-std\\i686-pc-windows-msvc\\release\\deps\\libstd_detect-a69ed9f77f14c6d8.rlib" "C:\\a\\rust\\rust\\build\\i686-pc-windows-msvc\\stage1-std\\i686-pc-windows-msvc\\release\\deps\\libhashbrown-507e55b862b40e66.rlib" "C:\\a\\rust\\rust\\build\\i686-pc-windows-msvc\\stage1-std\\i686-pc-windows-msvc\\release\\deps\\librustc_std_workspace_alloc-fdb56b91f2a6b275.rlib" "C:\\a\\rust\\rust\\build\\i686-pc-windows-msvc\\stage1-std\\i686-pc-windows-msvc\\release\\deps\\libunwind-270443aa374b9b30.rlib" "C:\\a\\rust\\rust\\build\\i686-pc-windows-msvc\\stage1-std\\i686-pc-windows-msvc\\release\\deps\\libcfg_if-6c3a820bb454cef2.rlib" "C:\\a\\rust\\rust\\build\\i686-pc-windows-msvc\\stage1-std\\i686-pc-windows-msvc\\release\\deps\\liballoc-5b3a33ea2fbc9d41.rlib" "C:\\a\\rust\\rust\\build\\i686-pc-windows-msvc\\stage1-std\\i686-pc-windows-msvc\\release\\deps\\librustc_std_workspace_core-a67c29f4a9c7a99d.rlib" "C:\\a\\rust\\rust\\build\\i686-pc-windows-msvc\\stage1-std\\i686-pc-windows-msvc\\release\\deps\\libcore-76c424679b11e231.rlib" "C:\\a\\rust\\rust\\build\\i686-pc-windows-msvc\\stage1-std\\i686-pc-windows-msvc\\release\\deps\\libcompiler_builtins-cf5341ff11d85827.rlib" "advapi32.lib" "ntdll.lib" "userenv.lib" "ws2_32.lib" "dbghelp.lib" "/defaultlib:libcmt" "C:\\a\\_temp\\msys64\\tmp\\rustcLo27Fv\\bcryptprimitives.dll_imports.lib" "C:\\a\\_temp\\msys64\\tmp\\rustcLo27Fv\\api-ms-win-core-synch-l1-2-0.dll_imports.lib" "/NXCOMPAT" "/LIBPATH:C:\\Program Files\\Microsoft Visual Studio\\2022\\Enterprise\\VC\\Tools\\MSVC\\14.41.34120\\atlmfc\\lib\\x86" "/LIBPATH:C:\\a\\rust\\rust\\build\\i686-pc-windows-msvc\\stage1-std\\i686-pc-windows-msvc\\release\\build\\compiler_builtins-f27dcd5984ecb24f\\out" "/OUT:C:\\a\\rust\\rust\\build\\i686-pc-windows-msvc\\stage1-std\\i686-pc-windows-msvc\\release\\deps\\std-3cf90c7c7c73bbaa.dll" "/OPT:REF,ICF" "/DLL" "/IMPLIB:C:\\a\\rust\\rust\\build\\i686-pc-windows-msvc\\stage1-std\\i686-pc-windows-msvc\\release\\deps\\std-3cf90c7c7c73bbaa.dll.lib" "/DEBUG" "/PDBALTPATH:%_PDB%"
  = note:    Creating library C:\a\rust\rust\build\i686-pc-windows-msvc\stage1-std\i686-pc-windows-msvc\release\deps\std-3cf90c7c7c73bbaa.dll.lib and object C:\a\rust\rust\build\i686-pc-windows-msvc\stage1-std\i686-pc-windows-msvc\release\deps\std-3cf90c7c7c73bbaa.dll.exp␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__CloseHandle referenced in function "?dtor$34@?0?_ZN4core3ops8function6FnOnce40call_once$u7b$$u7b$vtable.shim$u7d$$u7d$17h1190ffa4b0eda8b0E@4HA" (?dtor$34@?0?_ZN4core3ops8function6FnOnce40call_once$u7b$$u7b$vtable.shim$u7d$$u7d$17h1190ffa4b0eda8b0E@4HA)␍
            Hint on symbols that are defined and could potentially match:␍
              __imp__CloseHandle@4␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__WSAStartup referenced in function __ZN4core3ops8function6FnOnce40call_once$u7b$$u7b$vtable.shim$u7d$$u7d$17h4fe28182d3c490f8E␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__WSACleanup referenced in function __ZN4core3ops8function6FnOnce40call_once$u7b$$u7b$vtable.shim$u7d$$u7d$17h4fe28182d3c490f8E␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__FreeEnvironmentStringsW referenced in function __ZN4core3ptr52drop_in_place$LT$std..sys..pal..windows..os..Env$GT$17h4e601a5a69cd38b2E␍
            Hint on symbols that are defined and could potentially match:␍
              __imp__FreeEnvironmentStringsW@4␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__DeleteProcThreadAttributeList referenced in function __ZN4core3ptr77drop_in_place$LT$std..sys..pal..windows..process..ProcThreadAttributeList$GT$17hdcb087b4a1d89a4cE␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__CompareStringOrdinal referenced in function __ZN5alloc11collections5btree6search142_$LT$impl$u20$alloc..collections..btree..node..NodeRef$LT$BorrowType$C$K$C$V$C$alloc..collections..btree..node..marker..LeafOrInternal$GT$$GT$11search_tree17h3abe0af99138cc71E␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__GetLastError referenced in function __ZN5alloc11collections5btree6search142_$LT$impl$u20$alloc..collections..btree..node..NodeRef$LT$BorrowType$C$K$C$V$C$alloc..collections..btree..node..marker..LeafOrInternal$GT$$GT$11search_tree17h3abe0af99138cc71E␍
            Hint on symbols that are defined and could potentially match:␍
              __imp__GetLastError@0␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__AddVectoredExceptionHandler referenced in function __ZN3std2rt19lang_start_internal17ha6b48c67303632f1E␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__SetThreadStackGuarantee referenced in function __ZN3std2rt19lang_start_internal17ha6b48c67303632f1E␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__GetCurrentThread referenced in function __ZN3std2rt19lang_start_internal17ha6b48c67303632f1E␍
            Hint on symbols that are defined and could potentially match:␍
              __imp__GetCurrentThread@0␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__SwitchToThread referenced in function __ZN3std6thread9yield_now17h3a9a460e5e525067E␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__CreateWaitableTimerExW referenced in function __ZN3std6thread8sleep_ms17h9f0c0f04a30d3e0dE␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__SetWaitableTimer referenced in function __ZN3std6thread8sleep_ms17h9f0c0f04a30d3e0dE␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__WaitForSingleObject referenced in function __ZN3std6thread8sleep_ms17h9f0c0f04a30d3e0dE␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__Sleep referenced in function __ZN3std6thread8sleep_ms17h9f0c0f04a30d3e0dE␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__QueryPerformanceCounter referenced in function __ZN3std6thread11sleep_until17h814737e3147b03faE␍
            Hint on symbols that are defined and could potentially match:␍
              __imp__QueryPerformanceCounter@4␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__GetSystemInfo referenced in function __ZN3std6thread21available_parallelism17hd346ce21f6aff0f9E␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__GetCurrentProcess referenced in function __ZN3std9backtrace9Backtrace6create17hd8c22c467d597db3E␍
            Hint on symbols that are defined and could potentially match:␍
              __imp__GetCurrentProcess@0␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__RtlCaptureContext referenced in function __ZN3std9backtrace9Backtrace6create17hd8c22c467d597db3E␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__GetProcAddress referenced in function __ZN3std9backtrace9Backtrace6create17hd8c22c467d597db3E␍
            Hint on symbols that are defined and could potentially match:␍
              __imp__GetProcAddress@8␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__ReleaseMutex referenced in function __ZN3std9backtrace9Backtrace6create17hd8c22c467d597db3E␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__SetLastError referenced in function __ZN3std3env11current_dir17hfb92ee1bd6e5ba24E␍
            Hint on symbols that are defined and could potentially match:␍
              __imp__SetLastError@4␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__GetCurrentDirectoryW referenced in function __ZN3std3env11current_dir17hfb92ee1bd6e5ba24E␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__GetEnvironmentStringsW referenced in function __ZN3std3env7vars_os17heffd9a659c31348eE␍
            Hint on symbols that are defined and could potentially match:␍
              __imp__GetEnvironmentStringsW@0␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__GetEnvironmentVariableW referenced in function __ZN3std3env7_var_os17hbfdaba88969ba316E␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__GetUserProfileDirectoryW referenced in function __ZN3std3env8home_dir17h56741d14f387ca31E␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__GetCommandLineW referenced in function __ZN3std3env7args_os17h50051d36d8e19214E␍
            Hint on symbols that are defined and could potentially match:␍
              __imp__GetCommandLineW@0␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__GetFileInformationByHandle referenced in function __ZN3std2fs4read5inner17hb0d5a37117d046aaE␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__GetFileInformationByHandleEx referenced in function __ZN3std2fs4read5inner17hb0d5a37117d046aaE␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__NtWriteFile referenced in function __ZN3std2fs5write5inner17h2757c3a4c605c613E␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__RtlNtStatusToDosError referenced in function __ZN3std2fs5write5inner17h2757c3a4c605c613E␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__FlushFileBuffers referenced in function __ZN3std2fs4File8sync_all17hd758b4055bd4ba65E␍
            Hint on symbols that are defined and could potentially match:␍
              __imp__FlushFileBuffers@4␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__SetFileInformationByHandle referenced in function __ZN3std2fs4File7set_len17h0560fdf33bce0e38E␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__DuplicateHandle referenced in function __ZN3std2fs4File9try_clone17h3781e067a419a646E␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__SetFileTime referenced in function __ZN3std2fs4File9set_times17h460083a22bb8843eE␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__SetFilePointerEx referenced in function __ZN3std2fs24buffer_capacity_required17h1d1c1db608a5ed31E␍
            Hint on symbols that are defined and could potentially match:␍
              __imp__SetFilePointerEx@20␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__FindNextFileW referenced in function __ZN75_$LT$std..fs..ReadDir$u20$as$u20$core..iter..traits..iterator..Iterator$GT$4next17hf67f877c3fcdd62cE␍
            Hint on symbols that are defined and could potentially match:␍
              __imp__FindNextFileW@8␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__freeaddrinfo referenced in function __ZN3std3net11socket_addr19resolve_socket_addr17h3da814a505158d41E␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__WSASocketW referenced in function __ZN3std3net3tcp9TcpStream15connect_timeout17h3c2acab3dd908531E␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__WSAGetLastError referenced in function __ZN3std3net3tcp9TcpStream15connect_timeout17h3c2acab3dd908531E␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__SetHandleInformation referenced in function __ZN3std3net3tcp9TcpStream15connect_timeout17h3c2acab3dd908531E␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__closesocket referenced in function __ZN3std3net3tcp9TcpStream15connect_timeout17h3c2acab3dd908531E␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__shutdown referenced in function __ZN3std3net3tcp9TcpStream8shutdown17hf783670921d30170E␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__setsockopt referenced in function __ZN3std3net3udp9UdpSocket16set_read_timeout17hcc0fc99ea6813108E␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__getsockopt referenced in function __ZN3std3net3udp9UdpSocket12read_timeout17h6ef45cd952e65207E␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__recv referenced in function __ZN3std3net3udp9UdpSocket4peek17h409607d702f3f47aE␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__WSARecv referenced in function __ZN58_$LT$std..net..tcp..TcpStream$u20$as$u20$std..io..Read$GT$13read_vectored17h46d5c30ed239c0e2E␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__WSASend referenced in function __ZN59_$LT$std..net..tcp..TcpStream$u20$as$u20$std..io..Write$GT$14write_vectored17h506518c10d8adf55E␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__send referenced in function __ZN63_$LT$$RF$std..net..tcp..TcpStream$u20$as$u20$std..io..Write$GT$5write17h70ffeefdc47b6ebeE␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__accept referenced in function __ZN3std3net3tcp11TcpListener6accept17h912fff1a095c4b75E␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__ioctlsocket referenced in function __ZN3std3net3udp9UdpSocket15set_nonblocking17hcb2fd790e13277aeE␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__getpeername referenced in function __ZN3std3net3udp9UdpSocket9peer_addr17h9a56cb28c210be26E␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__GetStdHandle referenced in function __ZN80_$LT$std..io..stdio..Stdin$u20$as$u20$std..os..windows..io..raw..AsRawHandle$GT$13as_raw_handle17h7e2a736c72191fceE␍
            Hint on symbols that are defined and could potentially match:␍
              __imp__GetStdHandle@4␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__GetCurrentProcessId referenced in function __ZN3std2os7windows2io6socket14BorrowedSocket18try_clone_to_owned17hb14c841d27d660c6E␍
            Hint on symbols that are defined and could potentially match:␍
              __imp__GetCurrentProcessId@0␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__WSADuplicateSocketW referenced in function __ZN3std2os7windows2io6socket14BorrowedSocket18try_clone_to_owned17hb14c841d27d660c6E␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__WriteFileEx referenced in function __ZN59_$LT$std..process..ChildStdin$u20$as$u20$std..io..Write$GT$5write17h1b3d6ca5579981baE␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__SleepEx referenced in function __ZN59_$LT$std..process..ChildStdin$u20$as$u20$std..io..Write$GT$5write17h1b3d6ca5579981baE␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__ReadFileEx referenced in function __ZN59_$LT$std..process..ChildStdout$u20$as$u20$std..io..Read$GT$4read17h6aaa295726307665E␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__GetExitCodeProcess referenced in function __ZN3std7process7Command6output17h9bbd1f348d4732baE␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__TerminateProcess referenced in function __ZN3std7process5Child4kill17h23e5d8506b42f356E␍
            Hint on symbols that are defined and could potentially match:␍
              __imp__TerminateProcess@8␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__GetProcessId referenced in function __ZN3std7process5Child2id17h401d78368f4b0d2eE␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__ExitProcess referenced in function __ZN3std7process4exit17h0bb2957afaf7662bE␍
            Hint on symbols that are defined and could potentially match:␍
              __imp__ExitProcess@4␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__QueryPerformanceFrequency referenced in function __ZN3std4time7Instant22checked_duration_since17h3a250bf23b6d83d0E␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__GetSystemTimePreciseAsFileTime referenced in function __ZN3std4time10SystemTime3now17h928c7ba830295ae8E␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__getaddrinfo referenced in function __ZN3std3sys3pal6common14small_c_string24run_with_cstr_allocating17hb25ea1f2148d57dfE␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__HeapFree referenced in function __ZN3std3sys5alloc16realloc_fallback17hebed41d783c7a8cbE␍
            Hint on symbols that are defined and could potentially match:␍
              __imp__HeapFree@12␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__HeapReAlloc referenced in function ___rdl_realloc␍
            Hint on symbols that are defined and could potentially match:␍
              __imp__HeapReAlloc@16␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__IsDebuggerPresent referenced in function _rust_panic␍
            Hint on symbols that are defined and could potentially match:␍
              __imp__IsDebuggerPresent@0␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__WaitForSingleObjectEx referenced in function __ZN3std12backtrace_rs7dbghelp4init17h49f738a8d43392fcE␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__LoadLibraryA referenced in function __ZN3std12backtrace_rs7dbghelp4init17h49f738a8d43392fcE␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__lstrlenW referenced in function __ZN3std12backtrace_rs7dbghelp4init17h49f738a8d43392fcE␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__CreateMutexA referenced in function __ZN3std12backtrace_rs7dbghelp4init17h49f738a8d43392fcE␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__NtOpenFile referenced in function __ZN3std3sys3pal7windows2fs14remove_dir_all20open_link_no_reparse17h8cc5267c7db0ed0fE␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__FindClose referenced in function __ZN88_$LT$std..sys..pal..windows..fs..FindNextFileHandle$u20$as$u20$core..ops..drop..Drop$GT$4drop17h6dec213681a97ffeE␍
            Hint on symbols that are defined and could potentially match:␍
              __imp__FindClose@4␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__CreateFileW referenced in function __ZN3std3sys3pal7windows2fs4File4open17hccd538dcb5a17246E␍
            Hint on symbols that are defined and could potentially match:␍
              __imp__CreateFileW@28␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__CreateDirectoryW referenced in function __ZN3std3sys3pal7windows2fs10DirBuilder5mkdir17h9654859edcb6422bE␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__FindFirstFileW referenced in function __ZN3std3sys3pal7windows2fs7readdir17h01ed5b04870a22edE␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__DeleteFileW referenced in function __ZN3std3sys3pal7windows2fs6unlink17h3133370cab15ff73E␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__MoveFileExW referenced in function __ZN3std3sys3pal7windows2fs6rename17h6a8feafae135be5cE␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__RemoveDirectoryW referenced in function __ZN3std3sys3pal7windows2fs5rmdir17he1a3245f7c13accfE␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__DeviceIoControl referenced in function __ZN3std3sys3pal7windows2fs8readlink17h2a3d08bcd1d8e52eE␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__CreateSymbolicLinkW referenced in function __ZN3std3sys3pal7windows2fs13symlink_inner17hee1d9f5dbd332230E␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__CreateHardLinkW referenced in function __ZN3std3sys3pal7windows2fs4link17h09c9e927f5f0e8ccE␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__SetFileAttributesW referenced in function __ZN3std3sys3pal7windows2fs8set_perm17he0581280d13932cfE␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__GetFinalPathNameByHandleW referenced in function __ZN3std3sys3pal7windows2fs8get_path17habdec32b49984200E␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__CopyFileExW referenced in function __ZN3std3sys3pal7windows2fs4copy17h65c3d3490c7775f9E␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__CreateEventW referenced in function __ZN3std3sys3pal7windows6handle6Handle9new_event17h803876ac8c035783E␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__NtReadFile referenced in function __ZN3std3sys3pal7windows6handle6Handle4read17hb7611f89fc3182f4E␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__ReadFile referenced in function __ZN3std3sys3pal7windows6handle6Handle15read_overlapped17hfdd7c3910aa63ccfE␍
            Hint on symbols that are defined and could potentially match:␍
              __imp__ReadFile@20␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__GetOverlappedResult referenced in function __ZN3std3sys3pal7windows6handle6Handle17overlapped_result17hc31e3c50d0ed4305E␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__CancelIo referenced in function __ZN3std3sys3pal7windows6handle6Handle9cancel_io17h768bdc37a42e7776E␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__GetConsoleMode referenced in function __ZN3std3sys3pal7windows2io17handle_is_console17h7f84951583c7095dE␍
            Hint on symbols that are defined and could potentially match:␍
              __imp__GetConsoleMode@8␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__GetFileType referenced in function __ZN3std3sys3pal7windows2io17handle_is_console17h7f84951583c7095dE␍
            Hint on symbols that are defined and could potentially match:␍
              __imp__GetFileType@4␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__connect referenced in function __ZN3std3sys3pal7windows3net6Socket7connect17h97c82c1088300d20E␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__select referenced in function __ZN3std3sys3pal7windows3net6Socket15connect_timeout17h20cd3d734e6fcc1dE␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__recvfrom referenced in function __ZN3std3sys3pal7windows3net6Socket20recv_from_with_flags17h8a1cd2aa5b842e30E␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__GetModuleHandleW referenced in function __ZN3std3sys3pal7windows2os12error_string17hbcdbd46c032b387bE␍
            Hint on symbols that are defined and could potentially match:␍
              __imp__GetModuleHandleW@4␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__FormatMessageW referenced in function __ZN3std3sys3pal7windows2os12error_string17hbcdbd46c032b387bE␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__GetModuleFileNameW referenced in function __ZN3std3sys3pal7windows2os11current_exe17h754051eaf101be65E␍
            Hint on symbols that are defined and could potentially match:␍
              __imp__GetModuleFileNameW@12␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__SetCurrentDirectoryW referenced in function __ZN3std3sys3pal7windows2os5chdir17hdd7ef16238db3281E␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__SetEnvironmentVariableW referenced in function __ZN3std3sys3pal7windows2os6setenv17h0a289991aa48e33eE␍
            Hint on symbols that are defined and could potentially match:␍
              __imp__SetEnvironmentVariableW@8␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__CreateNamedPipeW referenced in function __ZN3std3sys3pal7windows4pipe9anon_pipe17h84c08506bd6780bdE␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__WaitForMultipleObjects referenced in function __ZN3std3sys3pal7windows4pipe5read217h990a8007acc2bfb1E␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__GetSystemDirectoryW referenced in function __ZN3std3sys3pal7windows7process7Command5spawn17hf4f2ce558d9e93ffE␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__GetWindowsDirectoryW referenced in function __ZN3std3sys3pal7windows7process7Command5spawn17hf4f2ce558d9e93ffE␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__GetFullPathNameW referenced in function __ZN3std3sys3pal7windows7process7Command5spawn17hf4f2ce558d9e93ffE␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__CreateProcessW referenced in function __ZN3std3sys3pal7windows7process7Command5spawn17hf4f2ce558d9e93ffE␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__GetFileAttributesW referenced in function __ZN3std3sys3pal7windows7process14program_exists17ha9d023746d4a77feE␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__InitializeProcThreadAttributeList referenced in function __ZN3std3sys3pal7windows7process31make_proc_thread_attribute_list17h04652efb8454a152E␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__UpdateProcThreadAttribute referenced in function __ZN3std3sys3pal7windows7process31make_proc_thread_attribute_list17h04652efb8454a152E␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__MultiByteToWideChar referenced in function __ZN3std3sys3pal7windows5stdio27write_valid_utf8_to_console17h0254323338dad9a7E␍
            Hint on symbols that are defined and could potentially match:␍
              __imp__MultiByteToWideChar@24␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__WriteConsoleW referenced in function __ZN3std3sys3pal7windows5stdio27write_valid_utf8_to_console17h0254323338dad9a7E␍
            Hint on symbols that are defined and could potentially match:␍
              __imp__WriteConsoleW@20␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__WideCharToMultiByte referenced in function __ZN70_$LT$std..sys..pal..windows..stdio..Stdin$u20$as$u20$std..io..Read$GT$4read17h3e9e23b875653513E␍
            Hint on symbols that are defined and could potentially match:␍
              __imp__WideCharToMultiByte@32␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__ReadConsoleW referenced in function __ZN3std3sys3pal7windows5stdio26read_u16s_fixup_surrogates17h735e2a0ec28473a2E␍
            Hint on symbols that are defined and could potentially match:␍
              __imp__ReadConsoleW@20␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__CreateThread referenced in function __ZN3std3sys3pal7windows6thread6Thread3new17h188c533d2b1780abE␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__GetModuleHandleA referenced in function __ZN3std3sys3pal7windows1c20SetThreadDescription4load17h1b70677396ade121E@8␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__GetTempPathW referenced in function __ZN3std3sys3pal7windows1c13GetTempPath2W8fallback17he9b299f049de8299E@8␍
            Hint on symbols that are defined and could potentially match:␍
              __imp__GetTempPathW@8␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__GetProcessHeap referenced in function __ZN3std3sys5alloc7windows27process_heap_init_and_alloc17h0d7094de47adbaf3E␍
            Hint on symbols that are defined and could potentially match:␍
              __imp__GetProcessHeap@0␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__HeapAlloc referenced in function __ZN3std3sys5alloc7windows27process_heap_init_and_alloc17h0d7094de47adbaf3E␍
            Hint on symbols that are defined and could potentially match:␍
              __imp__HeapAlloc@12␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__CreatePipe referenced in function __ZN3std3sys14anonymous_pipe7windows4pipe17h91854e2d993ae511E␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__getsockname referenced in function __ZN68_$LT$std..sys_common..net..TcpStream$u20$as$u20$core..fmt..Debug$GT$3fmt17h641d4058c5d327dfE␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__bind referenced in function __ZN3std10sys_common3net11TcpListener4bind17h1dc5577f8a8dfcccE␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__listen referenced in function __ZN3std10sys_common3net11TcpListener4bind17h1dc5577f8a8dfcccE␍
          std-3cf90c7c7c73bbaa.std.ba8189248480dd00-cgu.0.rcgu.o : error LNK2019: unresolved external symbol __imp__sendto referenced in function __ZN3std10sys_common3net9UdpSocket7send_to17h02e07332ab7ff7feE␍
          libpanic_unwind-01e67e98ed22372e.rlib(panic_unwind-01e67e98ed22372e.panic_unwind.c607e2fd00d48e86-cgu.0.rcgu.o) : error LNK2019: unresolved external symbol __CxxThrowException referenced in function ___rust_start_panic␍
            Hint on symbols that are defined and could potentially match:␍
              __CxxThrowException@8␍
          C:\a\rust\rust\build\i686-pc-windows-msvc\stage1-std\i686-pc-windows-msvc\release\deps\std-3cf90c7c7c73bbaa.dll : fatal error LNK1120: 125 unresolved externals␍

[RUSTC-TIMING] std test:false 19.532
error: could not compile `std` (lib) due to 1 previous error
Build completed unsuccessfully in 0:19:51
Build completed unsuccessfully in 0:19:51
make: *** [Makefile:106: ci-msvc-ps1] Error 1
  network time: Wed, 11 Sep 2024 08:58:12 GMT
##[error]Process completed with exit code 2.
Post job cleanup.
[command]"C:\Program Files\Git\bin\git.exe" version

@bors
Copy link
Contributor

bors commented Sep 11, 2024

💔 Test failed - checks-actions

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 11, 2024
@RalfJung
Copy link
Member Author

So this does indeed seem to fail on MSVC, and not just in the test I added.

@ChrisDenton
Copy link
Member

Those errors all seem related to DLL imports. Is this somehow preventing import libraries from being passed to the linker? I.e. the library mentioned in the #[link(name = "...")] attribute.

@RalfJung
Copy link
Member Author

I suspect it is related to this: the exact signature of the function actually matters for these calling conventions, so just always declaring the function without any arguments does not work.

@RalfJung
Copy link
Member Author

But... I am not sure, I have no idea where the link(name) attribute is passed to LLVM and whether we are now skipping over this. But a bunch of that happens in predefine_fn and we still do run that code.

@nikic do you know?

@ChrisDenton
Copy link
Member

I suspect it is related to this: the exact signature of the function actually matters for these calling conventions, so just always declaring the function without any arguments does not work.

Ah yeah, looking closer that would explain it. x86 uses name mangling even for system imports, unlike x86_64. So maybe that's an LLVM attribute because it's looking for e.g. __imp__CloseHandle instead of __imp__CloseHandle@4.

@RalfJung
Copy link
Member Author

I intend to propose a t-lang design meeting about this problem. Here's the writeup for that: https://hackmd.io/cEi0aL6XSk6DDDASwpVH-w
Please let me know if I missed anything important. :)

@bors
Copy link
Contributor

bors commented Sep 18, 2024

☔ The latest upstream changes (presumably #130519) made this pull request unmergeable. Please resolve the merge conflicts.

@RalfJung
Copy link
Member Author

Closing since the approach seems hopeless -- sadly larger LLVM changes would be required to make this work in a well-defined way.

Also see #46188 (comment).

@RalfJung RalfJung closed this Sep 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
perf-regression Performance regression. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Detect UB due to mismatching declarations? ill-typed unused FFI declarations can cause UB
9 participants