golang hello word segmentation fault

1,976 views
Skip to first unread message

brunetto

unread,
Jan 22, 2014, 9:33:17 AM1/22/14
to golan...@googlegroups.com
Hi!
May be I'm doing something stupid but I'm having problems with a small test in go.

I wrote this super-mini hello word as a test before writing a little program 
that has to be deployed on different (but similar) machines.

=================
package main

func main () {
print("Hi\n")
}

================

in a x86_64 linux computer and copied the binary (compiled with go build version go1.1.2 linux/amd64)
 on two other x86_64 linux computer.

It worked on the first (as expected), but result in segfault on the second. 
I tried to figure out what was happening with valgrind but I wasn't able to understand
and then I found that valgrind is not compatible with go...

What can I do? Am I doing something wrong?

thanks

brunetto


chris dollin

unread,
Jan 22, 2014, 9:37:06 AM1/22/14
to brunetto, golang-nuts
On 22 January 2014 14:33, brunetto <brunett...@gmail.com> wrote:
Hi!
May be I'm doing something stupid but I'm having problems with a small test in go.

I wrote this super-mini hello word as a test before writing a little program 
that has to be deployed on different (but similar) machines.

=================
package main

func main () {
print("Hi\n")
}

================

in a x86_64 linux computer and copied the binary (compiled with go build version go1.1.2 linux/amd64)
 on two other x86_64 linux computer.

Running what OS?

(And why use print rather than fmt.PrintWossname?)

Chris

--
Chris "allusive" Dollin

Brian Hatfield

unread,
Jan 22, 2014, 9:37:35 AM1/22/14
to brunetto, golan...@googlegroups.com
There's no such function as "print" - try import "fmt" and then use "fmt.Println()"


--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

brunetto

unread,
Jan 22, 2014, 9:42:27 AM1/22/14
to golan...@googlegroups.com, brunetto, ehog....@googlemail.com
Running what OS?

ubuntu 12.04, ubuntu 13.10 and Red Hat RHEL 5.6 with kernel 2.6.18-238.el5 and 2.6.32-279.el6.x86_64
 
(And why use print rather than fmt.PrintWossname?)

the first version was 

===========
package main

import (
"log"
"os"
"os/user"
)

func main () {
u, _ := user.Current()
host, _ := os.Hostname()
log.Println("Hi ", u.Username, " from ", host)
}
====================

and did segfault so I tried with the simplest I can think about, with no imports.
 

brunetto

brunetto

unread,
Jan 22, 2014, 9:45:52 AM1/22/14
to golan...@googlegroups.com, brunetto


On Wednesday, 22 January 2014 15:37:35 UTC+1, Brian Hatfield wrote:
There's no such function as "print" - try import "fmt" and then use "fmt.Println()"

print does exist and it works on all the other machines... it is just not the "go" way...

brunetto

chris dollin

unread,
Jan 22, 2014, 10:16:42 AM1/22/14
to Brian Hatfield, brunetto, golang-nuts
On 22 January 2014 14:37, Brian Hatfield <bmhat...@gmail.com> wrote:
There's no such function as "print" - try import "fmt" and then use "fmt.Println()"

From the spec:
 

Current implementations provide several built-in functions useful during bootstrapping. These functions are documented for completeness but are not guaranteed to stay in the language. They do not return a result.

Function   Behavior

print      prints all arguments; formatting of arguments is implementation-specific
println    like print but prints spaces between arguments and a newline at the end

chris dollin

unread,
Jan 22, 2014, 10:18:26 AM1/22/14
to brunetto, golang-nuts
On 22 January 2014 14:42, brunetto <brunett...@gmail.com> wrote:
Running what OS?

ubuntu 12.04, ubuntu 13.10 and Red Hat RHEL 5.6 with kernel 2.6.18-238.el5 and 2.6.32-279.el6.x86_64

from http://golang.org/doc/install:

Linux 2.6.23 or later with glibc amd64, 386, arm CentOS/RHEL 5.x not supported; no binary distribution for ARM yet

Chris

--
Chris "allusive" Dollin
Message has been deleted

brunetto

unread,
Jan 22, 2014, 10:27:39 AM1/22/14
to golan...@googlegroups.com, brunetto, ehog....@googlemail.com
thanks... I'll try cgo....

brunetto

Alex Skinner

unread,
Jan 22, 2014, 10:28:35 AM1/22/14
to golan...@googlegroups.com, brunetto, ehog....@googlemail.com
That specific kernel in RHEL 5.6 has a VDSO bug that was later fixed, and is the cause of the crash.  Even though not supported, some versions prior, and everything after 5.6 seem to work just fine. 

Alex

Dave Cheney

unread,
Jan 22, 2014, 3:42:53 PM1/22/14
to Alex Skinner, golang-nuts, brunetto, chris dollin

Alex Skinner

unread,
Jan 22, 2014, 4:42:38 PM1/22/14
to golan...@googlegroups.com, Alex Skinner, brunetto, chris dollin
Your site would have saved me many research hours - well not the building part as I gave up on that, but the segfault explanation.  Here are things I found along the way if anyone cares - I cannot guarantee 100% accurate as RH advisories often repeat things in different versions and can be generally a pain to follow.

This only applies to segmentation fault of running a binary, I cannot attest to building go from source on these systems.

VDSO first enabled by default in RHEL5.2
Bug seems to be introduced RHEL5.6 - released with kernel 2.6.18-238, which will segfault all go binaries.
Bug appears to have first been fixed in version 2.6.18-238.5 (see https://rhn.redhat.com/errata/RHSA-2011-0303.html and https://access.redhat.com/site/documentation/en-US/Red_Hat_Enterprise_Linux/5/html/5.6_Technical_Notes/kernel.html#RHSA-2011-0303)
RHEL5.7 release came with working kernel 2.6.18-274
Every subsequent release seems to work fine.

Ally Dale

unread,
Jan 22, 2014, 10:22:35 PM1/22/14
to golan...@googlegroups.com
Hi,could you show me your app name(the directory name of package main)? Try to rename another? 
I have met a similar situation on os Windows7 64bits version(6.1.7601),  go version go1.1.2 windows/386
A "hello world" application,if the app_name is "verify_update" or "update_verify", it need administrator authority

and runs without any output.
But if I change another app_name, eg "verify_up2date", it runs very well.

//.../verify_update/main.go
=================
package main

import (
"fmt"
)

func main() {
fmt.Println("verify_update")
}
=================

Thanks,
Ally

在 2014年1月22日星期三UTC+8下午10时33分17秒,brunetto写道:

minux

unread,
Jan 23, 2014, 1:16:22 AM1/23/14
to Ally Dale, golang-nuts
On Wed, Jan 22, 2014 at 10:22 PM, Ally Dale <vip...@gmail.com> wrote:
Hi,could you show me your app name(the directory name of package main)? Try to rename another? 
I have met a similar situation on os Windows7 64bits version(6.1.7601),  go version go1.1.2 windows/386
A "hello world" application,if the app_name is "verify_update" or "update_verify", it need administrator authority
this is a known issue of windows's "smart" detection of program installer and updaters.
basically it just detects "install", "update", "patch" or something like that in the name of
the program, and if there is a match, it will classify them as program installers and require
administrative privilege to execute them.

this has caused problem in the past, and forced us to rename the executable, for example,

brunetto

unread,
Jan 23, 2014, 5:34:49 AM1/23/14
to golan...@googlegroups.com, Alex Skinner, brunetto, chris dollin
thanks a lot, but I can't install or upgrade anithing on that machine... so in case I still segfault, I can't update the kernel...

burnetto

Ally Dale

unread,
Jan 23, 2014, 10:06:39 PM1/23/14
to golan...@googlegroups.com, Ally Dale
I got it.
Thanks.

在 2014年1月23日星期四UTC+8下午2时16分22秒,minux写道:
Reply all
Reply to author
Forward
0 new messages