https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68037
Bug ID: 68037
Summary: x86 interrupt attribute doesn't work with DRAP
Product: gcc
Version: 5.3.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: target
Assignee: unassigned at gcc dot gnu.org
Reporter: hjl.tools at gmail dot com
CC: julia.koval at intel dot com
Target Milestone: ---
Target: x86
ix86_expand_prologue has
/* Emit prologue code to adjust stack alignment and setup DRAP, in case
of DRAP is needed and stack realignment is really needed after reload */
if (stack_realign_drap)
{
int align_bytes = crtl->stack_alignment_needed / BITS_PER_UNIT;
/* Only need to push parameter pointer reg if it is caller saved. */
if (!call_used_regs[REGNO (crtl->drap_reg)])
{
/* Push arg pointer reg */
insn = emit_insn (gen_push (crtl->drap_reg));
RTX_FRAME_RELATED_P (insn) = 1;
}
/* Grab the argument pointer. */
t = plus_constant (Pmode, stack_pointer_rtx, m->fs.sp_offset);
insn = emit_insn (gen_rtx_SET (crtl->drap_reg, t));
RTX_FRAME_RELATED_P (insn) = 1;
m->fs.cfa_reg = crtl->drap_reg;
m->fs.cfa_offset = 0;
/* Align the stack. */
insn = emit_insn (ix86_gen_andsp (stack_pointer_rtx,
stack_pointer_rtx,
GEN_INT (-align_bytes)));
RTX_FRAME_RELATED_P (insn) = 1;
/* Replicate the return address on the stack so that return
address can be reached via (argp - 1) slot. This is needed
to implement macro RETURN_ADDR_RTX and intrinsic function
expand_builtin_return_addr etc. */
t = plus_constant (Pmode, crtl->drap_reg, -UNITS_PER_WORD);
t = gen_frame_mem (word_mode, t);
insn = emit_insn (gen_push (t));
RTX_FRAME_RELATED_P (insn) = 1;
It doesn't work with interrupt attribute:
[hjl@gnu-6 interrupt-9]$ cat bar.i
typedef unsigned int uword_t __attribute__ ((mode (__word__)));
uword_t error;
uword_t ip;
struct interrupt_frame
{
uword_t ip;
uword_t cs;
uword_t flags;
};
__attribute__((interrupt))
void
fn (struct interrupt_frame *frame)
{
if (ip != frame->ip)
__builtin_abort ();
}
[hjl@gnu-6 interrupt-9]$ /export/build/gnu/gcc-x32/build-x86_64-linux/gcc/xgcc
-B/export/build/gnu/gcc-x32/build-x86_64-linux/gcc/ -O2 -S bar.i
[hjl@gnu-6 interrupt-9]$ cat bar.s
.file "bar.i"
.text
.p2align 4,,15
.globl fn
.type fn, @function
fn:
.LFB0:
.cfi_startproc
pushq %r13
.cfi_def_cfa_offset 16
.cfi_offset 13, -16
leaq 16(%rsp), %r13
.cfi_def_cfa 13, 0
andq $-16, %rsp
pushq -8(%r13)
pushq %rbp
.cfi_escape 0x10,0x6,0x2,0x76,0
movq %rsp, %rbp
pushq %r11
pushq %r10
pushq %r9
pushq %r8
pushq %rdi
pushq %rsi
pushq %rcx
pushq %rdx
pushq %rax
subq $264, %rsp
.cfi_escape 0x10,0xb,0x2,0x76,0x78
.cfi_escape 0x10,0xa,0x2,0x76,0x70
.cfi_escape 0x10,0x9,0x2,0x76,0x68
.cfi_escape 0x10,0x8,0x2,0x76,0x60
.cfi_escape 0x10,0x5,0x2,0x76,0x58
.cfi_escape 0x10,0x4,0x2,0x76,0x50
.cfi_escape 0x10,0x2,0x2,0x76,0x48
.cfi_escape 0x10,0x1,0x2,0x76,0x40
.cfi_escape 0x10,0,0x3,0x76,0xb8,0x7f
movq ip(%rip), %rax
cmpq %rax, 8(%rbp)
^^^^^
RBP doesn't point to the interrupt data on stack.
movups %xmm0, -328(%rbp)
.cfi_escape 0x10,0x11,0x3,0x76,0xb8,0x7d
movups %xmm1, -312(%rbp)
.cfi_escape 0x10,0x12,0x3,0x76,0xc8,0x7d
movups %xmm2, -296(%rbp)
.cfi_escape 0x10,0x13,0x3,0x76,0xd8,0x7d
movups %xmm3, -280(%rbp)
.cfi_escape 0x10,0x14,0x3,0x76,0xe8,0x7d
movups %xmm4, -264(%rbp)
.cfi_escape 0x10,0x15,0x3,0x76,0xf8,0x7d
movups %xmm5, -248(%rbp)
.cfi_escape 0x10,0x16,0x3,0x76,0x88,0x7e
movups %xmm6, -232(%rbp)
.cfi_escape 0x10,0x17,0x3,0x76,0x98,0x7e
movups %xmm7, -216(%rbp)
.cfi_escape 0x10,0x18,0x3,0x76,0xa8,0x7e
movups %xmm8, -200(%rbp)
.cfi_escape 0x10,0x19,0x3,0x76,0xb8,0x7e
movups %xmm9, -184(%rbp)
.cfi_escape 0x10,0x1a,0x3,0x76,0xc8,0x7e
movups %xmm10, -168(%rbp)
.cfi_escape 0x10,0x1b,0x3,0x76,0xd8,0x7e
movups %xmm11, -152(%rbp)
.cfi_escape 0x10,0x1c,0x3,0x76,0xe8,0x7e
movups %xmm12, -136(%rbp)
.cfi_escape 0x10,0x1d,0x3,0x76,0xf8,0x7e
movups %xmm13, -120(%rbp)
.cfi_escape 0x10,0x1e,0x3,0x76,0x88,0x7f
movups %xmm14, -104(%rbp)
.cfi_escape 0x10,0x1f,0x3,0x76,0x98,0x7f
movups %xmm15, -88(%rbp)
.cfi_escape 0x10,0x20,0x3,0x76,0xa8,0x7f
jne .L5
movups -328(%rbp), %xmm0
movups -312(%rbp), %xmm1
movups -296(%rbp), %xmm2
movups -280(%rbp), %xmm3
movups -264(%rbp), %xmm4
movups -248(%rbp), %xmm5
movups -232(%rbp), %xmm6
movups -216(%rbp), %xmm7
movups -200(%rbp), %xmm8
movups -184(%rbp), %xmm9
movups -168(%rbp), %xmm10
movups -152(%rbp), %xmm11
movups -136(%rbp), %xmm12
movups -120(%rbp), %xmm13
movups -104(%rbp), %xmm14
movups -88(%rbp), %xmm15
addq $264, %rsp
.cfi_remember_state
.cfi_restore 31
.cfi_restore 30
.cfi_restore 29
.cfi_restore 28
.cfi_restore 27
.cfi_restore 26
.cfi_restore 25
.cfi_restore 24
.cfi_restore 23
.cfi_restore 22
.cfi_restore 21
.cfi_restore 20
.cfi_restore 19
.cfi_restore 18
.cfi_restore 17
popq %rax
popq %rdx
popq %rcx
popq %rsi
popq %rdi
popq %r8
popq %r9
popq %r10
popq %r11
popq %rbp
leaq -16(%r13), %rsp
.cfi_def_cfa 7, 16
popq %r13
.cfi_def_cfa_offset 8
iret
.L5:
.cfi_restore_state
call abort
.cfi_endproc
.LFE0:
.size fn, .-fn
.comm ip,8,8
.comm error,8,8
.ident "GCC: (GNU) 6.0.0 20151020 (experimental)"
.section .note.GNU-stack,"",@progbits
[hjl@gnu-6 interrupt-9]$
We need something like
/* Can't use DRAP in interrupt function. */
if (cfun->machine->func_type != TYPE_NORMAL)
sorry ("Dynamic Realign Argument Pointer (DRAP) not supported in "
"interrupt service routine. This may be worked around by "
"adding -maccumulate-outgoing-args.");
in ix86_expand_prologue.