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

Open
bsrdjan opened this issue May 18, 2020 · 6 comments
Open

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

bsrdjan opened this issue May 18, 2020 · 6 comments

Comments

@bsrdjan
Copy link

@bsrdjan 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
Copy link
Member

@ALTree 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

@alexbrainman alexbrainman commented May 21, 2020

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

@networkimprov networkimprov commented May 21, 2020

cc @ianlancetaylor re cgo.

@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented May 21, 2020

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 mattn commented May 22, 2020

@bsrdja Could you provide minimal example to reproduce?

@bsrdjan
Copy link
Author

@bsrdjan 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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
6 participants
You can’t perform that action at this time.