Skip to content
This repository has been archived by the owner on May 21, 2019. It is now read-only.

Commit

Permalink
[Sanitizer] Always initialize a Symbolizer (even if 'symbolize' is fa…
Browse files Browse the repository at this point in the history
…lse).

If 'symbolize' flag is not set, we still want to transform virtual address
to module+offset pair in the call to Symbolizer::SymbolizeCode().
See https://code.google.com/p/address-sanitizer/issues/detail?id=251 for
more details.


git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@197491 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
Alexey Samsonov committed Dec 17, 2013
1 parent bb6f936 commit 6bd601b
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 20 deletions.
7 changes: 1 addition & 6 deletions lib/asan/asan_rtl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -534,12 +534,7 @@ void __asan_init() {
// fork() on Mac locks the allocator.
InitializeAllocator();

// Start symbolizer process if necessary.
if (common_flags()->symbolize) {
Symbolizer::Init(common_flags()->external_symbolizer_path);
} else {
Symbolizer::Disable();
}
Symbolizer::Init(common_flags()->external_symbolizer_path);

// On Linux AsanThread::ThreadStart() calls malloc() that's why asan_inited
// should be set to 1 prior to initializing the threads.
Expand Down
9 changes: 7 additions & 2 deletions lib/lsan/lit_tests/TestCases/suppressions_file.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
// RUN: LSAN_BASE="use_registers=0:use_stacks=0:suppressions=%s.supp"
// RUN: LSAN_BASE="use_registers=0:use_stacks=0"
// RUN: %clangxx_lsan %s -o %t
// RUN: LSAN_OPTIONS=$LSAN_BASE not %t 2>&1 | FileCheck %s

// RUN: echo "leak:*LSanTestLeakingFunc*" > %t.supp1
// RUN: LSAN_OPTIONS=$LSAN_BASE:suppressions=%t.supp1 not %t 2>&1 | FileCheck %s

// RUN: echo "leak:%t" > %t.supp2
// RUN: LSAN_OPTIONS=$LSAN_BASE:suppressions="%t.supp2":symbolize=false %t

#include <stdio.h>
#include <stdlib.h>
Expand Down
1 change: 0 additions & 1 deletion lib/lsan/lit_tests/TestCases/suppressions_file.cc.supp

This file was deleted.

7 changes: 1 addition & 6 deletions lib/lsan/lsan.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,7 @@ extern "C" void __lsan_init() {
ThreadStart(tid, GetTid());
SetCurrentThread(tid);

// Start symbolizer process if necessary.
if (common_flags()->symbolize) {
Symbolizer::Init(common_flags()->external_symbolizer_path);
} else {
Symbolizer::Disable();
}
Symbolizer::Init(common_flags()->external_symbolizer_path);

InitCommonLsan();
if (common_flags()->detect_leaks && common_flags()->leak_check_at_exit)
Expand Down
2 changes: 2 additions & 0 deletions lib/sanitizer_common/sanitizer_flags.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ void ParseCommonFlagsFromString(CommonFlags *f, const char *str) {
// Do a sanity check for certain flags.
if (f->malloc_context_size < 1)
f->malloc_context_size = 1;
if (!f->symbolize)
f->external_symbolizer_path = "";
}

static bool GetFlagValue(const char *env, const char *name,
Expand Down
6 changes: 4 additions & 2 deletions lib/sanitizer_common/sanitizer_flags.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ void ParseFlag(const char *env, int *flag, const char *name);
void ParseFlag(const char *env, const char **flag, const char *name);

struct CommonFlags {
// If set, use the online symbolizer from common sanitizer runtime.
// If set, use the online symbolizer from common sanitizer runtime to turn
// virtual addresses to file/line locations.
bool symbolize;
// Path to external symbolizer. If it is NULL, symbolizer will be looked for
// in PATH. If it is empty, external symbolizer will not be started.
// in PATH. If it is empty (or if "symbolize" is false), external symbolizer
// will not be started.
const char *external_symbolizer_path;
// Strips this prefix from file paths in error reports.
const char *strip_path_prefix;
Expand Down
4 changes: 2 additions & 2 deletions lib/sanitizer_common/sanitizer_symbolizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,6 @@ class Symbolizer {
/// reasons as this function will check $PATH for an external symbolizer. Not
/// thread safe.
static Symbolizer *Init(const char* path_to_external = 0);
/// Initialize the symbolizer in a disabled state. Not thread safe.
static Symbolizer *Disable();
// Fills at most "max_frames" elements of "frames" with descriptions
// for a given address (in all inlined functions). Returns the number
// of descriptions actually filled.
Expand Down Expand Up @@ -121,6 +119,8 @@ class Symbolizer {
/// Create a symbolizer and store it to symbolizer_ without checking if one
/// already exists. Not thread safe.
static Symbolizer *CreateAndStore(const char *path_to_external);
/// Initialize the symbolizer in a disabled state. Not thread safe.
static Symbolizer *Disable();

static Symbolizer *symbolizer_;
static StaticSpinMutex init_mu_;
Expand Down
2 changes: 1 addition & 1 deletion lib/tsan/tests/unit/tsan_flags_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ void VerifyOptions1(Flags *f) {
EXPECT_EQ(f->io_sync, 1);

EXPECT_EQ(f->symbolize, 0);
EXPECT_EQ(f->external_symbolizer_path, std::string("asdfgh"));
EXPECT_EQ(f->external_symbolizer_path, std::string(""));
EXPECT_EQ(f->strip_path_prefix, std::string("zxcvb"));
EXPECT_EQ(f->fast_unwind_on_fatal, 0);
EXPECT_EQ(f->fast_unwind_on_malloc, 0);
Expand Down

0 comments on commit 6bd601b

Please sign in to comment.