[llvm-commits] PATCH: AddressSanitizer: get rid of stdlib.h, leave (smaller) stddef.h instead. (issue 5689069)

samsonov at google.com samsonov at google.com
Wed Feb 22 05:45:24 PST 2012


Reviewers: ramosian.glider, timurrrr_at_google_com, Evgeniy Stepanov,



Please review this at http://codereview.appspot.com/5689069/

Affected files:
   M     asan_interface.h
   M     asan_internal.h
   M     asan_posix.cc
   M     asan_rtl.cc
   M     asan_win.cc


-------------- next part --------------
Index: asan_rtl.cc
===================================================================
--- asan_rtl.cc	(revision 151158)
+++ asan_rtl.cc	(working copy)
@@ -44,7 +44,7 @@
 bool   FLAG_replace_cfallocator;  // Used on Mac only.
 size_t FLAG_max_malloc_fill_size = 0;
 bool   FLAG_use_fake_stack;
-int    FLAG_exitcode = EXIT_FAILURE;
+int    FLAG_exitcode = ASAN_DEFAULT_FAILURE_EXITCODE;
 bool   FLAG_allow_user_poisoning;
 int    FLAG_sleep_before_dying;
 
@@ -433,13 +433,14 @@
   FLAG_replace_str = IntFlagValue(options, "replace_str=", 1);
   FLAG_replace_intrin = IntFlagValue(options, "replace_intrin=", 1);
   FLAG_use_fake_stack = IntFlagValue(options, "use_fake_stack=", 1);
-  FLAG_exitcode = IntFlagValue(options, "exitcode=", EXIT_FAILURE);
+  FLAG_exitcode = IntFlagValue(options, "exitcode=",
+                               ASAN_DEFAULT_FAILURE_EXITCODE);
   FLAG_allow_user_poisoning = IntFlagValue(options,
                                            "allow_user_poisoning=", 1);
   FLAG_sleep_before_dying = IntFlagValue(options, "sleep_before_dying=", 0);
 
   if (FLAG_atexit) {
-    atexit(asan_atexit);
+    Atexit(asan_atexit);
   }
 
   // interceptors
Index: asan_posix.cc
===================================================================
--- asan_posix.cc	(revision 151158)
+++ asan_posix.cc	(working copy)
@@ -21,6 +21,7 @@
 
 #include <pthread.h>
 #include <signal.h>
+#include <stdlib.h>
 #include <sys/time.h>
 #include <sys/resource.h>
 #include <unistd.h>
@@ -99,6 +100,10 @@
   return _exit(exitcode);
 }
 
+int Atexit(void (*function)(void)) {
+  return atexit(function);
+}
+
 int AtomicInc(int *a) {
 #ifdef ANDROID
   return __atomic_inc(a) + 1;
Index: asan_internal.h
===================================================================
--- asan_internal.h	(revision 151159)
+++ asan_internal.h	(working copy)
@@ -18,7 +18,7 @@
 # error "This operating system is not supported by AddressSanitizer"
 #endif
 
-#include <stdlib.h>  // for size_t, uintptr_t, etc.
+#include <stddef.h>  // for size_t, uintptr_t, etc.
 
 #if defined(_WIN32)
 // There's no <stdint.h> in Visual Studio 9, so we have to define [u]int*_t.
@@ -75,6 +75,8 @@
 # define INT64_MAX              (__INT64_C(9223372036854775807))
 # define UINT64_MAX             (__UINT64_C(18446744073709551615))
 
+#define ASAN_DEFAULT_FAILURE_EXITCODE 1
+
 #if defined(__linux__)
 # define ASAN_LINUX   1
 #else
@@ -229,6 +231,7 @@
 void AsanDie();
 void SleepForSeconds(int seconds);
 void Exit(int exitcode);
+int Atexit(void (*function)(void));
 
 #define CHECK(cond) do { if (!(cond)) { \
   CheckFailed(#cond, __FILE__, __LINE__); \
Index: asan_win.cc
===================================================================
--- asan_win.cc	(revision 151158)
+++ asan_win.cc	(working copy)
@@ -16,6 +16,7 @@
 
 #include <dbghelp.h>
 #include <stdio.h>  // FIXME: get rid of this.
+#include <stdlib.h>
 
 #include <new>  // FIXME: temporarily needed for placement new in AsanLock.
 
@@ -260,6 +261,10 @@
   _exit(exitcode);
 }
 
+int Atexit(void (*function)(void)) {
+  return atexit(function);
+}
+
 }  // namespace __asan
 
 #endif  // _WIN32
Index: asan_interface.h
===================================================================
--- asan_interface.h	(revision 151158)
+++ asan_interface.h	(working copy)
@@ -15,6 +15,10 @@
 #ifndef ASAN_INTERFACE_H
 #define ASAN_INTERFACE_H
 
+// ----------- ATTENTION -------------
+// This header should NOT include any other headers from ASan runtime.
+// All functions in this header are extern "C" and start with __asan_.
+
 #if !defined(_WIN32)
 #include <stdint.h>  // for uintptr_t
 #define ASAN_INTERFACE_FUNCTION_ATTRIBUTE __attribute__((visibility("default")))
@@ -22,11 +26,8 @@
 // TODO(timurrrr): find out what we need on Windows. __declspec(dllexport) ?
 #define ASAN_INTERFACE_FUNCTION_ATTRIBUTE
 #endif
-#include <stdlib.h>  // for size_t
+#include <stddef.h>  // for size_t
 
-// This header should NOT include any other headers from ASan runtime.
-// All functions in this header are extern "C" and start with __asan_.
-
 extern "C" {
   // This function should be called at the very beginning of the process,
   // before any instrumented code is executed and before any call to malloc.


More information about the llvm-commits mailing list