I can't compile "hello, world" go program on Android 4.2/GNURoot Debian

Q. What is gnuroot debian?
A. Debian jessie on top of android, in a chroot jail. ( https://play.google.com/store/apps/details?id=com.gnuroot.debian&hl=en )

Q. Why don’t you use Termux instead? ( https://play.google.com/store/apps/details?id=com.termux&hl=en )
A. Even though it’s been reported that golang works with termux, termux requires minimum Android version 5.0 and I have Android 4.2. (And also out of sheer curiosity since gcc works and go is no more low-level than gcc (?))

Q. What did you try?
1) $ apt-get -t jessie-backports install golang
2) https://golang.org/doc/install --> “Test your installation”
3)

$ mkdir -p ~/go/src/hello
$ cd ~/go/src/hello
$ emacs hello.go --> Paste sample code from "Test your installation"
$ go build

I get:

go build _/root/go/src/hello: /usr/lib/go-1.7/pkg/tool/linux_arm/compile: signal: segmentation fault

Q. What does yes work on your system?
A.
-$ apt-get install build-essential” and then gcc/g++ on printf("hello world") program works as expected; and also I succeded to compile various tools/utilities from source using ‘./configure && make install’ in the past.

root@localhost:~/src/hello$ cat hello.cpp
#include <iostream>
using namespace std;

int main()
{
  cout << "Hello, World, 2!\n";
  return 0;
}
root@localhost:~/src/hello$ g++ hello.cpp
root@localhost:~/src/hello$ ./a.out
Hello, World, 2!
root@localhost:~/src/hello$

- python works.

root@localhost:~$ python
Python 2.7.9 (default, Aug 13 2016, 17:56:53)
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> reduce(lambda x,y: x+y, map(lambda x: x*x, range(1,11)))
385
>>>

Q. What else did you try?
1) Tried with/without setting GOARM=5, GOARCH=arm
2) Tried installing the latest version of go from https://golang.org/doc/install?download=go1.9.1.linux-armv6l.tar.gz , performing same “Test your installation” steps, now got a slightly different but essentially similar message:

$ go build
go build runtime/internal/sys: /usr/local/go/pkg/tool/linux_arm/compile: signal: illegal instruction

>> Tried with gdb:

$ gdb -batch -ex run -ex quit --args go build
...
[New LWP 19753]
go build runtime/internal/sys: /usr/local/go/pkg/tool/linux_arm/compile: signal: illegal instruction
[LWP 19753 exited]
[Inferior 1 (process 19733) exited with code 01]

>>> Suprisingly, this does yes work:

$ gdb -batch -ex run -ex quit --args /usr/local/go/pkg/tool/linux_arm/compile hello.go

--> yields ‘hello.o’ ; yet without gdb:

$ /usr/local/go/pkg/tool/linux_arm/compile hello.go
/usr/local/go/pkg/tool/linux_arm/compile: signal: illegal instruction

3) Tried installing gccgo (from debian repositories):

root@localhost:~$ apt-get -t jessie-backports install gccgo
root@localhost:~/go/src/hello$ gccgo hello.go
root@localhost:~/go/src/hello$ ls
a.out  hello.go
root@localhost:~/go/src/hello$ ./a.out
no debug info in ELF executable errno -1
fatal error: no debug info in ELF executable

runtime stack:
no debug info in ELF executable errno -1
panic during panic

okay, so tried with: -g switch:

root@localhost:~/go/src/hello$ gccgo -g hello.go 
root@localhost:~/go/src/hello$ ./a.out
hello, world
root@localhost:~/go/src/hello$

- voila! A finally working go ‘hello world’ program on my android! But not with latest go. And only with ‘-g’ flag, @#&?

root@localhost:~/go1.4/src$ ./make.bash
# Building C bootstrap tool.
cmd/dist

# Building compilers and Go bootstrap tool for host, linux/arm.
lib9
libbio
...
go/doc
go/build
cmd/go
./make.bash: line 161:  8579 Illegal instruction     "$GOTOOLDIR"/go_bootstrap clean -i std
root@localhost:~/go1.4/src$

So I guess my next bunch of questions is:
1) From which exact .c files ‘go_bootstrap’ binary is built? (I could sprinkle-in a few ‘printf("debug.")’ statements to pinpoint the exact location of the crash…)
2) How do I compile (make.bash) with debug info? (is there a command-line switch for that?)

Can anyone please help me out with those?

@rot13 thanks for responding. I tried with/without setting GOARM=5, GOARCH=arm just to see if anything works…

My cpuinfo on one of Android 4 devices I use:

$ cat /proc/cpuinfo
Processor       : ARMv7 Processor rev 3 (v7l)
processor       : 0
BogoMIPS        : 38.40

processor       : 1
BogoMIPS        : 38.40

processor       : 2
BogoMIPS        : 38.40

processor       : 3
BogoMIPS        : 38.40

Features        : swp half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt
CPU implementer : 0x41
CPU architecture: 7
CPU variant     : 0x0
CPU part        : 0xc07
CPU revision    : 3

Hardware        : Qualcomm MSM 8226 (Flattened Device Tree)
Revision        : 0006
Serial          : 0000000000000000
$ dpkg --print-architecture
armhf

@rot13: downloaded go1.4-bootstrap-20170531.tar.gz, ran, got ‘Illegal Instruction’ error:

root@localhost:~/go1.4/src# ./make.bash
# Building C bootstrap tool.
cmd/dist

# Building compilers and Go bootstrap tool for host, linux/arm.
lib9
libbio
liblink
cmd/cc
cmd/gc
cmd/5l
cmd/5a
cmd/5c
cmd/5g
runtime
errors
sync/atomic
sync
io
unicode
unicode/utf8
unicode/utf16
bytes
math
strings
strconv
bufio
sort
container/heap
encoding/base64
syscall
time
os
reflect
fmt
encoding
encoding/json
flag
path/filepath
path
io/ioutil
log
regexp/syntax
regexp
go/token
go/scanner
go/ast
go/parser
os/exec
os/signal
net/url
text/template/parse
text/template
go/doc
go/build
cmd/go
./make.bash: line 161:  8579 Illegal instruction     "$GOTOOLDIR"/go_bootstrap clean -i std
root@localhost:~/go1.4/src#

- Fugured out the ‘–no-clean’ switch from looking at make.bash source, ran make.bash --no-clean, then cd'd into ‘go1.4/pkg/tool/linux_arm’, ran: ./go_bootstrap clean -i std, got:

root@localhost:~/go1.4/pkg/tool/linux_arm# ./go_bootstrap clean -i std
Illegal instruction

- Now tried the same with gdb:

root@localhost:~/go1.4/pkg/tool/linux_arm# gdb -batch -ex run -ex quit --args go_bootstrap clean -i std
...
[Inferior 1 (process 500) exited normally]

As far as I recall if a program works with a debugger but doesn’t work standalone it suggests a memory overrun of some sort (I might be wrong)

So I guess my next bunch of questions is:
1) From which exact .c files ‘go_bootstrap’ binary is built? (I could sprinkle in afew printf("debug.") statements to pinpoint the exact location of the crash…)
2) How do I compile (make.bash) with debug info? (is there a command-line switch for that?)

Can anyone help me out with those?

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.