Skip to content
This repository was archived by the owner on Dec 20, 2019. It is now read-only.

Commit e0ed7c0

Browse files
committed
Misc. fixes for builtins lib on Windows
* Include ASM files when using MSVC-compatible clang-cl.exe as C compiler (and its assembler supporting AT&T syntax). * Disable buffer overflow checks to prevent dependencies on special MS C symbols. => /GS- * Use `/Zl` to prevent dragging in libcmt.lib. * Mark all i386 ASM files as SafeSEH-compatible on Win32.
1 parent 1dd2eb5 commit e0ed7c0

18 files changed

+59
-3
lines changed

lib/builtins/CMakeLists.txt

+8-3
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ set(x86_ARCH_SOURCES
240240
powixf2.c
241241
)
242242

243-
if (NOT MSVC)
243+
if (NOT CMAKE_ASM_COMPILER_ID MATCHES "MSVC")
244244
set(x86_64_SOURCES
245245
${GENERIC_TF_SOURCES}
246246
x86_64/floatdidf.c
@@ -286,7 +286,7 @@ if (NOT MSVC)
286286
i386/chkstk2.S
287287
)
288288
endif()
289-
else () # MSVC
289+
else () # MSVC assembler
290290
# Use C versions of functions when building on MSVC
291291
# MSVC's assembler takes Intel syntax, not AT&T syntax.
292292
# Also use only MSVC compilable builtin implementations.
@@ -298,12 +298,17 @@ else () # MSVC
298298
)
299299
set(x86_64h_SOURCES ${x86_64_SOURCES})
300300
set(i386_SOURCES ${GENERIC_SOURCES})
301-
endif () # if (NOT MSVC)
301+
endif ()
302302

303303
set(x86_64h_SOURCES ${x86_64h_SOURCES} ${x86_ARCH_SOURCES})
304304
set(x86_64_SOURCES ${x86_64_SOURCES} ${x86_ARCH_SOURCES})
305305
set(i386_SOURCES ${i386_SOURCES} ${x86_ARCH_SOURCES})
306306
set(i686_SOURCES ${i686_SOURCES} ${x86_ARCH_SOURCES})
307+
if (MSVC)
308+
set_source_files_properties(
309+
${x86_64h_SOURCES} ${x86_64_SOURCES} ${i386_SOURCES} ${i686_SOURCES}
310+
PROPERTIES COMPILE_FLAGS "/GS- /Zl")
311+
endif()
307312

308313
set(arm_SOURCES
309314
arm/bswapdi2.S

lib/builtins/i386/ashldi3.S

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
44

55
#include "../assembly.h"
6+
#include "safeseh.h"
67

78
// di_int __ashldi3(di_int input, int count);
89

@@ -17,6 +18,7 @@
1718
#ifdef __SSE2__
1819

1920
.text
21+
WIN32_SAFE_SEH_HEADER
2022
.balign 4
2123
DEFINE_COMPILERRT_FUNCTION(__ashldi3)
2224
movd 12(%esp), %xmm2 // Load count
@@ -37,6 +39,7 @@ END_COMPILERRT_FUNCTION(__ashldi3)
3739
#else // Use GPRs instead of SSE2 instructions, if they aren't available.
3840

3941
.text
42+
WIN32_SAFE_SEH_HEADER
4043
.balign 4
4144
DEFINE_COMPILERRT_FUNCTION(__ashldi3)
4245
movl 12(%esp), %ecx // Load count

lib/builtins/i386/ashrdi3.S

+3
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
44

55
#include "../assembly.h"
6+
#include "safeseh.h"
67

78
// di_int __ashrdi3(di_int input, int count);
89

910
#ifdef __i386__
1011
#ifdef __SSE2__
1112

1213
.text
14+
WIN32_SAFE_SEH_HEADER
1315
.balign 4
1416
DEFINE_COMPILERRT_FUNCTION(__ashrdi3)
1517
movd 12(%esp), %xmm2 // Load count
@@ -47,6 +49,7 @@ END_COMPILERRT_FUNCTION(__ashrdi3)
4749
#else // Use GPRs instead of SSE2 instructions, if they aren't available.
4850

4951
.text
52+
WIN32_SAFE_SEH_HEADER
5053
.balign 4
5154
DEFINE_COMPILERRT_FUNCTION(__ashrdi3)
5255
movl 12(%esp), %ecx // Load count

lib/builtins/i386/chkstk.S

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
44

55
#include "../assembly.h"
6+
#include "safeseh.h"
67

78
// _chkstk routine
89
// This routine is windows specific
@@ -11,6 +12,7 @@
1112
#ifdef __i386__
1213

1314
.text
15+
WIN32_SAFE_SEH_HEADER
1416
.balign 4
1517
DEFINE_COMPILERRT_FUNCTION(__chkstk_ms)
1618
push %ecx

lib/builtins/i386/chkstk2.S

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
44

55
#include "../assembly.h"
6+
#include "safeseh.h"
67

78
#ifdef __i386__
89

@@ -12,6 +13,7 @@
1213
// http://msdn.microsoft.com/en-us/library/ms648426.aspx
1314

1415
.text
16+
WIN32_SAFE_SEH_HEADER
1517
.balign 4
1618
DEFINE_COMPILERRT_FUNCTION(_alloca) // _chkstk and _alloca are the same function
1719
DEFINE_COMPILERRT_FUNCTION(__chkstk)

lib/builtins/i386/divdi3.S

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
44

55
#include "../assembly.h"
6+
#include "safeseh.h"
67

78
// di_int __divdi3(di_int a, di_int b);
89

@@ -20,6 +21,7 @@
2021
#ifdef __i386__
2122

2223
.text
24+
WIN32_SAFE_SEH_HEADER
2325
.balign 4
2426
DEFINE_COMPILERRT_FUNCTION(__divdi3)
2527

lib/builtins/i386/floatdidf.S

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
44

55
#include "../assembly.h"
6+
#include "safeseh.h"
67

78
// double __floatundidf(du_int a);
89

@@ -21,6 +22,7 @@ twop32:
2122
#define REL_ADDR(_a) (_a)-0b(%eax)
2223

2324
.text
25+
WIN32_SAFE_SEH_HEADER
2426
.balign 4
2527
DEFINE_COMPILERRT_FUNCTION(__floatdidf)
2628
cvtsi2sd 8(%esp), %xmm1

lib/builtins/i386/floatdisf.S

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
44

55
#include "../assembly.h"
6+
#include "safeseh.h"
67

78
// float __floatdisf(di_int a);
89

@@ -16,6 +17,7 @@
1617
#ifdef __i386__
1718

1819
.text
20+
WIN32_SAFE_SEH_HEADER
1921
.balign 4
2022
DEFINE_COMPILERRT_FUNCTION(__floatdisf)
2123
#ifndef TRUST_CALLERS_USE_64_BIT_STORES

lib/builtins/i386/floatdixf.S

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
44

55
#include "../assembly.h"
6+
#include "safeseh.h"
67

78
// float __floatdixf(di_int a);
89

@@ -16,6 +17,7 @@
1617
// It can be turned off by defining the TRUST_CALLERS_USE_64_BIT_STORES macro.
1718

1819
.text
20+
WIN32_SAFE_SEH_HEADER
1921
.balign 4
2022
DEFINE_COMPILERRT_FUNCTION(__floatdixf)
2123
#ifndef TRUST_CALLERS_USE_64_BIT_STORES

lib/builtins/i386/floatundidf.S

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
#include "../assembly.h"
14+
#include "safeseh.h"
1415

1516
// double __floatundidf(du_int a);
1617

@@ -33,6 +34,7 @@ twop84:
3334
#define REL_ADDR(_a) (_a)-0b(%eax)
3435

3536
.text
37+
WIN32_SAFE_SEH_HEADER
3638
.balign 4
3739
DEFINE_COMPILERRT_FUNCTION(__floatundidf)
3840
movss 8(%esp), %xmm1 // high 32 bits of a

lib/builtins/i386/floatundisf.S

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
44

55
#include "../assembly.h"
6+
#include "safeseh.h"
67

78
// float __floatundisf(du_int a);
89

@@ -28,6 +29,7 @@ twop64: .quad 0x0000000000000000
2829
#define TWOp64 twop64-0b(%ecx,%eax,8)
2930
3031
.text
32+
WIN32_SAFE_SEH_HEADER
3133
.balign 4
3234
DEFINE_COMPILERRT_FUNCTION(__floatundisf)
3335
movl 8(%esp), %eax
@@ -73,6 +75,7 @@ twelve:
7375
#define STICKY sticky-0b(%ecx,%eax,8)
7476

7577
.text
78+
WIN32_SAFE_SEH_HEADER
7679
.balign 4
7780
DEFINE_COMPILERRT_FUNCTION(__floatundisf)
7881
movl 8(%esp), %eax

lib/builtins/i386/floatundixf.S

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
44

55
#include "../assembly.h"
6+
#include "safeseh.h"
67

78
// long double __floatundixf(du_int a);16
89

@@ -25,6 +26,7 @@ twop84:
2526
#define REL_ADDR(_a) (_a)-0b(%eax)
2627

2728
.text
29+
WIN32_SAFE_SEH_HEADER
2830
.balign 4
2931
DEFINE_COMPILERRT_FUNCTION(__floatundixf)
3032
calll 0f

lib/builtins/i386/lshrdi3.S

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
44

55
#include "../assembly.h"
6+
#include "safeseh.h"
67

78
// di_int __lshrdi3(di_int input, int count);
89

@@ -17,6 +18,7 @@
1718
#ifdef __SSE2__
1819

1920
.text
21+
WIN32_SAFE_SEH_HEADER
2022
.balign 4
2123
DEFINE_COMPILERRT_FUNCTION(__lshrdi3)
2224
movd 12(%esp), %xmm2 // Load count
@@ -37,6 +39,7 @@ END_COMPILERRT_FUNCTION(__lshrdi3)
3739
#else // Use GPRs instead of SSE2 instructions, if they aren't available.
3840

3941
.text
42+
WIN32_SAFE_SEH_HEADER
4043
.balign 4
4144
DEFINE_COMPILERRT_FUNCTION(__lshrdi3)
4245
movl 12(%esp), %ecx // Load count

lib/builtins/i386/moddi3.S

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
44

55
#include "../assembly.h"
6+
#include "safeseh.h"
67

78
// di_int __moddi3(di_int a, di_int b);
89

@@ -21,6 +22,7 @@
2122
#ifdef __i386__
2223

2324
.text
25+
WIN32_SAFE_SEH_HEADER
2426
.balign 4
2527
DEFINE_COMPILERRT_FUNCTION(__moddi3)
2628

lib/builtins/i386/muldi3.S

+2
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
44

55
#include "../assembly.h"
6+
#include "safeseh.h"
67

78
// di_int __muldi3(di_int a, di_int b);
89

910
#ifdef __i386__
1011

1112
.text
13+
WIN32_SAFE_SEH_HEADER
1214
.balign 4
1315
DEFINE_COMPILERRT_FUNCTION(__muldi3)
1416
pushl %ebx

lib/builtins/i386/safeseh.h

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#ifdef _MSC_VER
2+
3+
#define WIN32_SAFE_SEH_HEADER \
4+
.def @feat.00; \
5+
.scl 3; \
6+
.type 0; \
7+
.endef; \
8+
.globl @feat.00; \
9+
.set @feat.00, 1;
10+
11+
#else
12+
13+
#define WIN32_SAFE_SEH_HEADER
14+
15+
#endif

lib/builtins/i386/udivdi3.S

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
44

55
#include "../assembly.h"
6+
#include "safeseh.h"
67

78
// du_int __udivdi3(du_int a, du_int b);
89

@@ -20,6 +21,7 @@
2021
#ifdef __i386__
2122

2223
.text
24+
WIN32_SAFE_SEH_HEADER
2325
.balign 4
2426
DEFINE_COMPILERRT_FUNCTION(__udivdi3)
2527

lib/builtins/i386/umoddi3.S

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
44

55
#include "../assembly.h"
6+
#include "safeseh.h"
67

78
// du_int __umoddi3(du_int a, du_int b);
89

@@ -21,6 +22,7 @@
2122
#ifdef __i386__
2223

2324
.text
25+
WIN32_SAFE_SEH_HEADER
2426
.balign 4
2527
DEFINE_COMPILERRT_FUNCTION(__umoddi3)
2628

0 commit comments

Comments
 (0)