Skip to content

affected/package: go在调用由go编译的dll出现bug #54806

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

Closed
Linkangyis opened this issue Sep 1, 2022 · 8 comments
Closed

affected/package: go在调用由go编译的dll出现bug #54806

Linkangyis opened this issue Sep 1, 2022 · 8 comments

Comments

@Linkangyis
Copy link

Linkangyis commented Sep 1, 2022

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

支持CGO的任意版本
go version go1.19 windows/amd64

Does this issue reproduce with the latest release?

在任意版本都出现

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

go env Output
$ go env
set GOARCH=amd64

What did you do?

我使用了CGO调用把go编译成了dll再由go进行调用

main.go:
package main

import (
    "syscall"
    "fmt"
)

func main(){
    dll := syscall.NewLazyDLL("test.dll")
    jiafa := dll.NewProc("Test")
    demo,err,msg := jiafa.Call()
    fmt.Println(demo)
    fmt.Println(err)
    fmt.Println(msg)
}

Test.dll go:
package main

import("fmt")

import "C"

//export Test
func Test(){
	fmt.Println("Value")
}

func main(){}

What did you expect to see?

正常使用dll

What did you see instead?

fatal error: bad sweepgen in refill

goroutine 1 [running, locked to thread]:
runtime.throw({0x5be45ab8?, 0x41f5a5?})
        C:/Program Files/Go/src/runtime/panic.go:1047 +0x65 fp=0xc000115950 sp=0xc000115920 pc=0x5bdb5045
runtime.(*mcache).refill(0x17264030108, 0x86?)
        C:/Program Files/Go/src/runtime/mcache.go:156 +0x216 fp=0xc000115990 sp=0xc000115950 pc=0x5bd94976
runtime.(*mcache).nextFree(0x17264030108, 0x4c)
        C:/Program Files/Go/src/runtime/malloc.go:819 +0x85 fp=0xc0001159d8 sp=0xc000115990 pc=0x5bd8bf05
runtime.mallocgc(0x800, 0x5be37a60, 0x1)
        C:/Program Files/Go/src/runtime/malloc.go:1018 +0x4c8 fp=0xc000115a50 sp=0xc0001159d8 pc=0x5bd8c568
runtime.makeslice(0x0?, 0x0?, 0x8?)
        C:/Program Files/Go/src/runtime/slice.go:103 +0x52 fp=0xc000115a78 sp=0xc000115a50 pc=0x5bdc6f52
sync.(*Pool).pinSlow(0x5be223a0)
        C:/Program Files/Go/src/sync/pool.go:230 +0x185 fp=0xc000115b10 sp=0xc000115a78 pc=0x5bde5b65
sync.(*Pool).pin(0x5be223a0)
        C:/Program Files/Go/src/sync/pool.go:209 +0x4e fp=0xc000115b28 sp=0xc000115b10 pc=0x5bde59ae
sync.(*Pool).Get(0x5be223a0)
        C:/Program Files/Go/src/sync/pool.go:131 +0x25 fp=0xc000115b60 sp=0xc000115b28 pc=0x5bde56e5
fmt.newPrinter()
        C:/Program Files/Go/src/fmt/print.go:137 +0x25 fp=0xc000115b88 sp=0xc000115b60 pc=0x5be09225
fmt.Fprintln({0x5be65d18, 0x0}, {0xc000115c00, 0x1, 0x1})
        C:/Program Files/Go/src/fmt/print.go:283 +0x36 fp=0xc000115bd8 sp=0xc000115b88 pc=0x5be094f6
fmt.Println(...)
        C:/Program Files/Go/src/fmt/print.go:294
main.Test(...)
        D:/工程文件目录/GO/test.go:9
_cgoexp_3a4230144ecb_Test(0x0?)
        _cgo_gotypes.go:39 +0x52 fp=0xc000115c20 sp=0xc000115bd8 pc=0x5be0eab2
runtime.cgocallbackg1(0x5be0ea60, 0x40372a?, 0x0)
        C:/Program Files/Go/src/runtime/cgocall.go:316 +0x2c2 fp=0xc000115cf0 sp=0xc000115c20 pc=0x5bd84082
runtime.cgocallbackg(0xc000050000?, 0x300000002?, 0xc000050000?)
        C:/Program Files/Go/src/runtime/cgocall.go:235 +0x105 fp=0xc000115d80 sp=0xc000115cf0 pc=0x5bd83cc5
runtime.cgocallbackg(0x5be0ea60, 0x662c1ff7af, 0x0)
        <autogenerated>:1 +0x36 fp=0xc000115da8 sp=0xc000115d80 pc=0x5bde0796
runtime: g 1: unexpected return pc for runtime.cgocallback called from 0x45c040
stack: frame={sp:0xc000115da8, fp:0xc000115dd0} stack=[0xc00010e000,0xc000116000)
0x000000c000115ca8:  0x000000c000115c65  0x000000c000050000
0x000000c000115cb8:  0x0000000200000003  0x000000c000050000
0x000000c000115cc8:  0x000000c000115ca0  0x0000000000000000
0x000000c000115cd8:  0x000000005be4bfb8  0x000000c000115d70
0x000000c000115ce8:  0x000000005bd83cc5 <runtime.cgocallbackg+0x0000000000000105>  0x000000005be0ea60 <_cgoexp_3a4230144ecb_Test+0x0000000000000000>
0x000000c000115cf8:  0x000000000040372a  0x0000000000000000
0x000000c000115d08:  0x000000000040372a  0x0000000000000000
0x000000c000115d18:  0x000000005be0ead0  0x0000000000000000
0x000000c000115d28:  0x000000c000115e48  0x000000005be0ead0
0x000000c000115d38:  0x0000000000000000  0x0000000000000000
0x000000c000115d48:  0x000000c000115dd8  0x000000c000050000
0x000000c000115d58:  0x0000000000543ae0  0x000000005be0ea60 <_cgoexp_3a4230144ecb_Test+0x0000000000000000>
0x000000c000115d68:  0x000000662c1ff7af  0x000000c000115d98
0x000000c000115d78:  0x000000005bde0796 <runtime.cgocallbackg+0x0000000000000036>  0x000000c000050000
0x000000c000115d88:  0x0000000300000002  0x000000c000050000
0x000000c000115d98:  0x000000662c1ff668  0x000000005bdde557 <runtime.cgocallback+0x00000000000000d7>
0x000000c000115da8: <0x000000005be0ea60 <_cgoexp_3a4230144ecb_Test+0x0000000000000000>  0x000000662c1ff7af
0x000000c000115db8:  0x0000000000000000  0x000000c000115dd8
0x000000c000115dc8: !0x000000000045c040 >0x000000000040378b
0x000000c000115dd8:  0x000000000045fc40  0x0000000000543da0
0x000000c000115de8:  0x0000000000458eba  0x0000000002030000
0x000000c000115df8:  0x0000000000543ae0  0x000000c000115e78 
0x000000c000115e08:  0x000000000045b109  0x000000000045fc40
0x000000c000115e18:  0x0000000000543da0  0x00000000004a879a
0x000000c000115e28:  0x0100000000000008  0x0000000000000000
0x000000c000115e38:  0x0000000000000000  0x0000000000000000
0x000000c000115e48:  0x0000000000000000  0x0000000000000000
0x000000c000115e58:  0x0000000000000000  0x0000000000000000
0x000000c000115e68:  0x0000000000543ae0  0x00000000004b1fc0
0x000000c000115e78:  0x000000c000115eb8  0x0000000000467605
0x000000c000115e88:  0x000000005be0ead0  0x0000000000000000
0x000000c000115e98:  0x0000000000000000  0x0000000000467a00
0x000000c000115ea8:  0x000000c00007a4b0  0x000000c000115ea0
0x000000c000115eb8:  0x000000c000115ee8  0x0000000000467ab0
0x000000c000115ec8:  0x000000c00007a4b0
runtime.cgocallback(0x40378b, 0x45fc40, 0x543da0)
        C:/Program Files/Go/src/runtime/asm_amd64.s:994 +0xd7 fp=0xc000115dd0 sp=0xc000115da8 pc=0x5bdde557

goroutine 1 [runnable, locked to thread]:
internal/poll.(*FD).Init(0x1c000004280?, {0x5be424c3?, 0x7?}, 0x0?)
        C:/Program Files/Go/src/internal/poll/fd_windows.go:283 +0x6d7 fp=0x1c000115b68 sp=0x1c000115b60 pc=0x5be04a77
os.newFile(0x320, {0x5be42b00, 0xa}, {0x5be41fce?, 0x4?})
        C:/Program Files/Go/src/os/file_windows.go:66 +0x167 fp=0x1c000115bb8 sp=0x1c000115b68 pc=0x5be064c7
os.NewFile(...)
        C:/Program Files/Go/src/os/file_windows.go:84
os.init()
        C:/Program Files/Go/src/os/file.go:65 +0x1f6 fp=0x1c000115bf0 sp=0x1c000115bb8 pc=0x5be068d6
runtime.doInit(0x5be14560)
        C:/Program Files/Go/src/runtime/proc.go:6321 +0x12d fp=0x1c000115d20 sp=0x1c000115bf0 pc=0x5bdc420d
runtime.doInit(0x5be13d40)
        C:/Program Files/Go/src/runtime/proc.go:6298 +0x71 fp=0x1c000115e50 sp=0x1c000115d20 pc=0x5bdc4151
runtime.doInit(0x5be12a40)
        C:/Program Files/Go/src/runtime/proc.go:6298 +0x71 fp=0x1c000115f80 sp=0x1c000115e50 pc=0x5bdc4151
runtime.main()
        C:/Program Files/Go/src/runtime/proc.go:233 +0x1bf fp=0x1c000115fe0 sp=0x1c000115f80 pc=0x5bdb773f
runtime.goexit()
        C:/Program Files/Go/src/runtime/asm_amd64.s:1594 +0x1 fp=0x1c000115fe8 sp=0x1c000115fe0 pc=0x5bdde7c1

goroutine 2 [force gc (idle)]:
runtime.gopark(0x0?, 0x0?, 0x0?, 0x0?, 0x0?)
        C:/Program Files/Go/src/runtime/proc.go:363 +0xd6 fp=0x1c000053fb0 sp=0x1c000053f90 pc=0x5bdb7b16
runtime.goparkunlock(...)
        C:/Program Files/Go/src/runtime/proc.go:369
runtime.forcegchelper()
        C:/Program Files/Go/src/runtime/proc.go:302 +0xb1 fp=0x1c000053fe0 sp=0x1c000053fb0 pc=0x5bdb79b1
runtime.goexit()
        C:/Program Files/Go/src/runtime/asm_amd64.s:1594 +0x1 fp=0x1c000053fe8 sp=0x1c000053fe0 pc=0x5bdde7c1
created by runtime.init.6
        C:/Program Files/Go/src/runtime/proc.go:290 +0x25

goroutine 3 [GC sweep wait]:
runtime.gopark(0x0?, 0x0?, 0x0?, 0x0?, 0x0?)
        C:/Program Files/Go/src/runtime/proc.go:363 +0xd6 fp=0x1c000055f90 sp=0x1c000055f70 pc=0x5bdb7b16
runtime.goparkunlock(...)
        C:/Program Files/Go/src/runtime/proc.go:369
runtime.bgsweep(0x0?)
        C:/Program Files/Go/src/runtime/mgcsweep.go:278 +0x8e fp=0x1c000055fc8 sp=0x1c000055f90 pc=0x5bda274e
runtime.gcenable.func1()
        C:/Program Files/Go/src/runtime/mgc.go:178 +0x26 fp=0x1c000055fe0 sp=0x1c000055fc8 pc=0x5bd974e6
runtime.goexit()
        C:/Program Files/Go/src/runtime/asm_amd64.s:1594 +0x1 fp=0x1c000055fe8 sp=0x1c000055fe0 pc=0x5bdde7c1
created by runtime.gcenable
        C:/Program Files/Go/src/runtime/mgc.go:178 +0x6b

goroutine 4 [GC scavenge wait]:
runtime.gopark(0x1c000060000?, 0x5be657a0?, 0x1?, 0x0?, 0x0?)
        C:/Program Files/Go/src/runtime/proc.go:363 +0xd6 fp=0x1c000067f70 sp=0x1c000067f50 pc=0x5bdb7b16
runtime.goparkunlock(...)
        C:/Program Files/Go/src/runtime/proc.go:369
runtime.(*scavengerState).park(0x5bec8dc0)
        C:/Program Files/Go/src/runtime/mgcscavenge.go:389 +0x53 fp=0x1c000067fa0 sp=0x1c000067f70 pc=0x5bda07d3
runtime.bgscavenge(0x0?)
        C:/Program Files/Go/src/runtime/mgcscavenge.go:617 +0x45 fp=0x1c000067fc8 sp=0x1c000067fa0 pc=0x5bda0dc5
runtime.gcenable.func2()
        C:/Program Files/Go/src/runtime/mgc.go:179 +0x26 fp=0x1c000067fe0 sp=0x1c000067fc8 pc=0x5bd97486
runtime.goexit()
        C:/Program Files/Go/src/runtime/asm_amd64.s:1594 +0x1 fp=0x1c000067fe8 sp=0x1c000067fe0 pc=0x5bdde7c1
created by runtime.gcenable
        C:/Program Files/Go/src/runtime/mgc.go:179 +0xaa

goroutine 5 [runnable]:
runtime.runfinq()
        C:/Program Files/Go/src/runtime/mfinal.go:162 fp=0x1c000057fe0 sp=0x1c000057fd8 pc=0x5bd964e0
runtime.goexit()
        C:/Program Files/Go/src/runtime/asm_amd64.s:1594 +0x1 fp=0x1c000057fe8 sp=0x1c000057fe0 pc=0x5bdde7c1
created by runtime.createfing
        C:/Program Files/Go/src/runtime/mfinal.go:157 +0x45
exit status 2

初步猜测是因为dll里面用到了接口,导致内存溢出

@ZekeLu
Copy link
Contributor

ZekeLu commented Sep 1, 2022

See #53969 (comment)

@hopehook
Copy link
Member

hopehook commented Sep 1, 2022

Closing as a dup of #38692. Thanks.

@hopehook hopehook closed this as completed Sep 1, 2022
@Linkangyis
Copy link
Author

#38692 的 dup 结尾。谢谢。

可我是Windows

@hopehook
Copy link
Member

hopehook commented Sep 1, 2022

The Go shared library that is opened by a program written in C (or C++ or some other non-Go language).

@Linkangyis
Copy link
Author

由用 C 语言(或C++或其他非 Go 语言)编写的程序打开的 Go 共享库。

我是由go调用go编译的动态库

@hopehook
Copy link
Member

hopehook commented Sep 1, 2022

Go cannot call Go DLLs. As @ZekeLu mentioned comments pointed out.

For more details, see issue #38692.

@cuiweixie
Copy link
Contributor

do this with go plugin may be a good choice.

@Linkangyis
Copy link
Author

使用go插件执行此操作可能是一个不错的选择

plugin库只能在linux unix使用

@golang golang locked and limited conversation to collaborators Sep 1, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants