Skip to content

ws2_offline: gta6rt links again without ws2_32 (RT-WS2-OFFLINE-LINK) - #2597

Merged
MoonEyes merged 1 commit into
ProjectLeonida:mainfrom
OreoFR:fix/ws2-offline-link
Nov 28, 2026
Merged

MoonEyes merged 1 commit into
ProjectLeonida:mainfrom
OreoFR:fix/ws2-offline-link

Conversation

@OreoFR

@OreoFR OreoFR commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

Item: RT-WS2-OFFLINE-LINK (claim: #2570 (comment))
Follows #2533 (fixes its Windows link failure), asked by @MoonEyes. Co-authored with @Tyrannys, the author of #2533.

What broke. Since #2533, gta6rt.exe no longer links with MSVC on Windows:
ws2_offline.cpp.obj : error LNK2019: unresolved external symbol __imp_WSAGetLastError in
rt::ws2::(anon)::wrap_extension_lookup.

Why. wrap_extension_lookup calls WSAGetLastError() directly. gta6rt does not link ws2_32, and that is
deliberate: the runtime keeps networking offline. Only ws2_offline_test links it, so the test target built and
the runtime did not. Everywhere else, the shim reaches the host's Winsock through host_proc
(LoadLibraryExW + GetProcAddress). That includes set_wsa_error and the WSAGetLastError that
bind_loopback_if_unbound resolves itself.

Fix. A wsa_last_error() helper next to set_wsa_error resolves WSAGetLastError through host_proc. If that
fails, it falls back to GetLastError (on Windows, Winsock's error is the thread's last-error value).
wrap_extension_lookup uses the helper. No new import and no CMake change.

diff --git a/runtime/shims/ws2_offline.cpp b/runtime/shims/ws2_offline.cpp
index fc124af13..309525c54 100644
--- a/runtime/shims/ws2_offline.cpp
+++ b/runtime/shims/ws2_offline.cpp
@@ -87,6 +87,13 @@ void set_wsa_error(int err) {
     }
 }
 
+// The host's WSAGetLastError through host_proc, like set_wsa_error: gta6rt does not link ws2_32.
+int wsa_last_error() {
+    using LastErrFn = int(WSAAPI*)();
+    static LastErrFn fn = host_proc<LastErrFn>("WSAGetLastError");
+    return fn ? fn() : static_cast<int>(GetLastError());
+}
+
 uint16_t read_be16(uint16_t net_val) {
     const auto* b = reinterpret_cast<const uint8_t*>(&net_val);
     return static_cast<uint16_t>((static_cast<uint16_t>(b[0]) << 8) | b[1]);
@@ -876,7 +883,7 @@ int wrap_extension_lookup(Fn real_fn, SOCKET s, DWORD io_control_code, LPVOID in
     std::memcpy(out_buf, &wrapped, sizeof(wrapped));
     const int rc = real_fn(s, io_control_code, in_buf, in_len, &answer->pointer, sizeof(answer->pointer),
                            &answer->returned, overlapped, completion);
-    const int error = rc == 0 ? 0 : WSAGetLastError();
+    const int error = rc == 0 ? 0 : wsa_last_error();
     if (rc == 0) {
         *bytes_returned = sizeof(wrapped);
         delete answer;

Tests (RTX 4070 Laptop, Windows 11, MSVC 2022 BuildTools, Ninja, RelWithDebInfo, LEONIDA_REQUIRE_VULKAN=ON):

AI-assisted (Claude Code, Claude Opus 5.5).

🤖 Generated with Claude Code

…s without ws2_32

wrap_extension_lookup (ProjectLeonida#2533) called WSAGetLastError directly. gta6rt does not link ws2_32 (only
ws2_offline_test does), so the MSVC link of gta6rt.exe failed with LNK2019 __imp_WSAGetLastError. The shim
reaches the host's Winsock through host_proc everywhere else; wsa_last_error does the same, mirroring
set_wsa_error, with GetLastError as the fallback. gta6rt.exe imports the same DLLs as before ProjectLeonida#2533, no WS2_32.

Co-authored-by: Tyrannys <80750971+Tyrannys@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@MoonEyes
MoonEyes merged commit e1d87a4 into ProjectLeonida:main Nov 28, 2026
5 of 11 checks passed
@MoonEyes

Copy link
Copy Markdown
Collaborator

Merged to unbreak the gta6rt.exe link on Windows/MSVC that #2533 caused (my merge). Thanks to OreoFR for catching it and for the fix: checked on Windows/MSVC by OreoFR (gta6rt.exe links, no WS2_32.dll import, ctest ws2_offline passes). Re-checked here: one file, the new wsa_last_error() goes through host_proc like set_wsa_error, and no other direct ws2_32 call is left in runtime/shims/ws2_offline.cpp; merged onto main a9e247c without conflict.

AI-assisted (Claude Code, Claude Opus 5.5), merged for MoonEyes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants