4

I have small program written in go that I'm trying to cross compile to get working on a MIPS architecture machine. I've been trying to cross compile using the XGO cross compilation library but have had limited success getting my program to run (https://github.com/karalabe/xgo).

Here is the cpuinfo of the device, which is currently running a version of openwrt.

system type     : Qualcomm Atheros QCA9533 ver 2 rev 0
machine         : GL.iNet GL-AR750
processor       : 0
cpu model       : MIPS 24Kc V7.4
BogoMIPS        : 432.53
wait instruction    : yes
microsecond timers  : yes
tlb_entries     : 16
extra interrupt vector  : yes
hardware watchpoint : yes, count: 4, address/irw mask: [0x0ffc, 0x0ffc, 0x0ffb, 0x0ffb]
isa         : mips1 mips2 mips32r1 mips32r2
ASEs implemented    : mips16
shadow register sets    : 1
kscratch registers  : 0
package         : 0
core            : 0
VCED exceptions     : not available
VCEI exceptions     : not available

Running the program I get a SIGILL Illegal instruction from the following:

Program terminated with signal SIGILL, Illegal instruction.
#0  0x008274a8 in __sigsetjmp_aux () 

I can see that __sigsetjmp_aux() is defined here

/usr/lib/gcc-cross/mips-linux-gnu/5/../../../../mips-linux-gnu/lib/../lib/libc.a(setjmp_aux.o): definition of __sigsetjmp_aux 

How can I ensure all my dependencies are compiled using SOFTFLOAT ?

I've been passing xgo the following environment variables but it seems GLIBC is not being compiled as soft-float

CC=mips-linux-gnu-gcc-5 CXX=mips-linux-gnu-g++-5 GOOS=linux GOARCH=mips GOMIPS=softfloat CGO_ENABLED=1 CFLAGS=msoft-float

Any help would be appreciated thanks!

EDIT Here is the asm layout

    0x8274a4 <__sigsetjmp_aux+4>    addiu  gp,gp,-19312                                                                                                                          │
  >│0x8274a8 <__sigsetjmp_aux+8>    sdc1   $f20,56(a0)                                                                                                                           │
   │0x8274ac <__sigsetjmp_aux+12>   sdc1   $f22,64(a0) 
MattLock
  • 174
  • 3
  • 17
  • 1
    Oh, and wildly guessing here, it is possible that your C library is built expecting FPU hardware. I'd have to see the assembly but that sigsetjmp function might be trying to save FPU register state, and that's a C library code, not Go. – Zan Lynx May 14 '19 at 21:14
  • @ZanLynx I've updated the question to show the assembly if that helps – MattLock May 15 '19 at 14:59
  • See https://stackoverflow.com/q/1165807/13422 that is a floating point instruction. – Zan Lynx May 15 '19 at 16:25

2 Answers2

4

I had to run Go on MIPS one time, and solved the problem by building the kernel with floating point emulation. It's slow but it works.

Zan Lynx
  • 53,022
  • 10
  • 79
  • 131
3

In addition to CFLAGS=-msoft-float add CGO_CFLAGS=-msoft-float and CGO_LDFLAGS=-msoft-float. Note that this will only work if you have a soft-float version of libc.a installed; look for /usr/lib/gcc-cross/mips-linux-gnu/5/../../../../mips-linux-gnu/lib/../lib/soft-float/libc.a (I added a soft-float directory at the end).

  • I tried adding the CGO_CFLAGS and CGO_LDFLAGS you mentioned, I run into the following issue: ```In file included from /usr/mips-linux-gnu/include/features.h:391:0, from /usr/mips-linux-gnu/include/stdlib.h:24, from _cgo_export.c:3: /usr/mips-linux-gnu/include/gnu/stubs.h:8:33: fatal error: gnu/stubs-o32_soft.h: No such file or directory``` Do you know where this file might be missing from and how I might include it in my build process? Thank you! – MattLock May 15 '19 at 15:12
  • 1
    You are missing the soft-float C library support. But I don't know where to get it. I do know that it will depend on the GNU/Linux distro you are using. – Ian Lance Taylor May 16 '19 at 17:29