Skip to content

x/sys/windows/mkwinsyscall: generates invalid calls for GOARCH=386 #42373

Open
@adriansr

Description

@adriansr

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

go version go1.15.3 windows/386

Does this issue reproduce with the latest release?

Yes

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

set GO111MODULE=
set GOARCH=386
set GOBIN=
set GOCACHE=C:\Users\vagrant\AppData\Local\go-build
set GOENV=C:\Users\vagrant\AppData\Roaming\go\env
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=386
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\vagrant\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\vagrant\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=C:\go\pkg\tool\windows_386
set GCCGO=gccgo
set GO386=sse2
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=C:\vagrant\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=-m32 -mthreads -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=C:\Users\vagrant\AppData\Local\Temp\go-build184742666=/tmp/go-build -gno-record-gcc-switches

What did you do?

package foo

//sys _Foo(param1 uint64, param2 int) (success bool, err error) = mylib._Foo

What did you expect to see?

For arches where an uintptr is 32-bit, the first parameter should take two arguments in Syscall:

func _Foo(param1 uint64, param2 int) (success bool, err error) {
        var (
                r0 uintptr
                e1 syscall.Errno
        )
        if unsafe.Sizeof(uintptr(0)) == unsafe.Sizeof(uint64(0)) {
                r0, _, e1 = syscall.Syscall(proc_Foo.Addr(), 2, uintptr(param1), uintptr(param2), 0)
        } else {
                var _p0 [2]uintptr = *(*[2]uintptr)(unsafe.Pointer(&param1))
                r0, _, e1 = syscall.Syscall(proc_Foo.Addr(), 3, _p0[0], _p0[1], uintptr(param2))
        }

        success = r0 != 0
        if success == 0 {
                err = errnoErr(e1)
        }
        return
}

What did you see instead?

func _Foo(param1 uint64, param2 int) (success bool, err error) {
        r0, _, e1 := syscall.Syscall(proc_Foo.Addr(), 2, uintptr(param1), uintptr(param2), 0)
        success = r0 != 0
        if success == 0 {
                err = errnoErr(e1)
        }
        return
}

This call won't be valid when GOARCH=386 as param1 (64bit) is being cast to an uintptr (32bit). The receiver would be expecting 64-bits on the stack for the first argument.

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.OS-Windows

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions