[asan] move the .preinit_array hack into a separate file (added used attribute)
authorKostya Serebryany <kcc@google.com>
Fri, 22 Feb 2013 07:51:26 +0000 (07:51 +0000)
committerKostya Serebryany <kcc@google.com>
Fri, 22 Feb 2013 07:51:26 +0000 (07:51 +0000)
llvm-svn: 175871

compiler-rt/lib/asan/CMakeLists.txt
compiler-rt/lib/asan/asan_intercepted_functions.h
compiler-rt/lib/asan/asan_preinit.cc [new file with mode: 0644]
compiler-rt/lib/asan/asan_rtl.cc

index cdd462e..e451e23 100644 (file)
@@ -14,6 +14,7 @@ set(ASAN_SOURCES
   asan_new_delete.cc
   asan_poisoning.cc
   asan_posix.cc
+  asan_preinit.cc
   asan_report.cc
   asan_rtl.cc
   asan_stack.cc
index 7cfbede..d529560 100644 (file)
@@ -103,7 +103,6 @@ int atoi(const char *nptr);
 long atol(const char *nptr);  // NOLINT
 long strtol(const char *nptr, char **endptr, int base);  // NOLINT
 void longjmp(void *env, int value);
-
 }
 # endif
 
diff --git a/compiler-rt/lib/asan/asan_preinit.cc b/compiler-rt/lib/asan/asan_preinit.cc
new file mode 100644 (file)
index 0000000..07e0a53
--- /dev/null
@@ -0,0 +1,29 @@
+//===-- asan_preinit.cc ---------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file is a part of AddressSanitizer, an address sanity checker.
+//
+// Call __asan_init at the very early stage of process startup.
+// On Linux we use .preinit_array section (unless PIC macro is defined).
+//===----------------------------------------------------------------------===//
+#include "asan_internal.h"
+
+#if ASAN_USE_PREINIT_ARRAY && !defined(PIC)
+  // On Linux, we force __asan_init to be called before anyone else
+  // by placing it into .preinit_array section.
+  // FIXME: do we have anything like this on Mac?
+  __attribute__((section(".preinit_array"), used))
+  void (*__asan_preinit)(void) =__asan_init;
+#elif defined(_WIN32) && defined(_DLL)
+  // On Windows, when using dynamic CRT (/MD), we can put a pointer
+  // to __asan_init into the global list of C initializers.
+  // See crt0dat.c in the CRT sources for the details.
+  #pragma section(".CRT$XIB", long, read)  // NOLINT
+  __declspec(allocate(".CRT$XIB")) void (*__asan_preinit)() = __asan_init;
+#endif
index 83aa1f4..7985903 100644 (file)
@@ -523,17 +523,3 @@ void __asan_init() {
     Report("AddressSanitizer Init done\n");
   }
 }
-
-#if ASAN_USE_PREINIT_ARRAY
-  // On Linux, we force __asan_init to be called before anyone else
-  // by placing it into .preinit_array section.
-  // FIXME: do we have anything like this on Mac?
-  __attribute__((section(".preinit_array")))
-  void (*__asan_preinit)(void) =__asan_init;
-#elif defined(_WIN32) && defined(_DLL)
-  // On Windows, when using dynamic CRT (/MD), we can put a pointer
-  // to __asan_init into the global list of C initializers.
-  // See crt0dat.c in the CRT sources for the details.
-  #pragma section(".CRT$XIB", long, read)  // NOLINT
-  __declspec(allocate(".CRT$XIB")) void (*__asan_preinit)() = __asan_init;
-#endif