Merge tag 'compiler-attributes-for-linus-v5.4' of git://github.com/ojeda/linux
authorLinus Torvalds <torvalds@linux-foundation.org>
Sat, 21 Sep 2019 16:47:19 +0000 (09:47 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Sat, 21 Sep 2019 16:47:19 +0000 (09:47 -0700)
Pull asm inline support from Miguel Ojeda:
 "Make use of gcc 9's "asm inline()" (Rasmus Villemoes):

  gcc 9+ (and gcc 8.3, 7.5) provides a way to override the otherwise
  crude heuristic that gcc uses to estimate the size of the code
  represented by an asm() statement. From the gcc docs

      If you use 'asm inline' instead of just 'asm', then for inlining
      purposes the size of the asm is taken as the minimum size, ignoring
      how many instructions GCC thinks it is.

  For compatibility with older compilers, we obviously want a

      #if [understands asm inline]
      #define asm_inline asm inline
      #else
      #define asm_inline asm
      #endif

  But since we #define the identifier inline to attach some attributes,
  we have to use an alternate spelling of that keyword. gcc provides
  both __inline__ and __inline, and we currently #define both to inline,
  so they all have the same semantics.

  We have to free up one of __inline__ and __inline, and the latter is
  by far the easiest.

  The two x86 changes cause smaller code gen differences than I'd
  expect, but I think we do want the asm_inline thing available sooner
  or later, so this is just to get the ball rolling"

* tag 'compiler-attributes-for-linus-v5.4' of git://github.com/ojeda/linux:
  x86: bug.h: use asm_inline in _BUG_FLAGS definitions
  x86: alternative.h: use asm_inline for all alternative variants
  compiler-types.h: add asm_inline definition
  compiler_types.h: don't #define __inline
  lib/zstd/mem.h: replace __inline by inline
  staging: rtl8723bs: replace __inline by inline

arch/x86/include/asm/alternative.h
arch/x86/include/asm/bug.h
include/linux/compiler_types.h
init/Kconfig
lib/zstd/mem.h

index 094fbc9c0b1c0332a267fb501fb037d3064a85ed..13adca37c99a36a3a8282e22283b130b4a5dd0ad 100644 (file)
@@ -201,10 +201,10 @@ static inline int alternatives_text_reserved(void *start, void *end)
  * without volatile and memory clobber.
  */
 #define alternative(oldinstr, newinstr, feature)                       \
-       asm volatile (ALTERNATIVE(oldinstr, newinstr, feature) : : : "memory")
+       asm_inline volatile (ALTERNATIVE(oldinstr, newinstr, feature) : : : "memory")
 
 #define alternative_2(oldinstr, newinstr1, feature1, newinstr2, feature2) \
-       asm volatile(ALTERNATIVE_2(oldinstr, newinstr1, feature1, newinstr2, feature2) ::: "memory")
+       asm_inline volatile(ALTERNATIVE_2(oldinstr, newinstr1, feature1, newinstr2, feature2) ::: "memory")
 
 /*
  * Alternative inline assembly with input.
@@ -218,7 +218,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
  * Leaving an unused argument 0 to keep API compatibility.
  */
 #define alternative_input(oldinstr, newinstr, feature, input...)       \
-       asm volatile (ALTERNATIVE(oldinstr, newinstr, feature)          \
+       asm_inline volatile (ALTERNATIVE(oldinstr, newinstr, feature)   \
                : : "i" (0), ## input)
 
 /*
@@ -231,18 +231,18 @@ static inline int alternatives_text_reserved(void *start, void *end)
  */
 #define alternative_input_2(oldinstr, newinstr1, feature1, newinstr2,       \
                           feature2, input...)                               \
-       asm volatile(ALTERNATIVE_2(oldinstr, newinstr1, feature1,            \
+       asm_inline volatile(ALTERNATIVE_2(oldinstr, newinstr1, feature1,     \
                newinstr2, feature2)                                         \
                : : "i" (0), ## input)
 
 /* Like alternative_input, but with a single output argument */
 #define alternative_io(oldinstr, newinstr, feature, output, input...)  \
-       asm volatile (ALTERNATIVE(oldinstr, newinstr, feature)          \
+       asm_inline volatile (ALTERNATIVE(oldinstr, newinstr, feature)   \
                : output : "i" (0), ## input)
 
 /* Like alternative_io, but for replacing a direct call with another one. */
 #define alternative_call(oldfunc, newfunc, feature, output, input...)  \
-       asm volatile (ALTERNATIVE("call %P[old]", "call %P[new]", feature) \
+       asm_inline volatile (ALTERNATIVE("call %P[old]", "call %P[new]", feature) \
                : output : [old] "i" (oldfunc), [new] "i" (newfunc), ## input)
 
 /*
@@ -253,7 +253,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
  */
 #define alternative_call_2(oldfunc, newfunc1, feature1, newfunc2, feature2,   \
                           output, input...)                                  \
-       asm volatile (ALTERNATIVE_2("call %P[old]", "call %P[new1]", feature1,\
+       asm_inline volatile (ALTERNATIVE_2("call %P[old]", "call %P[new1]", feature1,\
                "call %P[new2]", feature2)                                    \
                : output, ASM_CALL_CONSTRAINT                                 \
                : [old] "i" (oldfunc), [new1] "i" (newfunc1),                 \
index 6804d66427673ec314659944e65052b5dfba273e..facba9bc30caa4b9c7058c0b68efe122aa885dab 100644 (file)
@@ -32,7 +32,7 @@
 
 #define _BUG_FLAGS(ins, flags)                                         \
 do {                                                                   \
-       asm volatile("1:\t" ins "\n"                                    \
+       asm_inline volatile("1:\t" ins "\n"                             \
                     ".pushsection __bug_table,\"aw\"\n"                \
                     "2:\t" __BUG_REL(1b) "\t# bug_entry::bug_addr\n"   \
                     "\t"  __BUG_REL(%c0) "\t# bug_entry::file\n"       \
@@ -49,7 +49,7 @@ do {                                                                  \
 
 #define _BUG_FLAGS(ins, flags)                                         \
 do {                                                                   \
-       asm volatile("1:\t" ins "\n"                                    \
+       asm_inline volatile("1:\t" ins "\n"                             \
                     ".pushsection __bug_table,\"aw\"\n"                \
                     "2:\t" __BUG_REL(1b) "\t# bug_entry::bug_addr\n"   \
                     "\t.word %c0"        "\t# bug_entry::flags\n"      \
index b056a40116da9999f66ae5d0efdfe87dc7d3aa7a..72393a8c1a6c5daeab6bb6403252daeb2aecdb93 100644 (file)
@@ -146,8 +146,17 @@ struct ftrace_likely_data {
        __inline_maybe_unused notrace
 #endif
 
+/*
+ * gcc provides both __inline__ and __inline as alternate spellings of
+ * the inline keyword, though the latter is undocumented. New kernel
+ * code should only use the inline spelling, but some existing code
+ * uses __inline__. Since we #define inline above, to ensure
+ * __inline__ has the same semantics, we need this #define.
+ *
+ * However, the spelling __inline is strictly reserved for referring
+ * to the bare keyword.
+ */
 #define __inline__ inline
-#define __inline   inline
 
 /*
  * GCC does not warn about unused static inline functions for -Wunused-function.
@@ -197,6 +206,12 @@ struct ftrace_likely_data {
 #define asm_volatile_goto(x...) asm goto(x)
 #endif
 
+#ifdef CONFIG_CC_HAS_ASM_INLINE
+#define asm_inline asm __inline
+#else
+#define asm_inline asm
+#endif
+
 #ifndef __no_fgcse
 # define __no_fgcse
 #endif
index f4534c58342d7dc6070a6eb12b2e599a2889e105..7020238fd2638d02b6de04f3bf61335a5ef2086d 100644 (file)
@@ -33,6 +33,9 @@ config CC_HAS_ASM_GOTO
 config TOOLS_SUPPORT_RELR
        def_bool $(success,env "CC=$(CC)" "LD=$(LD)" "NM=$(NM)" "OBJCOPY=$(OBJCOPY)" $(srctree)/scripts/tools-support-relr.sh)
 
+config CC_HAS_ASM_INLINE
+       def_bool $(success,echo 'void foo(void) { asm inline (""); }' | $(CC) -x c - -c -o /dev/null)
+
 config CC_HAS_WARN_MAYBE_UNINITIALIZED
        def_bool $(cc-option,-Wmaybe-uninitialized)
        help
index 3a0f34c8706c2907be6634585fc964cf79c56f04..93d7a2c377fe3c8b4a8c0d055786bfa494c9846c 100644 (file)
@@ -27,7 +27,7 @@
 /*-****************************************
 *  Compiler specifics
 ******************************************/
-#define ZSTD_STATIC static __inline __attribute__((unused))
+#define ZSTD_STATIC static inline
 
 /*-**************************************************************
 *  Basic Types