Skip to content

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

@bsrdjan

Description

@bsrdjan

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.OS-WindowsWaitingForInfoIssue is not actionable because of missing required information, which needs to be provided.compiler/runtimeIssues related to the Go compiler and/or runtime.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions