public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [patch 01/10] compiler: define __attribute_unused__
@ 2007-05-02  4:28 David Rientjes
  2007-05-02  4:28 ` [patch 02/10] i386 pci: type may be unused David Rientjes
                   ` (2 more replies)
  0 siblings, 3 replies; 40+ messages in thread
From: David Rientjes @ 2007-05-02  4:28 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-kernel

For all supported versions of gcc (major version 3 and above), functions
and variables may be declared with __attribute__((unused)) to suppress
warnings if they are declared but unused.

This shouldn't be confused with functions being declared with
__attribute__((used)).  This specifies that the function code shall still
be emitted even if it appears to be unreferenced, normally used if
embedded in inline assembly.  For gcc 3.4 and later, unreferenced static
variables and functions are not emitted so this attribute is necessary to
force variables and functions to be output.  Earlier versions of gcc can
simply use __attribute__((unused)) to suppress warnings about such
variables: we do not require any special classification to ensure they are
emitted.

We introduce __attribute_unused__ for variables that should not produce a
compile warning if they can, due to preprocessor macros, go unreferenced.

Signed-off-by: David Rientjes <rientjes@google.com>
---
 include/linux/compiler-gcc.h |   16 ++++++++++++++++
 1 files changed, 16 insertions(+), 0 deletions(-)

diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h
--- a/include/linux/compiler-gcc.h
+++ b/include/linux/compiler-gcc.h
@@ -37,3 +37,19 @@
 #define  noinline			__attribute__((noinline))
 #define __attribute_pure__		__attribute__((pure))
 #define __attribute_const__		__attribute__((__const__))
+
+/*
+ * __attribute_unused__ shall be used for functions or variables to suppress
+ * warnings when they may be declared but, due to preprocessor macros,
+ * commenting, etc., go unreferenced.
+ *
+ * In contrast, __attribute_used__ shall be used only for functions.  gcc <3.4
+ * emits code for static functions that are unreferenced and outputs a warning.
+ * __attribute_used__ will correctly suppress this warning.  gcc >=3.4 does not
+ * emit code for static functions that are unreferenced (and thus there is no
+ * warning), but __attribute_used__ forces the function code to be output.  Use
+ * __attribute_unused__ to suppress warnings about functions being unused or
+ * __attribute_used__ to ensure code is emitted when it is referenced only in
+ * inline assembly.
+ */
+#define __attribute_unused__		__attribute__((unused))

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

end of thread, other threads:[~2007-05-07  1:28 UTC | newest]

Thread overview: 40+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-05-02  4:28 [patch 01/10] compiler: define __attribute_unused__ David Rientjes
2007-05-02  4:28 ` [patch 02/10] i386 pci: type may be unused David Rientjes
2007-05-02  4:28   ` [patch 03/10] sh: dma: use __attribute_unused__ David Rientjes
2007-05-02  4:28     ` [patch 04/10] scsi: fix ambiguous gdthtable definition David Rientjes
2007-05-02  4:28       ` [patch 05/10] frv: gdb: use __attribute_unused__ David Rientjes
2007-05-02  4:28         ` [patch 06/10] i386: voyager: " David Rientjes
2007-05-02  4:28           ` [patch 07/10] mips: excite: " David Rientjes
2007-05-02  4:28             ` [patch 08/10] mips: tlbex: " David Rientjes
2007-05-02  4:28               ` [patch 09/10] powerpc: ps3: " David Rientjes
2007-05-02  4:28                 ` [patch 10/10] i386 mmzone: " David Rientjes
2007-05-02 15:42                 ` [patch 09/10] powerpc: ps3: " Geoff Levand
2007-05-03 17:23               ` [patch 08/10] mips: tlbex: " Ralf Baechle
2007-05-03 17:23             ` [patch 07/10] mips: excite: " Ralf Baechle
2007-05-07  1:28     ` [patch 03/10] sh: dma: " Paul Mundt
2007-05-02 10:35   ` [patch 02/10] i386 pci: type may be unused Andi Kleen
2007-05-02 17:05     ` David Rientjes
2007-05-02  5:17 ` [patch 01/10] compiler: define __attribute_unused__ Alexey Dobriyan
2007-05-02  5:53   ` David Rientjes
2007-05-02  6:08     ` Andrew Morton
2007-05-02  6:46       ` Nick Piggin
2007-05-02  6:33     ` WANG Cong
2007-05-02  7:02   ` Robert P. J. Day
2007-05-02  7:17     ` David Rientjes
2007-05-02  7:47       ` Robert P. J. Day
2007-05-02  5:40 ` Rusty Russell
2007-05-02  6:06   ` David Rientjes
2007-05-02  6:25     ` David Rientjes
2007-05-02  6:29     ` Rusty Russell
2007-05-02  6:41       ` David Rientjes
2007-05-02  6:52         ` Andrew Morton
2007-05-02  7:04         ` Rusty Russell
2007-05-02  7:22           ` David Rientjes
2007-05-02  7:51             ` Rusty Russell
2007-05-02 14:55             ` Adrian Bunk
2007-05-02 15:05               ` Adrian Bunk
2007-05-02 17:16                 ` David Rientjes
2007-05-03 17:51                   ` Adrian Bunk
2007-05-03 18:56                     ` David Rientjes
2007-05-03 19:05                       ` Adrian Bunk
2007-05-03 19:24                         ` David Rientjes

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox