https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69575

            Bug ID: 69575
           Summary: [interrupt] The direction flag DF in the FLAGS
                    register may be wrong in interrupt handler
           Product: gcc
           Version: 6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: hjl.tools at gmail dot com
                CC: vaalfreja at gmail dot com
  Target Milestone: ---
            Target: x86

The x86 psABI says

The direction flag DF in the FLAGS register must be clear (set to “forward”
direction) on function entry and return. Other user flags have no specified
role in the standard calling sequence and are not preserved across calls

Since the direction flag DF in the FLAGS register is unknown in interrupt
handler, the result will be wrong if DF isn't cleared:

[hjl@gnu-tools-1 gcc]$ cat /tmp/x.i
extern void *a;
extern int b;

__attribute__ ((interrupt))
void
foo (void *frame)
{
  __builtin_memset (a, b, 40);
}
[hjl@gnu-tools-1 gcc]$ ./xgcc -B./ -c -Os /tmp/x.i
[hjl@gnu-tools-1 gcc]$ objdump -dwr x.o 

x.o:     file format elf64-x86-64


Disassembly of section .text:

0000000000000000 <foo>:
   0:   57                      push   %rdi
   1:   48 8b 3d 00 00 00 00    mov    0x0(%rip),%rdi        # 8 <foo+0x8>     
4: R_X86_64_PC32        a-0x4
   8:   51                      push   %rcx
   9:   50                      push   %rax
   a:   b9 28 00 00 00          mov    $0x28,%ecx
   f:   8a 05 00 00 00 00       mov    0x0(%rip),%al        # 15 <foo+0x15>    
11: R_X86_64_PC32       b-0x4
  15:   f3 aa                   rep stos %al,%es:(%rdi)
  17:   58                      pop    %rax
  18:   59                      pop    %rcx
  19:   5f                      pop    %rdi
  1a:   48 cf                   iretq  
[hjl@gnu-tools-1 gcc]$

Reply via email to