summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Davis <Matthew.Davis@sony.com>2018-07-31 23:37:24 +0000
committerMatt Davis <Matthew.Davis@sony.com>2018-07-31 23:37:24 +0000
commit89e8af6d9616ee01b7a669162b0094230d62d701 (patch)
tree1ce26c81e6484473d77428941a12cada5a6e480b
parent96beffba15bce42e086fde5569a67c5bbf4243ee (diff)
downloadbcm5719-llvm-89e8af6d9616ee01b7a669162b0094230d62d701.tar.gz
bcm5719-llvm-89e8af6d9616ee01b7a669162b0094230d62d701.zip
[compiler-rt] Add a routine to specify the mode used when creating profile dirs.
Summary: This patch introduces `llvm_profile_set_dir_mode` and `llvm_profile_get_dir_mode` to the compiler-rt profile API. Originally, profile data was placed into a directory that was created with a hard-coded mode value of 0755 (for non-win32 builds). In certain cases, it can be helpful to create directories with a different mode other than 0755. This patch introduces set/get routines to allow users to specify a desired mode. The default remains at 0755. Reviewers: void, probinson Reviewed By: probinson Subscribers: probinson, dberris, cfe-commits Differential Revision: https://reviews.llvm.org/D49953 llvm-svn: 338456
-rw-r--r--compiler-rt/lib/profile/InstrProfilingUtil.c11
-rw-r--r--compiler-rt/lib/profile/InstrProfilingUtil.h6
-rw-r--r--compiler-rt/test/profile/instrprof-set-dir-mode.c48
3 files changed, 64 insertions, 1 deletions
diff --git a/compiler-rt/lib/profile/InstrProfilingUtil.c b/compiler-rt/lib/profile/InstrProfilingUtil.c
index d053ab160ca..083bf14a326 100644
--- a/compiler-rt/lib/profile/InstrProfilingUtil.c
+++ b/compiler-rt/lib/profile/InstrProfilingUtil.c
@@ -35,6 +35,8 @@
#include "InstrProfiling.h"
#include "InstrProfilingUtil.h"
+COMPILER_RT_WEAK unsigned lprofDirMode = 0755;
+
COMPILER_RT_VISIBILITY
void __llvm_profile_recursive_mkdir(char *path) {
int i;
@@ -47,12 +49,19 @@ void __llvm_profile_recursive_mkdir(char *path) {
#ifdef _WIN32
_mkdir(path);
#else
- mkdir(path, 0755); /* Some of these will fail, ignore it. */
+ /* Some of these will fail, ignore it. */
+ mkdir(path, __llvm_profile_get_dir_mode());
#endif
path[i] = save;
}
}
+COMPILER_RT_VISIBILITY
+void __llvm_profile_set_dir_mode(unsigned Mode) { lprofDirMode = Mode; }
+
+COMPILER_RT_VISIBILITY
+unsigned __llvm_profile_get_dir_mode(void) { return lprofDirMode; }
+
#if COMPILER_RT_HAS_ATOMICS != 1
COMPILER_RT_VISIBILITY
uint32_t lprofBoolCmpXchg(void **Ptr, void *OldV, void *NewV) {
diff --git a/compiler-rt/lib/profile/InstrProfilingUtil.h b/compiler-rt/lib/profile/InstrProfilingUtil.h
index 2f2ea1b876a..147677fc870 100644
--- a/compiler-rt/lib/profile/InstrProfilingUtil.h
+++ b/compiler-rt/lib/profile/InstrProfilingUtil.h
@@ -16,6 +16,12 @@
/*! \brief Create a directory tree. */
void __llvm_profile_recursive_mkdir(char *Pathname);
+/*! Set the mode used when creating profile directories. */
+void __llvm_profile_set_dir_mode(unsigned Mode);
+
+/*! Return the directory creation mode. */
+unsigned __llvm_profile_get_dir_mode(void);
+
int lprofLockFd(int fd);
int lprofUnlockFd(int fd);
diff --git a/compiler-rt/test/profile/instrprof-set-dir-mode.c b/compiler-rt/test/profile/instrprof-set-dir-mode.c
new file mode 100644
index 00000000000..25eb29db533
--- /dev/null
+++ b/compiler-rt/test/profile/instrprof-set-dir-mode.c
@@ -0,0 +1,48 @@
+// UNSUPPORTED: windows
+// RUN: %clang_pgogen -o %t.bin %s -DTESTPATH=\"%t.dir\"
+// RUN: rm -rf %t.dir
+// RUN: %run %t.bin
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+
+void __llvm_profile_set_dir_mode(unsigned Mode);
+unsigned __llvm_profile_get_dir_mode(void);
+void __llvm_profile_recursive_mkdir(char *Path);
+
+static int test(unsigned Mode, const char *TestDir) {
+ int Ret = 0;
+
+ /* Create a dir and set the mode accordingly. */
+ char *Dir = strdup(TestDir);
+ if (!Dir)
+ return -1;
+ __llvm_profile_set_dir_mode(Mode);
+ __llvm_profile_recursive_mkdir(Dir);
+
+ if (Mode != __llvm_profile_get_dir_mode())
+ Ret = -1;
+ else {
+ const unsigned Expected = ~umask(0) & Mode;
+ struct stat DirSt;
+ if (stat(Dir, &DirSt) == -1)
+ Ret = -1;
+ else if (DirSt.st_mode != Expected) {
+ printf("Modes do not match: Expected %o but found %o (%s)\n", Expected,
+ DirSt.st_mode, Dir);
+ Ret = -1;
+ }
+ }
+
+ free(Dir);
+ return Ret;
+}
+
+int main(void) {
+ if (test(S_IFDIR | 0777, TESTPATH "/foo/bar/baz/") ||
+ test(S_IFDIR | 0666, TESTPATH "/foo/bar/qux/"))
+ return -1;
+ return 0;
+}
OpenPOWER on IntegriCloud