[PATCH] D16371: [compiler-rt/profile] Added Hostname to .profdata file

David Li via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 29 10:14:29 PST 2016


davidxl added a comment.

Windows has native API gethostname to get host name. I suggest define portability macro

In InstrProfilingPort.h:

#define COMPILER_RT_MAX_HOSTLEN 128
#ifdef _MSC_VER
#define COMPILER_RT_GETHOSTNAME(Name, Len) gethostname(Name, Len)
#else
#define COMPILER_RT_GETHOSTNAME(Name, Len) GetHostName(Name, Len)
#define COMPILER_RT_HAS_UNAME 1
#endif

in InstrProfilingFile.c

#ifdef COMPILER_RT_HAS_UNAME
int GetHostName(char *Name, int Len) {

  struct utsname N;
  int R;
  R = uname(&N);
  memcpy(Name, N.nodename, Len);
  return R;

}
#endif

The rest of the code will be greatly simplified:

char Name[COMPILER_RT_MAX_HOSTLEN];

if (COMPILER_RT_GETHOSTNAME(Name, COMPILER_RT_MAX_HOSTLEN))

  return -1;

..


http://reviews.llvm.org/D16371





More information about the llvm-commits mailing list