This meta bug covers all interrupt attribute issues on jkoval/interrupt/master branch in GCC git repo.
Created attachment 36324 [details] A patch to remove railing whitespaces in interrupt-switch-abi.c
Red zone isn't supported in interrupt handler: 'interrupt' Use this attribute to indicate that the specified void function without arguments is an interrupt handler. The compiler generates function entry and exit sequences suitable for use in an interrupt handler when this attribute is present. The 'IRET' instruction, instead of the 'RET' instruction, is used to return from interrupt handlers. All registers, except for the EFLAGS register which is restored by the 'IRET' instruction, are preserved by the compiler. The red zone isn't supported in an interrupt handler; that is an interrupt handler can't access stack beyond the current stack pointer. It is wrong to do - if (crtl->args.pops_args && crtl->args.size) + if (ix86_is_interrupt_p ()) + { + if (ix86_using_red_zone ()) + emit_insn (gen_adddi3 ( + gen_rtx_REG (DImode, SP_REG), + gen_rtx_REG (DImode, SP_REG), + GEN_INT (128))); GCC should assume that red zone isn't used in interrupt handler.
X87 instructions should be disallowed in interrupt handler: [hjl@gnu-6 interrupt-1]$ cat f.i extern long double y, x; void __attribute__((interrupt)) fn1 (void) { x += y; } [hjl@gnu-6 interrupt-1]$ make f.s /export/build/gnu/gcc-5/build-x86_64-linux/gcc/xgcc -B/export/build/gnu/gcc-5/build-x86_64-linux/gcc/ -O2 -S -o f.s f.i [hjl@gnu-6 interrupt-1]$ cat f.s .file "f.i" .section .text.unlikely,"ax",@progbits .LCOLDB1: .text .LHOTB1: .p2align 4,,15 .globl fn1 .type fn1, @function fn1: .LFB0: .cfi_startproc fldt y(%rip) addq $-128, %rsp fldt x(%rip) faddp %st, %st(1) fstpt x(%rip) ret .cfi_endproc .LFE0: .size fn1, .-fn1 .section .text.unlikely .LCOLDE1: .text .LHOTE1: .ident "GCC: (GNU) 5.2.1 20150911" .section .note.GNU-stack,"",@progbits [hjl@gnu-6 interrupt-1]$
MMX instructions should be disallowed in interrupt handler: [hjl@gnu-6 interrupt-1]$ cat m.i typedef short __v4hi __attribute__ ((__vector_size__ (8))); typedef int __m64 __attribute__ ((__vector_size__ (8), __may_alias__)); extern __m64 y, x; void __attribute__((interrupt)) fn1 (void) { x = (__m64) __builtin_ia32_packsswb ((__v4hi) x, (__v4hi) y); } [hjl@gnu-6 interrupt-1]$ make m.s /export/build/gnu/gcc-5/build-x86_64-linux/gcc/xgcc -B/export/build/gnu/gcc-5/build-x86_64-linux/gcc/ -O2 -S -o m.s m.i [hjl@gnu-6 interrupt-1]$ cat m.s .file "m.i" .section .text.unlikely,"ax",@progbits .LCOLDB0: .text .LHOTB0: .p2align 4,,15 .globl fn1 .type fn1, @function fn1: .LFB0: .cfi_startproc movq x(%rip), %mm0 addq $-128, %rsp packsswb y(%rip), %mm0 movq %mm0, x(%rip) ret .cfi_endproc .LFE0: .size fn1, .-fn1 .section .text.unlikely .LCOLDE0: .text .LHOTE0: .ident "GCC: (GNU) 5.2.1 20150911" .section .note.GNU-stack,"",@progbits [hjl@gnu-6 interrupt-1]$
Sorry, I don't understand why we shouldn't preserve the red zone. The function "foo", executing before the interrupt was called, used its red zone. If the interrupt does not adjust the stack pointer, who control that "foo" function's red zone would not be overwritten?
(In reply to Yulia Koval from comment #5) > Sorry, I don't understand why we shouldn't preserve the red zone. The > function "foo", executing before the interrupt was called, used its red > zone. If the interrupt does not adjust the stack pointer, who control that > "foo" function's red zone would not be overwritten? Please take a look at Exception- or Interrupt-Handler Procedures in Intel64 and IA-32 Architectures Software Developer’s Manual vol 3. There is no red zone on stack of interrupt handler, which is controlled by processor, independent of any calling conventions.
I think we should place if (current_function_decl && ix86_is_interrupt_p ()) { for (i = 0; i < FIRST_PSEUDO_REGISTER; i++) { if (!STACK_REGNO_P (i) && !MMX_REGNO_P (i)) { if (i == BP_REG || i == SP_REG) continue; if (i >= ARGP_REG && i <= FRAME_REG) continue; call_used_regs[i] = 0; fixed_regs[i] = 0; } } } at the beginning of ix86_conditional_register_usage.
Implemented for GCC 7.