summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans Wennborg <hans@hanshq.net>2015-07-23 23:03:42 +0000
committerHans Wennborg <hans@hanshq.net>2015-07-23 23:03:42 +0000
commite9383780c609f3fad3b85cbfb11dce2caff773ee (patch)
tree72d866212e13d7a25200bf766a74c5d4100e58c3
parent7e43caf78b07fd99dd5a2ad3e611b5ca6abb0c03 (diff)
downloadcompiler-rt-e9383780c609f3fad3b85cbfb11dce2caff773ee.tar.gz
Merging r242539 and r242540:
------------------------------------------------------------------------ r242539 | rnk | 2015-07-17 09:23:05 -0700 (Fri, 17 Jul 2015) | 14 lines compiler-rt: add support for mingw-w64 in builtins The is so that we can avoid using libgcc and use compiler-rt with mingw-w64. Related driver patch http://reviews.llvm.org/D11077 I have tested this with mingw-w64 and everything seems to be in order. I also sent this patch to the mingw-w64 mailing list for them to look at. Patch by Martell Malone. Differential Revision: http://reviews.llvm.org/D11085 ------------------------------------------------------------------------ ------------------------------------------------------------------------ r242540 | rnk | 2015-07-17 09:31:59 -0700 (Fri, 17 Jul 2015) | 1 line Add missing chkstk.S files from r242539 ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/branches/release_37@243059 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--CMakeLists.txt2
-rw-r--r--lib/builtins/CMakeLists.txt14
-rw-r--r--lib/builtins/enable_execute_stack.c14
-rw-r--r--lib/builtins/i386/chkstk.S34
-rw-r--r--lib/builtins/x86_64/chkstk.S39
5 files changed, 101 insertions, 2 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 66334869a..e147e3096 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -164,7 +164,7 @@ set(COMPILER_RT_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
# We support running instrumented tests when we're not cross compiling
# and target a UNIX-like system or Windows.
# We can run tests on Android even when we are cross-compiling.
-if(("${CMAKE_HOST_SYSTEM}" STREQUAL "${CMAKE_SYSTEM}" AND (UNIX OR MSVC)) OR ANDROID
+if(("${CMAKE_HOST_SYSTEM}" STREQUAL "${CMAKE_SYSTEM}" AND (UNIX OR WIN32)) OR ANDROID
OR COMPILER_RT_EMULATOR)
option(COMPILER_RT_CAN_EXECUTE_TESTS "Can we execute instrumented tests" ON)
else()
diff --git a/lib/builtins/CMakeLists.txt b/lib/builtins/CMakeLists.txt
index d79feae13..98d518a83 100644
--- a/lib/builtins/CMakeLists.txt
+++ b/lib/builtins/CMakeLists.txt
@@ -154,6 +154,12 @@ set(x86_64_SOURCES
x86_64/floatundixf.S
${GENERIC_SOURCES})
+if(WIN32)
+ set(x86_64_SOURCES
+ ${x86_64_SOURCES}
+ x86_64/chkstk.S)
+endif()
+
set(i386_SOURCES
i386/ashldi3.S
i386/ashrdi3.S
@@ -171,6 +177,12 @@ set(i386_SOURCES
i386/umoddi3.S
${GENERIC_SOURCES})
+if(WIN32)
+ set(i386_SOURCES
+ ${i386_SOURCES}
+ i386/chkstk.S)
+endif()
+
set(i686_SOURCES
${i386_SOURCES})
@@ -260,7 +272,7 @@ set(arm_SOURCES
add_custom_target(builtins)
-if (NOT WIN32)
+if (NOT WIN32 OR MINGW)
foreach (arch x86_64 i386 i686 arm)
if (CAN_TARGET_${arch})
# Filter out generic versions of routines that are re-implemented in
diff --git a/lib/builtins/enable_execute_stack.c b/lib/builtins/enable_execute_stack.c
index 63d836b31..23e494051 100644
--- a/lib/builtins/enable_execute_stack.c
+++ b/lib/builtins/enable_execute_stack.c
@@ -10,7 +10,9 @@
#include "int_lib.h"
+#ifndef _WIN32
#include <sys/mman.h>
+#endif
/* #include "config.h"
* FIXME: CMake - include when cmake system is ready.
@@ -18,9 +20,14 @@
*/
#define HAVE_SYSCONF 1
+#ifdef _WIN32
+#include <windef.h>
+#include <winbase.h>
+#else
#ifndef __APPLE__
#include <unistd.h>
#endif /* __APPLE__ */
+#endif /* _WIN32 */
#if __LP64__
#define TRAMPOLINE_SIZE 48
@@ -40,6 +47,12 @@ COMPILER_RT_ABI void
__enable_execute_stack(void* addr)
{
+#if _WIN32
+ MEMORY_BASIC_INFORMATION mbi;
+ if (!VirtualQuery (addr, &mbi, sizeof(mbi)))
+ return; /* We should probably assert here because there is no return value */
+ VirtualProtect (mbi.BaseAddress, mbi.RegionSize, PAGE_EXECUTE_READWRITE, &mbi.Protect);
+#else
#if __APPLE__
/* On Darwin, pagesize is always 4096 bytes */
const uintptr_t pageSize = 4096;
@@ -55,4 +68,5 @@ __enable_execute_stack(void* addr)
unsigned char* endPage = (unsigned char*)((p+TRAMPOLINE_SIZE+pageSize) & pageAlignMask);
size_t length = endPage - startPage;
(void) mprotect((void *)startPage, length, PROT_READ | PROT_WRITE | PROT_EXEC);
+#endif
}
diff --git a/lib/builtins/i386/chkstk.S b/lib/builtins/i386/chkstk.S
new file mode 100644
index 000000000..3733d722e
--- /dev/null
+++ b/lib/builtins/i386/chkstk.S
@@ -0,0 +1,34 @@
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+
+#include "../assembly.h"
+
+// _chkstk routine
+// This routine is windows specific
+// http://msdn.microsoft.com/en-us/library/ms648426.aspx
+
+#ifdef __i386__
+
+.text
+.balign 4
+DEFINE_COMPILERRT_FUNCTION(__chkstk_ms)
+ push %ecx
+ push %eax
+ cmp $0x1000,%eax
+ lea 12(%esp),%ecx
+ jb 1f
+2:
+ sub $0x1000,%ecx
+ orl $0,(%ecx)
+ sub $0x1000,%eax
+ cmp $0x1000,%eax
+ ja 2b
+1:
+ sub %eax,%ecx
+ orl $0,(%ecx)
+ pop %eax
+ pop %ecx
+ ret
+END_COMPILERRT_FUNCTION(__chkstk_ms)
+
+#endif // __i386__
diff --git a/lib/builtins/x86_64/chkstk.S b/lib/builtins/x86_64/chkstk.S
new file mode 100644
index 000000000..5759e8449
--- /dev/null
+++ b/lib/builtins/x86_64/chkstk.S
@@ -0,0 +1,39 @@
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+
+#include "../assembly.h"
+
+// _chkstk routine
+// This routine is windows specific
+// http://msdn.microsoft.com/en-us/library/ms648426.aspx
+
+// Notes from r227519
+// MSVC x64s __chkstk and cygmings ___chkstk_ms do not adjust %rsp
+// themselves. It also does not clobber %rax so we can reuse it when
+// adjusting %rsp.
+
+#ifdef __x86_64__
+
+.text
+.balign 4
+DEFINE_COMPILERRT_FUNCTION(___chkstk_ms)
+ push %rcx
+ push %rax
+ cmp $0x1000,%rax
+ lea 24(%rsp),%rcx
+ jb 1f
+2:
+ sub $0x1000,%rcx
+ orl $0,(%rcx)
+ sub $0x1000,%rax
+ cmp $0x1000,%rax
+ ja 2b
+1:
+ sub %rax,%rcx
+ orl $0,(%rcx)
+ pop %rax
+ pop %rcx
+ ret
+END_COMPILERRT_FUNCTION(___chkstk_ms)
+
+#endif // __x86_64__