[PGO] Improve prof library portability

Patch by: Johan Engelen

Introduce LLVM_LIBRARY_WEAK macro. Define LLVM_LIBRARY_WEAK
and LLVM_LIBRARY_VISIBIITY for MSVC

llvm-svn: 255688
diff --git a/compiler-rt/lib/profile/InstrProfilingFile.c b/compiler-rt/lib/profile/InstrProfilingFile.c
index 4fc7693..ac0eeff 100644
--- a/compiler-rt/lib/profile/InstrProfilingFile.c
+++ b/compiler-rt/lib/profile/InstrProfilingFile.c
@@ -56,8 +56,8 @@
   return RetVal;
 }
 
-__attribute__((weak)) int __llvm_profile_OwnsFilename = 0;
-__attribute__((weak)) const char *__llvm_profile_CurrentFilename = NULL;
+LLVM_LIBRARY_WEAK int __llvm_profile_OwnsFilename = 0;
+LLVM_LIBRARY_WEAK const char *__llvm_profile_CurrentFilename = NULL;
 
 static void truncateCurrentFile(void) {
   const char *Filename;
diff --git a/compiler-rt/lib/profile/InstrProfilingPort.h b/compiler-rt/lib/profile/InstrProfilingPort.h
index 977dc63..12f5ca7 100644
--- a/compiler-rt/lib/profile/InstrProfilingPort.h
+++ b/compiler-rt/lib/profile/InstrProfilingPort.h
@@ -11,12 +11,15 @@
 #define PROFILE_INSTRPROFILING_PORT_H_
 
 #ifdef _MSC_VER
-# define LLVM_ALIGNAS(x) __declspec(align(x))
+#define LLVM_ALIGNAS(x) __declspec(align(x))
+#define LLVM_LIBRARY_VISIBILITY
+#define LLVM_LIBRARY_WEAK __declspec(selectany)
 #elif __GNUC__
 #define LLVM_ALIGNAS(x) __attribute__((aligned(x)))
+#define LLVM_LIBRARY_VISIBILITY __attribute__((visibility("hidden")))
+#define LLVM_LIBRARY_WEAK __attribute__((weak))
 #endif
 
-#define LLVM_LIBRARY_VISIBILITY __attribute__((visibility("hidden")))
 #define LLVM_SECTION(Sect) __attribute__((section(Sect)))
 
 #define PROF_ERR(Format, ...)                                                  \
diff --git a/compiler-rt/lib/profile/InstrProfilingRuntime.cc b/compiler-rt/lib/profile/InstrProfilingRuntime.cc
index 081ecb2..77fca47 100644
--- a/compiler-rt/lib/profile/InstrProfilingRuntime.cc
+++ b/compiler-rt/lib/profile/InstrProfilingRuntime.cc
@@ -11,8 +11,7 @@
 
 #include "InstrProfiling.h"
 
-__attribute__((visibility("hidden"))) int __llvm_profile_runtime;
-
+LLVM_LIBRARY_VISIBILITY int __llvm_profile_runtime;
 }
 
 namespace {