<div dir="ltr">Since you are including InstrProfiling.h in WindowsMMap.c, you can probably simply just move that out of #if defined(_WIN32). <div><br></div><div>David</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Jan 5, 2016 at 4:22 PM, Nathan Slingerland via llvm-commits <span dir="ltr"><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>Hi Justin,</div><div><br></div><div>OK - it should be possible to change it to just add that file to the list of sources on Windows.</div><span class="HOEnZb"><font color="#888888"><div><br></div><div>-Nathan</div></font></span></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Jan 5, 2016 at 4:19 PM, Justin Bogner <span dir="ltr"><<a href="mailto:mail@justinbogner.com" target="_blank">mail@justinbogner.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Nathan Slingerland via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>><br>
writes:<br>
<span>> Author: slingn<br>
> Date: Tue Jan 5 11:27:01 2016<br>
> New Revision: 256848<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=256848&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=256848&view=rev</a><br>
> Log:<br>
> [PGO] Enable building compiler-rt profile support library on Windows<br>
><br>
> Summary: This change configures Windows builds to build the<br>
> complier-rt profile support library<br>
> (clang_rt.profile-i386.lib). Windows API incompatibilities in the<br>
> compiler-rt profile lib are also fixed.<br>
<br>
</span>My (-Werror) builds fail after this commit:<br>
<br>
.../llvm/projects/compiler-rt/lib/profile/WindowsMMap.c:128:20: error: ISO C requires a translation unit to contain at least one declaration [-Werror,-Wempty-translation-unit]<br>
#endif /* _WIN32 */<br>
^<br>
1 error generated.<br>
<div><div><br>
> Reviewers: davidxl, dnovillo<br>
><br>
> Subscribers: llvm-commits<br>
><br>
> Differential Revision: <a href="http://reviews.llvm.org/D15830" rel="noreferrer" target="_blank">http://reviews.llvm.org/D15830</a><br>
><br>
> Added:<br>
> compiler-rt/trunk/lib/profile/WindowsMMap.c<br>
> compiler-rt/trunk/lib/profile/WindowsMMap.h<br>
> Modified:<br>
> compiler-rt/trunk/cmake/config-ix.cmake<br>
> compiler-rt/trunk/lib/profile/CMakeLists.txt<br>
> compiler-rt/trunk/lib/profile/GCDAProfiling.c<br>
> compiler-rt/trunk/lib/profile/InstrProfilingFile.c<br>
><br>
> Modified: compiler-rt/trunk/cmake/config-ix.cmake<br>
> URL:<br>
> <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/cmake/config-ix.cmake?rev=256848&r1=256847&r2=256848&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/cmake/config-ix.cmake?rev=256848&r1=256847&r2=256848&view=diff</a><br>
> ==============================================================================<br>
> --- compiler-rt/trunk/cmake/config-ix.cmake (original)<br>
> +++ compiler-rt/trunk/cmake/config-ix.cmake Tue Jan 5 11:27:01 2016<br>
> @@ -559,7 +559,7 @@ else()<br>
> endif()<br>
><br>
> if (PROFILE_SUPPORTED_ARCH AND<br>
> - OS_NAME MATCHES "Darwin|Linux|FreeBSD")<br>
> + OS_NAME MATCHES "Darwin|Linux|FreeBSD|Windows")<br>
> set(COMPILER_RT_HAS_PROFILE TRUE)<br>
> else()<br>
> set(COMPILER_RT_HAS_PROFILE FALSE)<br>
><br>
> Modified: compiler-rt/trunk/lib/profile/CMakeLists.txt<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/profile/CMakeLists.txt?rev=256848&r1=256847&r2=256848&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/profile/CMakeLists.txt?rev=256848&r1=256847&r2=256848&view=diff</a><br>
> ==============================================================================<br>
> --- compiler-rt/trunk/lib/profile/CMakeLists.txt (original)<br>
> +++ compiler-rt/trunk/lib/profile/CMakeLists.txt Tue Jan 5 11:27:01 2016<br>
> @@ -35,7 +35,8 @@ set(PROFILE_SOURCES<br>
> InstrProfilingPlatformLinux.c<br>
> InstrProfilingPlatformOther.c<br>
> InstrProfilingRuntime.cc<br>
> - InstrProfilingUtil.c)<br>
> + InstrProfilingUtil.c<br>
> + WindowsMMap.c)<br>
><br>
> if(UNIX)<br>
> set(EXTRA_FLAGS<br>
><br>
> Modified: compiler-rt/trunk/lib/profile/GCDAProfiling.c<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/profile/GCDAProfiling.c?rev=256848&r1=256847&r2=256848&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/profile/GCDAProfiling.c?rev=256848&r1=256847&r2=256848&view=diff</a><br>
> ==============================================================================<br>
> --- compiler-rt/trunk/lib/profile/GCDAProfiling.c (original)<br>
> +++ compiler-rt/trunk/lib/profile/GCDAProfiling.c Tue Jan 5 11:27:01 2016<br>
> @@ -27,8 +27,13 @@<br>
> #include <stdio.h><br>
> #include <stdlib.h><br>
> #include <string.h><br>
> +<br>
> +#if defined(_WIN32)<br>
> +#include "WindowsMMap.h"<br>
> +#else<br>
> #include <sys/mman.h><br>
> #include <sys/file.h><br>
> +#endif<br>
><br>
> #define I386_FREEBSD (defined(__FreeBSD__) && defined(__i386__))<br>
><br>
> @@ -37,6 +42,7 @@<br>
> #endif<br>
><br>
> #if defined(_MSC_VER)<br>
> +typedef unsigned char uint8_t;<br>
> typedef unsigned int uint32_t;<br>
> typedef unsigned long long uint64_t;<br>
> #elif I386_FREEBSD<br>
><br>
> Modified: compiler-rt/trunk/lib/profile/InstrProfilingFile.c<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/profile/InstrProfilingFile.c?rev=256848&r1=256847&r2=256848&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/profile/InstrProfilingFile.c?rev=256848&r1=256847&r2=256848&view=diff</a><br>
> ==============================================================================<br>
> --- compiler-rt/trunk/lib/profile/InstrProfilingFile.c (original)<br>
> +++ compiler-rt/trunk/lib/profile/InstrProfilingFile.c Tue Jan 5 11:27:01 2016<br>
> @@ -17,6 +17,10 @@<br>
><br>
> #define UNCONST(ptr) ((void *)(uintptr_t)(ptr))<br>
><br>
> +#ifdef _MSC_VER<br>
> +#define snprintf _snprintf<br>
> +#endif<br>
> +<br>
> /* Return 1 if there is an error, otherwise return 0. */<br>
> static uint32_t fileWriter(ProfDataIOVec *IOVecs, uint32_t NumIOVecs,<br>
> void **WriterCtx) {<br>
><br>
> Added: compiler-rt/trunk/lib/profile/WindowsMMap.c<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/profile/WindowsMMap.c?rev=256848&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/profile/WindowsMMap.c?rev=256848&view=auto</a><br>
> ==============================================================================<br>
> --- compiler-rt/trunk/lib/profile/WindowsMMap.c (added)<br>
> +++ compiler-rt/trunk/lib/profile/WindowsMMap.c Tue Jan 5 11:27:01 2016<br>
> @@ -0,0 +1,128 @@<br>
> +/*<br>
> + * This code is derived from uClibc (original license follows).<br>
> + * <a href="https://git.uclibc.org/uClibc/tree/utils/mmap-windows.c" rel="noreferrer" target="_blank">https://git.uclibc.org/uClibc/tree/utils/mmap-windows.c</a><br>
> + */<br>
> + /* mmap() replacement for Windows<br>
> + *<br>
> + * Author: Mike Frysinger <<a href="mailto:vapier@gentoo.org" target="_blank">vapier@gentoo.org</a>><br>
> + * Placed into the public domain<br>
> + */<br>
> +<br>
> +/* References:<br>
> + * CreateFileMapping: <a href="http://msdn.microsoft.com/en-us/library/aa366537(VS.85).aspx" rel="noreferrer" target="_blank">http://msdn.microsoft.com/en-us/library/aa366537(VS.85).aspx</a><br>
> + * CloseHandle: <a href="http://msdn.microsoft.com/en-us/library/ms724211(VS.85).aspx" rel="noreferrer" target="_blank">http://msdn.microsoft.com/en-us/library/ms724211(VS.85).aspx</a><br>
> + * MapViewOfFile: <a href="http://msdn.microsoft.com/en-us/library/aa366761(VS.85).aspx" rel="noreferrer" target="_blank">http://msdn.microsoft.com/en-us/library/aa366761(VS.85).aspx</a><br>
> + * UnmapViewOfFile: <a href="http://msdn.microsoft.com/en-us/library/aa366882(VS.85).aspx" rel="noreferrer" target="_blank">http://msdn.microsoft.com/en-us/library/aa366882(VS.85).aspx</a><br>
> + */<br>
> +<br>
> +#if defined(_WIN32)<br>
> +<br>
> +#include "WindowsMMap.h"<br>
> +#include "InstrProfiling.h"<br>
> +<br>
> +#ifdef __USE_FILE_OFFSET64<br>
> +# define DWORD_HI(x) (x >> 32)<br>
> +# define DWORD_LO(x) ((x) & 0xffffffff)<br>
> +#else<br>
> +# define DWORD_HI(x) (0)<br>
> +# define DWORD_LO(x) (x)<br>
> +#endif<br>
> +<br>
> +COMPILER_RT_VISIBILITY<br>
> +void *mmap(void *start, size_t length, int prot, int flags, int fd, off_t offset)<br>
> +{<br>
> + if (prot & ~(PROT_READ | PROT_WRITE | PROT_EXEC))<br>
> + return MAP_FAILED;<br>
> + if (fd == -1) {<br>
> + if (!(flags & MAP_ANON) || offset)<br>
> + return MAP_FAILED;<br>
> + } else if (flags & MAP_ANON)<br>
> + return MAP_FAILED;<br>
> +<br>
> + DWORD flProtect;<br>
> + if (prot & PROT_WRITE) {<br>
> + if (prot & PROT_EXEC)<br>
> + flProtect = PAGE_EXECUTE_READWRITE;<br>
> + else<br>
> + flProtect = PAGE_READWRITE;<br>
> + } else if (prot & PROT_EXEC) {<br>
> + if (prot & PROT_READ)<br>
> + flProtect = PAGE_EXECUTE_READ;<br>
> + else if (prot & PROT_EXEC)<br>
> + flProtect = PAGE_EXECUTE;<br>
> + } else<br>
> + flProtect = PAGE_READONLY;<br>
> +<br>
> + off_t end = length + offset;<br>
> + HANDLE mmap_fd, h;<br>
> + if (fd == -1)<br>
> + mmap_fd = INVALID_HANDLE_VALUE;<br>
> + else<br>
> + mmap_fd = (HANDLE)_get_osfhandle(fd);<br>
> + h = CreateFileMapping(mmap_fd, NULL, flProtect, DWORD_HI(end), DWORD_LO(end), NULL);<br>
> + if (h == NULL)<br>
> + return MAP_FAILED;<br>
> +<br>
> + DWORD dwDesiredAccess;<br>
> + if (prot & PROT_WRITE)<br>
> + dwDesiredAccess = FILE_MAP_WRITE;<br>
> + else<br>
> + dwDesiredAccess = FILE_MAP_READ;<br>
> + if (prot & PROT_EXEC)<br>
> + dwDesiredAccess |= FILE_MAP_EXECUTE;<br>
> + if (flags & MAP_PRIVATE)<br>
> + dwDesiredAccess |= FILE_MAP_COPY;<br>
> + void *ret = MapViewOfFile(h, dwDesiredAccess, DWORD_HI(offset), DWORD_LO(offset), length);<br>
> + if (ret == NULL) {<br>
> + CloseHandle(h);<br>
> + ret = MAP_FAILED;<br>
> + }<br>
> + return ret;<br>
> +}<br>
> +<br>
> +COMPILER_RT_VISIBILITY<br>
> +void munmap(void *addr, size_t length)<br>
> +{<br>
> + UnmapViewOfFile(addr);<br>
> + /* ruh-ro, we leaked handle from CreateFileMapping() ... */<br>
> +}<br>
> +<br>
> +COMPILER_RT_VISIBILITY<br>
> +int msync(void *addr, size_t length, int flags)<br>
> +{<br>
> + if (flags & MS_INVALIDATE)<br>
> + return -1; /* Not supported. */<br>
> +<br>
> + /* Exactly one of MS_ASYNC or MS_SYNC must be specified. */<br>
> + switch (flags & (MS_ASYNC | MS_SYNC)) {<br>
> + case MS_SYNC:<br>
> + case MS_ASYNC:<br>
> + break;<br>
> + default:<br>
> + return -1;<br>
> + }<br>
> +<br>
> + if (!FlushViewOfFile(addr, length))<br>
> + return -1;<br>
> +<br>
> + if (flags & MS_SYNC) {<br>
> + /* FIXME: No longer have access to handle from CreateFileMapping(). */<br>
> + /*<br>
> + * if (!FlushFileBuffers(h))<br>
> + * return -1;<br>
> + */<br>
> + }<br>
> +<br>
> + return 0;<br>
> +}<br>
> +<br>
> +COMPILER_RT_VISIBILITY<br>
> +int flock(int fd, int operation)<br>
> +{<br>
> + return -1; /* Not supported. */<br>
> +}<br>
> +<br>
> +#undef DWORD_HI<br>
> +#undef DWORD_LO<br>
> +<br>
> +#endif /* _WIN32 */<br>
><br>
> Added: compiler-rt/trunk/lib/profile/WindowsMMap.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/profile/WindowsMMap.h?rev=256848&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/profile/WindowsMMap.h?rev=256848&view=auto</a><br>
> ==============================================================================<br>
> --- compiler-rt/trunk/lib/profile/WindowsMMap.h (added)<br>
> +++ compiler-rt/trunk/lib/profile/WindowsMMap.h Tue Jan 5 11:27:01 2016<br>
> @@ -0,0 +1,65 @@<br>
> +/*===- WindowsMMap.h - Support library for PGO instrumentation ------------===*\<br>
> +|*<br>
> +|* The LLVM Compiler Infrastructure<br>
> +|*<br>
> +|* This file is distributed under the University of Illinois Open Source<br>
> +|* License. See LICENSE.TXT for details.<br>
> +|*<br>
> +\*===----------------------------------------------------------------------===*/<br>
> +<br>
> +#ifndef PROFILE_INSTRPROFILING_WINDOWS_MMAP_H<br>
> +#define PROFILE_INSTRPROFILING_WINDOWS_MMAP_H<br>
> +<br>
> +#if defined(_WIN32)<br>
> +<br>
> +#include <BaseTsd.h><br>
> +#include <io.h><br>
> +#include <sys/types.h><br>
> +<br>
> +/*<br>
> + * mmap() flags<br>
> + */<br>
> +#define PROT_READ 0x1<br>
> +#define PROT_WRITE 0x2<br>
> +/* This flag is only available in WinXP+ */<br>
> +#ifdef FILE_MAP_EXECUTE<br>
> +#define PROT_EXEC 0x4<br>
> +#else<br>
> +#define PROT_EXEC 0x0<br>
> +#define FILE_MAP_EXECUTE 0<br>
> +#endif<br>
> +<br>
> +#define MAP_FILE 0x00<br>
> +#define MAP_SHARED 0x01<br>
> +#define MAP_PRIVATE 0x02<br>
> +#define MAP_ANONYMOUS 0x20<br>
> +#define MAP_ANON MAP_ANONYMOUS<br>
> +#define MAP_FAILED ((void *) -1)<br>
> +<br>
> +/*<br>
> + * msync() flags<br>
> + */<br>
> +#define MS_ASYNC 0x0001 /* return immediately */<br>
> +#define MS_INVALIDATE 0x0002 /* invalidate all cached data */<br>
> +#define MS_SYNC 0x0010 /* msync synchronously */<br>
> +<br>
> +/*<br>
> + * flock() operations<br>
> + */<br>
> +#define LOCK_SH 1 /* shared lock */<br>
> +#define LOCK_EX 2 /* exclusive lock */<br>
> +#define LOCK_NB 4 /* don't block when locking */<br>
> +#define LOCK_UN 8 /* unlock */<br>
> +<br>
> +void *mmap(void *start, size_t length, int prot, int flags, int fd,<br>
> + off_t offset);<br>
> +<br>
> +void munmap(void *addr, size_t length);<br>
> +<br>
> +int msync(void *addr, size_t length, int flags);<br>
> +<br>
> +int flock(int fd, int operation);<br>
> +<br>
> +#endif /* _WIN32 */<br>
> +<br>
> +#endif /* PROFILE_INSTRPROFILING_WINDOWS_MMAP_H */<br>
><br>
><br>
> _______________________________________________<br>
> llvm-commits mailing list<br>
> <a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a><br>
> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</div></div></blockquote></div><br></div>
</div></div><br>_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
<br></blockquote></div><br></div>