donglieshe4692 2019-05-09 20:04
浏览 170
已采纳

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 2019-05-11 01:39
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 C#调用python代码(python带有库)
  • ¥15 矩阵加法的规则是两个矩阵中对应位置的数的绝对值进行加和
  • ¥15 活动选择题。最多可以参加几个项目?
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题
  • ¥20 云服务Linux系统TCP-MSS值修改?
  • ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)
  • ¥20 怎么在stm32门禁成品上增加查询记录功能
  • ¥15 Source insight编写代码后使用CCS5.2版本import之后,代码跳到注释行里面
  • ¥50 NT4.0系统 STOP:0X0000007B