donglieshe4692
donglieshe4692
2019-05-09 20:04

Golang解释gdb SIGILL,非法指令

I've written a small go program to be run on a MIPS 32-bit router. I'm able to get a basic hello world program running on the router using the go build toolchain.

env GOOS=linux GOARCH=mips GOMIPS=softfloat go build -a

The program I'm trying to compile uses a the go-ethereum library and throws the following error when I try build

go build github.com/ethereum/go-ethereum/crypto/secp256k1: build constraints exclude all Go files in ~/go/src/github.com/ethereum/go-ethereum/crypto/secp256k1

I found the go cross-compilation tool xgo and have been successful in building a binary with that tool (https://github.com/karalabe/xgo). When I try to run the binary though I get the following 'Program terminated with signal SIGILL, Illegal instruction'. I was able to get a core dump from the file but I don't have much experience with GDB.

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

Running layout asm I get the following:

    0x8274a4 <__sigsetjmp_aux+4>    addiu  gp,gp,-19312                                                                                                                          │
  >│0x8274a8 <__sigsetjmp_aux+8>    sdc1   $f20,56(a0)                                                                                                                           │
   │0x8274ac <__sigsetjmp_aux+12>   sdc1   $f22,64(a0)   

I'm unsure how to interpret this any help would be much appreciated.

Here it he output of cat /proc/cpuinfo :

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

and the output of the file util on the binary:

ELF 32-bit MSB executable, MIPS, MIPS32 rel2 version 1, statically linked, for GNU/Linux 3.2.0, BuildID[sha1]=83c74323a279af9cba50869671ef03d5ad497db8, not stripped

I've spent quite a lot of time trying to get this program to run, even forking the xgo tool so it can accept the softfloat parameter. Any help or direction on this problem would be greatly appreciated, thanks.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • douna3367 douna3367 2年前

    I'm unsure how to interpret this

    Google for "MIPS sdc1" shows that this is a floating-point "Store Doubleword from Coprocessor-1" instruction.

    A guess: your embedded system doesn't have a floating-point co-processor?

    You would likely need to add -msoft-float to your xgo command and rebuild.

    Update:

    it is crashing on the same sdc1 call, the registers are the same $f20,56(a0).

    Yes, but is in the same function (__sigsetjmp_aux), or in some different one?

    Here is the call I'm building with xgo: xgo --go=1.12 --targets=linux/mips --ldflags '-extldflags "-static -msoft-float"' ~/path/to/project

    It looks like the routine __sigsetjmp_aux is coming from GLIBC, which is not built by xgo.

    And the version of GLIBC you are using was built without -msoft-float, so you are still linking in the code that expects hardware floating point, that your system lacks.

    Step 1: verify where __sigsetjmp_aux is coming from. To do so, you need to pass -y __sigsetjmp_aux to the linker. Maybe --ldflags '-extldflags "-static -msoft-float -Wl,-y,__sigsetjmp_aux"' will do that.

    You should see something similar to this:

    gcc t.o -Wl,-y,setjmp -static
    t.o: reference to setjmp
    /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libc.a(bsd-setjmp.o): definition of setjmp
    

    Assuming your definition of __sigsetjmp_aux does come from libc.a, you'll need to rebuild it with -msoft-float in CFLAGS.

    Note: passing -msoft-float to the linker is wrong and will have no effect -- it's a compiler flag.

    点赞 评论 复制链接分享

为你推荐