Make __asan_default_options a weak function that returns a const char*.

Users may define it to override the default ASan options.
This function has to be marked with __attribute__((no_address_safety_analysis)), because it is called before ASan is fully initialized.

Add an output test checking the __asan_default_options functionality.

llvm-svn: 160712
This commit is contained in:
Alexander Potapenko 2012-07-25 09:18:43 +00:00
parent 0b875a0c29
commit 9bac1cedbc
4 changed files with 18 additions and 3 deletions

View File

@ -25,7 +25,7 @@
extern "C" {
#if !defined(_WIN32)
// We do not need to redefine the defaults right now on Windows.
char *__asan_default_options SANITIZER_WEAK_ATTRIBUTE;
const char *__asan_default_options() SANITIZER_WEAK_ATTRIBUTE;
#endif
}
@ -89,6 +89,7 @@ struct Flags {
// to dump 16T+ core.
bool disable_core;
};
Flags *flags();
void InitializeFlags(Flags *f, const char *env);

View File

@ -128,10 +128,10 @@ void InitializeFlags(Flags *f, const char *env) {
// Override from user-specified string.
#if !defined(_WIN32)
if (__asan_default_options) {
ParseFlagsFromString(f, __asan_default_options);
ParseFlagsFromString(f, __asan_default_options());
if (flags()->verbosity) {
Report("Using the defaults from __asan_default_options: %s\n",
__asan_default_options);
__asan_default_options());
}
}
#endif

View File

@ -0,0 +1,12 @@
const char *kAsanDefaultOptions="verbosity=1 foo=bar";
extern "C"
__attribute__((no_address_safety_analysis))
const char *__asan_default_options() {
return kAsanDefaultOptions;
}
int main() {
// Check-Common: foo=bar
return 0;
}

View File

@ -39,6 +39,8 @@ check_program a.out $C_TEST.c CHECKSLEEP
export ASAN_OPTIONS=""
rm ./a.out
# FIXME: some tests do not need to be ran for all the combinations of arch
# and optimization mode.
for t in *.cc; do
for b in 32 64; do
for O in 0 1 2 3; do