Skip to content

MIPS host bootstrap: compiler_rt stack overflows #37823

Closed
@xen0n

Description

@xen0n

The cross-compiled MIPS host compilers are fine, but stage1 immediately segfaults when asked to do just about anything:

// x.rs
fn main() {
}
$ ./build/mips64el-unknown-linux-gnuabi64/stage1/bin/rustc ./x.rs

thread 'rustc' has overflowed its stack
fatal runtime error: stack overflow
[1]    3433 IOT instruction (core dumped)  ./build/mips64el-unknown-linux-gnuabi64/stage1/bin/rustc ./x.rs
(gdb) r ./x.rs
Starting program: /opt/store/src/rust/build/mips64el-unknown-linux-gnuabi64/stage1/bin/rustc ./x.rs
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
[New Thread 0xfff353ef10 (LWP 3476)]

Thread 2 "rustc" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0xfff353ef10 (LWP 3476)]
0x000000fff57198b8 in __ctzdi2 () from /opt/store/src/rust/build/mips64el-unknown-linux-gnuabi64/stage1/bin/../lib/../lib/librustc_llvm-d0f44aedc4c18d77.so
(gdb) disas
Dump of assembler code for function __ctzdi2:
   0x000000fff57198b0 <+0>:     daddiu  sp,sp,-32
   0x000000fff57198b4 <+4>:     sll     v0,a0,0x0
=> 0x000000fff57198b8 <+8>:     sd      s0,8(sp)
   0x000000fff57198bc <+12>:    sltiu   s0,v0,1
   0x000000fff57198c0 <+16>:    sd      gp,16(sp)
   0x000000fff57198c4 <+20>:    dnegu   s0,s0
   0x000000fff57198c8 <+24>:    lui     gp,0x96
   0x000000fff57198cc <+28>:    nor     a1,zero,s0
   0x000000fff57198d0 <+32>:    daddu   gp,gp,t9
   0x000000fff57198d4 <+36>:    dsra32  a0,a0,0x0
   0x000000fff57198d8 <+40>:    and     v1,a0,s0
   0x000000fff57198dc <+44>:    daddiu  gp,gp,18760
   0x000000fff57198e0 <+48>:    and     a0,a1,v0
   0x000000fff57198e4 <+52>:    ld      t9,-32584(gp)
   0x000000fff57198e8 <+56>:    or      a0,v1,a0
   0x000000fff57198ec <+60>:    dsll32  a0,a0,0x0
   0x000000fff57198f0 <+64>:    sd      ra,24(sp)
   0x000000fff57198f4 <+68>:    bal     0xfff57198b0 <__ctzdi2>
   0x000000fff57198f8 <+72>:    dsrl32  a0,a0,0x0
   0x000000fff57198fc <+76>:    ld      ra,24(sp)
   0x000000fff5719900 <+80>:    andi    s0,s0,0x20
   0x000000fff5719904 <+84>:    addu    v0,v0,s0
   0x000000fff5719908 <+88>:    ld      gp,16(sp)
   0x000000fff571990c <+92>:    ld      s0,8(sp)
   0x000000fff5719910 <+96>:    jr      ra
   0x000000fff5719914 <+100>:   daddiu  sp,sp,32
End of assembler dump.

Notice the recursion, which is obviously wrong, and non-existent on stage0:

$ ar x ../../../nightly/2016-11-14/lib/rustlib/mips64el-unknown-linux-gnuabi64/lib/libcompiler_builtins-e428224f6caf212a.rlib
$ objdump -d ctzdi2.o
ctzdi2.o:     file format elf64-tradlittlemips


Disassembly of section .text.__ctzdi2:

0000000000000000 <__ctzdi2>:
   0:   00041800        sll     v1,a0,0x0
   4:   2c650001        sltiu   a1,v1,1
   8:   0005282f        dnegu   a1,a1
   c:   0004203f        dsra32  a0,a0,0x0
  10:   0065200a        movz    a0,v1,a1
  14:   00041023        negu    v0,a0
  18:   00822024        and     a0,a0,v0
  1c:   70842020        clz     a0,a0
  20:   2402001f        li      v0,31
  24:   00441023        subu    v0,v0,a0
  28:   30a50020        andi    a1,a1,0x20
  2c:   03e00008        jr      ra
  30:   00a21021        addu    v0,a1,v0
  34:   00000000        nop

This is LLVM bug 11663. Maybe we should incorporate the workaround there as well.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions