[compiler-rt] r285620 - [asan] Move instrumented null-terminated strings to a special section, compiler-rt part

Kuba Brecka via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 31 11:52:32 PDT 2016


Author: kuba.brecka
Date: Mon Oct 31 13:52:32 2016
New Revision: 285620

URL: http://llvm.org/viewvc/llvm-project?rev=285620&view=rev
Log:
[asan] Move instrumented null-terminated strings to a special section, compiler-rt part

On Darwin, simple C null-terminated constant strings normally end up in the __TEXT,__cstring section of the resulting Mach-O binary. When instrumented with ASan, these strings are transformed in a way that they cannot be in __cstring (the linker unifies the content of this section and strips extra NUL bytes, which would break instrumentation), and are put into a generic __const section. This breaks some of the tools that we have: Some tools need to scan all C null-terminated strings in Mach-O binaries, and scanning all the contents of __const has a large performance penalty. This patch instead introduces a special section, __asan_cstring which will now hold the instrumented null-terminated strings.

Differential Revision: https://reviews.llvm.org/D25026


Added:
    compiler-rt/trunk/test/asan/TestCases/Darwin/cstring_section.c
Modified:
    compiler-rt/trunk/test/asan/TestCases/Darwin/odr-lto.cc

Added: compiler-rt/trunk/test/asan/TestCases/Darwin/cstring_section.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Darwin/cstring_section.c?rev=285620&view=auto
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/Darwin/cstring_section.c (added)
+++ compiler-rt/trunk/test/asan/TestCases/Darwin/cstring_section.c Mon Oct 31 13:52:32 2016
@@ -0,0 +1,17 @@
+// Test that AddressSanitizer moves constant strings into a separate section.
+
+// RUN: %clang_asan -c -o %t %s
+// RUN: llvm-objdump -s %t | FileCheck %s
+
+// Check that "Hello.\n" is in __asan_cstring and not in __cstring.
+// CHECK: Contents of section __asan_cstring:
+// CHECK: 48656c6c {{.*}} Hello.
+// CHECK: Contents of section __const:
+// CHECK-NOT: 48656c6c {{.*}} Hello.
+// CHECK: Contents of section __cstring:
+// CHECK-NOT: 48656c6c {{.*}} Hello.
+
+int main(int argc, char *argv[]) {
+  argv[0] = "Hello.\n";
+  return 0;
+}

Modified: compiler-rt/trunk/test/asan/TestCases/Darwin/odr-lto.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Darwin/odr-lto.cc?rev=285620&r1=285619&r2=285620&view=diff
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/Darwin/odr-lto.cc (original)
+++ compiler-rt/trunk/test/asan/TestCases/Darwin/odr-lto.cc Mon Oct 31 13:52:32 2016
@@ -19,9 +19,11 @@ void putstest();
 
 #if PART == 1
 
+static const char *my_global = "test\n\00abc";
+
 int main()
 {
-  fputs("test\n", stderr);
+  fputs(my_global, stderr);
   putstest();
   fprintf(stderr, "Done.\n");
   return 0;
@@ -29,9 +31,11 @@ int main()
 
 #else // PART == 1
 
+static const char *my_other_global = "test\n\00abc";
+
 void putstest()
 {
-  fputs("test\n", stderr);
+  fputs(my_other_global, stderr);
 }
 
 #endif // PART == 1




More information about the llvm-commits mailing list