Skip to contentSkip to conversation

compiler: Introduce __always_unused

PATCH In review Li Zefan 2 participants 6 messages Nov 2, 2009

Subsystems (2)
lore
Share & tools
lore

Li Zefan

author
#0 lore raw

PATCH 1/2 compiler: Introduce __always_unused

I wrote some code which is used as compile-time checker, and the code should be elided after compile.

So I need to annotate the code as "always unused", compared to "maybe unused".

---
 include/linux/compiler-gcc.h |    1 +
 include/linux/compiler.h     |    4 ++++
 2 files changed, 5 insertions(+), 0 deletions(-)
include/linux/compiler-gcc.h +1 -0
index a3ed7cb..73dcf80 100644
@@ -79,6 +79,7 @@
 #define  noinline			__attribute__((noinline))
 #define __attribute_const__		__attribute__((__const__))
 #define __maybe_unused			__attribute__((unused))
+#define __always_unused			__attribute__((unused))
 
 #define __gcc_header(x) #x
 #define _gcc_header(x) __gcc_header(linux/compiler-gcc##x.h)
include/linux/compiler.h +4 -0
index d1cc9f0..1ccebf4 100644
@@ -132,6 +132,10 @@ extern void __chk_io_ptr(const volatile void __iomem *);
 # define __maybe_unused		/* unimplemented */
 #endif
 
+#ifndef __always_unused
+# define __always_unused	/* unimplemented */
+#endif
+
 #ifndef noinline
 #define noinline
 #endif
Signature · 1 line
1.6.3
author
#1 lore raw

PATCH 2/2 tracing: Fix to use __always_unused attribute

____ftrace_check_##name() is used for compile-time check on F_printk() only, so it should be marked as __unused instead of __used.

---
 kernel/trace/trace_export.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
kernel/trace/trace_export.c +2 -2
index 934d81f..dff8c84 100644
@@ -48,11 +48,11 @@
 struct ____ftrace_##name {					\
 	tstruct							\
 };								\
-static void __used ____ftrace_check_##name(void)		\
+static void __always_unused ____ftrace_check_##name(void)	\
 {								\
 	struct ____ftrace_##name *__entry = NULL;		\
 								\
-	/* force cmpile-time check on F_printk() */		\
+	/* force compile-time check on F_printk() */		\
 	printk(print);						\
 }
 
Signature · 1 line
1.6.3
#3 lore raw
In reply to Li Zefan

On Mon, 02 Nov 2009 08:50:52 +0800
Li Zefan <[email protected]> wrote:

Hi,

Quoted 4 lines

I wrote some code which is used as compile-time checker, and the code should be elided after compile.
+#define __always_unused
__attribute__((unused))

I have a suggestion.
In addition to marking it attribute unused, would it be useful to also put a section attribute as part of this, to a section that we can then drop from the binary by way of the linker script ?

Signature · 3 lines
Arjan van de Ven 	Intel Open Source Technology Centre
For development, discussion and tips for power savings, 
visit http://www.lesswatts.org
author
#4 lore raw
Quoted 10 lines · Arjan van de Ven

On Mon, 02 Nov 2009 08:50:52 +0800
Li Zefan <[email protected]> wrote:

Hi,

Quoted 4 lines

I wrote some code which is used as compile-time checker, and the code should be elided after compile.
+#define __always_unused
__attribute__((unused))

Quoted 5 lines

I have a suggestion.
In addition to marking it attribute unused, would it be useful to also put a section attribute as part of this, to a section that we can then drop from the binary by way of the linker script ?

__unused is used to suppress define-but-unused warning. If the annotated symbol is really unused, it will be optimized out, so I think we don't need to add a section for this.

#5 lore raw
In reply to Li Zefan
Commit-ID:  7b2a35132ad0a70902dcd2844c27ed64cda0ce9b
Gitweb:     http://git.kernel.org/tip/7b2a35132ad0a70902dcd2844c27ed64cda0ce9b
Author:     Li Zefan <[email protected]>
AuthorDate: Mon, 2 Nov 2009 08:50:52 +0800
Committer:  Ingo Molnar <[email protected]>
CommitDate: Mon, 2 Nov 2009 15:47:54 +0100

compiler: Introduce __always_unused

I wrote some code which is used as compile-time checker, and the code should be elided after compile.

So I need to annotate the code as "always unused", compared to "maybe unused".

Cc Steven Rostedt <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Linus Torvalds <[email protected]>

LKML-Reference: <[email protected]>

---
 include/linux/compiler-gcc.h |    1 +
 include/linux/compiler.h     |    4 ++++
 2 files changed, 5 insertions(+), 0 deletions(-)
include/linux/compiler-gcc.h +1 -0
index a3ed7cb..73dcf80 100644
@@ -79,6 +79,7 @@
 #define  noinline			__attribute__((noinline))
 #define __attribute_const__		__attribute__((__const__))
 #define __maybe_unused			__attribute__((unused))
+#define __always_unused			__attribute__((unused))
 
 #define __gcc_header(x) #x
 #define _gcc_header(x) __gcc_header(linux/compiler-gcc##x.h)
include/linux/compiler.h +4 -0
index 04fb513..7947f4f 100644
@@ -213,6 +213,10 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
 # define __maybe_unused		/* unimplemented */
 #endif
 
+#ifndef __always_unused
+# define __always_unused	/* unimplemented */
+#endif
+
 #ifndef noinline
 #define noinline
 #endif
#2 lore raw

[tip:tracing/core] tracing: Fix to use __always_unused attribute

In reply to Li Zefan
Commit-ID:  5e9b397292ca0b9409dced33e3a22ec993377064
Gitweb:     http://git.kernel.org/tip/5e9b397292ca0b9409dced33e3a22ec993377064
Author:     Li Zefan <[email protected]>
AuthorDate: Mon, 2 Nov 2009 08:51:13 +0800
Committer:  Ingo Molnar <[email protected]>
CommitDate: Mon, 2 Nov 2009 15:47:54 +0100

tracing: Fix to use __always_unused attribute

____ftrace_check_##name() is used for compile-time check on F_printk() only, so it should be marked as __unused instead of __used.

Cc Steven Rostedt <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Linus Torvalds <[email protected]>

LKML-Reference: <[email protected]>

---
 kernel/trace/trace_export.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
kernel/trace/trace_export.c +2 -2
index 9753fcc..c74848d 100644
@@ -48,11 +48,11 @@
 struct ____ftrace_##name {					\
 	tstruct							\
 };								\
-static void __used ____ftrace_check_##name(void)		\
+static void __always_unused ____ftrace_check_##name(void)	\
 {								\
 	struct ____ftrace_##name *__entry = NULL;		\
 								\
-	/* force cmpile-time check on F_printk() */		\
+	/* force compile-time check on F_printk() */		\
 	printk(print);						\
 }