Skip to content

Commit 4a9a772

Browse files
committedJul 12, 2019
Enable compiler-rt on SPARC
This patch enables compiler-rt on SPARC targets. Most of the changes are straightforward: - Add 32 and 64-bit sparc to compiler-rt - lib/builtins/fp_lib.h needed to check if the int128_t and uint128_t types exist (which they don't on sparc) There's one issue of note: many asan tests fail to compile on Solaris/SPARC: fatal error: error in backend: Function "_ZN7testing8internal16BoolFromGTestEnvEPKcb": over-aligned dynamic alloca not supported. Therefore, while asan is still built, both asan and ubsan-with-asan testing is disabled. The goal is to check if asan keeps compiling on Solaris/SPARC. This serves asan in gcc, which doesn't have the problem above and works just fine. With this patch, sparcv9-sun-solaris2.11 test results are pretty good: Failing Tests (9): Builtins-sparc-sunos :: divtc3_test.c Builtins-sparcv9-sunos :: compiler_rt_logbl_test.c Builtins-sparcv9-sunos :: divtc3_test.c [...] UBSan-Standalone-sparc :: TestCases/TypeCheck/misaligned.cpp UBSan-Standalone-sparcv9 :: TestCases/TypeCheck/misaligned.cpp The builtin failures are due to Bugs 42493 and 42496. The tree contained a few additonal patches either currently in review or about to be submitted. Tested on sparcv9-sun-solaris2.11. Differential Revision: https://reviews.llvm.org/D40943 llvm-svn: 365880

File tree

9 files changed

+31
-12
lines changed

9 files changed

+31
-12
lines changed
 

‎compiler-rt/cmake/Modules/CompilerRTUtils.cmake

+6
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ macro(detect_target_arch)
162162
check_symbol_exists(__powerpc64le__ "" __PPC64LE)
163163
check_symbol_exists(__riscv "" __RISCV)
164164
check_symbol_exists(__s390x__ "" __S390X)
165+
check_symbol_exists(__sparc "" __SPARC)
166+
check_symbol_exists(__sparcv9 "" __SPARCV9)
165167
check_symbol_exists(__wasm32__ "" __WEBASSEMBLY32)
166168
check_symbol_exists(__wasm64__ "" __WEBASSEMBLY64)
167169
if(__ARM)
@@ -190,6 +192,10 @@ macro(detect_target_arch)
190192
endif()
191193
elseif(__S390X)
192194
add_default_target_arch(s390x)
195+
elseif(__SPARCV9)
196+
add_default_target_arch(sparcv9)
197+
elseif(__SPARC)
198+
add_default_target_arch(sparc)
193199
elseif(__WEBASSEMBLY32)
194200
add_default_target_arch(wasm32)
195201
elseif(__WEBASSEMBLY64)

‎compiler-rt/cmake/base-config-ix.cmake

+3
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,9 @@ macro(test_targets)
185185
endif()
186186
elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "s390x")
187187
test_target_arch(s390x "" "")
188+
elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "sparc")
189+
test_target_arch(sparc "" "-m32")
190+
test_target_arch(sparcv9 "" "-m64")
188191
elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "mipsel|mips64el")
189192
# Gcc doesn't accept -m32/-m64 so we do the next best thing and use
190193
# -mips32r2/-mips64r2. We don't use -mips1/-mips3 because we want to match

‎compiler-rt/cmake/builtin-config-ix.cmake

+3-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ set(MIPS64 mips64 mips64el)
3333
set(PPC64 powerpc64 powerpc64le)
3434
set(RISCV32 riscv32)
3535
set(RISCV64 riscv64)
36+
set(SPARC sparc)
37+
set(SPARCV9 sparcv9)
3638
set(WASM32 wasm32)
3739
set(WASM64 wasm64)
3840

@@ -43,7 +45,7 @@ if(APPLE)
4345
endif()
4446

4547
set(ALL_BUILTIN_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64}
46-
${HEXAGON} ${MIPS32} ${MIPS64} ${PPC64} ${RISCV32} ${RISCV64} ${WASM32} ${WASM64})
48+
${HEXAGON} ${MIPS32} ${MIPS64} ${PPC64} ${RISCV32} ${RISCV64} ${SPARC} ${SPARCV9} ${WASM32} ${WASM64})
4749

4850
include(CompilerRTUtils)
4951
include(CompilerRTDarwinUtils)

‎compiler-rt/cmake/config-ix.cmake

+6-4
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,8 @@ set(PPC64 powerpc64 powerpc64le)
219219
set(RISCV32 riscv32)
220220
set(RISCV64 riscv64)
221221
set(S390X s390x)
222+
set(SPARC sparc)
223+
set(SPARCV9 sparcv9)
222224
set(WASM32 wasm32)
223225
set(WASM64 wasm64)
224226

@@ -229,9 +231,9 @@ if(APPLE)
229231
endif()
230232

231233
set(ALL_SANITIZER_COMMON_SUPPORTED_ARCH ${X86} ${X86_64} ${PPC64}
232-
${ARM32} ${ARM64} ${MIPS32} ${MIPS64} ${S390X})
234+
${ARM32} ${ARM64} ${MIPS32} ${MIPS64} ${S390X} ${SPARC} ${SPARCV9})
233235
set(ALL_ASAN_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64}
234-
${MIPS32} ${MIPS64} ${PPC64} ${S390X})
236+
${MIPS32} ${MIPS64} ${PPC64} ${S390X} ${SPARC} ${SPARCV9})
235237
set(ALL_CRT_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64})
236238
set(ALL_DFSAN_SUPPORTED_ARCH ${X86_64} ${MIPS64} ${ARM64})
237239

@@ -256,10 +258,10 @@ endif()
256258
set(ALL_MSAN_SUPPORTED_ARCH ${X86_64} ${MIPS64} ${ARM64} ${PPC64})
257259
set(ALL_HWASAN_SUPPORTED_ARCH ${X86_64} ${ARM64})
258260
set(ALL_PROFILE_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} ${PPC64}
259-
${MIPS32} ${MIPS64} ${S390X})
261+
${MIPS32} ${MIPS64} ${S390X} ${SPARC} ${SPARCV9})
260262
set(ALL_TSAN_SUPPORTED_ARCH ${X86_64} ${MIPS64} ${ARM64} ${PPC64})
261263
set(ALL_UBSAN_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64}
262-
${MIPS32} ${MIPS64} ${PPC64} ${S390X})
264+
${MIPS32} ${MIPS64} ${PPC64} ${S390X} ${SPARC} ${SPARCV9})
263265
set(ALL_SAFESTACK_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM64} ${MIPS32} ${MIPS64})
264266
set(ALL_CFI_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} ${MIPS64})
265267
set(ALL_SCUDO_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} ${MIPS32} ${MIPS64} ${PPC64})

‎compiler-rt/lib/asan/tests/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ if(COMPILER_RT_CAN_EXECUTE_TESTS AND NOT ANDROID)
227227
if(APPLE)
228228
darwin_filter_host_archs(ASAN_SUPPORTED_ARCH ASAN_TEST_ARCH)
229229
endif()
230+
list(REMOVE_ITEM ASAN_TEST_ARCH sparc sparcv9)
230231
if(OS_NAME MATCHES "SunOS")
231232
list(REMOVE_ITEM ASAN_TEST_ARCH x86_64)
232233
endif()

‎compiler-rt/lib/builtins/CMakeLists.txt

+3
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,9 @@ set(riscv32_SOURCES
556556
)
557557
set(riscv64_SOURCES ${riscv_SOURCES})
558558

559+
set(sparc_SOURCES ${GENERIC_SOURCES} ${GENERIC_TF_SOURCES})
560+
set(sparcv9_SOURCES ${GENERIC_SOURCES} ${GENERIC_TF_SOURCES})
561+
559562
set(wasm32_SOURCES
560563
${GENERIC_TF_SOURCES}
561564
${GENERIC_SOURCES}

‎compiler-rt/lib/builtins/fp_lib.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ static __inline void wideMultiply(rep_t a, rep_t b, rep_t *hi, rep_t *lo) {
100100
COMPILER_RT_ABI fp_t __adddf3(fp_t a, fp_t b);
101101

102102
#elif defined QUAD_PRECISION
103-
#if __LDBL_MANT_DIG__ == 113
103+
#if __LDBL_MANT_DIG__ == 113 && defined(__SIZEOF_INT128__)
104104
#define CRT_LDBL_128BIT
105105
typedef __uint128_t rep_t;
106106
typedef __int128_t srep_t;
@@ -193,7 +193,7 @@ static __inline void wideMultiply(rep_t a, rep_t b, rep_t *hi, rep_t *lo) {
193193
#undef Word_HiMask
194194
#undef Word_LoMask
195195
#undef Word_FullMask
196-
#endif // __LDBL_MANT_DIG__ == 113
196+
#endif // __LDBL_MANT_DIG__ == 113 && __SIZEOF_INT128__
197197
#else
198198
#error SINGLE_PRECISION, DOUBLE_PRECISION or QUAD_PRECISION must be defined.
199199
#endif

‎compiler-rt/test/asan/CMakeLists.txt

+3-2
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ if (SHADOW_MAPPING_UNRELIABLE)
1818
endif()
1919

2020
macro(get_bits_for_arch arch bits)
21-
if (${arch} MATCHES "x86_64|powerpc64|powerpc64le|aarch64|arm64|mips64|mips64el|s390x")
21+
if (${arch} MATCHES "x86_64|powerpc64|powerpc64le|aarch64|arm64|mips64|mips64el|s390x|sparcv9")
2222
set(${bits} 64)
23-
elseif (${arch} MATCHES "i386|arm|mips|mipsel")
23+
elseif (${arch} MATCHES "i386|arm|mips|mipsel|sparc")
2424
set(${bits} 32)
2525
else()
2626
message(FATAL_ERROR "Unknown target architecture: ${arch}")
@@ -40,6 +40,7 @@ set(ASAN_TEST_ARCH ${ASAN_SUPPORTED_ARCH})
4040
if(APPLE)
4141
darwin_filter_host_archs(ASAN_SUPPORTED_ARCH ASAN_TEST_ARCH)
4242
endif()
43+
list(REMOVE_ITEM ASAN_TEST_ARCH sparc sparcv9)
4344
if(OS_NAME MATCHES "SunOS")
4445
list(REMOVE_ITEM ASAN_TEST_ARCH x86_64)
4546
endif()

‎compiler-rt/test/ubsan/CMakeLists.txt

+4-3
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,11 @@ foreach(arch ${UBSAN_TEST_ARCH})
4646

4747
if(COMPILER_RT_HAS_ASAN AND ";${ASAN_SUPPORTED_ARCH};" MATCHES ";${arch};")
4848
# TODO(wwchrome): Re-enable ubsan for asan win 64-bit when ready.
49-
# Disable ubsan with AddressSanitizer tests for Windows 64-bit and
50-
# 64-bit Solaris/x86.
49+
# Disable ubsan with AddressSanitizer tests for Windows 64-bit,
50+
# 64-bit Solaris/x86, and SPARC.
5151
if((NOT (OS_NAME MATCHES "Windows" AND CMAKE_SIZEOF_VOID_P EQUAL 8)) AND
52-
(NOT (OS_NAME MATCHES "SunOS" AND ${arch} MATCHES x86_64)))
52+
(NOT (OS_NAME MATCHES "SunOS" AND ${arch} MATCHES x86_64)) AND
53+
(NOT ${arch} MATCHES sparc))
5354
add_ubsan_testsuites("AddressSanitizer" asan ${arch})
5455
endif()
5556
endif()

0 commit comments

Comments
 (0)
Please sign in to comment.