aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorqmuntal <quimmuntal@gmail.com>2024-01-19 10:59:39 +0100
committerQuim Muntal <quimmuntal@gmail.com>2024-01-22 17:00:04 +0000
commit558919b45474bcdf191e9c9d8865699b036bc054 (patch)
tree5c2736c7375371c11706c17816759644eeb858b6
parent29cea6583ead4fa5b12a333e6a9dabe3f8a52fdd (diff)
downloadgo-558919b45474bcdf191e9c9d8865699b036bc054.tar.xz
runtime: avoid loading winmm.dll on newer Windows versions
winmm.dll is only used for timeBeginPeriod and timeEndPeriod, which are not needed on Windows versions supporting high resolution timers, that is Windows 10 version 1803, and later. Updates #56745. Change-Id: Ie9576638fb8d2b4e648283bec3170aefa76f9f82 Reviewed-on: https://go-review.googlesource.com/c/go/+/556935 Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Bryan Mills <bcmills@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
-rw-r--r--src/runtime/os_windows.go25
1 files changed, 15 insertions, 10 deletions
diff --git a/src/runtime/os_windows.go b/src/runtime/os_windows.go
index 6533b64004..cd0a3c260e 100644
--- a/src/runtime/os_windows.go
+++ b/src/runtime/os_windows.go
@@ -257,16 +257,6 @@ func loadOptionalSyscalls() {
_RtlGetCurrentPeb = windowsFindfunc(n32, []byte("RtlGetCurrentPeb\000"))
_RtlGetNtVersionNumbers = windowsFindfunc(n32, []byte("RtlGetNtVersionNumbers\000"))
- m32 := windowsLoadSystemLib(winmmdll[:])
- if m32 == 0 {
- throw("winmm.dll not found")
- }
- _timeBeginPeriod = windowsFindfunc(m32, []byte("timeBeginPeriod\000"))
- _timeEndPeriod = windowsFindfunc(m32, []byte("timeEndPeriod\000"))
- if _timeBeginPeriod == nil || _timeEndPeriod == nil {
- throw("timeBegin/EndPeriod not found")
- }
-
ws232 := windowsLoadSystemLib(ws2_32dll[:])
if ws232 == 0 {
throw("ws2_32.dll not found")
@@ -421,6 +411,21 @@ func initHighResTimer() {
if h != 0 {
haveHighResTimer = true
stdcall1(_CloseHandle, h)
+ } else {
+ // Only load winmm.dll if we need it.
+ // This avoids a dependency on winmm.dll for Go programs
+ // that run on new Windows versions.
+ m32 := windowsLoadSystemLib(winmmdll[:])
+ if m32 == 0 {
+ print("runtime: LoadLibraryExW failed; errno=", getlasterror(), "\n")
+ throw("winmm.dll not found")
+ }
+ _timeBeginPeriod = windowsFindfunc(m32, []byte("timeBeginPeriod\000"))
+ _timeEndPeriod = windowsFindfunc(m32, []byte("timeEndPeriod\000"))
+ if _timeBeginPeriod == nil || _timeEndPeriod == nil {
+ print("runtime: GetProcAddress failed; errno=", getlasterror(), "\n")
+ throw("timeBegin/EndPeriod not found")
+ }
}
}