int128: move __uint128_t compiler test to Kconfig
authorArd Biesheuvel <ardb@kernel.org>
Fri, 8 Nov 2019 12:22:27 +0000 (13:22 +0100)
committerHerbert Xu <herbert@gondor.apana.org.au>
Sun, 17 Nov 2019 01:02:42 +0000 (09:02 +0800)
In order to use 128-bit integer arithmetic in C code, the architecture
needs to have declared support for it by setting ARCH_SUPPORTS_INT128,
and it requires a version of the toolchain that supports this at build
time. This is why all existing tests for ARCH_SUPPORTS_INT128 also test
whether __SIZEOF_INT128__ is defined, since this is only the case for
compilers that can support 128-bit integers.

Let's fold this additional test into the Kconfig declaration of
ARCH_SUPPORTS_INT128 so that we can also use the symbol in Makefiles,
e.g., to decide whether a certain object needs to be included in the
first place.

Cc: Masahiro Yamada <yamada.masahiro@socionext.com>
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
arch/arm64/Kconfig
arch/riscv/Kconfig
arch/x86/Kconfig
crypto/ecc.c
init/Kconfig
lib/ubsan.c
lib/ubsan.h

index 41a9b4257b727710bcd4be1e9bcf47e6739a908d..a591a06736946c4113ab043c089c604cfcec0450 100644 (file)
@@ -67,7 +67,7 @@ config ARM64
        select ARCH_USE_QUEUED_SPINLOCKS
        select ARCH_SUPPORTS_MEMORY_FAILURE
        select ARCH_SUPPORTS_ATOMIC_RMW
-       select ARCH_SUPPORTS_INT128 if GCC_VERSION >= 50000 || CC_IS_CLANG
+       select ARCH_SUPPORTS_INT128 if CC_HAS_INT128 && (GCC_VERSION >= 50000 || CC_IS_CLANG)
        select ARCH_SUPPORTS_NUMA_BALANCING
        select ARCH_WANT_COMPAT_IPC_PARSE_VERSION if COMPAT
        select ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT
index 8eebbc8860bbd10bd18af96d81dec8370b042c9e..75a6c91176221bd83f4eae129d162eb8deb5b1e0 100644 (file)
@@ -164,7 +164,7 @@ config ARCH_RV32I
 config ARCH_RV64I
        bool "RV64I"
        select 64BIT
-       select ARCH_SUPPORTS_INT128 if GCC_VERSION >= 50000
+       select ARCH_SUPPORTS_INT128 if CC_HAS_INT128 && GCC_VERSION >= 50000
        select HAVE_FUNCTION_TRACER
        select HAVE_FUNCTION_GRAPH_TRACER
        select HAVE_FTRACE_MCOUNT_RECORD
index d6e1faa28c58ebaea297e8e450e9edf2319b3a1a..f4d9d1e55e5cb14c4b7bfa6fa63ecfc1f67f71c6 100644 (file)
@@ -24,7 +24,7 @@ config X86_64
        depends on 64BIT
        # Options that are inherently 64-bit kernel only:
        select ARCH_HAS_GIGANTIC_PAGE
-       select ARCH_SUPPORTS_INT128
+       select ARCH_SUPPORTS_INT128 if CC_HAS_INT128
        select ARCH_USE_CMPXCHG_LOCKREF
        select HAVE_ARCH_SOFT_DIRTY
        select MODULES_USE_ELF_RELA
index 8ee787723c5c2116042d955b1a5f9813d69961d7..02d35be7702b971a9ec5199fc523e5244a86ac58 100644 (file)
@@ -336,7 +336,7 @@ static u64 vli_usub(u64 *result, const u64 *left, u64 right,
 static uint128_t mul_64_64(u64 left, u64 right)
 {
        uint128_t result;
-#if defined(CONFIG_ARCH_SUPPORTS_INT128) && defined(__SIZEOF_INT128__)
+#if defined(CONFIG_ARCH_SUPPORTS_INT128)
        unsigned __int128 m = (unsigned __int128)left * right;
 
        result.m_low  = m;
index b4daad2bac233cfc32744bfb7b78a6d0ab466744..020526f681c0328208833ee5c8ce11f8c1ca4fb7 100644 (file)
@@ -785,6 +785,10 @@ config ARCH_SUPPORTS_NUMA_BALANCING
 config ARCH_WANT_BATCHED_UNMAP_TLB_FLUSH
        bool
 
+config CC_HAS_INT128
+       def_bool y
+       depends on !$(cc-option,-D__SIZEOF_INT128__=0)
+
 #
 # For architectures that know their GCC __int128 support is sound
 #
index e7d31735950de7c0980967164ce21ba0ca8b77c0..b652cc14dd60904b9299cbf17a57ebc69288ce77 100644 (file)
@@ -119,7 +119,7 @@ static void val_to_string(char *str, size_t size, struct type_descriptor *type,
 {
        if (type_is_int(type)) {
                if (type_bit_width(type) == 128) {
-#if defined(CONFIG_ARCH_SUPPORTS_INT128) && defined(__SIZEOF_INT128__)
+#if defined(CONFIG_ARCH_SUPPORTS_INT128)
                        u_max val = get_unsigned_val(type, value);
 
                        scnprintf(str, size, "0x%08x%08x%08x%08x",
index b8fa83864467ffa00e6b3d544440eb17a02e5a0f..7b56c09473a98e7fcff4c8e6640459d1d178c49c 100644 (file)
@@ -78,7 +78,7 @@ struct invalid_value_data {
        struct type_descriptor *type;
 };
 
-#if defined(CONFIG_ARCH_SUPPORTS_INT128) && defined(__SIZEOF_INT128__)
+#if defined(CONFIG_ARCH_SUPPORTS_INT128)
 typedef __int128 s_max;
 typedef unsigned __int128 u_max;
 #else