2440ed8c0d1149cea192d8b857e6d1241755b8ec
[openwrt/openwrt.git] / target / linux / generic / backport-4.19 / 013-disable-Wattribute-alias-warning-for-SYSCALL_DEFINEx.patch
1 From: Arnd Bergmann <arnd@arndb.de>
2 Date: Tue, 19 Jun 2018 13:14:57 -0700
3 Subject: [PATCH] disable -Wattribute-alias warning for SYSCALL_DEFINEx()
4
5 gcc-8 warns for every single definition of a system call entry
6 point, e.g.:
7
8 include/linux/compat.h:56:18: error: 'compat_sys_rt_sigprocmask' alias between functions of incompatible types 'long int(int, compat_sigset_t *, compat_sigset_t *, compat_size_t)' {aka 'long int(int, struct <anonymous> *, struct <anonymous> *, unsigned int)'} and 'long int(long int, long int, long int, long int)' [-Werror=attribute-alias]
9 asmlinkage long compat_sys##name(__MAP(x,__SC_DECL,__VA_ARGS__))\
10 ^~~~~~~~~~
11 include/linux/compat.h:45:2: note: in expansion of macro 'COMPAT_SYSCALL_DEFINEx'
12 COMPAT_SYSCALL_DEFINEx(4, _##name, __VA_ARGS__)
13 ^~~~~~~~~~~~~~~~~~~~~~
14 kernel/signal.c:2601:1: note: in expansion of macro 'COMPAT_SYSCALL_DEFINE4'
15 COMPAT_SYSCALL_DEFINE4(rt_sigprocmask, int, how, compat_sigset_t __user *, nset,
16 ^~~~~~~~~~~~~~~~~~~~~~
17 include/linux/compat.h:60:18: note: aliased declaration here
18 asmlinkage long compat_SyS##name(__MAP(x,__SC_LONG,__VA_ARGS__))\
19 ^~~~~~~~~~
20
21 The new warning seems reasonable in principle, but it doesn't
22 help us here, since we rely on the type mismatch to sanitize the
23 system call arguments. After I reported this as GCC PR82435, a new
24 -Wno-attribute-alias option was added that could be used to turn the
25 warning off globally on the command line, but I'd prefer to do it a
26 little more fine-grained.
27
28 Interestingly, turning a warning off and on again inside of
29 a single macro doesn't always work, in this case I had to add
30 an extra statement inbetween and decided to copy the __SC_TEST
31 one from the native syscall to the compat syscall macro. See
32 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83256 for more details
33 about this.
34
35 [paul.burton@mips.com:
36 - Rebase atop current master.
37 - Split GCC & version arguments to __diag_ignore() in order to match
38 changes to the preceding patch.
39 - Add the comment argument to match the preceding patch.]
40
41 Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82435
42 Signed-off-by: Arnd Bergmann <arnd@arndb.de>
43 Signed-off-by: Paul Burton <paul.burton@mips.com>
44 Tested-by: Christophe Leroy <christophe.leroy@c-s.fr>
45 Tested-by: Stafford Horne <shorne@gmail.com>
46 Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
47 ---
48
49 --- a/include/linux/compat.h
50 +++ b/include/linux/compat.h
51 @@ -48,6 +48,9 @@
52 COMPAT_SYSCALL_DEFINEx(6, _##name, __VA_ARGS__)
53
54 #define COMPAT_SYSCALL_DEFINEx(x, name, ...) \
55 + __diag_push(); \
56 + __diag_ignore(GCC, 8, "-Wattribute-alias", \
57 + "Type aliasing is used to sanitize syscall arguments");\
58 asmlinkage long compat_sys##name(__MAP(x,__SC_DECL,__VA_ARGS__))\
59 __attribute__((alias(__stringify(compat_SyS##name)))); \
60 static inline long C_SYSC##name(__MAP(x,__SC_DECL,__VA_ARGS__));\
61 @@ -56,6 +59,7 @@
62 { \
63 return C_SYSC##name(__MAP(x,__SC_DELOUSE,__VA_ARGS__)); \
64 } \
65 + __diag_pop(); \
66 static inline long C_SYSC##name(__MAP(x,__SC_DECL,__VA_ARGS__))
67
68 #ifndef compat_user_stack_pointer
69 --- a/include/linux/syscalls.h
70 +++ b/include/linux/syscalls.h
71 @@ -208,6 +208,9 @@ static inline int is_syscall_trace_event
72
73 #define __PROTECT(...) asmlinkage_protect(__VA_ARGS__)
74 #define __SYSCALL_DEFINEx(x, name, ...) \
75 + __diag_push(); \
76 + __diag_ignore(GCC, 8, "-Wattribute-alias", \
77 + "Type aliasing is used to sanitize syscall arguments");\
78 asmlinkage long sys##name(__MAP(x,__SC_DECL,__VA_ARGS__)) \
79 __attribute__((alias(__stringify(SyS##name)))); \
80 static inline long SYSC##name(__MAP(x,__SC_DECL,__VA_ARGS__)); \
81 @@ -219,6 +222,7 @@ static inline int is_syscall_trace_event
82 __PROTECT(x, ret,__MAP(x,__SC_ARGS,__VA_ARGS__)); \
83 return ret; \
84 } \
85 + __diag_pop(); \
86 static inline long SYSC##name(__MAP(x,__SC_DECL,__VA_ARGS__))
87
88 /*