[compiler-rt] r259979 - [asan] properly report an un-aligned global variable instead of just crashing
Kostya Serebryany via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 5 19:22:25 PST 2016
Author: kcc
Date: Fri Feb 5 21:22:24 2016
New Revision: 259979
URL: http://llvm.org/viewvc/llvm-project?rev=259979&view=rev
Log:
[asan] properly report an un-aligned global variable instead of just crashing
Added:
compiler-rt/trunk/test/asan/TestCases/Linux/odr_c_test.c
Modified:
compiler-rt/trunk/lib/asan/asan_globals.cc
Modified: compiler-rt/trunk/lib/asan/asan_globals.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_globals.cc?rev=259979&r1=259978&r2=259979&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_globals.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_globals.cc Fri Feb 5 21:22:24 2016
@@ -144,7 +144,16 @@ static void RegisterGlobal(const Global
ReportGlobal(*g, "Added");
CHECK(flags()->report_globals);
CHECK(AddrIsInMem(g->beg));
- CHECK(AddrIsAlignedByGranularity(g->beg));
+ if (!AddrIsAlignedByGranularity(g->beg)) {
+ Report("The following global variable is not properly aligned.\n");
+ Report("This may happen if another global with the same name\n");
+ Report("resides in another non-instrumented module.\n");
+ Report("Or the global comes from a C file built w/o -fno-common.\n");
+ Report("In either case this is likely an ODR violation bug,\n");
+ Report("but AddressSanitizer can not provide more details.\n");
+ ReportODRViolation(g, FindRegistrationSite(g), g, FindRegistrationSite(g));
+ CHECK(AddrIsAlignedByGranularity(g->beg));
+ }
CHECK(AddrIsAlignedByGranularity(g->size_with_redzone));
if (flags()->detect_odr_violation) {
// Try detecting ODR (One Definition Rule) violation, i.e. the situation
Added: compiler-rt/trunk/test/asan/TestCases/Linux/odr_c_test.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Linux/odr_c_test.c?rev=259979&view=auto
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/Linux/odr_c_test.c (added)
+++ compiler-rt/trunk/test/asan/TestCases/Linux/odr_c_test.c Fri Feb 5 21:22:24 2016
@@ -0,0 +1,25 @@
+// Test that we can properly report an ODR violation
+// between an instrumented global and a non-instrumented global.
+
+// RUN: %clang_asan %s -fPIC -shared -o %t-1.so -DFILE1
+// RUN: %clang_asan %s -fPIC -shared -o %t-2.so -DFILE2
+// RUN: %clang_asan %s -fPIE %t-1.so %t-2.so -Wl,-R`pwd` -o %t
+// RUN: not %run %t 2>&1 | FileCheck %s
+//
+// REQUIRES: x86_64-supported-target
+//
+// CHECK: The following global variable is not properly aligned.
+// CHECK: ERROR: AddressSanitizer: odr-violation
+#if defined(FILE1)
+__attribute__((aligned(8))) int x;
+__attribute__((aligned(1))) char y;
+__attribute__((aligned(1))) char ZZZ[100];
+#elif defined(FILE2)
+int ZZZ = 1;
+#else
+extern int ZZZ;
+int main() {
+ return ZZZ;
+}
+#endif
+
More information about the llvm-commits
mailing list