Skip to contentSkip to conversation

include/linux/compiler*.h: add version detection to asm_volatile_goto

PATCH Superseded Nick Desaulniers 2 participants 2 messages Sep 7, 2018 – Sep 9, 2018

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 include/linux/compiler*.h: add version detection to asm_volatile_goto

The comment above asm_volatile_goto mentions working around a GCC bug, and links to a bug report that claims this has been fixed in newer versions of GCC. Testing shows that this was resolved in GCC 4.8.2. asm_volatile_goto should also be defined for other compilers that support asm goto.

---
 include/linux/compiler-gcc.h   | 7 ++++++-
 include/linux/compiler_types.h | 4 ++++
 2 files changed, 10 insertions(+), 1 deletion(-)
include/linux/compiler-gcc.h +6 -1
index 763bbad1e258..149f411b4366 100644
@@ -171,7 +171,7 @@
 #endif
 
 /*
- * GCC 'asm goto' miscompiles certain code sequences:
+ * GCC < 4.8.2 'asm goto' miscompiles certain code sequences:
  *
  *   http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58670
  *
@@ -179,7 +179,12 @@
  *
  * (asm goto is automatically volatile - the naming reflects this.)
  */
+#if GCC_VERSION < 40802
 #define asm_volatile_goto(x...)	do { asm goto(x); asm (""); } while (0)
+#else
+#define asm_volatile_goto(x...)	asm goto(x)
+#endif
+
 
 /*
  * sparse (__CHECKER__) pretends to be gcc, but can't do constant
include/linux/compiler_types.h +4 -0
index 3525c179698c..61449dbf30d8 100644
@@ -151,6 +151,10 @@ struct ftrace_likely_data {
 #define __assume_aligned(a, ...)
 #endif
 
+#ifndef asm_volatile_goto
+#define asm_volatile_goto(x...) asm goto(x)
+#endif
+
 /* Are two types/vars the same type (ignoring qualifiers)? */
 #define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b))
 
Signature · 1 line
2.19.0.rc2.392.g5ba43deb5a-goog
Reviewed-by on v1 1/1
#1 lore raw

Hi Nick,

Quoted 17 lines · Nick Desaulniers

The comment above asm_volatile_goto mentions working around a GCC bug, and links to a bug report that claims this has been fixed in newer versions of GCC. Testing shows that this was resolved in GCC 4.8.2. asm_volatile_goto should also be defined for other compilers that support asm goto.

---
 include/linux/compiler-gcc.h   | 7 ++++++-
 include/linux/compiler_types.h | 4 ++++
 2 files changed, 10 insertions(+), 1 deletion(-)
include/linux/compiler-gcc.h +0 -0
index 763bbad1e258..149f411b4366 100644

include/linux/compiler-gcc.h line 175

Quoted 6 lines
include/linux/compiler-gcc.h +1 -1
@@ -171,7 +171,7 @@
 #endif
 
 /*
- * GCC 'asm goto' miscompiles certain code sequences:
+ * GCC < 4.8.2 'asm goto' miscompiles certain code sequences:
  *

Nice catch. Indeed, it seems broken since 4.5.3 and fixed in every version after 4.8.1 (at least the ones in godbolt).

By the way, arch/arm64/include/asm/jump_label.h is the only place in the kernel using "asm goto" directly (e.g. the arm64 one isn't). Even if old gcc doesn't trigger the bug in that case, we should use the same everywhere for consistency, unless there is a special reason not to (not documented). I will send a patch.

Cheers,
Miguel