Segmentation fault debian 8 golang

huangapple go评论161阅读模式
英文:

Segmentation fault debian 8 golang

问题

tstx程序代码(使用golang编写)

package main

import "fmt"

func main(){
 fmt.Printf("Hello")
}

在开发计算机上(基于Debian的Linux),一切正常,但是当我在服务器计算机上运行它(Debian 8)时,出现了段错误。

两个系统都是amd64架构,代码使用编译。

[strace ./tstx] - 输出如下:

execve("./tstx", ["./tstx"], [/* 16 vars */]) = 0
--- SIGSEGV {si_signo=SIGSEGV, si_code=SEGV_MAPERR, si_addr=0xffffffffffffff8b} ---
+++ killed by SIGSEGV +++
英文:

tstx program code (golang)

package main

import "fmt"

func main(){
 fmt.Printf("Hello")
}

On dev computer (debian based linux) all ok, but
when i run it on server computer (Debian 8) i got segmentation fault

both systems are amd64, code compilled with

[strace ./tstx] - says

execve("./tstx", ["./tstx"], [/* 16 vars */]) = 0                                                                                                                                                                  
--- SIGSEGV {si_signo=SIGSEGV, si_code=SEGV_MAPERR, si_addr=0xffffffffffffff8b} ---                                                                                                                                
+++ killed by SIGSEGV +++    

答案1

得分: 2

由于您正在一个机器上编译并移动到另一个机器上,您确实希望确保DLL不是一个问题。首先,使用以下命令进行构建:

CGO_ENABLED=0 go build...

然后,使用以下命令确保它正常:

ldd tstx

(它应该返回“not a dynamic executable”或类似的结果)。

禁用CGO意味着可执行文件会变大(所有内容都静态链接),但是由于它是自包含的,dll不会成为问题。最后,通过uname命令验证它们的架构是否相同也是一个好主意...

英文:

Since you're compiling on one machine and moving to another, you'll really want to be sure that DLLs aren't an issue. First, build with:

CGO_ENABLED=0 go build...

And ensure it looks good with:

ldd tstx

(It should come back with "not a dynamic executable" or similar).

Disabling CGO means that the executable will be larger (everything statically linked), but dlls won't be an issue since it's self-contained. Finally, it can't hurt to verify that their architectures are the same via uname...

huangapple
  • 本文由 发表于 2016年8月25日 21:37:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/39146871.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定