summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKuba Brecka <kuba.brecka@gmail.com>2015-07-06 17:17:06 +0000
committerKuba Brecka <kuba.brecka@gmail.com>2015-07-06 17:17:06 +0000
commitf3a493638fffbb8dede86cb50126f5ba24b3b78e (patch)
tree3b73acac29c77c48bc5194c4ee44dbfdf2359979
parentdb7781c6e917651a81226a60d0622f34adae6143 (diff)
downloadbcm5719-llvm-f3a493638fffbb8dede86cb50126f5ba24b3b78e.tar.gz
bcm5719-llvm-f3a493638fffbb8dede86cb50126f5ba24b3b78e.zip
[asan] Fix an OS X startup crash when an empty section is present
On OS X, when the main instrumented binary contains a custom section with zero length, ASan will crash (assert failure) early in the initialization. Reviewed at http://reviews.llvm.org/D10944 llvm-svn: 241474
-rw-r--r--compiler-rt/lib/sanitizer_common/sanitizer_posix.cc1
-rw-r--r--compiler-rt/test/asan/TestCases/Darwin/empty-section.cc12
2 files changed, 13 insertions, 0 deletions
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_posix.cc b/compiler-rt/lib/sanitizer_common/sanitizer_posix.cc
index de4b8d1406e..5754c9029ed 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_posix.cc
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_posix.cc
@@ -270,6 +270,7 @@ bool MemoryRangeIsAvailable(uptr range_start, uptr range_end) {
while (proc_maps.Next(&start, &end,
/*offset*/0, /*filename*/0, /*filename_size*/0,
/*protection*/0)) {
+ if (start == end) continue; // Empty range.
CHECK_NE(0, end);
if (!IntervalsAreSeparate(start, end - 1, range_start, range_end))
return false;
diff --git a/compiler-rt/test/asan/TestCases/Darwin/empty-section.cc b/compiler-rt/test/asan/TestCases/Darwin/empty-section.cc
new file mode 100644
index 00000000000..5b006b54548
--- /dev/null
+++ b/compiler-rt/test/asan/TestCases/Darwin/empty-section.cc
@@ -0,0 +1,12 @@
+// Regression test with an empty (length = 0) custom section.
+
+// RUN: %clangxx_asan -g -O0 %s -c -o %t.o
+// RUN: %clangxx_asan -g -O0 %t.o -o %t -sectcreate mysegment mysection /dev/null
+// RUN: %run %t 2>&1 | FileCheck %s
+
+#include <stdio.h>
+
+int main() {
+ printf("Hello, world!\n");
+ // CHECK: Hello, world!
+}
OpenPOWER on IntegriCloud