Adhemerval Zanella wrote: Sorry for the late reply - but I think it's getting there. A few more comments:
+ /* If function uses stacked arguments save the old stack value so morestack + can return it. */ + reg11 = gen_rtx_REG (Pmode, R11_REGNUM); + if (cfun->machine->frame.saved_regs_size + || cfun->machine->frame.saved_varargs_size) + emit_move_insn (reg11, stack_pointer_rtx); This doesn't look right - we could have many arguments even without varargs or saved regs. This would need to check varargs as well as ctrl->args.size (I believe that is the size of the arguments on the stack). It's fine to omit this optimization in the first version - we already emit 2-3 extra instructions for the check anyway. +void +aarch64_split_stack_space_check (rtx size, rtx label) { + rtx mem, ssvalue, cc, cmp, jump, temp; + rtx requested = gen_reg_rtx (Pmode); + /* Offset from thread pointer to __private_ss. */ + int psso = 0x10; + + /* Load __private_ss from TCB. */ + ssvalue = gen_rtx_REG (Pmode, R9_REGNUM); ssvalue doesn't need to be a hardcoded register. + emit_insn (gen_aarch64_load_tp_hard (ssvalue)); + mem = gen_rtx_MEM (Pmode, plus_constant (Pmode, ssvalue, psso)); + emit_move_insn (ssvalue, mem); + + temp = gen_rtx_REG (Pmode, R10_REGNUM); + + /* And compare it with frame pointer plus required stack. */ + size = force_reg (Pmode, size); + emit_move_insn (requested, gen_rtx_MINUS (Pmode, stack_pointer_rtx, size)); + + /* Jump to __morestack call if current __private_ss is not suffice. */ + cc = aarch64_gen_compare_reg (LT, temp, ssvalue); This uses X10, but where is it set??? + cmp = gen_rtx_fmt_ee (GEU, VOIDmode, cc, const0_rtx); + jump = emit_jump_insn (gen_condjump (cmp, cc, label)); + JUMP_LABEL (jump) = label; +} So neither X10 nor X12 are set before potentially calling __morestack, so I don't think it will work. Could this be causing the crash you mentioned? Wilco