[PGO] Stop leaking libc function to buffer API impl

llvm-svn: 254943
This commit is contained in:
Xinliang David Li 2015-12-07 21:18:16 +00:00
parent a1c712fae5
commit 55d927a4fd
4 changed files with 10 additions and 4 deletions

View File

@ -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);

View File

@ -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__)

View File

@ -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");

View File

@ -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