public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/5] Add support for GCC's __builtin_unreachable() and use it in BUG (v2.1).
@ 2009-12-05  1:43 David Daney
  2009-12-05  1:44 ` [PATCH 1/5] Add support for GCC-4.5's __builtin_unreachable() to compiler.h (v2) David Daney
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: David Daney @ 2009-12-05  1:43 UTC (permalink / raw)
  To: Linus Torvalds, Andrew Morton, linux-arch; +Cc: Linux Kernel Mailing List

Greetings Linus et al.,

 From the announcement of the first version:

     Starting with version 4.5, GCC has a new built-in function called
     __builtin_unreachable().  The function tells the compiler that
     control flow will never reach that point.  Currently we trick the
     compiler by putting in for(;;); but this has the disadvantage that
     extra code is emitted for an endless loop.  For an i386 kernel
     using __builtin_unreachable() results in an defaultconfig that is
     nearly 4000 bytes smaller.

     This patch set adds support to compiler.h creating a new macro
     usable in the kernel called unreachable().  If the compiler lacks
     __builtin_unreachable(), it just expands to for(;;).


For version 2:

     I fixed a couple of checkpatch issues, and simplified the
     unreachable() macro for the pre-GCC-4.5 case (as suggested by
     Richard Henderson).  Also several Acked-by: were added.

For this version 2.1:

     I removed patches from the set for which there were no Acked-by,
     and rebased and tested against 2.6.32.

I will reply with the 5 patches.

David Daney (5):
   Add support for GCC-4.5's __builtin_unreachable() to compiler.h (v2)
   x86: Convert BUG() to use unreachable()
   MIPS: Convert BUG() to use unreachable()
   s390: Convert BUG() to use unreachable()
   avr32: Convert BUG() to use unreachable()

  arch/avr32/include/asm/bug.h  |    2 +-
  arch/mips/include/asm/bug.h   |    4 +---
  arch/s390/include/asm/bug.h   |    2 +-
  arch/x86/include/asm/bug.h    |    4 ++--
  include/linux/compiler-gcc4.h |   14 ++++++++++++++
  include/linux/compiler.h      |    5 +++++
  6 files changed, 24 insertions(+), 7 deletions(-)


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

* [PATCH 1/5] Add support for GCC-4.5's __builtin_unreachable() to compiler.h (v2)
  2009-12-05  1:43 [PATCH 0/5] Add support for GCC's __builtin_unreachable() and use it in BUG (v2.1) David Daney
@ 2009-12-05  1:44 ` David Daney
  2009-12-05  1:44 ` [PATCH 2/5] x86: Convert BUG() to use unreachable() David Daney
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: David Daney @ 2009-12-05  1:44 UTC (permalink / raw)
  To: torvalds, akpm; +Cc: linux-kernel, linux-arch, David Daney, Ralf Baechle

Starting with version 4.5, GCC has a new built-in function
__builtin_unreachable() that can be used in places like the kernel's
BUG() where inline assembly is used to transfer control flow.  This
eliminated the need for an endless loop in these places.

The patch adds a new macro 'unreachable()' that will expand to either
__builtin_unreachable() or an endless loop depending on the compiler
version.

Change from v1: Simplify unreachable() for non-GCC 4.5 case.

Signed-off-by: David Daney <ddaney@caviumnetworks.com>
Acked-by: Ralf Baechle <ralf@linux-mips.org>
CC: Ralf Baechle <ralf@linux-mips.org>
---
 include/linux/compiler-gcc4.h |   14 ++++++++++++++
 include/linux/compiler.h      |    5 +++++
 2 files changed, 19 insertions(+), 0 deletions(-)

diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
index 450fa59..ab3af40 100644
--- a/include/linux/compiler-gcc4.h
+++ b/include/linux/compiler-gcc4.h
@@ -36,4 +36,18 @@
    the kernel context */
 #define __cold			__attribute__((__cold__))
 
+
+#if __GNUC_MINOR__ >= 5
+/*
+ * Mark a position in code as unreachable.  This can be used to
+ * suppress control flow warnings after asm blocks that transfer
+ * control elsewhere.
+ *
+ * Early snapshots of gcc 4.5 don't support this and we can't detect
+ * this in the preprocessor, but we can live with this because they're
+ * unreleased.  Really, we need to have autoconf for the kernel.
+ */
+#define unreachable() __builtin_unreachable()
+#endif
+
 #endif
diff --git a/include/linux/compiler.h b/include/linux/compiler.h
index 04fb513..59f2089 100644
--- a/include/linux/compiler.h
+++ b/include/linux/compiler.h
@@ -144,6 +144,11 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
 # define barrier() __memory_barrier()
 #endif
 
+/* Unreachable code */
+#ifndef unreachable
+# define unreachable() do { } while (1)
+#endif
+
 #ifndef RELOC_HIDE
 # define RELOC_HIDE(ptr, off)					\
   ({ unsigned long __ptr;					\
-- 
1.6.2.5


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

* [PATCH 2/5] x86: Convert BUG() to use unreachable()
  2009-12-05  1:43 [PATCH 0/5] Add support for GCC's __builtin_unreachable() and use it in BUG (v2.1) David Daney
  2009-12-05  1:44 ` [PATCH 1/5] Add support for GCC-4.5's __builtin_unreachable() to compiler.h (v2) David Daney
@ 2009-12-05  1:44 ` David Daney
  2009-12-05  1:44 ` [PATCH 3/5] MIPS: " David Daney
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: David Daney @ 2009-12-05  1:44 UTC (permalink / raw)
  To: torvalds, akpm
  Cc: linux-kernel, linux-arch, David Daney, H. Peter Anvin,
	Thomas Gleixner, Ingo Molnar, x86

Use the new unreachable() macro instead of for(;;);.  When
allyesconfig is built with a GCC-4.5 snapshot on i686 the size of the
text segment is reduced by 3987 bytes (from 6827019 to 6823032).

Signed-off-by: David Daney <ddaney@caviumnetworks.com>
Acked-by: "H. Peter Anvin" <hpa@zytor.com>
CC: "H. Peter Anvin" <hpa@zytor.com>
CC: Thomas Gleixner <tglx@linutronix.de>
CC: Ingo Molnar <mingo@redhat.com>
CC: x86@kernel.org
---
 arch/x86/include/asm/bug.h |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/include/asm/bug.h b/arch/x86/include/asm/bug.h
index d9cf1cd..f654d1b 100644
--- a/arch/x86/include/asm/bug.h
+++ b/arch/x86/include/asm/bug.h
@@ -22,14 +22,14 @@ do {								\
 		     ".popsection"				\
 		     : : "i" (__FILE__), "i" (__LINE__),	\
 		     "i" (sizeof(struct bug_entry)));		\
-	for (;;) ;						\
+	unreachable();						\
 } while (0)
 
 #else
 #define BUG()							\
 do {								\
 	asm volatile("ud2");					\
-	for (;;) ;						\
+	unreachable();						\
 } while (0)
 #endif
 
-- 
1.6.2.5


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

* [PATCH 3/5] MIPS: Convert BUG() to use unreachable()
  2009-12-05  1:43 [PATCH 0/5] Add support for GCC's __builtin_unreachable() and use it in BUG (v2.1) David Daney
  2009-12-05  1:44 ` [PATCH 1/5] Add support for GCC-4.5's __builtin_unreachable() to compiler.h (v2) David Daney
  2009-12-05  1:44 ` [PATCH 2/5] x86: Convert BUG() to use unreachable() David Daney
@ 2009-12-05  1:44 ` David Daney
  2009-12-05  1:44 ` [PATCH 4/5] s390: " David Daney
  2009-12-05  1:44 ` [PATCH 5/5] avr32: " David Daney
  4 siblings, 0 replies; 6+ messages in thread
From: David Daney @ 2009-12-05  1:44 UTC (permalink / raw)
  To: torvalds, akpm
  Cc: linux-kernel, linux-arch, David Daney, Ralf Baechle, linux-mips

Use the new unreachable() macro instead of while(1);

Signed-off-by: David Daney <ddaney@caviumnetworks.com>
Acked-by: Ralf Baechle <ralf@linux-mips.org>
CC: Ralf Baechle <ralf@linux-mips.org>
CC: linux-mips@linux-mips.org
---
 arch/mips/include/asm/bug.h |    4 +---
 1 files changed, 1 insertions(+), 3 deletions(-)

diff --git a/arch/mips/include/asm/bug.h b/arch/mips/include/asm/bug.h
index 6cf29c2..540c98a 100644
--- a/arch/mips/include/asm/bug.h
+++ b/arch/mips/include/asm/bug.h
@@ -11,9 +11,7 @@
 static inline void __noreturn BUG(void)
 {
 	__asm__ __volatile__("break %0" : : "i" (BRK_BUG));
-	/* Fool GCC into thinking the function doesn't return. */
-	while (1)
-		;
+	unreachable();
 }
 
 #define HAVE_ARCH_BUG
-- 
1.6.2.5


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

* [PATCH 4/5] s390: Convert BUG() to use unreachable()
  2009-12-05  1:43 [PATCH 0/5] Add support for GCC's __builtin_unreachable() and use it in BUG (v2.1) David Daney
                   ` (2 preceding siblings ...)
  2009-12-05  1:44 ` [PATCH 3/5] MIPS: " David Daney
@ 2009-12-05  1:44 ` David Daney
  2009-12-05  1:44 ` [PATCH 5/5] avr32: " David Daney
  4 siblings, 0 replies; 6+ messages in thread
From: David Daney @ 2009-12-05  1:44 UTC (permalink / raw)
  To: torvalds, akpm
  Cc: linux-kernel, linux-arch, David Daney, Martin Schwidefsky,
	Heiko Carstens, linux390, linux-s390

Use the new unreachable() macro instead of for(;;);

Signed-off-by: David Daney <ddaney@caviumnetworks.com>
Acked-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
CC: Martin Schwidefsky <schwidefsky@de.ibm.com>
CC: Heiko Carstens <heiko.carstens@de.ibm.com>
CC: linux390@de.ibm.com
CC: linux-s390@vger.kernel.org
---
 arch/s390/include/asm/bug.h |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/arch/s390/include/asm/bug.h b/arch/s390/include/asm/bug.h
index 7efd0ab..efb74fd 100644
--- a/arch/s390/include/asm/bug.h
+++ b/arch/s390/include/asm/bug.h
@@ -49,7 +49,7 @@
 
 #define BUG() do {					\
 	__EMIT_BUG(0);					\
-	for (;;);					\
+	unreachable();					\
 } while (0)
 
 #define WARN_ON(x) ({					\
-- 
1.6.2.5


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

* [PATCH 5/5] avr32: Convert BUG() to use unreachable()
  2009-12-05  1:43 [PATCH 0/5] Add support for GCC's __builtin_unreachable() and use it in BUG (v2.1) David Daney
                   ` (3 preceding siblings ...)
  2009-12-05  1:44 ` [PATCH 4/5] s390: " David Daney
@ 2009-12-05  1:44 ` David Daney
  4 siblings, 0 replies; 6+ messages in thread
From: David Daney @ 2009-12-05  1:44 UTC (permalink / raw)
  To: torvalds, akpm; +Cc: linux-kernel, linux-arch, David Daney, Haavard Skinnemoen

Use the new unreachable() macro instead of for(;;);

Signed-off-by: David Daney <ddaney@caviumnetworks.com>
Acked-by: Haavard Skinnemoen <haavard.skinnemoen@atmel.com>
CC: Haavard Skinnemoen <haavard.skinnemoen@atmel.com>
---
 arch/avr32/include/asm/bug.h |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/arch/avr32/include/asm/bug.h b/arch/avr32/include/asm/bug.h
index 331d45b..2aa373c 100644
--- a/arch/avr32/include/asm/bug.h
+++ b/arch/avr32/include/asm/bug.h
@@ -52,7 +52,7 @@
 #define BUG()								\
 	do {								\
 		_BUG_OR_WARN(0);					\
-		for (;;);						\
+		unreachable();						\
 	} while (0)
 
 #define WARN_ON(condition)							\
-- 
1.6.2.5


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

end of thread, other threads:[~2009-12-05  2:07 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-12-05  1:43 [PATCH 0/5] Add support for GCC's __builtin_unreachable() and use it in BUG (v2.1) David Daney
2009-12-05  1:44 ` [PATCH 1/5] Add support for GCC-4.5's __builtin_unreachable() to compiler.h (v2) David Daney
2009-12-05  1:44 ` [PATCH 2/5] x86: Convert BUG() to use unreachable() David Daney
2009-12-05  1:44 ` [PATCH 3/5] MIPS: " David Daney
2009-12-05  1:44 ` [PATCH 4/5] s390: " David Daney
2009-12-05  1:44 ` [PATCH 5/5] avr32: " David Daney

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