[compiler-rt] r367064 - [profile] In Android, do not mkdir() dirs in GCOV_PREFIX

Pirama Arumuga Nainar via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 25 15:10:56 PDT 2019


Author: pirama
Date: Thu Jul 25 15:10:56 2019
New Revision: 367064

URL: http://llvm.org/viewvc/llvm-project?rev=367064&view=rev
Log:
[profile] In Android, do not mkdir() dirs in GCOV_PREFIX

Summary:
In Android, attempting to mkdir() or even stat() top-level directories
like /data causes noisy selinux denials.  During whole-system coverage
instrumentation, this causes a deluge of noisy messages that drown out
legitimate selinux denials, that should be audited and fixed.

To avoid this, skip creating any directory in GCOV_PREFIX (thereby
assuming that it exists).

- Android platform ensures that the GCOV_PREFIX used in Android is
created and read/writable by all processes.
- This only affects the Android platform (by checking against
__ANDROID_API_FUTURE__) and for apps built with Clang coverage, the
runtime will still create any non-existent parent directories for the
coverage files.

Reviewers: srhines, davidxl

Subscribers: krytarowski, #sanitizers, danalbert, llvm-commits

Tags: #sanitizers, #llvm

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

Modified:
    compiler-rt/trunk/lib/profile/InstrProfilingUtil.c

Modified: compiler-rt/trunk/lib/profile/InstrProfilingUtil.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/profile/InstrProfilingUtil.c?rev=367064&r1=367063&r2=367064&view=diff
==============================================================================
--- compiler-rt/trunk/lib/profile/InstrProfilingUtil.c (original)
+++ compiler-rt/trunk/lib/profile/InstrProfilingUtil.c Thu Jul 25 15:10:56 2019
@@ -39,8 +39,25 @@ COMPILER_RT_WEAK unsigned lprofDirMode =
 COMPILER_RT_VISIBILITY
 void __llvm_profile_recursive_mkdir(char *path) {
   int i;
+  int start = 1;
 
-  for (i = 1; path[i] != '\0'; ++i) {
+#if defined(__ANDROID__) && defined(__ANDROID_API__) &&                        \
+    defined(__ANDROID_API_FUTURE__) &&                                         \
+    __ANDROID_API__ == __ANDROID_API_FUTURE__
+  // Avoid spammy selinux denial messages in Android by not attempting to
+  // create directories in GCOV_PREFIX.  These denials occur when creating (or
+  // even attempting to stat()) top-level directories like "/data".
+  //
+  // Do so by ignoring ${GCOV_PREFIX} when invoking mkdir().
+  const char *gcov_prefix = getenv("GCOV_PREFIX");
+  if (gcov_prefix != NULL) {
+    const int gcov_prefix_len = strlen(gcov_prefix);
+    if (strncmp(path, gcov_prefix, gcov_prefix_len) == 0)
+      start = gcov_prefix_len;
+  }
+#endif
+
+  for (i = start; path[i] != '\0'; ++i) {
     char save = path[i];
     if (!IS_DIR_SEPARATOR(path[i]))
       continue;




More information about the llvm-commits mailing list