[asan] move the .preinit_array hack into a separate file (added used attribute)

llvm-svn: 175871
This commit is contained in:
Kostya Serebryany 2013-02-22 07:51:26 +00:00
parent 1c73911d42
commit 1d63d13ce2
4 changed files with 30 additions and 15 deletions

View 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

View 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

View File

@ -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

View 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