diff options
| -rw-r--r-- | compiler-rt/lib/profile/InstrProfiling.c | 5 | ||||
| -rw-r--r-- | compiler-rt/lib/profile/InstrProfiling.h | 7 | ||||
| -rw-r--r-- | compiler-rt/lib/profile/InstrProfilingFile.c | 1 | ||||
| -rw-r--r-- | compiler-rt/test/profile/instrprof-without-libc.c | 1 | 
4 files changed, 10 insertions, 4 deletions
diff --git a/compiler-rt/lib/profile/InstrProfiling.c b/compiler-rt/lib/profile/InstrProfiling.c index d864d1bf41f..0ba504aed65 100644 --- a/compiler-rt/lib/profile/InstrProfiling.c +++ b/compiler-rt/lib/profile/InstrProfiling.c @@ -39,6 +39,8 @@ uint32_t BoolCmpXchg(void **Ptr, void *OldV, void *NewV) {    __sync_bool_compare_and_swap(Ptr, OldV, NewV)  #endif +char *(*GetEnvHook)(const char *) = 0; +  LLVM_LIBRARY_VISIBILITY uint64_t __llvm_profile_get_magic(void) {    return sizeof(void *) == sizeof(uint64_t) ? (INSTR_PROF_RAW_MAGIC_64)                                              : (INSTR_PROF_RAW_MAGIC_32); @@ -203,7 +205,8 @@ __llvm_profile_instrument_target(uint64_t TargetValue, void *Data,     data buffer. The size of the extra space is controlled by an environment     varaible. */  static unsigned getVprofExtraBytes() { -  const char *ExtraStr = getenv("LLVM_VALUE_PROF_BUFFER_EXTRA"); +  const char *ExtraStr = +      GetEnvHook ? GetEnvHook("LLVM_VALUE_PROF_BUFFER_EXTRA") : 0;    if (!ExtraStr || !ExtraStr[0])      return 1024;    return (unsigned)atoi(ExtraStr); diff --git a/compiler-rt/lib/profile/InstrProfiling.h b/compiler-rt/lib/profile/InstrProfiling.h index 54142c4227d..f62a77bccf2 100644 --- a/compiler-rt/lib/profile/InstrProfiling.h +++ b/compiler-rt/lib/profile/InstrProfiling.h @@ -19,10 +19,11 @@  #define LLVM_LIBRARY_VISIBILITY __attribute__((visibility("hidden")))  #define LLVM_SECTION(Sect) __attribute__((section(Sect))) -#define PROF_ERR(Format, ...) \ - if (getenv("LLVM_PROFILE_VERBOSE_ERRORS")) \ -   fprintf(stderr, Format, __VA_ARGS__ ); +#define PROF_ERR(Format, ...)                                                  \ +  if (GetEnvHook && GetEnvHook("LLVM_PROFILE_VERBOSE_ERRORS"))                 \ +    fprintf(stderr, Format, __VA_ARGS__); +extern char *(*GetEnvHook)(const char *);  #if defined(__FreeBSD__) && defined(__i386__) diff --git a/compiler-rt/lib/profile/InstrProfilingFile.c b/compiler-rt/lib/profile/InstrProfilingFile.c index 8e9d2dab5b4..35a3b48db84 100644 --- a/compiler-rt/lib/profile/InstrProfilingFile.c +++ b/compiler-rt/lib/profile/InstrProfilingFile.c @@ -192,6 +192,7 @@ LLVM_LIBRARY_VISIBILITY  int __llvm_profile_write_file(void) {    int rc; +  GetEnvHook = &getenv;    /* Check the filename. */    if (!__llvm_profile_CurrentFilename) {      PROF_ERR("LLVM Profile: Failed to write file : %s\n", "Filename not set"); diff --git a/compiler-rt/test/profile/instrprof-without-libc.c b/compiler-rt/test/profile/instrprof-without-libc.c index fc6c9b25b3b..f23149186cf 100644 --- a/compiler-rt/test/profile/instrprof-without-libc.c +++ b/compiler-rt/test/profile/instrprof-without-libc.c @@ -56,5 +56,6 @@ int main(int argc, const char *argv[]) {  // CHECK-SYMBOLS-NOT: _fopen  // CHECK-SYMBOLS-NOT: _fwrite  // CHECK-SYMBOLS-NOT: _getenv +// CHECK-SYMBOLS-NOT: getenv  // CHECK-SYMBOLS-NOT: _malloc  // CHECK-SYMBOLS-NOT: _open  | 

