Commit 0d7ebbbc authored by David Rientjes's avatar David Rientjes Committed by Linus Torvalds

compiler: introduce __used and __maybe_unused

__used is defined to be __attribute__((unused)) for all pre-3.3 gcc
compilers to suppress warnings for unused functions because perhaps they
are referenced only in inline assembly.  It is defined to be
__attribute__((used)) for gcc 3.3 and later so that the code is still
emitted for such functions.

__maybe_unused is defined to be __attribute__((unused)) for both function
and variable use if it could possibly be unreferenced due to the evaluation
of preprocessor macros.  Function prototypes shall be marked with
__maybe_unused if the actual definition of the function is dependant on
preprocessor macros.

No update to compiler-intel.h is necessary because ICC supports both
__attribute__((used)) and __attribute__((unused)) as specified by the gcc
manual.

__attribute_used__ is deprecated and will be removed once all current
code is converted to using __used.

Cc: Rusty Russell <rusty@rustcorp.com.au>
Cc: Adrian Bunk <bunk@stusta.de>
Signed-off-by: default avatarDavid Rientjes <rientjes@google.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent f7e4217b
...@@ -40,3 +40,4 @@ ...@@ -40,3 +40,4 @@
#define noinline __attribute__((noinline)) #define noinline __attribute__((noinline))
#define __attribute_pure__ __attribute__((pure)) #define __attribute_pure__ __attribute__((pure))
#define __attribute_const__ __attribute__((__const__)) #define __attribute_const__ __attribute__((__const__))
#define __maybe_unused __attribute__((unused))
...@@ -4,9 +4,11 @@ ...@@ -4,9 +4,11 @@
#include <linux/compiler-gcc.h> #include <linux/compiler-gcc.h>
#if __GNUC_MINOR__ >= 3 #if __GNUC_MINOR__ >= 3
# define __attribute_used__ __attribute__((__used__)) # define __used __attribute__((__used__))
# define __attribute_used__ __used /* deprecated */
#else #else
# define __attribute_used__ __attribute__((__unused__)) # define __used __attribute__((__unused__))
# define __attribute_used__ __used /* deprecated */
#endif #endif
#if __GNUC_MINOR__ >= 4 #if __GNUC_MINOR__ >= 4
......
...@@ -12,7 +12,8 @@ ...@@ -12,7 +12,8 @@
# define __inline __inline __attribute__((always_inline)) # define __inline __inline __attribute__((always_inline))
#endif #endif
#define __attribute_used__ __attribute__((__used__)) #define __used __attribute__((__used__))
#define __attribute_used__ __used /* deprecated */
#define __must_check __attribute__((warn_unused_result)) #define __must_check __attribute__((warn_unused_result))
#define __compiler_offsetof(a,b) __builtin_offsetof(a,b) #define __compiler_offsetof(a,b) __builtin_offsetof(a,b)
#define __always_inline inline __attribute__((always_inline)) #define __always_inline inline __attribute__((always_inline))
......
...@@ -108,15 +108,30 @@ extern void __chk_io_ptr(const void __iomem *); ...@@ -108,15 +108,30 @@ extern void __chk_io_ptr(const void __iomem *);
* Allow us to avoid 'defined but not used' warnings on functions and data, * Allow us to avoid 'defined but not used' warnings on functions and data,
* as well as force them to be emitted to the assembly file. * as well as force them to be emitted to the assembly file.
* *
* As of gcc 3.3, static functions that are not marked with attribute((used)) * As of gcc 3.4, static functions that are not marked with attribute((used))
* may be elided from the assembly file. As of gcc 3.3, static data not so * may be elided from the assembly file. As of gcc 3.4, static data not so
* marked will not be elided, but this may change in a future gcc version. * marked will not be elided, but this may change in a future gcc version.
* *
* NOTE: Because distributions shipped with a backported unit-at-a-time
* compiler in gcc 3.3, we must define __used to be __attribute__((used))
* for gcc >=3.3 instead of 3.4.
*
* In prior versions of gcc, such functions and data would be emitted, but * In prior versions of gcc, such functions and data would be emitted, but
* would be warned about except with attribute((unused)). * would be warned about except with attribute((unused)).
*
* Mark functions that are referenced only in inline assembly as __used so
* the code is emitted even though it appears to be unreferenced.
*/ */
#ifndef __attribute_used__ #ifndef __attribute_used__
# define __attribute_used__ /* unimplemented */ # define __attribute_used__ /* deprecated */
#endif
#ifndef __used
# define __used /* unimplemented */
#endif
#ifndef __maybe_unused
# define __maybe_unused /* unimplemented */
#endif #endif
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment