[PATCH] D49953: [compiler-rt] Add a routine to specify the mode used when creating profile dirs.
Matt Davis via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Jul 27 20:31:22 PDT 2018
mattd created this revision.
mattd added a reviewer: void.
Herald added a subscriber: dberris.
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.
https://reviews.llvm.org/D49953
Files:
lib/profile/InstrProfilingUtil.c
lib/profile/InstrProfilingUtil.h
test/profile/instrprof-set-dir-mode.c
Index: test/profile/instrprof-set-dir-mode.c
===================================================================
--- /dev/null
+++ test/profile/instrprof-set-dir-mode.c
@@ -0,0 +1,17 @@
+// RUN: %clang_pgogen -o %t %s
+// RUN: %run %t
+
+void __llvm_profile_set_dir_mode(unsigned Mode);
+unsigned __llvm_profile_get_dir_mode(void);
+
+int main(void) {
+ __llvm_profile_set_dir_mode(0777);
+ if (__llvm_profile_get_dir_mode() != 0777)
+ return -1;
+
+ __llvm_profile_set_dir_mode(0666);
+ if (__llvm_profile_get_dir_mode() != 0666)
+ return -1;
+
+ return 0;
+}
Index: lib/profile/InstrProfilingUtil.h
===================================================================
--- lib/profile/InstrProfilingUtil.h
+++ 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);
Index: lib/profile/InstrProfilingUtil.c
===================================================================
--- lib/profile/InstrProfilingUtil.c
+++ 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 @@
#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) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D49953.157833.patch
Type: text/x-patch
Size: 2108 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180728/2924bacc/attachment-0001.bin>
More information about the cfe-commits
mailing list