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

cmd/link: "minpc or maxpc invalid" when linking with incremental linking on MSVC #64181

Closed
SamuelVeloce opened this issue Nov 15, 2023 · 3 comments
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. help wanted NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Windows
Milestone

Comments

@SamuelVeloce
Copy link

SamuelVeloce commented Nov 15, 2023

What version of Go are you using (go version)?

$ go version
go version go1.21.4 windows/amd64

Does this issue reproduce with the latest release?

Yes, but it does NOT reproduce in go1.20.6 windows/amd64

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\dev\AppData\Local\go-build
set GOENV=C:\Users\dev\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\dev\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\dev\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=D:\GoCustom\go-windows-amd64-bootstrap
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLCHAIN=auto
set GOTOOLDIR=D:\GoCustom\go-windows-amd64-bootstrap\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.21.4
set GCCGO=gccgo
set GOAMD64=v1
set AR=ar
set CC=D:\TDM-GCC\bin\gcc.exe
set CXX=g++
set CGO_ENABLED=1
set GOMOD=D:\project\go.mod
set GOWORK=
set CGO_CFLAGS=-O2 -g
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-O2 -g
set CGO_FFLAGS=-O2 -g
set CGO_LDFLAGS=-O2 -g
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=C:\Users\dev\AppData\Local\Temp\go-build1419264131=/tmp/go-build -gno-record-gcc-switches

Go compiled from source using GOOS=windows GOARCH=amd64.
Library compiled with GOOS=windows GOARCH=amd64
Running on windows 64bit

What did you do?

Upgraded an existing (functional) go library from go1.20.6 to go1.21.4, compiled with -buildmode=c-archive.
The runtime is initialised using _rt0_amd64_windows_lib, as described in #42190 . This part works.
In MSVC's linker settings, Enable Incremental Linking is enabled.
Disabled Randomized Base Address to make the dump more readable.

Disabling incremental linking solves the issue.

What did you expect to see?

Library is usable, no panic on startup.

What did you see instead?

Panic on launch (full message further below).

minpc= 0x140028277 min= 0x140046e60 maxpc= 0x1404cac39 max= 0x1404cac39
fatal error: minpc or maxpc invalid
runtime: panic before malloc heap initialized

I've dumped the disassembly of the program (using dumpbin /disasm) to look at these addresses.

0x140028277 is part of the incremental link table that gets generated for "Enable Incremental Linking". It jumps to go:buildid

@ILT+160370(go:buildid):
  0000000140028277: E9 E4 EB 01 00     jmp         go:buildid

0x140046e60 is the address of the first instruction of go:buildid

go:buildid:
  0000000140046E60: FF 20              jmp         qword ptr [rax]
  0000000140046E62: 47 6F              outs        dx,dword ptr [rsi]
  0000000140046E64: 20 62 75           and         byte ptr [rdx+75h],ah
  0000000140046E67: 69 6C 64 20 49 44  imul        ebp,dword ptr [rsp+20h],203A4449h
                    3A 20
  // [function continues]
Full panic message
minpc= 0x140028277 min= 0x140046e60 maxpc= 0x1404cac39 max= 0x1404cac39
fatal error: minpc or maxpc invalid
runtime: panic before malloc heap initialized
Running main() from e:\a\_work\2100\s\thirdparty\googletest\googletest\src\gtest_main.cc
[==========] Running 336 tests from 32 test cases.
[----------] Global test environment set-up.

runtime stack:
runtime.siftupTimer({0x140081d60, 0x140fcc6fb, 0x16}, 0x4ffe50)
D:/GoCustom/go-windows-amd64-bootstrap/src/runtime/time.go:1070 fp=0x4ffd18 sp=0x4ffd10 pc=0x140081d45
runtime: g 0: unexpected return pc for runtime.siftupTimer called from 0x4ffd18
stack: frame={sp:0x4ffd10, fp:0x4ffd18} stack=[0x4efea0,0x4ffea0)
0x00000000004ffc10: 0x00000000004ffc80 0x000000014008257e <runtime.traceEventLocked+0xfffffffffffe165e>
0x00000000004ffc20: 0x0000000140fc7b37 0x00000000004ffc58
0x00000000004ffc30: 0x0000000140085dd0 <runtime.traceback2+0xfffffffffffe15f0> 0x0000000141a3cbc0
0x00000000004ffc40: 0x0000000000000000 0x0100000140085e00
0x00000000004ffc50: 0x0000000000000008 0x00000000004ffc80
0x00000000004ffc60: 0x000000014008239c <runtime.traceEventLocked+0xfffffffffffe147c> 0x0000000140fdab01
0x00000000004ffc70: 0x0000000140081d45 <runtime.siftupTimer+0xfffffffffffe1545> 0x00000000004ffd10
0x00000000004ffc80: 0x00000000004ffcc0 0x00000001400820c5 <runtime.traceReader+0xfffffffffffe1465>
0x00000000004ffc90: 0x0000000141a3cbc0 0x00000001410e5b20
0x00000000004ffca0: 0x0000000000000001 0x00000000004ffd10
0x00000000004ffcb0: 0x0000000140081d45 <runtime.siftupTimer+0xfffffffffffe1545> 0x0000000141a3cbc0
0x00000000004ffcc0: 0x00000000004ffd00 0x0000000140082045 <runtime.siftdownTimer+0xfffffffffffe16e5>
0x00000000004ffcd0: 0x00000000004ffce0 0x0000000141a3cbc0
0x00000000004ffce0: 0x0000000140082080 <runtime.traceReader+0xfffffffffffe1420> 0x0000000141a3cbc0
0x00000000004ffcf0: 0x0000000140081d45 <runtime.siftupTimer+0xfffffffffffe1545> 0x00000000004ffd10
0x00000000004ffd00: 0x00000000004ffd30 0x0000000140081d45 <runtime.siftupTimer+0xfffffffffffe1545>
0x00000000004ffd10: <0x00000000004ffd18 >0x0000000140081d60 <runtime.siftupTimer+0xfffffffffffe1560>
0x00000000004ffd20: 0x0000000140fcc6fb 0x0000000000000016
0x00000000004ffd30: 0x00000000004ffe50 0x000000014009c5e5 <sync/atomic.(*Pointer[interface {}]).Store+0xfffffffffffe1485>
0x00000000004ffd40: 0x0000000140fcc6fb 0x00000000004ffd68
0x00000000004ffd50: 0x0000000000000000 0xfffffff100000000
0x00000000004ffd60: 0x00000000004ffdb0 0x00000000004ffda0
0x00000000004ffd70: 0x0000000000003c04 0x0000000140046e60 <runtime.gcMarkTermination+0xfffffffffffe1fc0>
0x00000000004ffd80: 0x00000001404cac39 0x00000000004ffd80
0x00000000004ffd90: 0x00000000004ffde0 0x00000001400b15ca <sort.pdqsort_func+0xfffffffffffe162a>
0x00000000004ffda0: 0x00000000004ffdb8 0x000000014007eff6 <runtime.step+0xfffffffffffe14d6>
0x00000000004ffdb0: 0x0000000000000001 0x00000000004ffe30
0x00000000004ffdc0: 0x00000001404cac39 0x0000000140028277 fatal error: index out of range
runtime: panic before malloc heap initialized
panic during panic

runtime stack:
runtime.siftupTimer({0x0000000140081d60, 0x0000000140fc9363, 0x0000000000000012}, 0x00000000004ff310)
D:/GoCustom/go-windows-amd64-bootstrap/src/runtime/time.go:1070 fp=0x00000000004ff2d8 sp=0x00000000004ff2d0 pc=0x0000000140081d45
runtime: g 0: unexpected return pc for runtime.siftupTimer called from 0x00000000004ff2d8
stack: frame={sp:0x00000000004ff2d0, fp:0x00000000004ff2d8} stack=[0x00000000004efea0,0x00000000004ffea0)
0x00000000004ff1d0: 0x00000000004ff240 0x000000014008257e <runtime.traceEventLocked+0xfffffffffffe165e>
0x00000000004ff1e0: 0x0000000140fc7b37 0x00000000004ff220
0x00000000004ff1f0: 0x0000000140fca09b 0x0000000141a3cbc0
0x00000000004ff200: 0x0000000140fca09b 0x0100000000000013
0x00000000004ff210: 0x0000000000000008 0x00000000004ff240
0x00000000004ff220: 0x000000014008234a <runtime.traceEvent+0xfffffffffffe154a> 0x0000000140fca09b
0x00000000004ff230: 0x0000000140081d45 <runtime.siftupTimer+0xfffffffffffe1545> 0x00000000004ff2d0
0x00000000004ff240: 0x00000000004ff280 0x00000001400820c5 <runtime.traceReader+0xfffffffffffe1465>
0x00000000004ff250: 0x0000000141a3cbc0 0x00000001410e5b20
0x00000000004ff260: 0x0000000000000001 0x00000000004ff2d0
0x00000000004ff270: 0x0000000140081d45 <runtime.siftupTimer+0xfffffffffffe1545> 0x0000000141a3cbc0
0x00000000004ff280: 0x00000000004ff2c0 0x0000000140082045 <runtime.siftdownTimer+0xfffffffffffe16e5>
0x00000000004ff290: 0x00000000004ff2a0 0x0000000141a3cbc0
0x00000000004ff2a0: 0x0000000140082080 <runtime.traceReader+0xfffffffffffe1420> 0x0000000141a3cbc0
0x00000000004ff2b0: 0x0000000140081d45 <runtime.siftupTimer+0xfffffffffffe1545> 0x00000000004ff2d0
0x00000000004ff2c0: 0x00000000004ff2f0 0x0000000140081d45 <runtime.siftupTimer+0xfffffffffffe1545>
0x00000000004ff2d0: <0x00000000004ff2d8 >0x0000000140081d60 <runtime.siftupTimer+0xfffffffffffe1560>
0x00000000004ff2e0: 0x0000000140fc9363 0x0000000000000012
0x00000000004ff2f0: 0x00000000004ff310 0x000000014007f925 <runtime.(*abiDesc).tryRegAssignArg+0xfffffffffffe17a5>
0x00000000004ff300: 0x0000000140fc9363 0x0000000140083ff4 <runtime.(*unwinder).initAt+0xfffffffffffe16f4>
0x00000000004ff310: 0x00000000004ff350 0x000000014007f9ee <runtime.callbackWrap+0xfffffffffffe14ee>
0x00000000004ff320: 0x0000000000000000 0x0000000140fc9363
0x00000000004ff330: 0x0000000000000012 0x00000001410e5ab8
0x00000000004ff340: 0x0000000000000001 0x0000000000000001
0x00000000004ff350: 0x00000000004ff370 0x000000014009cf59 <internal/reflectlite.Swapper+0xfffffffffffe1859>
0x00000000004ff360: 0x0000000000460894 0x0000000000003c05
0x00000000004ff370: 0x00000000004ff3e0 0x0000000140084245 <runtime.(*unwinder).resolveInternal+0xfffffffffffe1605>
0x00000000004ff380: 0x00000000004ff39f 0x0000000000000001
0x00000000004ff390: 0x00000000004ff3e0 0x2000000140083ff4
0x00000000004ff3a0: 0x000000000000000c 0x000000014009db20 <internal/reflectlite.rtype.In+0xfffffffffffe14c0>
0x00000000004ff3b0: 0x0000000140028277 fatal error: index out of range
runtime: panic before malloc heap initialized
stack trace unavailable

@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Nov 15, 2023
@qmuntal
Copy link
Contributor

qmuntal commented Nov 15, 2023

@golang/windows

@qmuntal qmuntal added OS-Windows NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Nov 15, 2023
@mknyszek mknyszek added this to the Backlog milestone Nov 22, 2023
@mknyszek
Copy link
Contributor

I think according to https://github.com/golang/go/wiki/cgo#windows linking with MSVC is not supported, though if it's easy to fix I don't think we'd be opposed to fixing it or accepting a change that fixes it. If you could bisect to the change that broke this, that would be helpful. Thanks.

CC @golang/compiler

@mknyszek mknyszek changed the title runtime: "minpc or maxpc invalid" when linking with incremental linking on MSVC cmd/link: "minpc or maxpc invalid" when linking with incremental linking on MSVC Nov 22, 2023
@cherrymui
Copy link
Member

As @mknyszek mentioned, linking with MSVC is not supported, not to mention that incremental linking adds another layer of complexity. Thanks.

@cherrymui cherrymui closed this as not planned Won't fix, can't repro, duplicate, stale Nov 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. help wanted NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Windows
Projects
None yet
Development

No branches or pull requests

5 participants