[pkg-d-commits] [ldc] 27/149: Update profile-rt for LLVM 3.9 and 4.0.
Matthias Klumpp
mak at moszumanska.debian.org
Sun Apr 23 22:36:54 UTC 2017
This is an automated email from the git hooks/post-receive script.
mak pushed a commit to annotated tag v1.2.0
in repository ldc.
commit 46892e267f0757f89ed109e181884dd288512fe4
Author: Johan Engelen <jbc.engelen at gmail.com>
Date: Sat Jan 7 21:02:05 2017 +0100
Update profile-rt for LLVM 3.9 and 4.0.
Because of https://reviews.llvm.org/D27178 , profile-rt no longer needs ws2_32.lib on Windows (LLVM >= 4.0).
---
runtime/profile-rt/DefineBuildProfileRT.cmake | 6 +-
runtime/profile-rt/profile-rt-39/GCDAProfiling.c | 42 +++---------
.../profile-rt/profile-rt-39/InstrProfilingFile.c | 6 +-
.../profile-rt-39/InstrProfilingInternal.h | 14 ++++
.../profile-rt/profile-rt-39/InstrProfilingPort.h | 14 ++++
.../profile-rt/profile-rt-39/InstrProfilingUtil.c | 57 +++++++++++++++-
runtime/profile-rt/profile-rt-40/InstrProfiling.c | 12 +++-
runtime/profile-rt/profile-rt-40/InstrProfiling.h | 22 +++++++
.../profile-rt/profile-rt-40/InstrProfilingFile.c | 76 ++++++++++++++++------
.../profile-rt-40/InstrProfilingInternal.h | 8 ++-
.../profile-rt/profile-rt-40/InstrProfilingPort.h | 6 +-
.../profile-rt/profile-rt-40/InstrProfilingUtil.c | 14 +++-
.../profile-rt/profile-rt-40/InstrProfilingValue.c | 2 +-
runtime/profile-rt/profile-rt-40/WindowsMMap.c | 3 +
14 files changed, 217 insertions(+), 65 deletions(-)
diff --git a/runtime/profile-rt/DefineBuildProfileRT.cmake b/runtime/profile-rt/DefineBuildProfileRT.cmake
index 2ac53bb..80816ef 100644
--- a/runtime/profile-rt/DefineBuildProfileRT.cmake
+++ b/runtime/profile-rt/DefineBuildProfileRT.cmake
@@ -12,8 +12,10 @@ if (LDC_WITH_PGO)
# Omit Default Library Name from the library, so it will work with both release and debug builds
set(PROFRT_EXTRA_FLAGS "/Zl")
- # Add library needed for `gethostname`
- set(PROFRT_EXTRA_LDFLAGS "Ws2_32.lib")
+ # Add library needed for `gethostname` (LLVM <= 3.9)
+ if (NOT (LDC_LLVM_VER GREATER 309))
+ set(PROFRT_EXTRA_LDFLAGS "Ws2_32.lib")
+ endif()
else()
set(PROFRT_EXTRA_FLAGS "-fPIC -O3")
endif()
diff --git a/runtime/profile-rt/profile-rt-39/GCDAProfiling.c b/runtime/profile-rt/profile-rt-39/GCDAProfiling.c
index 1079f24..2756084 100644
--- a/runtime/profile-rt/profile-rt-39/GCDAProfiling.c
+++ b/runtime/profile-rt/profile-rt-39/GCDAProfiling.c
@@ -20,6 +20,8 @@
|*
\*===----------------------------------------------------------------------===*/
+#include "InstrProfilingInternal.h"
+#include "InstrProfilingPort.h"
#include "InstrProfilingUtil.h"
#include <errno.h>
@@ -170,44 +172,16 @@ static uint64_t read_64bit_value() {
static char *mangle_filename(const char *orig_filename) {
char *new_filename;
- size_t filename_len, prefix_len;
+ size_t prefix_len;
int prefix_strip;
- int level = 0;
- const char *fname, *ptr;
- const char *prefix = getenv("GCOV_PREFIX");
- const char *prefix_strip_str = getenv("GCOV_PREFIX_STRIP");
+ const char *prefix = lprofGetPathPrefix(&prefix_strip, &prefix_len);
- if (prefix == NULL || prefix[0] == '\0')
+ if (prefix == NULL)
return strdup(orig_filename);
- if (prefix_strip_str) {
- prefix_strip = atoi(prefix_strip_str);
-
- /* Negative GCOV_PREFIX_STRIP values are ignored */
- if (prefix_strip < 0)
- prefix_strip = 0;
- } else {
- prefix_strip = 0;
- }
-
- fname = orig_filename;
- for (level = 0, ptr = fname + 1; level < prefix_strip; ++ptr) {
- if (*ptr == '\0')
- break;
- if (*ptr != '/')
- continue;
- fname = ptr;
- ++level;
- }
-
- filename_len = strlen(fname);
- prefix_len = strlen(prefix);
- new_filename = malloc(prefix_len + 1 + filename_len + 1);
- memcpy(new_filename, prefix, prefix_len);
-
- if (prefix[prefix_len - 1] != '/')
- new_filename[prefix_len++] = '/';
- memcpy(new_filename + prefix_len, fname, filename_len + 1);
+ new_filename = malloc(prefix_len + 1 + strlen(orig_filename) + 1);
+ lprofApplyPathPrefix(new_filename, orig_filename, prefix, prefix_len,
+ prefix_strip);
return new_filename;
}
diff --git a/runtime/profile-rt/profile-rt-39/InstrProfilingFile.c b/runtime/profile-rt/profile-rt-39/InstrProfilingFile.c
index 1bd6c63..32762d1 100644
--- a/runtime/profile-rt/profile-rt-39/InstrProfilingFile.c
+++ b/runtime/profile-rt/profile-rt-39/InstrProfilingFile.c
@@ -229,7 +229,11 @@ static void truncateCurrentFile(void) {
return;
/* Create the directory holding the file, if needed. */
- if (strchr(Filename, '/') || strchr(Filename, '\\')) {
+ if (strchr(Filename, DIR_SEPARATOR)
+#if defined(DIR_SEPARATOR_2)
+ || strchr(Filename, DIR_SEPARATOR_2)
+#endif
+ ) {
char *Copy = (char *)COMPILER_RT_ALLOCA(Length + 1);
strncpy(Copy, Filename, Length + 1);
__llvm_profile_recursive_mkdir(Copy);
diff --git a/runtime/profile-rt/profile-rt-39/InstrProfilingInternal.h b/runtime/profile-rt/profile-rt-39/InstrProfilingInternal.h
index bcbe29a..44f3082 100644
--- a/runtime/profile-rt/profile-rt-39/InstrProfilingInternal.h
+++ b/runtime/profile-rt/profile-rt-39/InstrProfilingInternal.h
@@ -163,6 +163,20 @@ void lprofSetupValueProfiler();
* to dump merged profile data into its own profile file. */
uint64_t lprofGetLoadModuleSignature();
+/* GCOV_PREFIX and GCOV_PREFIX_STRIP support */
+/* Return the path prefix specified by GCOV_PREFIX environment variable.
+ * If GCOV_PREFIX_STRIP is also specified, the strip level (integer value)
+ * is returned via \c *PrefixStrip. The prefix length is stored in *PrefixLen.
+ */
+const char *lprofGetPathPrefix(int *PrefixStrip, size_t *PrefixLen);
+/* Apply the path prefix specified in \c Prefix to path string in \c PathStr,
+ * and store the result to buffer pointed to by \c Buffer. If \c PrefixStrip
+ * is not zero, path prefixes are stripped from \c PathStr (the level of
+ * stripping is specified by \c PrefixStrip) before \c Prefix is added.
+ */
+void lprofApplyPathPrefix(char *Dest, const char *PathStr, const char *Prefix,
+ size_t PrefixLen, int PrefixStrip);
+
COMPILER_RT_VISIBILITY extern char *(*GetEnvHook)(const char *);
COMPILER_RT_VISIBILITY extern void (*FreeHook)(void *);
COMPILER_RT_VISIBILITY extern uint8_t *DynamicBufferIOBuffer;
diff --git a/runtime/profile-rt/profile-rt-39/InstrProfilingPort.h b/runtime/profile-rt/profile-rt-39/InstrProfilingPort.h
index 4fd8aca..c947153 100644
--- a/runtime/profile-rt/profile-rt-39/InstrProfilingPort.h
+++ b/runtime/profile-rt/profile-rt-39/InstrProfilingPort.h
@@ -84,6 +84,20 @@
(DomType *)lprofPtrFetchAdd((void **)&PtrVar, sizeof(DomType) * PtrIncr)
#endif
+#if defined(_WIN32)
+#define DIR_SEPARATOR '\\'
+#define DIR_SEPARATOR_2 '/'
+#else
+#define DIR_SEPARATOR '/'
+#endif
+
+#ifndef DIR_SEPARATOR_2
+#define IS_DIR_SEPARATOR(ch) ((ch) == DIR_SEPARATOR)
+#else /* DIR_SEPARATOR_2 */
+#define IS_DIR_SEPARATOR(ch) \
+ (((ch) == DIR_SEPARATOR) || ((ch) == DIR_SEPARATOR_2))
+#endif /* DIR_SEPARATOR_2 */
+
#define PROF_ERR(Format, ...) \
fprintf(stderr, "LLVM Profile Error: " Format, __VA_ARGS__);
diff --git a/runtime/profile-rt/profile-rt-39/InstrProfilingUtil.c b/runtime/profile-rt/profile-rt-39/InstrProfilingUtil.c
index be10121..5c66933 100644
--- a/runtime/profile-rt/profile-rt-39/InstrProfilingUtil.c
+++ b/runtime/profile-rt/profile-rt-39/InstrProfilingUtil.c
@@ -26,6 +26,7 @@
#include <sys/utsname.h>
#endif
+#include <stdlib.h>
#include <string.h>
COMPILER_RT_VISIBILITY
@@ -103,8 +104,9 @@ COMPILER_RT_VISIBILITY FILE *lprofOpenFileEx(const char *ProfileName) {
f = fdopen(fd, "r+b");
#elif defined(_WIN32)
- HANDLE h = CreateFile(ProfileName, GENERIC_READ | GENERIC_WRITE, 0, 0,
- OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
+ // FIXME: Use the wide variants to handle Unicode filenames.
+ HANDLE h = CreateFileA(ProfileName, GENERIC_READ | GENERIC_WRITE, 0, 0,
+ OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
if (h == INVALID_HANDLE_VALUE)
return NULL;
@@ -131,3 +133,54 @@ COMPILER_RT_VISIBILITY FILE *lprofOpenFileEx(const char *ProfileName) {
return f;
}
+
+COMPILER_RT_VISIBILITY const char *lprofGetPathPrefix(int *PrefixStrip,
+ size_t *PrefixLen) {
+ const char *Prefix = getenv("GCOV_PREFIX");
+ const char *PrefixStripStr = getenv("GCOV_PREFIX_STRIP");
+
+ *PrefixLen = 0;
+ *PrefixStrip = 0;
+ if (Prefix == NULL || Prefix[0] == '\0')
+ return NULL;
+
+ if (PrefixStripStr) {
+ *PrefixStrip = atoi(PrefixStripStr);
+
+ /* Negative GCOV_PREFIX_STRIP values are ignored */
+ if (*PrefixStrip < 0)
+ *PrefixStrip = 0;
+ } else {
+ *PrefixStrip = 0;
+ }
+ *PrefixLen = strlen(Prefix);
+
+ return Prefix;
+}
+
+COMPILER_RT_VISIBILITY void
+lprofApplyPathPrefix(char *Dest, const char *PathStr, const char *Prefix,
+ size_t PrefixLen, int PrefixStrip) {
+
+ const char *Ptr;
+ int Level;
+ const char *StrippedPathStr = PathStr;
+
+ for (Level = 0, Ptr = PathStr + 1; Level < PrefixStrip; ++Ptr) {
+ if (*Ptr == '\0')
+ break;
+
+ if (!IS_DIR_SEPARATOR(*Ptr))
+ continue;
+
+ StrippedPathStr = Ptr;
+ ++Level;
+ }
+
+ memcpy(Dest, Prefix, PrefixLen);
+
+ if (!IS_DIR_SEPARATOR(Prefix[PrefixLen - 1]))
+ Dest[PrefixLen++] = DIR_SEPARATOR;
+
+ memcpy(Dest + PrefixLen, StrippedPathStr, strlen(StrippedPathStr) + 1);
+}
diff --git a/runtime/profile-rt/profile-rt-40/InstrProfiling.c b/runtime/profile-rt/profile-rt-40/InstrProfiling.c
index b7ba25f..6828a3d 100644
--- a/runtime/profile-rt/profile-rt-40/InstrProfiling.c
+++ b/runtime/profile-rt/profile-rt-40/InstrProfiling.c
@@ -16,7 +16,6 @@
#define INSTR_PROF_VALUE_PROF_DATA
#include "InstrProfData.inc"
-COMPILER_RT_VISIBILITY char *(*GetEnvHook)(const char *) = 0;
COMPILER_RT_WEAK uint64_t INSTR_PROF_RAW_VERSION_VAR = INSTR_PROF_RAW_VERSION;
@@ -27,6 +26,16 @@ COMPILER_RT_VISIBILITY uint64_t __llvm_profile_get_magic(void) {
: (INSTR_PROF_RAW_MAGIC_32);
}
+static unsigned ProfileDumped = 0;
+
+COMPILER_RT_VISIBILITY unsigned lprofProfileDumped() {
+ return ProfileDumped;
+}
+
+COMPILER_RT_VISIBILITY void lprofSetProfileDumped() {
+ ProfileDumped = 1;
+}
+
/* Return the number of bytes needed to add to SizeInBytes to make it
* the result a multiple of 8.
*/
@@ -68,4 +77,5 @@ COMPILER_RT_VISIBILITY void __llvm_profile_reset_counters(void) {
}
}
}
+ ProfileDumped = 0;
}
diff --git a/runtime/profile-rt/profile-rt-40/InstrProfiling.h b/runtime/profile-rt/profile-rt-40/InstrProfiling.h
index 0ffb402..945f1c4 100644
--- a/runtime/profile-rt/profile-rt-40/InstrProfiling.h
+++ b/runtime/profile-rt/profile-rt-40/InstrProfiling.h
@@ -118,6 +118,28 @@ void INSTR_PROF_VALUE_PROF_FUNC(
int __llvm_profile_write_file(void);
/*!
+ * \brief this is a wrapper interface to \c __llvm_profile_write_file.
+ * After this interface is invoked, a arleady dumped flag will be set
+ * so that profile won't be dumped again during program exit.
+ * Invocation of interface __llvm_profile_reset_counters will clear
+ * the flag. This interface is designed to be used to collect profile
+ * data from user selected hot regions. The use model is
+ * __llvm_profile_reset_counters();
+ * ... hot region 1
+ * __llvm_profile_dump();
+ * .. some other code
+ * __llvm_profile_reset_counters();
+ * ... hot region 2
+ * __llvm_profile_dump();
+ *
+ * It is expected that on-line profile merging is on with \c %m specifier
+ * used in profile filename . If merging is not turned on, user is expected
+ * to invoke __llvm_profile_set_filename to specify different profile names
+ * for different regions before dumping to avoid profile write clobbering.
+ */
+int __llvm_profile_dump(void);
+
+/*!
* \brief Set the filename for writing instrumentation data.
*
* Sets the filename to be used for subsequent calls to
diff --git a/runtime/profile-rt/profile-rt-40/InstrProfilingFile.c b/runtime/profile-rt/profile-rt-40/InstrProfilingFile.c
index 6b4b9cd..f82080c 100644
--- a/runtime/profile-rt/profile-rt-40/InstrProfilingFile.c
+++ b/runtime/profile-rt/profile-rt-40/InstrProfilingFile.c
@@ -59,10 +59,13 @@ static const char *getPNSStr(ProfileNameSpecifier PNS) {
}
#define MAX_PID_SIZE 16
-/* Data structure holding the result of parsed filename pattern. */
+/* Data structure holding the result of parsed filename pattern. */
typedef struct lprofFilename {
/* File name string possibly with %p or %h specifiers. */
const char *FilenamePat;
+ /* A flag indicating if FilenamePat's memory is allocated
+ * by runtime. */
+ unsigned OwnsFilenamePat;
const char *ProfilePathPrefix;
char PidChars[MAX_PID_SIZE];
char Hostname[COMPILER_RT_MAX_HOSTLEN];
@@ -79,7 +82,8 @@ typedef struct lprofFilename {
ProfileNameSpecifier PNS;
} lprofFilename;
-lprofFilename lprofCurFilename = {0, 0, {0}, {0}, 0, 0, 0, PNS_unknown};
+COMPILER_RT_WEAK lprofFilename lprofCurFilename = {0, 0, 0, {0}, {0},
+ 0, 0, 0, PNS_unknown};
int getpid(void);
static int getCurFilenameLength();
@@ -250,6 +254,9 @@ static void truncateCurrentFile(void) {
static const char *DefaultProfileName = "default.profraw";
static void resetFilenameToDefault(void) {
+ if (lprofCurFilename.FilenamePat && lprofCurFilename.OwnsFilenamePat) {
+ free((void *)lprofCurFilename.FilenamePat);
+ }
memset(&lprofCurFilename, 0, sizeof(lprofCurFilename));
lprofCurFilename.FilenamePat = DefaultProfileName;
lprofCurFilename.PNS = PNS_default;
@@ -265,7 +272,8 @@ static int containsMergeSpecifier(const char *FilenamePat, int I) {
/* Parses the pattern string \p FilenamePat and stores the result to
* lprofcurFilename structure. */
-static int parseFilenamePattern(const char *FilenamePat) {
+static int parseFilenamePattern(const char *FilenamePat,
+ unsigned CopyFilenamePat) {
int NumPids = 0, NumHosts = 0, I;
char *PidChars = &lprofCurFilename.PidChars[0];
char *Hostname = &lprofCurFilename.Hostname[0];
@@ -276,25 +284,34 @@ static int parseFilenamePattern(const char *FilenamePat) {
free((void *)lprofCurFilename.ProfilePathPrefix);
memset(&lprofCurFilename, 0, sizeof(lprofCurFilename));
- lprofCurFilename.FilenamePat = FilenamePat;
+ if (lprofCurFilename.FilenamePat && lprofCurFilename.OwnsFilenamePat) {
+ free((void *)lprofCurFilename.FilenamePat);
+ }
+
+ if (!CopyFilenamePat)
+ lprofCurFilename.FilenamePat = FilenamePat;
+ else {
+ lprofCurFilename.FilenamePat = strdup(FilenamePat);
+ lprofCurFilename.OwnsFilenamePat = 1;
+ }
/* Check the filename for "%p", which indicates a pid-substitution. */
for (I = 0; FilenamePat[I]; ++I)
if (FilenamePat[I] == '%') {
if (FilenamePat[++I] == 'p') {
if (!NumPids++) {
if (snprintf(PidChars, MAX_PID_SIZE, "%d", getpid()) <= 0) {
- PROF_WARN(
- "Unable to parse filename pattern %s. Using the default name.",
- FilenamePat);
+ PROF_WARN("Unable to get pid for filename pattern %s. Using the "
+ "default name.",
+ FilenamePat);
return -1;
}
}
} else if (FilenamePat[I] == 'h') {
if (!NumHosts++)
if (COMPILER_RT_GETHOSTNAME(Hostname, COMPILER_RT_MAX_HOSTLEN)) {
- PROF_WARN(
- "Unable to parse filename pattern %s. Using the default name.",
- FilenamePat);
+ PROF_WARN("Unable to get hostname for filename pattern %s. Using "
+ "the default name.",
+ FilenamePat);
return -1;
}
} else if (containsMergeSpecifier(FilenamePat, I)) {
@@ -319,7 +336,8 @@ static int parseFilenamePattern(const char *FilenamePat) {
}
static void parseAndSetFilename(const char *FilenamePat,
- ProfileNameSpecifier PNS) {
+ ProfileNameSpecifier PNS,
+ unsigned CopyFilenamePat) {
const char *OldFilenamePat = lprofCurFilename.FilenamePat;
ProfileNameSpecifier OldPNS = lprofCurFilename.PNS;
@@ -336,17 +354,19 @@ static void parseAndSetFilename(const char *FilenamePat,
}
/* When PNS >= OldPNS, the last one wins. */
- if (!FilenamePat || parseFilenamePattern(FilenamePat))
+ if (!FilenamePat || parseFilenamePattern(FilenamePat, CopyFilenamePat))
resetFilenameToDefault();
lprofCurFilename.PNS = PNS;
if (!OldFilenamePat) {
- PROF_NOTE("Set profile file path to \"%s\" via %s.\n",
- lprofCurFilename.FilenamePat, getPNSStr(PNS));
+ if (getenv("LLVM_PROFILE_VERBOSE"))
+ PROF_NOTE("Set profile file path to \"%s\" via %s.\n",
+ lprofCurFilename.FilenamePat, getPNSStr(PNS));
} else {
- PROF_NOTE("Override old profile path \"%s\" via %s to \"%s\" via %s.\n",
- OldFilenamePat, getPNSStr(OldPNS), lprofCurFilename.FilenamePat,
- getPNSStr(PNS));
+ if (getenv("LLVM_PROFILE_VERBOSE"))
+ PROF_NOTE("Override old profile path \"%s\" via %s to \"%s\" via %s.\n",
+ OldFilenamePat, getPNSStr(OldPNS), lprofCurFilename.FilenamePat,
+ getPNSStr(PNS));
}
truncateCurrentFile();
@@ -483,7 +503,7 @@ void __llvm_profile_initialize_file(void) {
PNS = PNS_default;
}
- parseAndSetFilename(SelectedPat, PNS);
+ parseAndSetFilename(SelectedPat, PNS, 0);
}
/* This API is directly called by the user application code. It has the
@@ -492,7 +512,7 @@ void __llvm_profile_initialize_file(void) {
*/
COMPILER_RT_VISIBILITY
void __llvm_profile_set_filename(const char *FilenamePat) {
- parseAndSetFilename(FilenamePat, PNS_runtime_api);
+ parseAndSetFilename(FilenamePat, PNS_runtime_api, 1);
}
/* The public API for writing profile data into the file with name
@@ -505,6 +525,12 @@ int __llvm_profile_write_file(void) {
const char *Filename;
char *FilenameBuf;
+ if (lprofProfileDumped()) {
+ PROF_NOTE("Profile data not written to file: %s.\n",
+ "already written");
+ return 0;
+ }
+
Length = getCurFilenameLength();
FilenameBuf = (char *)COMPILER_RT_ALLOCA(Length + 1);
Filename = getCurFilename(FilenameBuf);
@@ -531,6 +557,18 @@ int __llvm_profile_write_file(void) {
return rc;
}
+COMPILER_RT_VISIBILITY
+int __llvm_profile_dump(void) {
+ if (!doMerging())
+ PROF_WARN("Later invocation of __llvm_profile_dump can lead to clobbering "
+ " of previously dumped profile data : %s. Either use %%m "
+ "in profile name or change profile name before dumping.\n",
+ "online profile merging is not on");
+ int rc = __llvm_profile_write_file();
+ lprofSetProfileDumped();
+ return rc;
+}
+
static void writeFileWithoutReturn(void) { __llvm_profile_write_file(); }
COMPILER_RT_VISIBILITY
diff --git a/runtime/profile-rt/profile-rt-40/InstrProfilingInternal.h b/runtime/profile-rt/profile-rt-40/InstrProfilingInternal.h
index bcbe29a..c73b291 100644
--- a/runtime/profile-rt/profile-rt-40/InstrProfilingInternal.h
+++ b/runtime/profile-rt/profile-rt-40/InstrProfilingInternal.h
@@ -163,7 +163,13 @@ void lprofSetupValueProfiler();
* to dump merged profile data into its own profile file. */
uint64_t lprofGetLoadModuleSignature();
-COMPILER_RT_VISIBILITY extern char *(*GetEnvHook)(const char *);
+/*
+ * Return non zero value if the profile data has already been
+ * dumped to the file.
+ */
+unsigned lprofProfileDumped();
+void lprofSetProfileDumped();
+
COMPILER_RT_VISIBILITY extern void (*FreeHook)(void *);
COMPILER_RT_VISIBILITY extern uint8_t *DynamicBufferIOBuffer;
COMPILER_RT_VISIBILITY extern uint32_t VPBufferSize;
diff --git a/runtime/profile-rt/profile-rt-40/InstrProfilingPort.h b/runtime/profile-rt/profile-rt-40/InstrProfilingPort.h
index c947153..5789351 100644
--- a/runtime/profile-rt/profile-rt-40/InstrProfilingPort.h
+++ b/runtime/profile-rt/profile-rt-40/InstrProfilingPort.h
@@ -40,14 +40,14 @@
#endif
#define COMPILER_RT_MAX_HOSTLEN 128
-#ifdef _MSC_VER
-#define COMPILER_RT_GETHOSTNAME(Name, Len) gethostname(Name, Len)
-#elif defined(__ORBIS__)
+#ifdef __ORBIS__
#define COMPILER_RT_GETHOSTNAME(Name, Len) ((void)(Name), (void)(Len), (-1))
#else
#define COMPILER_RT_GETHOSTNAME(Name, Len) lprofGetHostName(Name, Len)
+#ifndef _MSC_VER
#define COMPILER_RT_HAS_UNAME 1
#endif
+#endif
#if COMPILER_RT_HAS_ATOMICS == 1
#ifdef _MSC_VER
diff --git a/runtime/profile-rt/profile-rt-40/InstrProfilingUtil.c b/runtime/profile-rt/profile-rt-40/InstrProfilingUtil.c
index ead537d..321c719 100644
--- a/runtime/profile-rt/profile-rt-40/InstrProfilingUtil.c
+++ b/runtime/profile-rt/profile-rt-40/InstrProfilingUtil.c
@@ -66,7 +66,19 @@ void *lprofPtrFetchAdd(void **Mem, long ByteIncr) {
#endif
-#ifdef COMPILER_RT_HAS_UNAME
+#ifdef _MSC_VER
+COMPILER_RT_VISIBILITY int lprofGetHostName(char *Name, int Len) {
+ WCHAR Buffer[COMPILER_RT_MAX_HOSTLEN];
+ DWORD BufferSize = sizeof(Buffer);
+ BOOL Result =
+ GetComputerNameExW(ComputerNameDnsFullyQualified, Buffer, &BufferSize);
+ if (!Result)
+ return -1;
+ if (WideCharToMultiByte(CP_UTF8, 0, Buffer, -1, Name, Len, NULL, NULL) == 0)
+ return -1;
+ return 0;
+}
+#elif defined(COMPILER_RT_HAS_UNAME)
COMPILER_RT_VISIBILITY int lprofGetHostName(char *Name, int Len) {
struct utsname N;
int R;
diff --git a/runtime/profile-rt/profile-rt-40/InstrProfilingValue.c b/runtime/profile-rt/profile-rt-40/InstrProfilingValue.c
index 93957e3..6648f89 100644
--- a/runtime/profile-rt/profile-rt-40/InstrProfilingValue.c
+++ b/runtime/profile-rt/profile-rt-40/InstrProfilingValue.c
@@ -192,7 +192,7 @@ __llvm_profile_instrument_target(uint64_t TargetValue, void *Data,
* the runtime can wipe out more than one lowest count entries
* to give space for hot targets.
*/
- if (!(--MinCountVNode->Count)) {
+ if (!MinCountVNode->Count || !(--MinCountVNode->Count)) {
CurVNode = MinCountVNode;
CurVNode->Value = TargetValue;
CurVNode->Count++;
diff --git a/runtime/profile-rt/profile-rt-40/WindowsMMap.c b/runtime/profile-rt/profile-rt-40/WindowsMMap.c
index 1f73420..f81d7da 100644
--- a/runtime/profile-rt/profile-rt-40/WindowsMMap.c
+++ b/runtime/profile-rt/profile-rt-40/WindowsMMap.c
@@ -20,6 +20,9 @@
#include "WindowsMMap.h"
#include "InstrProfiling.h"
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+
#ifdef __USE_FILE_OFFSET64
# define DWORD_HI(x) (x >> 32)
# define DWORD_LO(x) ((x) & 0xffffffff)
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-d/ldc.git
More information about the pkg-d-commits
mailing list