https://llvm.org/bugs/show_bug.cgi?id=26406

            Bug ID: 26406
           Summary: The direction flag in the FLAGS register may be wrong
                    in interrupt handler
           Product: new-bugs
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: new bugs
          Assignee: unassignedb...@nondot.org
          Reporter: hjl.to...@gmail.com
                CC: a.bat...@hotmail.com, amjad.ab...@intel.com,
                    llvm-bugs@lists.llvm.org
    Classification: Unclassified

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 undetermined in
interrupt handler, the result will be wrong if DF isn't cleared:

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

__attribute__ ((interrupt))
void
foo (void *frame)
{
  __builtin_memset (a, b, 40);
}
[hjl@gnu-6 bin]$ ./clang -S -Os /tmp/x.i -m32 -mno-sse
[hjl@gnu-6 bin]$ cat x.s
    .text
    .file    "/tmp/x.i"
    .globl    foo
    .type    foo,@function
foo:                                    # @foo
# BB#0:                                 # %entry
    pushl    %esp
    pushl    %edx
    pushl    %ecx
    pushl    %eax
    subl    $12, %esp
    subl    $4, %esp
    pushl    $40
    pushl    b
    pushl    a
    calll    memset
    addl    $16, %esp
    addl    $12, %esp
    popl    %eax
    popl    %ecx
    popl    %edx
    popl    %esp
    iretl
.Lfunc_end0:
    .size    foo, .Lfunc_end0-foo


    .ident    "clang version 3.9.0 (http://llvm.org/git/clang.git
1f64ddbc4c5d1036b68ec896765a7535537ded85) (http://llvm.org/git/llvm.git
43b517fe4e0a181b1cf20f36fd9eb92f7b32946c)"
    .section    ".note.GNU-stack","",@progbits
[hjl@gnu-6 bin]$ 

The current interrupt spec:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66960#c4

has

Since the direction flag in the FLAGS register in interrupt (exception)
handlers is undetermined, cld instruction must be emitted in function
prologue if rep string instructions are used in interrupt (exception)
handler or interrupt (exception) handler isn't a leaf function.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to