-
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
Only register WSACleanup
if WSAStartup
is actually ever called
#85595
Conversation
(rust-highfive has picked a reviewer for you, use r? to override) |
library/std/src/sys/windows/net.rs
Outdated
@@ -28,6 +28,10 @@ pub struct Socket(c::SOCKET); | |||
|
|||
static INIT: Once = Once::new(); | |||
|
|||
// Workaround to prevent linking to `WS2_32.dll` when no network functionality is used. | |||
// See issue #85441. | |||
static mut CLEANUP: Option<unsafe extern "system" fn() -> i32> = None; |
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.
Consider using SyncLazy
/SyncOnceCell
for the INIT
.
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.
I combined the two statics in a SyncOnceCell
.
This seems okay to me. Is there any way a test could be written for this? |
For example from issue, output will be:
we can grep output, but this is ugly. |
I could add a |
|
Test |
I added a |
Works, at least under |
📌 Commit f798596 has been approved by |
Only register `WSACleanup` if `WSAStartup` is actually ever called Fix for rust-lang#85441. Because `WSACleanup` appears in `cleanup` currently `WS2_32.dll` is always linked, even if no network functionality is ever used. To prevent this, `WSACleanup` has to only appear in `init`, hence the workaround of registering it in a static. If anyone knows a cleaner solution, let me know.
Good news, using |
This comment has been minimized.
This comment has been minimized.
@CDirkx Ping from triage, any updates on this? |
I had trouble getting the tests to run under |
@@ -26,26 +26,31 @@ pub mod netc { | |||
|
|||
pub struct Socket(c::SOCKET); | |||
|
|||
static INIT: Once = Once::new(); | |||
static WSA: SyncOnceCell<unsafe extern "system" fn() -> i32> = SyncOnceCell::new(); |
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.
Could this be named WSA_CLEANUP
? Or otherwise wrap the fn
pointer in a struct
- as it stands, the WSA
name doesn't make it obvious what the fn
pointer is supposed to be.
Ping from triage: |
I looked at the build failure. I believe this is likely related to the fact that the rust/compiler/rustc_target/src/spec/windows_gnu_base.rs Lines 66 to 67 in 21e1cd9
I don't think re-enabling the function sections is going to be feasible, so we should only run that test on Since Christiaan seems to be away since at least July, I'm going to close this and open a fixed PR. |
FWIW I think it's not an issue with |
Only register `WSACleanup` if `WSAStartup` is actually ever called See rust-lang#85595 Fixes rust-lang#85441
Only register `WSACleanup` if `WSAStartup` is actually ever called See rust-lang#85595 Fixes rust-lang#85441
Fix for #85441.
Because
WSACleanup
appears incleanup
currentlyWS2_32.dll
is always linked, even if no network functionality is ever used.To prevent this,
WSACleanup
has to only appear ininit
, hence the workaround of registering it in a static.If anyone knows a cleaner solution, let me know.