linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] unlock patched C gccs
@ 2020-12-14 17:51 sylvain.bertrand
  2020-12-14 22:54 ` kernel test robot
  0 siblings, 1 reply; 2+ messages in thread
From: sylvain.bertrand @ 2020-12-14 17:51 UTC (permalink / raw)
  To: linux-kernel

From: Sylvain BERTRAND <sylvain.bertrand@legeek.net>

unlock the usage of patched gccs with proper warnings and fix the
blocking usage of c11 _Generic by using builtins available on
much more C and CXX gccs

Signed-off-by: Sylvain BERTRAND <sylvain.bertrand@legeek.net>
---
 tested on mainline 2c85ebc57b3e1817b6ce1a6b703928e113a90442 building
    a running kernel.
 include/linux/compiler-gcc.h: unlock blocking macros with warnings.
 include/linux/compiler_types.h: use a __generic() wrapper macro
    with common builtins instead of c11 _Generic. 
 include/linux/seqlock.h use the: __generic() macro instead of c11
    _Generic.
 Makefile: benign blocking gcc option.

--- a/include/linux/compiler-gcc.h
+++ b/include/linux/compiler-gcc.h
@@ -10,9 +10,30 @@
 		     + __GNUC_MINOR__ * 100	\
 		     + __GNUC_PATCHLEVEL__)
 
+#if GCC_VERSION < 40800
+#define GCC_C
+/* comment out/patch out to acknowledge the following warning message */
+# warning you need to patch gcc:
+# warning "gcc 4.7.x would need:"
+# warning "https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58145"
+# warning "https://gcc.gnu.org/legacy-ml/gcc-patches/2012-04/msg00452.html"
+#elif GCC_VERSION < 40900
 /* https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58145 */
-#if GCC_VERSION < 40900
-# error Sorry, your version of GCC is too old - please use 4.9 or newer.
+# error Sorry, your version of GCC misses some bug fixes and features - please use 4.9 or patch your GCC.
+#else
+#define GCC_CXX
+#endif
+
+/* help prevent planned obsolescence due to the use of recent c11 _Generic */
+#if GCC_VERSION >= 40900
+#define __generic(expr, t, yes, no)                                     \
+        _Generic(expr, t: yes, default: no)
+#elif GCC_VERSION >= 30100
+#define __generic(expr, t, yes, no)                                     \
+        __builtin_choose_expr(                                          \
+            __builtin_types_compatible_p(__typeof(expr), t), yes, no)
+#else
+# error your gcc compiler cannot support the __generic macro
 #endif
 
 /*
--- a/include/linux/compiler_types.h
+++ b/include/linux/compiler_types.h
@@ -254,23 +254,19 @@
  * __unqual_scalar_typeof(x) - Declare an unqualified scalar type, leaving
  *			       non-scalar types unchanged.
  */
-/*
- * Prefer C11 _Generic for better compile-times and simpler code. Note: 'char'
- * is not type-compatible with 'signed char', and we define a separate case.
- */
-#define __scalar_type_to_expr_cases(type)				\
-		unsigned type:	(unsigned type)0,			\
-		signed type:	(signed type)0
-
 #define __unqual_scalar_typeof(x) typeof(				\
-		_Generic((x),						\
-			 char:	(char)0,				\
-			 __scalar_type_to_expr_cases(char),		\
-			 __scalar_type_to_expr_cases(short),		\
-			 __scalar_type_to_expr_cases(int),		\
-			 __scalar_type_to_expr_cases(long),		\
-			 __scalar_type_to_expr_cases(long long),	\
-			 default: (x)))
+	__generic((x), char, (char)0,					\
+	__generic((x), unsigned char, (unsigned char)0,			\
+	__generic((x), signed char, (unsigned char)0,			\
+	__generic((x), unsigned short, (unsigned short)0,		\
+	__generic((x), signed short, (signed short)0,			\
+	__generic((x), unsigned int, (unsigned int)0,			\
+	__generic((x), signed int, (signed int)0,			\
+	__generic((x), unsigned long, (unsigned long)0,			\
+	__generic((x), signed long, (signed long)0,			\
+	__generic((x), unsigned long long, (unsigned long long)0,	\
+	__generic((x), signed long long, (signed long long)0,		\
+	(x)))))))))))))
 
 /* Is this type a native word size -- useful for atomic operations */
 #define __native_word(t) \
--- a/include/linux/seqlock.h
+++ b/include/linux/seqlock.h
@@ -296,17 +296,20 @@
 #define SEQCNT_MUTEX_ZERO(name, lock)		SEQCOUNT_LOCKNAME_ZERO(name, lock)
 #define SEQCNT_WW_MUTEX_ZERO(name, lock) 	SEQCOUNT_LOCKNAME_ZERO(name, lock)
 
-#define __seqprop_case(s, lockname, prop)				\
-	seqcount_##lockname##_t: __seqprop_##lockname##_##prop((void *)(s))
-
-#define __seqprop(s, prop) _Generic(*(s),				\
-	seqcount_t:		__seqprop_##prop((void *)(s)),		\
-	__seqprop_case((s),	raw_spinlock,	prop),			\
-	__seqprop_case((s),	spinlock,	prop),			\
-	__seqprop_case((s),	rwlock,		prop),			\
-	__seqprop_case((s),	mutex,		prop),			\
-	__seqprop_case((s),	ww_mutex,	prop))
-
+#define __seqprop(s, prop) 						\
+	__generic(*(s), seqcount_t, __seqprop_##prop((void *)(s)),	\
+	__generic(*(s), seqcount_raw_spinlock_t,			\
+			__seqprop_raw_spinlock_##prop((void *)(s)),	\
+	__generic(*(s), seqcount_spinlock_t,				\
+			__seqprop_spinlock_##prop((void *)(s)),		\
+	__generic(*(s), seqcount_rwlock_t,				\
+			__seqprop_rwlock_##prop((void *)(s)),		\
+	__generic(*(s), seqcount_mutex_t,				\
+			__seqprop_mutex_##prop((void *)(s)),		\
+	__generic(*(s), seqcount_ww_mutex_t,				\
+			__seqprop_ww_mutex_##prop((void *)(s)),		\
+	panic("seqlock:__seqprop:unsupported type")))))))
+	
 #define __seqcount_ptr(s)		__seqprop(s, ptr)
 #define __seqcount_sequence(s)		__seqprop(s, sequence)
 #define __seqcount_lock_preemptible(s)	__seqprop(s, preemptible)
--- a/Makefile
+++ b/Makefile
@@ -936,9 +936,6 @@
 # conserve stack if available
 KBUILD_CFLAGS   += $(call cc-option,-fconserve-stack)
 
-# Prohibit date/time macros, which would make the build non-deterministic
-KBUILD_CFLAGS   += -Werror=date-time
-
 # enforce correct pointer usage
 KBUILD_CFLAGS   += $(call cc-option,-Werror=incompatible-pointer-types)
 


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] unlock patched C gccs
  2020-12-14 17:51 [PATCH] unlock patched C gccs sylvain.bertrand
@ 2020-12-14 22:54 ` kernel test robot
  0 siblings, 0 replies; 2+ messages in thread
From: kernel test robot @ 2020-12-14 22:54 UTC (permalink / raw)
  To: sylvain.bertrand, linux-kernel; +Cc: kbuild-all, clang-built-linux

[-- Attachment #1: Type: text/plain, Size: 12619 bytes --]

Hi,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on linux/master]
[also build test ERROR on kbuild/for-next linus/master v5.10]
[cannot apply to tip/locking/core next-20201214]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/sylvain-bertrand-legeek-net/unlock-patched-C-gccs/20201215-021711
base:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 09162bc32c880a791c6c0668ce0745cf7958f576
config: arm-randconfig-r022-20201214 (attached as .config)
compiler: clang version 12.0.0 (https://github.com/llvm/llvm-project d38205144febf4dc42c9270c6aa3d978f1ef65e1)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # install arm cross compiling tool for clang build
        # apt-get install binutils-arm-linux-gnueabi
        # https://github.com/0day-ci/linux/commit/2a8dfb33ffef5f529b5e6b728aa8f69024165f47
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review sylvain-bertrand-legeek-net/unlock-patched-C-gccs/20201215-021711
        git checkout 2a8dfb33ffef5f529b5e6b728aa8f69024165f47
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=arm 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   In file included from scripts/mod/devicetable-offsets.c:3:
   In file included from include/linux/mod_devicetable.h:13:
   In file included from include/linux/uuid.h:12:
   In file included from include/linux/string.h:6:
   In file included from include/linux/compiler.h:246:
   In file included from ./arch/arm/include/generated/asm/rwonce.h:1:
>> include/asm-generic/rwonce.h:67:9: error: implicit declaration of function '__generic' [-Werror,-Wimplicit-function-declaration]
           return __READ_ONCE(*(unsigned long *)addr);
                  ^
   include/asm-generic/rwonce.h:44:42: note: expanded from macro '__READ_ONCE'
   #define __READ_ONCE(x)  (*(const volatile __unqual_scalar_typeof(x) *)&(x))
                                             ^
   include/linux/compiler_types.h:258:2: note: expanded from macro '__unqual_scalar_typeof'
           __generic((x), char, (char)0,                                   \
           ^
   In file included from scripts/mod/devicetable-offsets.c:3:
   In file included from include/linux/mod_devicetable.h:13:
   In file included from include/linux/uuid.h:12:
   In file included from include/linux/string.h:6:
   In file included from include/linux/compiler.h:246:
   In file included from ./arch/arm/include/generated/asm/rwonce.h:1:
>> include/asm-generic/rwonce.h:67:9: error: expected expression
   include/asm-generic/rwonce.h:44:42: note: expanded from macro '__READ_ONCE'
   #define __READ_ONCE(x)  (*(const volatile __unqual_scalar_typeof(x) *)&(x))
                                             ^
   include/linux/compiler_types.h:258:17: note: expanded from macro '__unqual_scalar_typeof'
           __generic((x), char, (char)0,                                   \
                          ^
   In file included from scripts/mod/devicetable-offsets.c:3:
   In file included from include/linux/mod_devicetable.h:13:
   In file included from include/linux/uuid.h:12:
   In file included from include/linux/string.h:6:
   In file included from include/linux/compiler.h:246:
   In file included from ./arch/arm/include/generated/asm/rwonce.h:1:
>> include/asm-generic/rwonce.h:67:9: error: expected expression
   include/asm-generic/rwonce.h:44:42: note: expanded from macro '__READ_ONCE'
   #define __READ_ONCE(x)  (*(const volatile __unqual_scalar_typeof(x) *)&(x))
                                             ^
   include/linux/compiler_types.h:259:17: note: expanded from macro '__unqual_scalar_typeof'
           __generic((x), unsigned char, (unsigned char)0,                 \
                          ^
   In file included from scripts/mod/devicetable-offsets.c:3:
   In file included from include/linux/mod_devicetable.h:13:
   In file included from include/linux/uuid.h:12:
   In file included from include/linux/string.h:6:
   In file included from include/linux/compiler.h:246:
   In file included from ./arch/arm/include/generated/asm/rwonce.h:1:
>> include/asm-generic/rwonce.h:67:9: error: expected expression
   include/asm-generic/rwonce.h:44:42: note: expanded from macro '__READ_ONCE'
   #define __READ_ONCE(x)  (*(const volatile __unqual_scalar_typeof(x) *)&(x))
                                             ^
   include/linux/compiler_types.h:260:17: note: expanded from macro '__unqual_scalar_typeof'
           __generic((x), signed char, (unsigned char)0,                   \
                          ^
   In file included from scripts/mod/devicetable-offsets.c:3:
   In file included from include/linux/mod_devicetable.h:13:
   In file included from include/linux/uuid.h:12:
   In file included from include/linux/string.h:6:
   In file included from include/linux/compiler.h:246:
   In file included from ./arch/arm/include/generated/asm/rwonce.h:1:
>> include/asm-generic/rwonce.h:67:9: error: expected expression
   include/asm-generic/rwonce.h:44:42: note: expanded from macro '__READ_ONCE'
   #define __READ_ONCE(x)  (*(const volatile __unqual_scalar_typeof(x) *)&(x))
                                             ^
   include/linux/compiler_types.h:261:17: note: expanded from macro '__unqual_scalar_typeof'
           __generic((x), unsigned short, (unsigned short)0,               \
                          ^
   In file included from scripts/mod/devicetable-offsets.c:3:
   In file included from include/linux/mod_devicetable.h:13:
   In file included from include/linux/uuid.h:12:
   In file included from include/linux/string.h:6:
   In file included from include/linux/compiler.h:246:
   In file included from ./arch/arm/include/generated/asm/rwonce.h:1:
>> include/asm-generic/rwonce.h:67:9: error: expected expression
   include/asm-generic/rwonce.h:44:42: note: expanded from macro '__READ_ONCE'
   #define __READ_ONCE(x)  (*(const volatile __unqual_scalar_typeof(x) *)&(x))
                                             ^
   include/linux/compiler_types.h:262:17: note: expanded from macro '__unqual_scalar_typeof'
           __generic((x), signed short, (signed short)0,                   \
                          ^
   In file included from scripts/mod/devicetable-offsets.c:3:
   In file included from include/linux/mod_devicetable.h:13:
   In file included from include/linux/uuid.h:12:
   In file included from include/linux/string.h:6:
   In file included from include/linux/compiler.h:246:
   In file included from ./arch/arm/include/generated/asm/rwonce.h:1:
>> include/asm-generic/rwonce.h:67:9: error: expected expression
   include/asm-generic/rwonce.h:44:42: note: expanded from macro '__READ_ONCE'
   #define __READ_ONCE(x)  (*(const volatile __unqual_scalar_typeof(x) *)&(x))
                                             ^
   include/linux/compiler_types.h:263:17: note: expanded from macro '__unqual_scalar_typeof'
           __generic((x), unsigned int, (unsigned int)0,                   \
                          ^
   In file included from scripts/mod/devicetable-offsets.c:3:
   In file included from include/linux/mod_devicetable.h:13:
   In file included from include/linux/uuid.h:12:
   In file included from include/linux/string.h:6:
   In file included from include/linux/compiler.h:246:
   In file included from ./arch/arm/include/generated/asm/rwonce.h:1:
>> include/asm-generic/rwonce.h:67:9: error: expected expression
   include/asm-generic/rwonce.h:44:42: note: expanded from macro '__READ_ONCE'
   #define __READ_ONCE(x)  (*(const volatile __unqual_scalar_typeof(x) *)&(x))
                                             ^
   include/linux/compiler_types.h:264:17: note: expanded from macro '__unqual_scalar_typeof'
           __generic((x), signed int, (signed int)0,                       \
                          ^
   In file included from scripts/mod/devicetable-offsets.c:3:
   In file included from include/linux/mod_devicetable.h:13:
   In file included from include/linux/uuid.h:12:
   In file included from include/linux/string.h:6:
   In file included from include/linux/compiler.h:246:
   In file included from ./arch/arm/include/generated/asm/rwonce.h:1:
>> include/asm-generic/rwonce.h:67:9: error: expected expression
   include/asm-generic/rwonce.h:44:42: note: expanded from macro '__READ_ONCE'
   #define __READ_ONCE(x)  (*(const volatile __unqual_scalar_typeof(x) *)&(x))
                                             ^
   include/linux/compiler_types.h:265:17: note: expanded from macro '__unqual_scalar_typeof'
           __generic((x), unsigned long, (unsigned long)0,                 \
                          ^
   In file included from scripts/mod/devicetable-offsets.c:3:
   In file included from include/linux/mod_devicetable.h:13:
   In file included from include/linux/uuid.h:12:
   In file included from include/linux/string.h:6:
   In file included from include/linux/compiler.h:246:
   In file included from ./arch/arm/include/generated/asm/rwonce.h:1:
>> include/asm-generic/rwonce.h:67:9: error: expected expression
   include/asm-generic/rwonce.h:44:42: note: expanded from macro '__READ_ONCE'
   #define __READ_ONCE(x)  (*(const volatile __unqual_scalar_typeof(x) *)&(x))
                                             ^
   include/linux/compiler_types.h:266:17: note: expanded from macro '__unqual_scalar_typeof'
           __generic((x), signed long, (signed long)0,                     \
                          ^
   In file included from scripts/mod/devicetable-offsets.c:3:
   In file included from include/linux/mod_devicetable.h:13:
   In file included from include/linux/uuid.h:12:
   In file included from include/linux/string.h:6:
   In file included from include/linux/compiler.h:246:
   In file included from ./arch/arm/include/generated/asm/rwonce.h:1:
>> include/asm-generic/rwonce.h:67:9: error: expected expression
   include/asm-generic/rwonce.h:44:42: note: expanded from macro '__READ_ONCE'
   #define __READ_ONCE(x)  (*(const volatile __unqual_scalar_typeof(x) *)&(x))
                                             ^
   include/linux/compiler_types.h:267:17: note: expanded from macro '__unqual_scalar_typeof'
           __generic((x), unsigned long long, (unsigned long long)0,       \
                          ^
   In file included from scripts/mod/devicetable-offsets.c:3:
   In file included from include/linux/mod_devicetable.h:13:
   In file included from include/linux/uuid.h:12:
   In file included from include/linux/string.h:6:
   In file included from include/linux/compiler.h:246:
   In file included from ./arch/arm/include/generated/asm/rwonce.h:1:
>> include/asm-generic/rwonce.h:67:9: error: expected expression
   include/asm-generic/rwonce.h:44:42: note: expanded from macro '__READ_ONCE'
   #define __READ_ONCE(x)  (*(const volatile __unqual_scalar_typeof(x) *)&(x))
                                             ^
   include/linux/compiler_types.h:268:17: note: expanded from macro '__unqual_scalar_typeof'
           __generic((x), signed long long, (signed long long)0,           \
                          ^
   12 errors generated.
   make[2]: *** [scripts/Makefile.build:117: scripts/mod/devicetable-offsets.s] Error 1
   make[2]: Target '__build' not remade because of errors.
   make[1]: *** [Makefile:1196: prepare0] Error 2
   make[1]: Target 'prepare' not remade because of errors.
   make: *** [Makefile:185: __sub-make] Error 2
   make: Target 'prepare' not remade because of errors.

vim +/__generic +67 include/asm-generic/rwonce.h

e506ea451254ab1 Will Deacon 2019-10-15  63  
e506ea451254ab1 Will Deacon 2019-10-15  64  static __no_sanitize_or_inline
e506ea451254ab1 Will Deacon 2019-10-15  65  unsigned long __read_once_word_nocheck(const void *addr)
e506ea451254ab1 Will Deacon 2019-10-15  66  {
e506ea451254ab1 Will Deacon 2019-10-15 @67  	return __READ_ONCE(*(unsigned long *)addr);
e506ea451254ab1 Will Deacon 2019-10-15  68  }
e506ea451254ab1 Will Deacon 2019-10-15  69  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 37998 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-12-14 22:56 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-14 17:51 [PATCH] unlock patched C gccs sylvain.bertrand
2020-12-14 22:54 ` kernel test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).