]> code.delx.au - gnu-emacs/commitdiff
Port better to AddressSanitizer.
authorPaul Eggert <eggert@cs.ucla.edu>
Sun, 30 Nov 2014 07:30:22 +0000 (23:30 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Sun, 30 Nov 2014 07:32:29 +0000 (23:32 -0800)
These changes suffice for temacs on x86-64 with GCC 4.9.2 and
-fsanitize=address.
* alloc.c (valid_pointer_p) [ADDRESS_SANITIZER]:
Return -1 or 0, as the pipe trick doesn't work.
* alloc.c (relocatable_string_data_p, mark_object, sweep_symbols):
* data.c (Ffset):
* print.c (print_object):
When a pointer-check primitive returns -1, do not assume this
means the pointer is valid or that the underlying system has failed.
It could just be that addresses are being sanitized so Emacs can't
test for pointer validity.
* lisp.h (defined_GC_CHECK_STRING_BYTES): New constant.
(USE_STACK_STRING) [GC_CHECK_STRING_BYTES]: Now false, since the
string validity checker doesn't work on stack-based strings.

src/ChangeLog
src/alloc.c
src/data.c
src/lisp.h
src/print.c

index 668c3e809f6a117c81d59700d1a17ebb77f78e72..c977eb490f53781cb048997bbf453097bb1617b8 100644 (file)
@@ -1,3 +1,21 @@
+2014-11-30  Paul Eggert  <eggert@cs.ucla.edu>
+
+       Port better to AddressSanitizer.
+       These changes suffice for temacs on x86-64 with GCC 4.9.2 and
+       -fsanitize=address.
+       * alloc.c (valid_pointer_p) [ADDRESS_SANITIZER]:
+       Return -1 or 0, as the pipe trick doesn't work.
+       * alloc.c (relocatable_string_data_p, mark_object, sweep_symbols):
+       * data.c (Ffset):
+       * print.c (print_object):
+       When a pointer-check primitive returns -1, do not assume this
+       means the pointer is valid or that the underlying system has failed.
+       It could just be that addresses are being sanitized so Emacs can't
+       test for pointer validity.
+       * lisp.h (defined_GC_CHECK_STRING_BYTES): New constant.
+       (USE_STACK_STRING) [GC_CHECK_STRING_BYTES]: Now false, since the
+       string validity checker doesn't work on stack-based strings.
+
 2014-11-29  Paul Eggert  <eggert@cs.ucla.edu>
 
        Improve clarity of USE_LSB_TAG definition.
index faad0b59c878e845dc764d19c55b422d0b062cbe..1019c2af6ccd03135afb95d3ae02e84c5d9ec3b3 100644 (file)
@@ -4934,6 +4934,10 @@ valid_pointer_p (void *p)
 #ifdef WINDOWSNT
   return w32_valid_pointer_p (p, 16);
 #else
+
+  if (ADDRESS_SANITIZER)
+    return p ? -1 : 0;
+
   int fd[2];
 
   /* Obviously, we cannot just access it (we would SEGV trying), so we
@@ -4949,7 +4953,7 @@ valid_pointer_p (void *p)
       return valid;
     }
 
-    return -1;
+  return -1;
 #endif
 }
 
@@ -5048,8 +5052,8 @@ relocatable_string_data_p (const char *str)
       struct sdata *sdata
        = (struct sdata *) (str - offsetof (struct sdata, data));
 
-      if (valid_pointer_p (sdata)
-         && valid_pointer_p (sdata->string)
+      if (0 < valid_pointer_p (sdata)
+         && 0 < valid_pointer_p (sdata->string)
          && maybe_lisp_pointer (sdata->string))
        return (valid_lisp_object_p
                (make_lisp_ptr (sdata->string, Lisp_String))
@@ -6364,7 +6368,7 @@ mark_object (Lisp_Object arg)
        CHECK_ALLOCATED_AND_LIVE (live_symbol_p);
        ptr->gcmarkbit = 1;
        /* Attempt to catch bogus objects.  */
-        eassert (valid_lisp_object_p (ptr->function) >= 1);
+        eassert (valid_lisp_object_p (ptr->function));
        mark_object (ptr->function);
        mark_object (ptr->plist);
        switch (ptr->redirect)
@@ -6749,7 +6753,7 @@ sweep_symbols (void)
               ++num_used;
               sym->s.gcmarkbit = 0;
               /* Attempt to catch bogus objects.  */
-              eassert (valid_lisp_object_p (sym->s.function) >= 1);
+              eassert (valid_lisp_object_p (sym->s.function));
             }
         }
 
index 9977a3aaadd6d23f099790518290ab02264abaa7..b48dbbebabc3f934db46c3606d5883c1e9aeb166 100644 (file)
@@ -729,7 +729,7 @@ DEFUN ("fset", Ffset, Sfset, 2, 2, 0,
 
   /* Convert to eassert or remove after GC bug is found.  In the
      meantime, check unconditionally, at a slight perf hit.  */
-  if (valid_lisp_object_p (definition) < 1)
+  if (! valid_lisp_object_p (definition))
     emacs_abort ();
 
   set_symbol_function (symbol, definition);
index 42bb33704fa438846e04c288b2dc9952bac0b1ba..a56c4a73bf875b2269dad58db8531ea1a072f679 100644 (file)
@@ -4604,6 +4604,12 @@ lisp_word_count (ptrdiff_t nbytes)
 # define USE_STACK_LISP_OBJECTS false
 #endif
 
+#ifdef GC_CHECK_STRING_BYTES
+enum { defined_GC_CHECK_STRING_BYTES = true };
+#else
+enum { defined_GC_CHECK_STRING_BYTES = false };
+#endif
+
 /* Struct inside unions that are typically no larger and aligned enough.  */
 
 union Aligned_Cons
@@ -4628,6 +4634,7 @@ enum
     USE_STACK_CONS = (USE_STACK_LISP_OBJECTS
                      && alignof (union Aligned_Cons) % GCALIGNMENT == 0),
     USE_STACK_STRING = (USE_STACK_CONS
+                       && !defined_GC_CHECK_STRING_BYTES
                        && alignof (union Aligned_String) % GCALIGNMENT == 0)
   };
 
index 49331ef0984dafe02eb7e49203e432b6d3fb6f1b..7723b98348a7711d6a1f5d11359f157baf31e322 100644 (file)
@@ -2098,14 +2098,16 @@ print_object (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag)
                for (i = 0; i < limit; i++)
                  {
                    Lisp_Object maybe = area[i];
+                   int valid = valid_lisp_object_p (maybe);
 
-                   if (valid_lisp_object_p (maybe) > 0)
+                   if (0 < valid)
                      {
                        PRINTCHAR (' ');
                        print_object (maybe, printcharfun, escapeflag);
                      }
                    else
-                     strout (" <invalid>", -1, -1, printcharfun);
+                     strout (valid ? " <some>" : " <invalid>",
+                             -1, -1, printcharfun);
                  }
                if (i == limit && i < amount)
                  strout (" ...", 4, 4, printcharfun);