summaryrefslogtreecommitdiffstats
path: root/compiler-rt/test/builtins/Unit/enable_execute_stack_test.c
diff options
context:
space:
mode:
authorReid Kleckner <rnk@google.com>2017-04-07 16:35:09 +0000
committerReid Kleckner <rnk@google.com>2017-04-07 16:35:09 +0000
commit8c78ca2e8f14ba15dbfcee13259806fff0649735 (patch)
treed87d25aa957f4ade3edb875383977416508c9212 /compiler-rt/test/builtins/Unit/enable_execute_stack_test.c
parent478b81982f3457c47ab02e4fee3fbd880eb88d3a (diff)
downloadbcm5719-llvm-8c78ca2e8f14ba15dbfcee13259806fff0649735.tar.gz
bcm5719-llvm-8c78ca2e8f14ba15dbfcee13259806fff0649735.zip
[builtins] Get the builtins tests passing on Windows
Many things were broken: - We stopped building most builtins on Windows in r261432 for reasons that are not at all clear to me. This essentially reverts that patch. - Fix %librt to expand to clang_rt.builtins-$arch.lib on Windows instead of libclang_rt.builtins-$arch.a. - Fix memory protection tests (trampoline, enable executable, clear cache) on Windows. One issue was that the MSVC incremental linker generates ILT thunks for functions with external linkage, so memcpying the functions into the executable stack buffer wasn't working. You can't memcpy an RIP-relative jump without fixing up the offset. - Disable tests that rely on C99 complex library functions when using the MSVC CRT, which isn't compatible with clang's C99 _Complex. In theory, these could all be separate patches, but it would not green the tests, so let's try for it all at once. Hopefully this fixes the clang-x64-ninja-win7 bot. llvm-svn: 299780
Diffstat (limited to 'compiler-rt/test/builtins/Unit/enable_execute_stack_test.c')
-rw-r--r--compiler-rt/test/builtins/Unit/enable_execute_stack_test.c32
1 files changed, 4 insertions, 28 deletions
diff --git a/compiler-rt/test/builtins/Unit/enable_execute_stack_test.c b/compiler-rt/test/builtins/Unit/enable_execute_stack_test.c
index 24165ed9fb7..72fc042e6dc 100644
--- a/compiler-rt/test/builtins/Unit/enable_execute_stack_test.c
+++ b/compiler-rt/test/builtins/Unit/enable_execute_stack_test.c
@@ -13,39 +13,14 @@
#include <stdio.h>
#include <string.h>
#include <stdint.h>
-#if defined(_WIN32)
-#include <windows.h>
-void __clear_cache(void* start, void* end)
-{
- if (!FlushInstructionCache(GetCurrentProcess(), start, end-start))
- exit(1);
-}
-void __enable_execute_stack(void *addr)
-{
- MEMORY_BASIC_INFORMATION b;
-
- if (!VirtualQuery(addr, &b, sizeof(b)))
- exit(1);
- if (!VirtualProtect(b.BaseAddress, b.RegionSize, PAGE_EXECUTE_READWRITE, &b.Protect))
- exit(1);
-}
-#else
-#include <sys/mman.h>
extern void __clear_cache(void* start, void* end);
extern void __enable_execute_stack(void* addr);
-#endif
typedef int (*pfunc)(void);
-int func1()
-{
- return 1;
-}
-
-int func2()
-{
- return 2;
-}
+// Make these static to avoid ILT jumps for incremental linking on Windows.
+static int func1() { return 1; }
+static int func2() { return 2; }
void *__attribute__((noinline))
memcpy_f(void *dst, const void *src, size_t n) {
@@ -69,6 +44,7 @@ int main()
// verify you can copy and execute a function
pfunc f1 = (pfunc)memcpy_f(execution_buffer, func1, 128);
__clear_cache(execution_buffer, &execution_buffer[128]);
+ printf("f1: %p\n", f1);
if ((*f1)() != 1)
return 1;
OpenPOWER on IntegriCloud