[asan] split detect_odr_violation into two: =2 detects all ODR violations, =1 detects only those where the variable sizes are different. BTW, the detector seems to be working well and finding nice bugs. Early adopters are welcome.

llvm-svn: 207415
This commit is contained in:
Kostya Serebryany 2014-04-28 12:47:58 +00:00
parent 9645090181
commit 4f9c31a2fa
4 changed files with 16 additions and 6 deletions

View File

@ -64,7 +64,7 @@ struct Flags {
bool start_deactivated; bool start_deactivated;
int detect_invalid_pointer_pairs; int detect_invalid_pointer_pairs;
bool detect_container_overflow; bool detect_container_overflow;
bool detect_odr_violation; int detect_odr_violation;
}; };
extern Flags asan_flags_dont_use_directly; extern Flags asan_flags_dont_use_directly;

View File

@ -99,7 +99,8 @@ static void RegisterGlobal(const Global *g) {
// This check may not be enough: if the first global is much larger // This check may not be enough: if the first global is much larger
// the entire redzone of the second global may be within the first global. // the entire redzone of the second global may be within the first global.
for (ListOfGlobals *l = list_of_all_globals; l; l = l->next) { for (ListOfGlobals *l = list_of_all_globals; l; l = l->next) {
if (g->beg == l->g->beg) if (g->beg == l->g->beg &&
(flags()->detect_odr_violation >= 2 || g->size != l->g->size))
ReportODRViolation(g, l->g); ReportODRViolation(g, l->g);
} }
} }

View File

@ -226,9 +226,10 @@ static void ParseFlagsFromString(Flags *f, const char *str) {
"If true, honor the container overflow annotations. " "If true, honor the container overflow annotations. "
"See https://code.google.com/p/address-sanitizer/wiki/ContainerOverflow"); "See https://code.google.com/p/address-sanitizer/wiki/ContainerOverflow");
ParseFlag(str, &f->detect_odr_violation, ParseFlag(str, &f->detect_odr_violation, "detect_odr_violation",
"detect_odr_violation", "If >=2, detect violation of One-Definition-Rule (ODR); "
"If true, detect violation of One-Definition-Rule (ODR) "); "If ==1, detect ODR-violation only if the two variables "
"have different sizes");
} }
void InitializeFlags(Flags *f, const char *env) { void InitializeFlags(Flags *f, const char *env) {

View File

@ -1,8 +1,16 @@
// RUN: %clangxx_asan -DBUILD_SO=1 -fPIC -shared %s -o %t.so
// RUN: %clangxx_asan %s %t.so -Wl,-R. -o %t // RUN: %clangxx_asan %s %t.so -Wl,-R. -o %t
//
// Different size: detect a bug if detect_odr_violation>=1
// RUN: %clangxx_asan -DBUILD_SO=1 -fPIC -shared %s -o %t.so
// RUN: ASAN_OPTIONS=detect_odr_violation=1 not %t 2>&1 | FileCheck %s // RUN: ASAN_OPTIONS=detect_odr_violation=1 not %t 2>&1 | FileCheck %s
// RUN: ASAN_OPTIONS=detect_odr_violation=2 not %t 2>&1 | FileCheck %s
// RUN: ASAN_OPTIONS=detect_odr_violation=0 %t 2>&1 | FileCheck %s --check-prefix=DISABLED // RUN: ASAN_OPTIONS=detect_odr_violation=0 %t 2>&1 | FileCheck %s --check-prefix=DISABLED
// RUN: %t 2>&1 | FileCheck %s --check-prefix=DISABLED // RUN: %t 2>&1 | FileCheck %s --check-prefix=DISABLED
//
// Same size: report a bug only if detect_odr_violation>=2.
// RUN: %clangxx_asan -DBUILD_SO=1 -fPIC -shared %s -o %t.so -DSZ=100
// RUN: ASAN_OPTIONS=detect_odr_violation=1 %t 2>&1 | FileCheck %s --check-prefix=DISABLED
// RUN: ASAN_OPTIONS=detect_odr_violation=2 not %t 2>&1 | FileCheck %s
#ifndef SZ #ifndef SZ
# define SZ 4 # define SZ 4