[compiler-rt] r299780 - [builtins] Get the builtins tests passing on Windows
Reid Kleckner via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 7 09:35:10 PDT 2017
Author: rnk
Date: Fri Apr 7 11:35:09 2017
New Revision: 299780
URL: http://llvm.org/viewvc/llvm-project?rev=299780&view=rev
Log:
[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.
Modified:
compiler-rt/trunk/lib/builtins/CMakeLists.txt
compiler-rt/trunk/test/builtins/CMakeLists.txt
compiler-rt/trunk/test/builtins/Unit/clear_cache_test.c
compiler-rt/trunk/test/builtins/Unit/divdc3_test.c
compiler-rt/trunk/test/builtins/Unit/divsc3_test.c
compiler-rt/trunk/test/builtins/Unit/divtc3_test.c
compiler-rt/trunk/test/builtins/Unit/divxc3_test.c
compiler-rt/trunk/test/builtins/Unit/enable_execute_stack_test.c
compiler-rt/trunk/test/builtins/Unit/lit.cfg
compiler-rt/trunk/test/builtins/Unit/lit.site.cfg.in
compiler-rt/trunk/test/builtins/Unit/muldc3_test.c
compiler-rt/trunk/test/builtins/Unit/mulsc3_test.c
compiler-rt/trunk/test/builtins/Unit/mulxc3_test.c
compiler-rt/trunk/test/builtins/Unit/trampoline_setup_test.c
Modified: compiler-rt/trunk/lib/builtins/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/builtins/CMakeLists.txt?rev=299780&r1=299779&r2=299780&view=diff
==============================================================================
--- compiler-rt/trunk/lib/builtins/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/builtins/CMakeLists.txt Fri Apr 7 11:35:09 2017
@@ -176,15 +176,6 @@ if(COMPILER_RT_HAS_ATOMIC_KEYWORD AND NO
atomic.c)
endif()
-set(MSVC_SOURCES
- divsc3.c
- divdc3.c
- divxc3.c
- mulsc3.c
- muldc3.c
- mulxc3.c)
-
-
if(APPLE)
set(GENERIC_SOURCES
${GENERIC_SOURCES}
@@ -264,9 +255,9 @@ else () # MSVC
x86_64/floatdidf.c
x86_64/floatdisf.c
x86_64/floatdixf.c
- ${MSVC_SOURCES})
+ ${GENERIC_SOURCES})
set(x86_64h_SOURCES ${x86_64_SOURCES})
- set(i386_SOURCES ${MSVC_SOURCES})
+ set(i386_SOURCES ${GENERIC_SOURCES})
set(i686_SOURCES ${i386_SOURCES})
endif () # if (NOT MSVC)
Modified: compiler-rt/trunk/test/builtins/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/builtins/CMakeLists.txt?rev=299780&r1=299779&r2=299780&view=diff
==============================================================================
--- compiler-rt/trunk/test/builtins/CMakeLists.txt (original)
+++ compiler-rt/trunk/test/builtins/CMakeLists.txt Fri Apr 7 11:35:09 2017
@@ -13,6 +13,8 @@ configure_lit_site_cfg(
include(builtin-config-ix)
+pythonize_bool(MSVC)
+
#TODO: Add support for Apple.
if (NOT APPLE)
foreach(arch ${BUILTIN_SUPPORTED_ARCH})
Modified: compiler-rt/trunk/test/builtins/Unit/clear_cache_test.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/builtins/Unit/clear_cache_test.c?rev=299780&r1=299779&r2=299780&view=diff
==============================================================================
--- compiler-rt/trunk/test/builtins/Unit/clear_cache_test.c (original)
+++ compiler-rt/trunk/test/builtins/Unit/clear_cache_test.c Fri Apr 7 11:35:09 2017
@@ -16,12 +16,6 @@
#include <stdint.h>
#if defined(_WIN32)
#include <windows.h>
-void __clear_cache(void* start, void* end)
-{
- if (!FlushInstructionCache(GetCurrentProcess(), start, end-start))
- exit(1);
-}
-
static uintptr_t get_page_size() {
SYSTEM_INFO si;
GetSystemInfo(&si);
@@ -30,27 +24,20 @@ static uintptr_t get_page_size() {
#else
#include <unistd.h>
#include <sys/mman.h>
-extern void __clear_cache(void* start, void* end);
static uintptr_t get_page_size() {
return sysconf(_SC_PAGE_SIZE);
}
#endif
-
+extern void __clear_cache(void* start, void* end);
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) {
Modified: compiler-rt/trunk/test/builtins/Unit/divdc3_test.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/builtins/Unit/divdc3_test.c?rev=299780&r1=299779&r2=299780&view=diff
==============================================================================
--- compiler-rt/trunk/test/builtins/Unit/divdc3_test.c (original)
+++ compiler-rt/trunk/test/builtins/Unit/divdc3_test.c Fri Apr 7 11:35:09 2017
@@ -17,6 +17,8 @@
#include <complex.h>
#include <stdio.h>
+// REQUIRES: c99-complex
+
// Returns: the quotient of (a + ib) / (c + id)
COMPILER_RT_ABI double _Complex
Modified: compiler-rt/trunk/test/builtins/Unit/divsc3_test.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/builtins/Unit/divsc3_test.c?rev=299780&r1=299779&r2=299780&view=diff
==============================================================================
--- compiler-rt/trunk/test/builtins/Unit/divsc3_test.c (original)
+++ compiler-rt/trunk/test/builtins/Unit/divsc3_test.c Fri Apr 7 11:35:09 2017
@@ -17,6 +17,8 @@
#include <complex.h>
#include <stdio.h>
+// REQUIRES: c99-complex
+
// Returns: the quotient of (a + ib) / (c + id)
COMPILER_RT_ABI float _Complex
Modified: compiler-rt/trunk/test/builtins/Unit/divtc3_test.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/builtins/Unit/divtc3_test.c?rev=299780&r1=299779&r2=299780&view=diff
==============================================================================
--- compiler-rt/trunk/test/builtins/Unit/divtc3_test.c (original)
+++ compiler-rt/trunk/test/builtins/Unit/divtc3_test.c Fri Apr 7 11:35:09 2017
@@ -18,6 +18,8 @@
#include <math.h>
#include <complex.h>
+// REQUIRES: c99-complex
+
// Returns: the quotient of (a + ib) / (c + id)
COMPILER_RT_ABI long double _Complex
Modified: compiler-rt/trunk/test/builtins/Unit/divxc3_test.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/builtins/Unit/divxc3_test.c?rev=299780&r1=299779&r2=299780&view=diff
==============================================================================
--- compiler-rt/trunk/test/builtins/Unit/divxc3_test.c (original)
+++ compiler-rt/trunk/test/builtins/Unit/divxc3_test.c Fri Apr 7 11:35:09 2017
@@ -19,6 +19,8 @@
#include <complex.h>
#include <stdio.h>
+// REQUIRES: c99-complex
+
// Returns: the quotient of (a + ib) / (c + id)
COMPILER_RT_ABI long double _Complex
Modified: compiler-rt/trunk/test/builtins/Unit/enable_execute_stack_test.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/builtins/Unit/enable_execute_stack_test.c?rev=299780&r1=299779&r2=299780&view=diff
==============================================================================
--- compiler-rt/trunk/test/builtins/Unit/enable_execute_stack_test.c (original)
+++ compiler-rt/trunk/test/builtins/Unit/enable_execute_stack_test.c Fri Apr 7 11:35:09 2017
@@ -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;
Modified: compiler-rt/trunk/test/builtins/Unit/lit.cfg
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/builtins/Unit/lit.cfg?rev=299780&r1=299779&r2=299780&view=diff
==============================================================================
--- compiler-rt/trunk/test/builtins/Unit/lit.cfg (original)
+++ compiler-rt/trunk/test/builtins/Unit/lit.cfg Fri Apr 7 11:35:09 2017
@@ -24,15 +24,21 @@ default_builtins_opts = ''
config.test_source_root = os.path.dirname(__file__)
# Path to the static library
-base_lib = os.path.join(config.compiler_rt_libdir, "libclang_rt.builtins-%s.a "
- % config.target_arch)
+is_msvc = get_required_attr(config, "builtins_is_msvc")
+if is_msvc:
+ base_lib = os.path.join(config.compiler_rt_libdir, "clang_rt.builtins-%s.lib "
+ % config.target_arch)
+ config.substitutions.append( ("%librt ", base_lib) )
+else:
+ base_lib = os.path.join(config.compiler_rt_libdir, "libclang_rt.builtins-%s.a"
+ % config.target_arch)
+ config.substitutions.append( ("%librt ", base_lib + ' -lc -lm ') )
builtins_source_dir = os.path.join(
get_required_attr(config, "compiler_rt_src_root"), "lib", "builtins")
builtins_lit_source_dir = get_required_attr(config, "builtins_lit_source_dir")
extra_link_flags = ["-nodefaultlibs"]
-config.substitutions.append( ("%librt ", base_lib + ' -lc -lm ') )
target_cflags = [get_required_attr(config, "target_cflags")]
target_cflags += ['-fno-builtin', '-I', builtins_source_dir]
@@ -46,6 +52,8 @@ clang_builtins_static_cxxflags = config.
clang_builtins_cflags = clang_builtins_static_cflags
clang_builtins_cxxflags = clang_builtins_static_cxxflags
+if not is_msvc:
+ config.available_features.add('c99-complex')
config.available_features.add('not-android')
clang_wrapper = ""
Modified: compiler-rt/trunk/test/builtins/Unit/lit.site.cfg.in
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/builtins/Unit/lit.site.cfg.in?rev=299780&r1=299779&r2=299780&view=diff
==============================================================================
--- compiler-rt/trunk/test/builtins/Unit/lit.site.cfg.in (original)
+++ compiler-rt/trunk/test/builtins/Unit/lit.site.cfg.in Fri Apr 7 11:35:09 2017
@@ -4,7 +4,7 @@ config.name_suffix = "@BUILTINS_TEST_CON
config.builtins_lit_source_dir = "@BUILTINS_LIT_SOURCE_DIR@/Unit"
config.target_cflags = "@BUILTINS_TEST_TARGET_CFLAGS@"
config.target_arch = "@BUILTINS_TEST_TARGET_ARCH@"
-
+config.builtins_is_msvc = "@MSVC_PYBOOL@"
# Load common config for all compiler-rt lit tests.
lit_config.load_config(config, "@COMPILER_RT_BINARY_DIR@/test/lit.common.configured")
Modified: compiler-rt/trunk/test/builtins/Unit/muldc3_test.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/builtins/Unit/muldc3_test.c?rev=299780&r1=299779&r2=299780&view=diff
==============================================================================
--- compiler-rt/trunk/test/builtins/Unit/muldc3_test.c (original)
+++ compiler-rt/trunk/test/builtins/Unit/muldc3_test.c Fri Apr 7 11:35:09 2017
@@ -17,6 +17,8 @@
#include <complex.h>
#include <stdio.h>
+// REQUIRES: c99-complex
+
// Returns: the product of a + ib and c + id
COMPILER_RT_ABI double _Complex
Modified: compiler-rt/trunk/test/builtins/Unit/mulsc3_test.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/builtins/Unit/mulsc3_test.c?rev=299780&r1=299779&r2=299780&view=diff
==============================================================================
--- compiler-rt/trunk/test/builtins/Unit/mulsc3_test.c (original)
+++ compiler-rt/trunk/test/builtins/Unit/mulsc3_test.c Fri Apr 7 11:35:09 2017
@@ -19,6 +19,8 @@
#include <complex.h>
#include <stdio.h>
+// REQUIRES: c99-complex
+
// Returns: the product of a + ib and c + id
COMPILER_RT_ABI float _Complex
Modified: compiler-rt/trunk/test/builtins/Unit/mulxc3_test.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/builtins/Unit/mulxc3_test.c?rev=299780&r1=299779&r2=299780&view=diff
==============================================================================
--- compiler-rt/trunk/test/builtins/Unit/mulxc3_test.c (original)
+++ compiler-rt/trunk/test/builtins/Unit/mulxc3_test.c Fri Apr 7 11:35:09 2017
@@ -19,6 +19,8 @@
#include <complex.h>
#include <stdio.h>
+// REQUIRES: c99-complex
+
// Returns: the product of a + ib and c + id
COMPILER_RT_ABI long double _Complex
Modified: compiler-rt/trunk/test/builtins/Unit/trampoline_setup_test.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/builtins/Unit/trampoline_setup_test.c?rev=299780&r1=299779&r2=299780&view=diff
==============================================================================
--- compiler-rt/trunk/test/builtins/Unit/trampoline_setup_test.c (original)
+++ compiler-rt/trunk/test/builtins/Unit/trampoline_setup_test.c Fri Apr 7 11:35:09 2017
@@ -13,7 +13,6 @@
#include <stdio.h>
#include <string.h>
#include <stdint.h>
-#include <sys/mman.h>
/*
* Tests nested functions
More information about the llvm-commits
mailing list