[compiler-rt] r254943 - [PGO] Stop leaking libc function to buffer API impl
Xinliang David Li via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 7 13:18:17 PST 2015
Author: davidxl
Date: Mon Dec 7 15:18:16 2015
New Revision: 254943
URL: http://llvm.org/viewvc/llvm-project?rev=254943&view=rev
Log:
[PGO] Stop leaking libc function to buffer API impl
Modified:
compiler-rt/trunk/lib/profile/InstrProfiling.c
compiler-rt/trunk/lib/profile/InstrProfiling.h
compiler-rt/trunk/lib/profile/InstrProfilingFile.c
compiler-rt/trunk/test/profile/instrprof-without-libc.c
Modified: compiler-rt/trunk/lib/profile/InstrProfiling.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/profile/InstrProfiling.c?rev=254943&r1=254942&r2=254943&view=diff
==============================================================================
--- compiler-rt/trunk/lib/profile/InstrProfiling.c (original)
+++ compiler-rt/trunk/lib/profile/InstrProfiling.c Mon Dec 7 15:18:16 2015
@@ -39,6 +39,8 @@ uint32_t BoolCmpXchg(void **Ptr, void *O
__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_
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);
Modified: compiler-rt/trunk/lib/profile/InstrProfiling.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/profile/InstrProfiling.h?rev=254943&r1=254942&r2=254943&view=diff
==============================================================================
--- compiler-rt/trunk/lib/profile/InstrProfiling.h (original)
+++ compiler-rt/trunk/lib/profile/InstrProfiling.h Mon Dec 7 15:18:16 2015
@@ -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__)
Modified: compiler-rt/trunk/lib/profile/InstrProfilingFile.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/profile/InstrProfilingFile.c?rev=254943&r1=254942&r2=254943&view=diff
==============================================================================
--- compiler-rt/trunk/lib/profile/InstrProfilingFile.c (original)
+++ compiler-rt/trunk/lib/profile/InstrProfilingFile.c Mon Dec 7 15:18:16 2015
@@ -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");
Modified: compiler-rt/trunk/test/profile/instrprof-without-libc.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/profile/instrprof-without-libc.c?rev=254943&r1=254942&r2=254943&view=diff
==============================================================================
--- compiler-rt/trunk/test/profile/instrprof-without-libc.c (original)
+++ compiler-rt/trunk/test/profile/instrprof-without-libc.c Mon Dec 7 15:18:16 2015
@@ -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
More information about the llvm-commits
mailing list