Skip to content

Commit 0b999ae

Browse files
committed
Merge tag 'compiler-attributes-for-linus-v5.0-rc7' of git://github.com/ojeda/linux
Pull compiler attributes fixes from Miguel Ojeda: "Clean the new GCC 9 -Wmissing-attributes warnings The upcoming GCC 9 release extends the -Wmissing-attributes warnings (enabled by -Wall) to C and aliases: it warns when particular function attributes are missing in the aliases but not in their target, e.g.: void __cold f(void) {} void __alias("f") g(void); diagnoses: warning: 'g' specifies less restrictive attribute than its target 'f': 'cold' [-Wmissing-attributes] These patch series clean these new warnings. Most of them are caused by the module_init/exit macros" Link: https://lore.kernel.org/lkml/20190125104353.2791-1-labbott@redhat.com/ * tag 'compiler-attributes-for-linus-v5.0-rc7' of git://github.com/ojeda/linux: include/linux/module.h: copy __init/__exit attrs to init/cleanup_module Compiler Attributes: add support for __copy (gcc >= 9) lib/crc32.c: mark crc32_le_base/__crc32c_le_base aliases as __pure
2 parents 5ded587 + a6e60d8 commit 0b999ae

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

include/linux/compiler_attributes.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#ifndef __has_attribute
3535
# define __has_attribute(x) __GCC4_has_attribute_##x
3636
# define __GCC4_has_attribute___assume_aligned__ (__GNUC_MINOR__ >= 9)
37+
# define __GCC4_has_attribute___copy__ 0
3738
# define __GCC4_has_attribute___designated_init__ 0
3839
# define __GCC4_has_attribute___externally_visible__ 1
3940
# define __GCC4_has_attribute___noclone__ 1
@@ -100,6 +101,19 @@
100101
*/
101102
#define __attribute_const__ __attribute__((__const__))
102103

104+
/*
105+
* Optional: only supported since gcc >= 9
106+
* Optional: not supported by clang
107+
* Optional: not supported by icc
108+
*
109+
* gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-copy-function-attribute
110+
*/
111+
#if __has_attribute(__copy__)
112+
# define __copy(symbol) __attribute__((__copy__(symbol)))
113+
#else
114+
# define __copy(symbol)
115+
#endif
116+
103117
/*
104118
* Don't. Just don't. See commit 771c035372a0 ("deprecate the '__deprecated'
105119
* attribute warnings entirely and for good") for more information.

include/linux/module.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,13 @@ extern void cleanup_module(void);
129129
#define module_init(initfn) \
130130
static inline initcall_t __maybe_unused __inittest(void) \
131131
{ return initfn; } \
132-
int init_module(void) __attribute__((alias(#initfn)));
132+
int init_module(void) __copy(initfn) __attribute__((alias(#initfn)));
133133

134134
/* This is only required if you want to be unloadable. */
135135
#define module_exit(exitfn) \
136136
static inline exitcall_t __maybe_unused __exittest(void) \
137137
{ return exitfn; } \
138-
void cleanup_module(void) __attribute__((alias(#exitfn)));
138+
void cleanup_module(void) __copy(exitfn) __attribute__((alias(#exitfn)));
139139

140140
#endif
141141

lib/crc32.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,8 @@ u32 __pure __weak __crc32c_le(u32 crc, unsigned char const *p, size_t len)
206206
EXPORT_SYMBOL(crc32_le);
207207
EXPORT_SYMBOL(__crc32c_le);
208208

209-
u32 crc32_le_base(u32, unsigned char const *, size_t) __alias(crc32_le);
210-
u32 __crc32c_le_base(u32, unsigned char const *, size_t) __alias(__crc32c_le);
209+
u32 __pure crc32_le_base(u32, unsigned char const *, size_t) __alias(crc32_le);
210+
u32 __pure __crc32c_le_base(u32, unsigned char const *, size_t) __alias(__crc32c_le);
211211

212212
/*
213213
* This multiplies the polynomials x and y modulo the given modulus.

0 commit comments

Comments
 (0)