[compiler-rt] r241474 - [asan] Fix an OS X startup crash when an empty section is present

Kuba Brecka kuba.brecka at gmail.com
Mon Jul 6 10:17:07 PDT 2015


Author: kuba.brecka
Date: Mon Jul  6 12:17:06 2015
New Revision: 241474

URL: http://llvm.org/viewvc/llvm-project?rev=241474&view=rev
Log:
[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


Added:
    compiler-rt/trunk/test/asan/TestCases/Darwin/empty-section.cc
Modified:
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix.cc

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix.cc?rev=241474&r1=241473&r2=241474&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix.cc Mon Jul  6 12:17:06 2015
@@ -270,6 +270,7 @@ bool MemoryRangeIsAvailable(uptr range_s
   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;

Added: compiler-rt/trunk/test/asan/TestCases/Darwin/empty-section.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Darwin/empty-section.cc?rev=241474&view=auto
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/Darwin/empty-section.cc (added)
+++ compiler-rt/trunk/test/asan/TestCases/Darwin/empty-section.cc Mon Jul  6 12:17:06 2015
@@ -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!
+}





More information about the llvm-commits mailing list