Bug#469058: looking over GCC 4.3 release notes

Aurelien Jarno aurelien at aurel32.net
Wed Mar 5 09:22:18 UTC 2008


tag 469058 + patch
thanks

On Wed, Mar 05, 2008 at 03:12:52AM +0100, Aurelien Jarno wrote:
> reassign 469058 sbcl
> retitle 469058 sbcl don't reset direction flag upon exit
> thanks
> 
> Nikodemus Siivola a écrit :
> > Looking at http://gcc.gnu.org/gcc-4.3/changes.html, this is the only
> > thing that really jumps out:
> > 
> > "GCC no longer places the cld instruction before string operations.
> > Both i386 and x86-64 ABI documents mandate the direction flag to be
> > clear at the entry of a function. It is now invalid to set the flag in
> > asm statement without reseting it afterward."
> > 
> > ...but (1) SBCL _should_ be resetting the direction flag before any
> > calls to libc code, and (2) I would expect problems caused by this to
> > be more deterministic.
> 
> It actually doesn't reset it. The problem causes the sigemptyset()
> function from the glibc to not work correctly.
> 
> I have identified the potential part from SBCL causing the problem, I am
> currently testing a fix.
> 

Please find below the patch to fix the problem. I only tested on amd64,
but it should work the same way on i386.

--- sbcl-1.0.14.0.orig/src/compiler/x86/call.lisp
+++ sbcl-1.0.14.0/src/compiler/x86/call.lisp
@@ -364,7 +364,8 @@
       ;; Restore EDI, and reset the stack.
       (emit-label restore-edi)
       (loadw edi-tn ebx-tn (frame-word-offset 1))
-      (inst mov esp-tn ebx-tn))))
+      (inst mov esp-tn ebx-tn)
+      (inst cld))))
   (values))
 
 ;;;; unknown values receiving
@@ -1376,7 +1377,8 @@
        (inst sub ecx 1)
        (inst jmp :nz loop)
        ;; NIL out the last cons.
-       (storew nil-value dst 1 list-pointer-lowtag))
+       (storew nil-value dst 1 list-pointer-lowtag)
+       (inst cld))
       (emit-label done))))
 
 ;;; Return the location and size of the &MORE arg glob created by
--- sbcl-1.0.14.0.orig/src/compiler/x86/values.lisp
+++ sbcl-1.0.14.0/src/compiler/x86/values.lisp
@@ -38,6 +38,7 @@
     (inst movs :dword)
     (inst cmp esp-tn esi)
     (inst jmp :be loop)
+    (inst cld)
     DONE
     (inst lea esp-tn (make-ea :dword :base edi :disp n-word-bytes))
     (inst sub edi esi)
--- sbcl-1.0.14.0.orig/src/compiler/x86/nlx.lisp
+++ sbcl-1.0.14.0/src/compiler/x86/nlx.lisp
@@ -237,6 +237,7 @@
     (inst std)
     (inst rep)
     (inst movs :dword)
+    (inst cld)
 
     DONE
     ;; Reset the CSP at last moved arg.
--- sbcl-1.0.14.0.orig/src/compiler/x86-64/call.lisp
+++ sbcl-1.0.14.0/src/compiler/x86-64/call.lisp
@@ -356,7 +356,8 @@
       ;; Restore EDI, and reset the stack.
       (emit-label restore-edi)
       (loadw rdi-tn rbx-tn (- (1+ 1)))
-      (inst mov rsp-tn rbx-tn))))
+      (inst mov rsp-tn rbx-tn)
+      (inst cld))))
   (values))
 
 ;;;; unknown values receiving
@@ -1320,7 +1321,8 @@
        (inst sub rcx 1)
        (inst jmp :nz loop)
        ;; NIL out the last cons.
-       (storew nil-value dst 1 list-pointer-lowtag))
+       (storew nil-value dst 1 list-pointer-lowtag)
+       (inst cld))
       (emit-label done))))
 
 ;;; Return the location and size of the &MORE arg glob created by
--- sbcl-1.0.14.0.orig/src/compiler/x86-64/values.lisp
+++ sbcl-1.0.14.0/src/compiler/x86-64/values.lisp
@@ -38,6 +38,7 @@
     (inst movs :qword)
     (inst cmp rsp-tn rsi)
     (inst jmp :be LOOP)
+    (inst cld)
     DONE
     (inst lea rsp-tn (make-ea :qword :base rdi :disp n-word-bytes))
     (inst sub rdi rsi)
--- sbcl-1.0.14.0.orig/src/compiler/x86-64/nlx.lisp
+++ sbcl-1.0.14.0/src/compiler/x86-64/nlx.lisp
@@ -212,6 +212,7 @@
     (inst std)
     (inst rep)
     (inst movs :qword)
+    (inst cld)
 
     DONE
     ;; Reset the CSP at last moved arg.
--- sbcl-1.0.14.0.orig/src/assembly/x86/assem-rtns.lisp
+++ sbcl-1.0.14.0/src/assembly/x86/assem-rtns.lisp
@@ -54,6 +54,7 @@
   (inst lea edi (make-ea :dword :base ebx :disp (- n-word-bytes)))
   (inst rep)
   (inst movs :dword)
+  (inst cld)                            ; restore direction bit
 
   ;; solaris requires DF being zero.
   #!+sunos (inst cld)
@@ -153,6 +154,7 @@
   (inst sub esi (fixnumize 1))
   (inst rep)
   (inst movs :dword)
+  (inst cld)                            ; restore direction bit
 
   ;; solaris requires DF being zero.
   #!+sunos (inst cld)
--- sbcl-1.0.14.0.orig/src/assembly/x86-64/assem-rtns.lisp
+++ sbcl-1.0.14.0/src/assembly/x86-64/assem-rtns.lisp
@@ -54,6 +54,7 @@
   (inst lea edi (make-ea :qword :base ebx :disp (- n-word-bytes)))
   (inst rep)
   (inst movs :qword)
+  (inst cld)                            ; restore direction bit
 
   ;; Restore the count.
   (inst mov ecx edx)
@@ -150,6 +151,7 @@
   (inst sub esi (fixnumize 1))
   (inst rep)
   (inst movs :qword)
+  (inst cld)                            ; restore direction bit
 
   ;; Load the register arguments carefully.
   (loadw edx rbp-tn -1)

-- 
  .''`.  Aurelien Jarno	            | GPG: 1024D/F1BCDB73
 : :' :  Debian developer           | Electrical Engineer
 `. `'   aurel32 at debian.org         | aurelien at aurel32.net
   `-    people.debian.org/~aurel32 | www.aurel32.net





More information about the pkg-common-lisp-devel mailing list