2015-12-10 06:46:49 +08:00
|
|
|
|
|
|
|
CHECK_CXX_SOURCE_COMPILES("
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
#include <Intrin.h> /* Workaround for PR19898. */
|
|
|
|
#include <windows.h>
|
|
|
|
#endif
|
|
|
|
int main() {
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
volatile LONG val = 1;
|
|
|
|
MemoryBarrier();
|
|
|
|
InterlockedCompareExchange(&val, 0, 1);
|
|
|
|
InterlockedIncrement(&val);
|
|
|
|
InterlockedDecrement(&val);
|
|
|
|
#else
|
|
|
|
volatile unsigned long val = 1;
|
|
|
|
__sync_synchronize();
|
|
|
|
__sync_val_compare_and_swap(&val, 1, 0);
|
|
|
|
__sync_add_and_fetch(&val, 1);
|
|
|
|
__sync_sub_and_fetch(&val, 1);
|
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
" COMPILER_RT_TARGET_HAS_ATOMICS)
|
|
|
|
|
2016-06-06 11:17:58 +08:00
|
|
|
CHECK_CXX_SOURCE_COMPILES("
|
|
|
|
#if defined(__linux__)
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
#include <fcntl.h>
|
|
|
|
int fd;
|
|
|
|
int main() {
|
|
|
|
struct flock s_flock;
|
|
|
|
|
|
|
|
s_flock.l_type = F_WRLCK;
|
|
|
|
fcntl(fd, F_SETLKW, &s_flock);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
" COMPILER_RT_TARGET_HAS_FCNTL_LCK)
|
|
|
|
|
2017-12-15 03:01:04 +08:00
|
|
|
CHECK_CXX_SOURCE_COMPILES("
|
|
|
|
#include <sys/utsname.h>
|
|
|
|
int main() {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
" COMPILER_RT_TARGET_HAS_UNAME)
|
|
|
|
|
2016-08-27 04:52:22 +08:00
|
|
|
add_compiler_rt_component(profile)
|
2014-02-18 17:33:45 +08:00
|
|
|
|
2014-04-23 02:49:32 +08:00
|
|
|
set(PROFILE_SOURCES
|
|
|
|
GCDAProfiling.c
|
|
|
|
InstrProfiling.c
|
2015-12-11 04:24:09 +08:00
|
|
|
InstrProfilingValue.c
|
2014-04-23 02:49:32 +08:00
|
|
|
InstrProfilingBuffer.c
|
|
|
|
InstrProfilingFile.c
|
2016-03-04 02:54:46 +08:00
|
|
|
InstrProfilingMerge.c
|
|
|
|
InstrProfilingMergeFile.c
|
2017-06-30 01:42:24 +08:00
|
|
|
InstrProfilingNameVar.c
|
2015-11-19 05:08:03 +08:00
|
|
|
InstrProfilingWriter.c
|
2014-04-23 02:49:32 +08:00
|
|
|
InstrProfilingPlatformDarwin.c
|
2018-07-25 11:01:35 +08:00
|
|
|
InstrProfilingPlatformFuchsia.c
|
2015-10-14 02:40:00 +08:00
|
|
|
InstrProfilingPlatformLinux.c
|
2014-04-23 02:49:32 +08:00
|
|
|
InstrProfilingPlatformOther.c
|
[InstrProf] Implement static profdata registration
Summary:
The motivating use case is eliminating duplicate profile data registered
for the same inline function in two object files. Before this change,
users would observe multiple symbol definition errors with VC link, but
links with LLD would succeed.
Users (Mozilla) have reported that PGO works well with clang-cl and LLD,
but when using LLD without this static registration, we would get into a
"relocation against a discarded section" situation. I'm not sure what
happens in that situation, but I suspect that duplicate, unused profile
information was retained. If so, this change will reduce the size of
such binaries with LLD.
Now, Windows uses static registration and is in line with all the other
platforms.
Reviewers: davidxl, wmi, inglorion, void, calixte
Subscribers: mgorny, krytarowski, eraman, fedor.sergeev, hiraditya, #sanitizers, dmajor, llvm-commits
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D57929
llvm-svn: 353547
2019-02-09 03:03:50 +08:00
|
|
|
InstrProfilingPlatformWindows.c
|
2015-07-10 01:21:52 +08:00
|
|
|
InstrProfilingRuntime.cc
|
2016-01-07 00:55:21 +08:00
|
|
|
InstrProfilingUtil.c)
|
|
|
|
|
2018-07-10 21:00:17 +08:00
|
|
|
set(PROFILE_HEADERS
|
|
|
|
InstrProfData.inc
|
|
|
|
InstrProfiling.h
|
|
|
|
InstrProfilingInternal.h
|
|
|
|
InstrProfilingPort.h
|
|
|
|
InstrProfilingUtil.h
|
|
|
|
WindowsMMap.h)
|
|
|
|
|
2016-01-07 00:55:21 +08:00
|
|
|
if(WIN32)
|
|
|
|
list(APPEND PROFILE_SOURCES WindowsMMap.c)
|
|
|
|
endif()
|
2014-03-20 11:57:33 +08:00
|
|
|
|
2018-05-10 05:24:06 +08:00
|
|
|
if(FUCHSIA OR UNIX)
|
2015-11-14 06:33:07 +08:00
|
|
|
set(EXTRA_FLAGS
|
|
|
|
-fPIC
|
|
|
|
-Wno-pedantic)
|
|
|
|
endif()
|
|
|
|
|
2015-12-10 06:46:49 +08:00
|
|
|
if(COMPILER_RT_TARGET_HAS_ATOMICS)
|
|
|
|
set(EXTRA_FLAGS
|
|
|
|
${EXTRA_FLAGS}
|
|
|
|
-DCOMPILER_RT_HAS_ATOMICS=1)
|
|
|
|
endif()
|
|
|
|
|
2016-06-06 11:17:58 +08:00
|
|
|
if(COMPILER_RT_TARGET_HAS_FCNTL_LCK)
|
|
|
|
set(EXTRA_FLAGS
|
|
|
|
${EXTRA_FLAGS}
|
|
|
|
-DCOMPILER_RT_HAS_FCNTL_LCK=1)
|
|
|
|
endif()
|
|
|
|
|
2017-12-15 03:01:04 +08:00
|
|
|
if(COMPILER_RT_TARGET_HAS_UNAME)
|
|
|
|
set(EXTRA_FLAGS
|
|
|
|
${EXTRA_FLAGS}
|
|
|
|
-DCOMPILER_RT_HAS_UNAME=1)
|
|
|
|
endif()
|
|
|
|
|
2016-06-18 02:12:50 +08:00
|
|
|
# This appears to be a C-only warning banning the use of locals in aggregate
|
|
|
|
# initializers. All other compilers accept this, though.
|
|
|
|
# nonstandard extension used : 'identifier' : cannot be initialized using address of automatic variable
|
|
|
|
append_list_if(COMPILER_RT_HAS_WD4221_FLAG /wd4221 EXTRA_FLAGS)
|
|
|
|
|
2014-04-23 02:49:32 +08:00
|
|
|
if(APPLE)
|
2015-08-26 03:53:09 +08:00
|
|
|
add_compiler_rt_runtime(clang_rt.profile
|
|
|
|
STATIC
|
2015-10-01 05:23:22 +08:00
|
|
|
OS ${PROFILE_SUPPORTED_OS}
|
2015-08-26 03:53:09 +08:00
|
|
|
ARCHS ${PROFILE_SUPPORTED_ARCH}
|
2016-06-09 00:21:35 +08:00
|
|
|
CFLAGS ${EXTRA_FLAGS}
|
2015-08-26 03:53:09 +08:00
|
|
|
SOURCES ${PROFILE_SOURCES}
|
2018-07-10 21:00:17 +08:00
|
|
|
ADDITIONAL_HEADERS ${PROFILE_HEADERS}
|
2015-08-26 03:53:09 +08:00
|
|
|
PARENT_TARGET profile)
|
2013-03-25 22:20:11 +08:00
|
|
|
else()
|
2015-08-26 03:53:09 +08:00
|
|
|
add_compiler_rt_runtime(clang_rt.profile
|
|
|
|
STATIC
|
|
|
|
ARCHS ${PROFILE_SUPPORTED_ARCH}
|
2015-11-14 06:33:07 +08:00
|
|
|
CFLAGS ${EXTRA_FLAGS}
|
2015-08-26 03:53:09 +08:00
|
|
|
SOURCES ${PROFILE_SOURCES}
|
2018-07-10 21:00:17 +08:00
|
|
|
ADDITIONAL_HEADERS ${PROFILE_HEADERS}
|
2015-08-26 03:53:09 +08:00
|
|
|
PARENT_TARGET profile)
|
2013-03-19 17:17:35 +08:00
|
|
|
endif()
|