[compiler-rt] r365880 - Enable compiler-rt on SPARC

Rainer Orth via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 12 01:30:17 PDT 2019


Author: ro
Date: Fri Jul 12 01:30:17 2019
New Revision: 365880

URL: http://llvm.org/viewvc/llvm-project?rev=365880&view=rev
Log:
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

Modified:
    compiler-rt/trunk/cmake/Modules/CompilerRTUtils.cmake
    compiler-rt/trunk/cmake/base-config-ix.cmake
    compiler-rt/trunk/cmake/builtin-config-ix.cmake
    compiler-rt/trunk/cmake/config-ix.cmake
    compiler-rt/trunk/lib/asan/tests/CMakeLists.txt
    compiler-rt/trunk/lib/builtins/CMakeLists.txt
    compiler-rt/trunk/lib/builtins/fp_lib.h
    compiler-rt/trunk/test/asan/CMakeLists.txt
    compiler-rt/trunk/test/ubsan/CMakeLists.txt

Modified: compiler-rt/trunk/cmake/Modules/CompilerRTUtils.cmake
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/cmake/Modules/CompilerRTUtils.cmake?rev=365880&r1=365879&r2=365880&view=diff
==============================================================================
--- compiler-rt/trunk/cmake/Modules/CompilerRTUtils.cmake (original)
+++ compiler-rt/trunk/cmake/Modules/CompilerRTUtils.cmake Fri Jul 12 01:30:17 2019
@@ -162,6 +162,8 @@ macro(detect_target_arch)
   check_symbol_exists(__powerpc64le__ "" __PPC64LE)
   check_symbol_exists(__riscv "" __RISCV)
   check_symbol_exists(__s390x__ "" __S390X)
+  check_symbol_exists(__sparc "" __SPARC)
+  check_symbol_exists(__sparcv9 "" __SPARCV9)
   check_symbol_exists(__wasm32__ "" __WEBASSEMBLY32)
   check_symbol_exists(__wasm64__ "" __WEBASSEMBLY64)
   if(__ARM)
@@ -190,6 +192,10 @@ macro(detect_target_arch)
     endif()
   elseif(__S390X)
     add_default_target_arch(s390x)
+  elseif(__SPARCV9)
+    add_default_target_arch(sparcv9)
+  elseif(__SPARC)
+    add_default_target_arch(sparc)
   elseif(__WEBASSEMBLY32)
     add_default_target_arch(wasm32)
   elseif(__WEBASSEMBLY64)

Modified: compiler-rt/trunk/cmake/base-config-ix.cmake
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/cmake/base-config-ix.cmake?rev=365880&r1=365879&r2=365880&view=diff
==============================================================================
--- compiler-rt/trunk/cmake/base-config-ix.cmake (original)
+++ compiler-rt/trunk/cmake/base-config-ix.cmake Fri Jul 12 01:30:17 2019
@@ -185,6 +185,9 @@ macro(test_targets)
       endif()
     elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "s390x")
       test_target_arch(s390x "" "")
+    elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "sparc")
+      test_target_arch(sparc "" "-m32")
+      test_target_arch(sparcv9 "" "-m64")
     elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "mipsel|mips64el")
       # Gcc doesn't accept -m32/-m64 so we do the next best thing and use
       # -mips32r2/-mips64r2. We don't use -mips1/-mips3 because we want to match

Modified: compiler-rt/trunk/cmake/builtin-config-ix.cmake
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/cmake/builtin-config-ix.cmake?rev=365880&r1=365879&r2=365880&view=diff
==============================================================================
--- compiler-rt/trunk/cmake/builtin-config-ix.cmake (original)
+++ compiler-rt/trunk/cmake/builtin-config-ix.cmake Fri Jul 12 01:30:17 2019
@@ -33,6 +33,8 @@ set(MIPS64 mips64 mips64el)
 set(PPC64 powerpc64 powerpc64le)
 set(RISCV32 riscv32)
 set(RISCV64 riscv64)
+set(SPARC sparc)
+set(SPARCV9 sparcv9)
 set(WASM32 wasm32)
 set(WASM64 wasm64)
 
@@ -43,7 +45,7 @@ if(APPLE)
 endif()
 
 set(ALL_BUILTIN_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64}
-    ${HEXAGON} ${MIPS32} ${MIPS64} ${PPC64} ${RISCV32} ${RISCV64} ${WASM32} ${WASM64})
+    ${HEXAGON} ${MIPS32} ${MIPS64} ${PPC64} ${RISCV32} ${RISCV64} ${SPARC} ${SPARCV9} ${WASM32} ${WASM64})
 
 include(CompilerRTUtils)
 include(CompilerRTDarwinUtils)

Modified: compiler-rt/trunk/cmake/config-ix.cmake
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/cmake/config-ix.cmake?rev=365880&r1=365879&r2=365880&view=diff
==============================================================================
--- compiler-rt/trunk/cmake/config-ix.cmake (original)
+++ compiler-rt/trunk/cmake/config-ix.cmake Fri Jul 12 01:30:17 2019
@@ -219,6 +219,8 @@ set(PPC64 powerpc64 powerpc64le)
 set(RISCV32 riscv32)
 set(RISCV64 riscv64)
 set(S390X s390x)
+set(SPARC sparc)
+set(SPARCV9 sparcv9)
 set(WASM32 wasm32)
 set(WASM64 wasm64)
 
@@ -229,9 +231,9 @@ if(APPLE)
 endif()
 
 set(ALL_SANITIZER_COMMON_SUPPORTED_ARCH ${X86} ${X86_64} ${PPC64}
-    ${ARM32} ${ARM64} ${MIPS32} ${MIPS64} ${S390X})
+    ${ARM32} ${ARM64} ${MIPS32} ${MIPS64} ${S390X} ${SPARC} ${SPARCV9})
 set(ALL_ASAN_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64}
-    ${MIPS32} ${MIPS64} ${PPC64} ${S390X})
+    ${MIPS32} ${MIPS64} ${PPC64} ${S390X} ${SPARC} ${SPARCV9})
 set(ALL_CRT_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64})
 set(ALL_DFSAN_SUPPORTED_ARCH ${X86_64} ${MIPS64} ${ARM64})
 
@@ -256,10 +258,10 @@ endif()
 set(ALL_MSAN_SUPPORTED_ARCH ${X86_64} ${MIPS64} ${ARM64} ${PPC64})
 set(ALL_HWASAN_SUPPORTED_ARCH ${X86_64} ${ARM64})
 set(ALL_PROFILE_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} ${PPC64}
-    ${MIPS32} ${MIPS64} ${S390X})
+    ${MIPS32} ${MIPS64} ${S390X} ${SPARC} ${SPARCV9})
 set(ALL_TSAN_SUPPORTED_ARCH ${X86_64} ${MIPS64} ${ARM64} ${PPC64})
 set(ALL_UBSAN_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64}
-    ${MIPS32} ${MIPS64} ${PPC64} ${S390X})
+    ${MIPS32} ${MIPS64} ${PPC64} ${S390X} ${SPARC} ${SPARCV9})
 set(ALL_SAFESTACK_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM64} ${MIPS32} ${MIPS64})
 set(ALL_CFI_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} ${MIPS64})
 set(ALL_SCUDO_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} ${MIPS32} ${MIPS64} ${PPC64})

Modified: compiler-rt/trunk/lib/asan/tests/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/tests/CMakeLists.txt?rev=365880&r1=365879&r2=365880&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/tests/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/asan/tests/CMakeLists.txt Fri Jul 12 01:30:17 2019
@@ -227,6 +227,7 @@ if(COMPILER_RT_CAN_EXECUTE_TESTS AND NOT
   if(APPLE)
     darwin_filter_host_archs(ASAN_SUPPORTED_ARCH ASAN_TEST_ARCH)
   endif()
+  list(REMOVE_ITEM ASAN_TEST_ARCH sparc sparcv9)
   if(OS_NAME MATCHES "SunOS")
     list(REMOVE_ITEM ASAN_TEST_ARCH x86_64)
   endif()

Modified: compiler-rt/trunk/lib/builtins/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/builtins/CMakeLists.txt?rev=365880&r1=365879&r2=365880&view=diff
==============================================================================
--- compiler-rt/trunk/lib/builtins/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/builtins/CMakeLists.txt Fri Jul 12 01:30:17 2019
@@ -556,6 +556,9 @@ set(riscv32_SOURCES
 )
 set(riscv64_SOURCES ${riscv_SOURCES})
 
+set(sparc_SOURCES ${GENERIC_SOURCES} ${GENERIC_TF_SOURCES})
+set(sparcv9_SOURCES ${GENERIC_SOURCES} ${GENERIC_TF_SOURCES})
+
 set(wasm32_SOURCES
   ${GENERIC_TF_SOURCES}
   ${GENERIC_SOURCES}

Modified: compiler-rt/trunk/lib/builtins/fp_lib.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/builtins/fp_lib.h?rev=365880&r1=365879&r2=365880&view=diff
==============================================================================
--- compiler-rt/trunk/lib/builtins/fp_lib.h (original)
+++ compiler-rt/trunk/lib/builtins/fp_lib.h Fri Jul 12 01:30:17 2019
@@ -100,7 +100,7 @@ static __inline void wideMultiply(rep_t
 COMPILER_RT_ABI fp_t __adddf3(fp_t a, fp_t b);
 
 #elif defined QUAD_PRECISION
-#if __LDBL_MANT_DIG__ == 113
+#if __LDBL_MANT_DIG__ == 113 && defined(__SIZEOF_INT128__)
 #define CRT_LDBL_128BIT
 typedef __uint128_t rep_t;
 typedef __int128_t srep_t;
@@ -193,7 +193,7 @@ static __inline void wideMultiply(rep_t
 #undef Word_HiMask
 #undef Word_LoMask
 #undef Word_FullMask
-#endif // __LDBL_MANT_DIG__ == 113
+#endif // __LDBL_MANT_DIG__ == 113 && __SIZEOF_INT128__
 #else
 #error SINGLE_PRECISION, DOUBLE_PRECISION or QUAD_PRECISION must be defined.
 #endif

Modified: compiler-rt/trunk/test/asan/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/CMakeLists.txt?rev=365880&r1=365879&r2=365880&view=diff
==============================================================================
--- compiler-rt/trunk/test/asan/CMakeLists.txt (original)
+++ compiler-rt/trunk/test/asan/CMakeLists.txt Fri Jul 12 01:30:17 2019
@@ -18,9 +18,9 @@ if (SHADOW_MAPPING_UNRELIABLE)
 endif()
 
 macro(get_bits_for_arch arch bits)
-  if (${arch} MATCHES "x86_64|powerpc64|powerpc64le|aarch64|arm64|mips64|mips64el|s390x")
+  if (${arch} MATCHES "x86_64|powerpc64|powerpc64le|aarch64|arm64|mips64|mips64el|s390x|sparcv9")
     set(${bits} 64)
-  elseif (${arch} MATCHES "i386|arm|mips|mipsel")
+  elseif (${arch} MATCHES "i386|arm|mips|mipsel|sparc")
     set(${bits} 32)
   else()
     message(FATAL_ERROR "Unknown target architecture: ${arch}")
@@ -40,6 +40,7 @@ set(ASAN_TEST_ARCH ${ASAN_SUPPORTED_ARCH
 if(APPLE)
   darwin_filter_host_archs(ASAN_SUPPORTED_ARCH ASAN_TEST_ARCH)
 endif()
+list(REMOVE_ITEM ASAN_TEST_ARCH sparc sparcv9)
 if(OS_NAME MATCHES "SunOS")
   list(REMOVE_ITEM ASAN_TEST_ARCH x86_64)
 endif()

Modified: compiler-rt/trunk/test/ubsan/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/ubsan/CMakeLists.txt?rev=365880&r1=365879&r2=365880&view=diff
==============================================================================
--- compiler-rt/trunk/test/ubsan/CMakeLists.txt (original)
+++ compiler-rt/trunk/test/ubsan/CMakeLists.txt Fri Jul 12 01:30:17 2019
@@ -46,10 +46,11 @@ foreach(arch ${UBSAN_TEST_ARCH})
 
   if(COMPILER_RT_HAS_ASAN AND ";${ASAN_SUPPORTED_ARCH};" MATCHES ";${arch};")
     # TODO(wwchrome): Re-enable ubsan for asan win 64-bit when ready.
-    # Disable ubsan with AddressSanitizer tests for Windows 64-bit and
-    # 64-bit Solaris/x86.
+    # Disable ubsan with AddressSanitizer tests for Windows 64-bit,
+    # 64-bit Solaris/x86, and SPARC.
     if((NOT (OS_NAME MATCHES "Windows" AND CMAKE_SIZEOF_VOID_P EQUAL 8)) AND
-       (NOT (OS_NAME MATCHES "SunOS" AND ${arch} MATCHES x86_64)))
+       (NOT (OS_NAME MATCHES "SunOS" AND ${arch} MATCHES x86_64)) AND
+       (NOT ${arch} MATCHES sparc))
       add_ubsan_testsuites("AddressSanitizer" asan ${arch})
     endif()
   endif()




More information about the llvm-commits mailing list