Skip to content

windows cross compile to linux,Run the program appears Segmentation fault #42227

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
hoslo opened this issue Oct 27, 2020 · 5 comments
Closed

Comments

@hoslo
Copy link

hoslo commented Oct 27, 2020

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

$ go version
go version go1.15.3 windows/amd64

Does this issue reproduce with the latest release?

yes

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

go env Output
windows $ go env
set GO111MODULE=on
set GOARCH=amd64
set GOBIN=C:\Users\yangshuai_ou\Downloads\go1.15.3.windows-amd64\bin
set GOCACHE=C:\Users\yangshuai_ou\AppData\Local\go-build
set GOENV=C:\Users\yangshuai_ou\AppData\Roaming\go\env
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\yangshuai_ou\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\yangshuai_ou\go
set GOPRIVATE=
set GOPROXY=https://goproxy.cn,direct
set GOROOT=C:\Users\yangshuai_ou\Downloads\go1.15.3.windows-amd64
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=C:\Users\yangshuai_ou\Downloads\go1.15.3.windows-amd64\pkg\tool\windows_amd64
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=0
set GOMOD=D:\projects\image_server\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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=C:\Users\YANGSH~1\AppData\Local\Temp\go-build926649678=/tmp/go-build -gno-record-gcc-switches
go env Output
linux $ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN="/opt/app/go/bin"
GOCACHE="/home/shuai_yang/.cache/go-build"
GOENV="/home/shuai_yang/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/opt/app/goprogram/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/opt/app/goprogram"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/opt/app/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/opt/app/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build053440172=/tmp/go-build -gno-record-gcc-switches"
### What did you do? in windows env CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build . in linux ./my_program

What did you expect to see?

What did you see instead?

Segmentation fault

@mattn
Copy link
Member

mattn commented Oct 27, 2020

Could you please provide stack trace of the panic or small steps to reproduce?

@hoslo
Copy link
Author

hoslo commented Oct 27, 2020

Could you please provide stack trace of the panic or small steps to reproduce?

gdb bt return this

#0  0x00007f2869bb1607 in kill () from /lib64/libc.so.6
#1  0x00005601f5255636 in ?? ()
#2  0x00005601f5c687f0 in ?? ()
#3  0x00007f2869be8f5b in __GI__IO_file_doallocate () from /lib64/libc.so.6
#4  0x0000000000000000 in ?? ()

@mattn
Copy link
Member

mattn commented Oct 27, 2020

Can you provide the minimal code to reproduce?

@hoslo
Copy link
Author

hoslo commented Oct 27, 2020

Can you provide the minimal code to reproduce?

Can you provide the minimal code to reproduce?

my program is a web service, using the following libraries

require (
	github.com/astaxie/beego v1.12.2
	github.com/disintegration/imaging v1.6.2
	github.com/gin-gonic/gin v1.6.3
	github.com/spf13/viper v1.7.1
)

I run this cmd in windows

 env CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -gcflags "-N -l" -a -o image_server .

and run the binary program image_server in linux,
I also run cmd in windows

 env CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -gcflags "-N -l" -a -o image_server.exe  .

and use dumpbin image_server.exe return this

File Type: EXECUTABLE IMAGE                     
                                                
  Image has the following dependencies:         
                                                
    kernel32.dll                                
                                                
  Summary                                       
                                                
       8F000 .data                              
        1000 .debug_gdb_scripts                 
        1000 .idata                             
      5C4000 .rdata                             
       43000 .reloc                             
      123000 .symtab                            
      6A6000 .text                              
        1000 .zdebug_abbrev                     
       35000 .zdebug_frame                      
      159000 .zdebug_info                       
       E8000 .zdebug_line                       
       EC000 .zdebug_loc                        
        7000 .zdebug_pubnames                   
       17000 .zdebug_pubtypes                   
       53000 .zdebug_ranges                     

@hoslo
Copy link
Author

hoslo commented Oct 27, 2020

problem solved

@hoslo hoslo closed this as completed Oct 27, 2020
@golang golang locked and limited conversation to collaborators Oct 27, 2021
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

3 participants