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

runtime: error error 3221226356 (C0000374) in CGO module in Windows #39127

Closed
bsrdjan opened this issue May 18, 2020 · 7 comments
Closed

runtime: error error 3221226356 (C0000374) in CGO module in Windows #39127

bsrdjan opened this issue May 18, 2020 · 7 comments
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Windows WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@bsrdjan
Copy link

bsrdjan commented May 18, 2020

The CGO module gorfc provides GO bindings to pre-compiled SAP NWRFC SDK binaries. The module works fine on Linux and macOS and never worked quite stable on Windows. Currently, it occasionally terminates on Windows, with heap corruption error 3221226356 (hex C0000374).

I am not sure if the toolchain and compiler flags are maybe part of the problem, here further details.

Toolchain

SAP NWRFC SDK binaries require Microsoft C Runtime DLLs version 12.0 and our Windows toolchain is based on MinGW64, with following settings:

Version: 8.1.0
Architecture: x86_64
Threads: win32
Exception: seh
Build revision: 0

The TDM GCC is not used because this issue still occurs: error adding symbols: File in wrong format

Is this the optimal toolchain for building CGO modules on Windows, or another approach could be considered?

Compiler flags

Compiler flags recommended for SAP NWRFC SDK bindings on Windows platform, are given for Windows native compiler and linker:

cl.exe -DSAPonNT -D_CRT_NON_CONFORMING_SWPRINTFS -D_CRT_SECURE_NO_DEPRECATE 
-D_CRT_NONSTDC_NO_DEPRECATE -D_AFXDLL -DWIN32 -D_WIN32_WINNT=0x0502 -DWIN64 
-D_AMD64_ -DNDEBUG -DSAPwithUNICODE -DUNICODE -D_UNICODE -DSAPwithTHREADS 
-Inwrfcsdk/include -EHs -Gy -J -MD -nologo -W3 -Z7 -D_ATL_ALLOW_CHAR_UNSIGNED -GL 
-O2 -Oy- /we4552 /we4700 /we4789 -c -FosflightClient.obj sflightClient.c

link.exe -OUT:sflightClient.exe -PDB:sflightClient.pdb -NXCOMPAT -STACK:0x2000000 
-SWAPRUN:NET -DEBUG -OPT:REF -DEBUGTYPE:CV,FIXUP -MACHINE:amd64 -nologo 
-LTCG  ole32.lib oleaut32.lib uuid.lib kernel32.lib advapi32.lib user32.lib gdi32.lib winspool.lib ws2_32.lib comdlg32.lib shell32.lib sflightClient.obj nwrfcsdk/lib/sapnwrfc.lib nwrfcsdk/lib/libsapucum.lib

GCC counterparts are currently missing for some of them, commented in gorfc source)

Any help/ideas on toolchain, flags, possible root causes and troubleshooting approach, would be of a great help.

Here the details about GO environment on Windows.

PS C:\src\GO\src\github.com\sap\gorfc>go version
go version go1.14 windows/amd64

PS C:\src\GO\src\github.com\sap\gorfc> go env
set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\d037732\AppData\Local\go-build
set GOENV=C:\Users\d037732\AppData\Roaming\go\env
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=c:\src\GO
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Tools\GOLANG
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=C:\Tools\GOLANG\pkg\tool\windows_amd64
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=C:\src\GO\src\github.com\sap\gorfc\go.mod
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\d037732\AppData\Local\Temp\go-build050373882=/tmp/go-build -gno-record-gcc-switches
@ALTree ALTree added OS-Windows NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels May 18, 2020
@ALTree
Copy link
Member

ALTree commented May 18, 2020

cc @alexbrainman probably knows if this is a supported configuration on windows.

@ALTree ALTree changed the title Error error 3221226356 (C0000374) in CGO module in Windows runtime: error error 3221226356 (C0000374) in CGO module in Windows May 18, 2020
@alexbrainman
Copy link
Member

cc @alexbrainman probably knows if this is a supported configuration on windows.

I don't know, if this is a supported configuration or not.

I don't use Cgo in my Windows programs.

Alex

@networkimprov
Copy link

cc @ianlancetaylor re cgo.

@ianlancetaylor
Copy link
Contributor

I also don't know, sorry.

But from the problem description I think it's fairly unlikely to be a toolchain or compiler flag problem. Those kind of problems manifest as build failures or immediate crashes. You are describing an occasional crash likely due to memory corruption. That is more likely to be due to some sort of error passing memory between Go and C. The fact that it works reliably on GNU/Linux and macOS does not preclude a problem on Windows, as Windows is of course quite different in many ways.

Sorry I can't help.

@mattn
Copy link
Member

mattn commented May 22, 2020

@bsrdja Could you provide minimal example to reproduce?

@bsrdjan
Copy link
Author

bsrdjan commented May 25, 2020

The example itself is simple: https://github.com/SAP/gorfc/blob/master/example/hello_gorfc.go

The challenge could be the setup, requiring SAP ABAP backend system and SAP NWRFC SDK binary libraries, installed on GO client system.

You probably don't have access to any of them and we need to find out how to test?

@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Jul 7, 2022
@seankhliao seankhliao added this to the Unplanned milestone Aug 27, 2022
@seankhliao seankhliao added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Aug 27, 2022
@gopherbot
Copy link

Timed out in state WaitingForInfo. Closing.

(I am just a bot, though. Please speak up if this is a mistake or you have the requested information.)

@golang golang locked and limited conversation to collaborators Sep 27, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Windows WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

8 participants