how to build go 1.6 on Target: mips64el-redhat-linux

293 views
Skip to first unread message

uticdmar...@gmail.com

unread,
Mar 19, 2016, 9:50:38 AM3/19/16
to golang-nuts
There are so many reasons I want to upgrade the os from fc21 to anything more recent, but unfortunately I can't.

I'm just trying to build the latest golang using the following:
GOPATH=/root/Code
GOROOT=/root/loongson-golang

root@sunhaiyong:~/Code/src/github.com/omac777# go version
go version xgcc (GCC) 4.9.3 20150626 (Red Hat 4.9.3-3) linux/mipsn64

GOROOT_BOOTSTRAP=/root/loongson-golang ./all.bash

##### Building Go bootstrap tool.
cmd/dist
# _/root/go/src/cmd/dist
cmd/dist/test.go:183:5: error: reference to undefined identifier ‘os.Unsetenv’
  os.Unsetenv("GOROOT_FINAL")
     ^
cmd/dist/build.go:127:6: error: reference to undefined name ‘cansse2’
   if cansse2() {
      ^
cmd/dist/util.go:493:3: error: reference to undefined name ‘useVFPv1’
   useVFPv1() // might fail with SIGILL
   ^
cmd/dist/util.go:495:3: error: reference to undefined name ‘useVFPv3’
   useVFPv3() // might fail with SIGILL
   ^



root@sunhaiyong:~/Code/src/github.com/omac777# uname -a
Linux sunhaiyong 4.1.19-1.fc21.loongson.1.mips64el #1 SMP PREEMPT Tue Mar 8 07:47:34 UTC 2016 mips64 mips64 mips64 GNU/Linux


root@sunhaiyong:~/Code/src/github.com/omac777# go build -x -v -v -work -ccflags '-v' -gccgoflags -v  hello.go
WORK=/tmp/go-build218067275
command-line-arguments
mkdir -p $WORK/command-line-arguments/_obj/
cd /root/Code/src/github.com/omac777
gccgo -I $WORK -c -g -fgo-relative-import-path=_/root/Code/src/github.com/omac777 -o $WORK/command-line-arguments/_obj/main.o -v ./hello.go
# command-line-arguments
Using built-in specs.
COLLECT_GCC=gccgo
Target: mips64el-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --enable-languages=c,c++,objc,obj-c++,fortran,go,lto --enable-plugin --enable-initfini-array --disable-libgcj --with-isl=/root/rpmbuild/BUILD/gcc-4.9.3/obj-mips64el-redhat-linux/isl-install --with-cloog=/root/rpmbuild/BUILD/gcc-4.9.3/obj-mips64el-redhat-linux/cloog-install --enable-gnu-indirect-function --with-long-double-128 --build=mips64el-redhat-linux
Thread model: posix
gcc version 4.9.3 20150626 (Red Hat 4.9.3-3) (GCC)
COLLECT_GCC_OPTIONS='-I' '/tmp/go-build218067275' '-c' '-g' '-fgo-relative-import-path=_/root/Code/src/github.com/omac777' '-o' '/tmp/go-build218067275/command-line-arguments/_obj/main.o' '-v' '-shared-libgcc' '-mllsc' '-mno-shared' '-EL' '-mabi=64'
 /usr/libexec/gcc/mips64el-redhat-linux/4.9.3/go1 ./hello.go -mel -quiet -dumpbase hello.go -mllsc -mno-shared -mabi=64 -auxbase-strip $WORK/command-line-arguments/_obj/main.o -g -version -fgo-relative-import-path=_/root/Code/src/github.com/omac777 -I $WORK -L/usr/lib/gcc/mips64el-redhat-linux/4.9.3 -L/usr/lib/gcc/mips64el-redhat-linux/4.9.3/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/lib/gcc/mips64el-redhat-linux/4.9.3/../../.. -o /tmp/ccbkllV8.s
GNU Go (GCC) version 4.9.3 20150626 (Red Hat 4.9.3-3) (mips64el-redhat-linux)
    compiled by GNU C version 4.9.3 20150626 (Red Hat 4.9.3-3), GMP version 6.0.0, MPFR version 3.1.2, MPC version 1.0.2
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
GNU Go (GCC) version 4.9.3 20150626 (Red Hat 4.9.3-3) (mips64el-redhat-linux)
    compiled by GNU C version 4.9.3 20150626 (Red Hat 4.9.3-3), GMP version 6.0.0, MPFR version 3.1.2, MPC version 1.0.2
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
COLLECT_GCC_OPTIONS='-I' '/tmp/go-build218067275' '-c' '-g' '-fgo-relative-import-path=_/root/Code/src/github.com/omac777' '-o' '/tmp/go-build218067275/command-line-arguments/_obj/main.o' '-v' '-shared-libgcc' '-mllsc' '-mno-shared' '-EL' '-mabi=64'
 as -v -I $WORK -EL -O1 -g -no-mdebug -mabi=64 -mno-shared -KPIC -o $WORK/command-line-arguments/_obj/main.o /tmp/ccbkllV8.s
GNU assembler version 2.24 (mips64el-redhat-linux) using BFD version version 2.24
COMPILER_PATH=/usr/libexec/gcc/mips64el-redhat-linux/4.9.3/:/usr/libexec/gcc/mips64el-redhat-linux/4.9.3/:/usr/libexec/gcc/mips64el-redhat-linux/:/usr/lib/gcc/mips64el-redhat-linux/4.9.3/:/usr/lib/gcc/mips64el-redhat-linux/
LIBRARY_PATH=/usr/lib/gcc/mips64el-redhat-linux/4.9.3/:/usr/lib/gcc/mips64el-redhat-linux/4.9.3/../../../../lib64/:/lib/../lib64/:/usr/lib/../lib64/:/usr/lib/gcc/mips64el-redhat-linux/4.9.3/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-I' '/tmp/go-build218067275' '-c' '-g' '-fgo-relative-import-path=_/root/Code/src/github.com/omac777' '-o' '/tmp/go-build218067275/command-line-arguments/_obj/main.o' '-v' '-shared-libgcc' '-mllsc' '-mno-shared' '-EL' '-mabi=64'
ar cru $WORK/libcommand-line-arguments.a $WORK/command-line-arguments/_obj/main.o
cd .
gccgo -o hello $WORK/command-line-arguments/_obj/main.o -Wl,-( -Wl,-) -v
# command-line-arguments
Using built-in specs.
COLLECT_GCC=gccgo
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/mips64el-redhat-linux/4.9.3/lto-wrapper
Target: mips64el-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --enable-languages=c,c++,objc,obj-c++,fortran,go,lto --enable-plugin --enable-initfini-array --disable-libgcj --with-isl=/root/rpmbuild/BUILD/gcc-4.9.3/obj-mips64el-redhat-linux/isl-install --with-cloog=/root/rpmbuild/BUILD/gcc-4.9.3/obj-mips64el-redhat-linux/cloog-install --enable-gnu-indirect-function --with-long-double-128 --build=mips64el-redhat-linux
Thread model: posix
gcc version 4.9.3 20150626 (Red Hat 4.9.3-3) (GCC)
COMPILER_PATH=/usr/libexec/gcc/mips64el-redhat-linux/4.9.3/:/usr/libexec/gcc/mips64el-redhat-linux/4.9.3/:/usr/libexec/gcc/mips64el-redhat-linux/:/usr/lib/gcc/mips64el-redhat-linux/4.9.3/:/usr/lib/gcc/mips64el-redhat-linux/
LIBRARY_PATH=/usr/lib/gcc/mips64el-redhat-linux/4.9.3/:/usr/lib/gcc/mips64el-redhat-linux/4.9.3/../../../../lib64/:/lib/../lib64/:/usr/lib/../lib64/:/usr/lib/gcc/mips64el-redhat-linux/4.9.3/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-o' 'hello' '-v' '-shared-libgcc' '-mllsc' '-mno-shared' '-EL' '-mabi=64'
 /usr/libexec/gcc/mips64el-redhat-linux/4.9.3/collect2 -plugin /usr/libexec/gcc/mips64el-redhat-linux/4.9.3/liblto_plugin.so -plugin-opt=/usr/libexec/gcc/mips64el-redhat-linux/4.9.3/lto-wrapper -plugin-opt=-fresolution=/tmp/cc7OdiyK.res -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc --build-id --no-add-needed --eh-frame-hdr -EL -EL -dynamic-linker /lib64/ld.so.1 -melf64ltsmip -o hello /usr/lib/gcc/mips64el-redhat-linux/4.9.3/../../../../lib64/crt1.o /usr/lib/gcc/mips64el-redhat-linux/4.9.3/../../../../lib64/crti.o /usr/lib/gcc/mips64el-redhat-linux/4.9.3/crtbegin.o -L/usr/lib/gcc/mips64el-redhat-linux/4.9.3 -L/usr/lib/gcc/mips64el-redhat-linux/4.9.3/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/lib/gcc/mips64el-redhat-linux/4.9.3/../../.. $WORK/command-line-arguments/_obj/main.o -( -) -lgobegin -lgo -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/lib/gcc/mips64el-redhat-linux/4.9.3/crtend.o /usr/lib/gcc/mips64el-redhat-linux/4.9.3/../../../../lib64/crtn.o

Dave Cheney

unread,
Mar 19, 2016, 10:02:57 AM3/19/16
to golang-nuts
You've got gccgo installed. Uninstall gccgo and try building again.

uticdmar...@gmail.com

unread,
Mar 25, 2016, 8:32:41 AM3/25/16
to golang-nuts
I did as you said.

I removed gccgo.
root@sunhaiyong:~# apt-get remove gccgo
Reading package lists... Done
Building dependency tree      
Reading state information... Done
The following packages will be REMOVED:
  gccgo
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
After this operation, 12.3 kB disk space will be freed.
Do you want to continue? [Y/n]
(Reading database ... 53925 files and directories currently installed.)
Removing gccgo (4:5.3.1-1) ...


root@sunhaiyong:~# git clone https://go.googlesource.com/go
Cloning into 'go'...
remote: Sending approximately 102.02 MiB ...
remote: Counting objects: 6119, done
remote: Finding sources: 100% (289/289)
remote: Total 250332 (delta 200425), reused 250259 (delta 200425)
Receiving objects: 100% (250332/250332), 102.25 MiB | 4.68 MiB/s, done.
Resolving deltas: 100% (200425/200425), done.
Checking connectivity... done.
Checking out files: 100% (5384/5384), done.

root@sunhaiyong:~# cd go/src/
root@sunhaiyong:~/go/src# GOROOT_BOOTSTRAP=/usr GOOS="linux" GOARCH="mipsn64" ./bootstrap.bash
#### Copying to ../../go-linux-mipsn64-bootstrap

#### Cleaning ../../go-linux-mipsn64-bootstrap

#### Building ../../go-linux-mipsn64-bootstrap


##### Building Go bootstrap tool.
cmd/dist

# _/root/go-linux-mipsn64-bootstrap/src/cmd/dist
cmd/dist/build.go:130:6: error: reference to undefined name ‘cansse2’
   if cansse2() {
      ^
cmd/dist/util.go:494:3: error: reference to undefined name ‘useVFPv1’

   useVFPv1() // might fail with SIGILL
   ^
cmd/dist/util.go:496:3: error: reference to undefined name ‘useVFPv3’

   useVFPv3() // might fail with SIGILL
   ^


The cansse2() has to do with Intel cpu.  I understand the loongson-3 has intel cpu instruction emulation capability.  It could possibly compile and run this.
The VFPv1 and VFPv3 are ARM CPU instructions.  The loongson-3 has no arm cpu emulation capability. It shouldn't compile ARM instructions.

=========================NOISE==============================
SOME ADDITIONAL INFORMATION
ABOUT MY LOONGSON-3 MOTHERBOARD ENVIRONMENT
THAT MAY BETTER PROVIDE INSIGHT AS TO WHERE THE ACTUAL PROBLEM RESIDES:
To better increase my odds of succeeding, I added a second drive and attempted to prepare it as a debian sid setup rather than fc21.
Unfortunately, I can't boot with the latest kernel onto it.  Grub for the Debian on the mips64el isn't working.  For the interim I chroot onto it from fedora core 21:
mount -t ext4 /dev/sdb1 /mnt/lap
mount --bind /dev /mnt/lap/dev
mount --bind /sys /mnt/lap/sys
mount --bind /proc /mnt/lap/proc
mount devpts /mnt/lap/dev/pts -t devpts

root@sunhaiyong:~# uname -a
Linux sunhaiyong 4.1.15-2.fc21.loongson.3.mips64el #1 SMP PREEMPT Mon Feb 29 03:38:12 UTC 2016 mips64 mips64 mips64 GNU/Linux
chroot /mnt/lap

I HAVE OBSERVED MEDIATEMPLE.NET ROCKS!  Nobody outside of China except mediatemple.net have loongson-3 binaries on their repos. 
The Lemote/Loongson/Loongnix mirrors in China are all terribly slow because of the GFW.  I tried this repo: 
#deb http://mipsdebian.imgtec.com/debian sid main
#deb-src http://mipsdebian.imgtec.com/debian sid main
which has packages in the very same loongson-3 format uses "mips64el", but intended for other boards called '5kc-malta' and there was no grub package for mips64el at this site either.  There are qemu binaries for emulating mips64el available, BUT there are no qemu binaries available to run directly on mips64el which grub depends on if I understood correctly.

cat /etc/apt/sources.list
deb http://mirrors.mediatemple.net/debian sid main contrib non-free
deb-src http://mirrors.mediatemple.net/debian sid main contrib non-free

apt-get update
apt-get upgrade
apt-get install -f
apt-get dist-upgrade
apt-get install -f

That places the second drive with the most recent binaries I could find for loongson-3.
I currently see packages golang* but apt tells me I can't install them on loongson-3. Broken.

cat /proc/cpuinfo
system type        : generic-loongson-machine
machine            : Unknown
processor        :  0 to 5( 6-cores in this case)
cpu model        : ICT Loongson-3 V0.7  FPU V0.1
model name        : ICT Loongson-3B R2 (Loongson-3B1500) @ 1199MHz
BogoMIPS        : 956.04
wait instruction    : no
microsecond timers    : yes
tlb_entries        : 64
extra interrupt vector    : no
hardware watchpoint    : yes, count: 0, address/irw mask: []
isa            : mips1 mips2 mips3 mips4 mips5 mips32r1 mips64r1
ASEs implemented    :
shadow register sets    : 1
kscratch registers    : 0
package            : 0
core            : 7
VCED exceptions        : not available
VCEI exceptions        : not available

root@sunhaiyong:/# cat /proc/meminfo
MemTotal:        3971456 kB
MemFree:         1808048 kB
MemAvailable:    3673632 kB
Buffers:          195024 kB
Cached:          1595728 kB
SwapCached:            0 kB
Active:          1165424 kB
Inactive:         811280 kB
Active(anon):     189856 kB
Inactive(anon):    12192 kB
Active(file):     975568 kB
Inactive(file):   799088 kB
Unevictable:          32 kB
Mlocked:              32 kB
SwapTotal:       3905520 kB
SwapFree:        3905520 kB
Dirty:                 0 kB
Writeback:             0 kB
AnonPages:        185952 kB
Mapped:           122576 kB
Shmem:             16128 kB
Slab:             151312 kB
SReclaimable:     120640 kB
SUnreclaim:        30672 kB
KernelStack:        3856 kB
PageTables:         6800 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:     5891248 kB
Committed_AS:    1288384 kB
VmallocTotal:   137434759136 kB
VmallocUsed:       12720 kB
VmallocChunk:   137434665808 kB

Within the /dev/sda1 where Fedora Core 21's boot grub2 resides the file /boot/grub2/grub.cfg.  It contains this one that boots fc21 kernel 4.1 correctly, but when I try to change the entry to point to /dev/sdb1 along with the vmlinux and initrd as created by the debian sid within this grub.cfg it fails.  The only thing that works at present is if I change:

menuentry 'Fedora, with Linux 4.1.15-2.fc21.loongson.3.mips64el' --class fedora --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-4.1.15-2.fc21.loongson.3.mips64el-advanced-914196c3-7acc-4dd8-8bae-89ae9b27ff44' {
>>>>>    load_video
    insmod gzio
    insmod part_msdos
    insmod ext2
    set root='hd0,msdos1'
    if [ x$feature_platform_search_hint = xy ]; then
      search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1  cc95357a-f416-4d66-b5f1-bb99fe67de3f
    else
      search --no-floppy --fs-uuid --set=root cc95357a-f416-4d66-b5f1-bb99fe67de3f
    fi
>>>>>>>    linux /vmlinuz-4.1.15-2.fc21.loongson.3.mips64el root=UUID=914196c3-7acc-4dd8-8bae-89ae9b27ff44 ro rhgb quiet
    initrd /initramfs-4.1.15-2.fc21.loongson.3.mips64el.img
    boot
}

Pressing e from within grub menu on the same entry I change those two lines to:
>>>>
>>>>>>>    linux /vmlinuz-4.1.15-2.fc21.loongson.3.mips64el root=/dev/sdb1 rw
Then Press F10 to continue to boot

This brings up Debian Sid with the fc21 kernel running on the loongson-3 motherboard.

Ian Lance Taylor

unread,
Mar 25, 2016, 1:08:38 PM3/25/16
to David Marceau, golang-nuts
mipsn64 is a GOARCH value used by gccgo, but not by gc. The gc
compiler uses mips64 and mips64le. It's not clear to me how we are
going to resolve this.

Ian
> --
> 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/d/optout.

David Marceau

unread,
Mar 27, 2016, 3:56:23 PM3/27/16
to Dave Cheney, ia...@golang.org, golan...@googlegroups.com
Mr. Cheney and Mr. Taylor,

I greatly appreciate your time. Thank you both. I wanted to report my
success with your suggestions.

Mr. Cheney, I succeeded in cross-compiling/running to mips64le binaries
as you recommended.

Mr. Taylor I cannot natively build the go1.6 tool base on loongson-3,
but I am happy to simply cross-compile and run an entire TLS/http2 web
server/microservices with port 80 redirector. I am ecstatic it ran out
of the box first-shot with no hitches. The golang team rocks!

Here is exactly what I did:
ON THE AMD64 OCTACORE BOX:
cd /home/loongson/golangMips64leAdequatechWebServer/

env GOOS=linux GOARCH=mips64le go build golangMips64leAdequatechWebServer.go

env GOOS=linux GOARCH=mips64le go build
golangMips64leAdequatechHttpRedirector.go

scp -r /home/loongson/golangMips64leAdequatechWebServer/
loon...@192.168.1.12:/home/loongson/

ON THE LOONGSON-3 HEXACORE BOX:
firewall-cmd --zone=public --add-port=17777/tcp
firewall-cmd --zone=public --add-port=80/tcp

cd /home/loongson/golangMips64leAdequatechWebServer/
sudo ./bringupGolangWebServers.sh


cat bringupGolangWebServers.sh
killall -r golangMips64leAdequatechHttpRedirector
killall -r golangMips64leAdequatechWebServer
sleep 2
nohup
/home/loongson/golangMips64leAdequatechWebServer/golangMips64leAdequatechWebServer
>/dev/null 2>&1 &
nohup
/home/loongson/golangMips64leAdequatechWebServer/golangMips64leAdequatechHttpRedirector
>/dev/null 2>&1 &

I know I could be using systemd unit service files to make this
start/stop more elegantly, but for just testing this is fine.

This one is directly on Fedora-Core 21 loongson-3. I imagine no issues
with Debian Sid using the cross-compile method.

Happy Easter!


On 03/25/2016 08:56 PM, Dave Cheney wrote:
> Hello David,
>
> This should already
> be supported by go 1.6 and the development version of Go. Before trying
> anything complicated I recommend cross compiling the tranditional
> helloworld program on another machine and trying to run it on your loongson
> board.
>
> env GOOS=linux GOARCH=mip64le go build helloworld.go
>
> Then scp the resulting ./helloworld binary to your loongson machine and
> trying to run it. If that works, then it's time to try something more
> complicated. If this does not work, please raise an issue
> https://golang.org/issue/new
>
> Thanks
>
> Dave
>

James Cowgill

unread,
Feb 28, 2017, 12:29:24 PM2/28/17
to Ian Lance Taylor, golan...@googlegroups.com
Hi,

Stumbling over this thread:
https://groups.google.com/forum/#!topic/golang-nuts/waTy56I_KWQ

On 25/03/16 17:08, Ian Lance Taylor wrote:
> mipsn64 is a GOARCH value used by gccgo, but not by gc. The gc
> compiler uses mips64 and mips64le. It's not clear to me how we are
> going to resolve this.

This is still a problem. It is currently not possible to build golang
using gccgo on mips* due to it. What is the solution? Why can't (for
instance) gccgo move to using the GOARCH values from golang?

Thanks,
James

signature.asc

Ian Lance Taylor

unread,
Feb 28, 2017, 12:30:39 PM2/28/17
to James Cowgill, golang-nuts
The complexity is that since gccgo is based on GCC, it supports
multiple different calling conventions. Which calling convention
should "mips64" represent? I don't have an answer. I also haven't
really thought about it.

Ian

James Cowgill

unread,
Feb 28, 2017, 12:42:03 PM2/28/17
to Ian Lance Taylor, golang-nuts
Hi,
I think there already is a mapping:

mips, mipsle = o32
mips64p32, mips64p32le = n32
mips64, mips64le = n64

I see there is "support" for o64 in gccgo. That ABI (and the other MIPS
ABIs gcc supports) have close to 0 users so I expect there isn't anyone
using it for go.

I can have a go at writing a patch for this. I was just wondering if
this was a good idea.

James

Ian Lance Taylor

unread,
Feb 28, 2017, 12:50:57 PM2/28/17
to James Cowgill, golang-nuts
I guess if that makes sense to you it's OK with me.

Ian
Reply all
Reply to author
Forward
0 new messages