Skip to contentSkip to conversation

staging: rtl8723bs: Fix build error with Clang when inlining is disabled

PATCH Superseded Nathan Chancellor 2 participants 6 messages Jan 16, 2019 Staging

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 staging: rtl8723bs: Fix build error with Clang when inlining is disabled

When CONFIG_NO_AUTO_INLINE was present in linux-next (which added '-fno-inline-functions' to KBUILD_CFLAGS), an allyesconfig build with Clang failed at the modpost stage:

ERROR: "is_broadcast_mac_addr" [drivers/staging/rtl8723bs/r8723bs.ko] undefined!
ERROR: "is_zero_mac_addr" [drivers/staging/rtl8723bs/r8723bs.ko] undefined!
ERROR: "is_multicast_mac_addr" [drivers/staging/rtl8723bs/r8723bs.ko] undefined!

These functions were marked as extern inline, meaning that if inlining doesn't happen, the function will be undefined, as it is above.

This happens to work with GCC because the '-fno-inline-functions' option respects the __inline attribute so all instances of these functions are inlined as expected and the definition doesn't actually matter. However, with Clang and '-fno-inline-functions', a function has to be marked with the __always_inline attribute to be considered for inlining, which none of these functions are. Clang tries to find the symbol definition elsewhere as it was told and fails, which trickles down to modpost.

To make sure that this code compiles regardless of compiler and make the intention of the code clearer, use 'static __always_inline' to ensure that these functions are always inlined. Some alternative solutions included 'extern __always_inline' or converting these functions to macros (so the preprocessor deals with them) but I would argue this is the more "standard" solution.

---
 drivers/staging/rtl8723bs/include/ieee80211.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/staging/rtl8723bs/include/ieee80211.h +3 -3
index bcc8dfa8e672..959e822315b5 100644
@@ -850,18 +850,18 @@ enum ieee80211_state {
 #define IP_FMT "%pI4"
 #define IP_ARG(x) (x)
 
-extern __inline int is_multicast_mac_addr(const u8 *addr)
+static __always_inline int is_multicast_mac_addr(const u8 *addr)
 {
         return ((addr[0] != 0xff) && (0x01 & addr[0]));
 }
 
-extern __inline int is_broadcast_mac_addr(const u8 *addr)
+static __always_inline int is_broadcast_mac_addr(const u8 *addr)
 {
 	return ((addr[0] == 0xff) && (addr[1] == 0xff) && (addr[2] == 0xff) &&   \
 		(addr[3] == 0xff) && (addr[4] == 0xff) && (addr[5] == 0xff));
 }
 
-extern __inline int is_zero_mac_addr(const u8 *addr)
+static __always_inline int is_zero_mac_addr(const u8 *addr)
 {
 	return ((addr[0] == 0x00) && (addr[1] == 0x00) && (addr[2] == 0x00) &&   \
 		(addr[3] == 0x00) && (addr[4] == 0x00) && (addr[5] == 0x00));
Signature · 1 line
2.20.1
#1 lore raw
Quoted 36 lines · Nathan Chancellor

When CONFIG_NO_AUTO_INLINE was present in linux-next (which added '-fno-inline-functions' to KBUILD_CFLAGS), an allyesconfig build with Clang failed at the modpost stage:

ERROR: "is_broadcast_mac_addr" [drivers/staging/rtl8723bs/r8723bs.ko] undefined!
ERROR: "is_zero_mac_addr" [drivers/staging/rtl8723bs/r8723bs.ko] undefined!
ERROR: "is_multicast_mac_addr" [drivers/staging/rtl8723bs/r8723bs.ko] undefined!

These functions were marked as extern inline, meaning that if inlining doesn't happen, the function will be undefined, as it is above.

This happens to work with GCC because the '-fno-inline-functions' option respects the __inline attribute so all instances of these functions are inlined as expected and the definition doesn't actually matter. However, with Clang and '-fno-inline-functions', a function has to be marked with the __always_inline attribute to be considered for inlining, which none of these functions are. Clang tries to find the symbol definition elsewhere as it was told and fails, which trickles down to modpost.

To make sure that this code compiles regardless of compiler and make the intention of the code clearer, use 'static __always_inline' to ensure that these functions are always inlined. Some alternative solutions included 'extern __always_inline' or converting these functions to macros (so the preprocessor deals with them) but I would argue this is the more "standard" solution.

---
 drivers/staging/rtl8723bs/include/ieee80211.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/staging/rtl8723bs/include/ieee80211.h +0 -0
index bcc8dfa8e672..959e822315b5 100644

drivers/staging/rtl8723bs/include/ieee80211.h enum ieee80211_state { · line 853

Quoted 5 lines
drivers/staging/rtl8723bs/include/ieee80211.h +1 -1
@@ -850,18 +850,18 @@ enum ieee80211_state {
 #define IP_FMT "%pI4"
 #define IP_ARG(x) (x)
 
-extern __inline int is_multicast_mac_addr(const u8 *addr)
+static __always_inline int is_multicast_mac_addr(const u8 *addr)

Ick, really? This is in a .h file, the .c file sees this, so why isn't clang picking it up? Worst case it just makes it a "normal" function and doesn't inline it, right?

How about just replacing "extern" with "static", that should solve this, adding "__always_inline" everywhere is not going to be fun and doesn't make any sense.

thanks,

greg k-h

#2 lore raw
Quoted 40 lines · Greg Kroah-Hartman
Quoted 39 lines · Nathan Chancellor

When CONFIG_NO_AUTO_INLINE was present in linux-next (which added '-fno-inline-functions' to KBUILD_CFLAGS), an allyesconfig build with Clang failed at the modpost stage:

ERROR: "is_broadcast_mac_addr" [drivers/staging/rtl8723bs/r8723bs.ko] undefined!
ERROR: "is_zero_mac_addr" [drivers/staging/rtl8723bs/r8723bs.ko] undefined!
ERROR: "is_multicast_mac_addr" [drivers/staging/rtl8723bs/r8723bs.ko] undefined!

These functions were marked as extern inline, meaning that if inlining doesn't happen, the function will be undefined, as it is above.

This happens to work with GCC because the '-fno-inline-functions' option respects the __inline attribute so all instances of these functions are inlined as expected and the definition doesn't actually matter. However, with Clang and '-fno-inline-functions', a function has to be marked with the __always_inline attribute to be considered for inlining, which none of these functions are. Clang tries to find the symbol definition elsewhere as it was told and fails, which trickles down to modpost.

To make sure that this code compiles regardless of compiler and make the intention of the code clearer, use 'static __always_inline' to ensure that these functions are always inlined. Some alternative solutions included 'extern __always_inline' or converting these functions to macros (so the preprocessor deals with them) but I would argue this is the more "standard" solution.

---
 drivers/staging/rtl8723bs/include/ieee80211.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/staging/rtl8723bs/include/ieee80211.h +0 -0
index bcc8dfa8e672..959e822315b5 100644
@@ -850,18 +850,18 @@ enum ieee80211_state {
 #define IP_FMT "%pI4"
 #define IP_ARG(x) (x)
 
Quoted 7 lines

drivers/staging/rtl8723bs/include/ieee80211.h enum ieee80211_state { · line 853

Quoted 2 lines
drivers/staging/rtl8723bs/include/ieee80211.h +1 -1
-extern __inline int is_multicast_mac_addr(const u8 *addr)
+static __always_inline int is_multicast_mac_addr(const u8 *addr)

Ick, really? This is in a .h file, the .c file sees this, so why isn't clang picking it up? Worst case it just makes it a "normal" function and doesn't inline it, right?

As I understand it, the meaning of 'extern inline' is basically use this defintion when inlining, otherwise use one from a different file or translation unit. See commit d0a8d9378d16 ("x86/paravirt: Make native_save_fl() extern inline"). These functions don't have any other declaration/definition so when they aren't inlined, they don't exist.

Quoted 4 lines

How about just replacing "extern" with "static", that should solve this, adding "__always_inline" everywhere is not going to be fun and doesn't make any sense.

Yes, that would work (and what I originally tested). My assumption with the code is that it was intended for this function to always be inlined but if you'd rather it just be 'static', I am happy to send a v2!

Quoted 3 lines

thanks,

greg k-h

Thanks for the quick reply and review,
Nathan

#3 lore raw
Quoted 55 lines · Nathan Chancellor
Quoted 40 lines · Greg Kroah-Hartman
Quoted 39 lines · Nathan Chancellor

When CONFIG_NO_AUTO_INLINE was present in linux-next (which added '-fno-inline-functions' to KBUILD_CFLAGS), an allyesconfig build with Clang failed at the modpost stage:

ERROR: "is_broadcast_mac_addr" [drivers/staging/rtl8723bs/r8723bs.ko] undefined!
ERROR: "is_zero_mac_addr" [drivers/staging/rtl8723bs/r8723bs.ko] undefined!
ERROR: "is_multicast_mac_addr" [drivers/staging/rtl8723bs/r8723bs.ko] undefined!

These functions were marked as extern inline, meaning that if inlining doesn't happen, the function will be undefined, as it is above.

This happens to work with GCC because the '-fno-inline-functions' option respects the __inline attribute so all instances of these functions are inlined as expected and the definition doesn't actually matter. However, with Clang and '-fno-inline-functions', a function has to be marked with the __always_inline attribute to be considered for inlining, which none of these functions are. Clang tries to find the symbol definition elsewhere as it was told and fails, which trickles down to modpost.

To make sure that this code compiles regardless of compiler and make the intention of the code clearer, use 'static __always_inline' to ensure that these functions are always inlined. Some alternative solutions included 'extern __always_inline' or converting these functions to macros (so the preprocessor deals with them) but I would argue this is the more "standard" solution.

---
 drivers/staging/rtl8723bs/include/ieee80211.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/staging/rtl8723bs/include/ieee80211.h +0 -0
index bcc8dfa8e672..959e822315b5 100644
@@ -850,18 +850,18 @@ enum ieee80211_state {
 #define IP_FMT "%pI4"
 #define IP_ARG(x) (x)
 
Quoted 7 lines

drivers/staging/rtl8723bs/include/ieee80211.h enum ieee80211_state { · line 853

Quoted 2 lines
drivers/staging/rtl8723bs/include/ieee80211.h +1 -1
-extern __inline int is_multicast_mac_addr(const u8 *addr)
+static __always_inline int is_multicast_mac_addr(const u8 *addr)

Ick, really? This is in a .h file, the .c file sees this, so why isn't clang picking it up? Worst case it just makes it a "normal" function and doesn't inline it, right?

As I understand it, the meaning of 'extern inline' is basically use this defintion when inlining, otherwise use one from a different file or translation unit. See commit d0a8d9378d16 ("x86/paravirt: Make native_save_fl() extern inline"). These functions don't have any other declaration/definition so when they aren't inlined, they don't exist.

Quoted 8 lines
Quoted 4 lines

How about just replacing "extern" with "static", that should solve this, adding "__always_inline" everywhere is not going to be fun and doesn't make any sense.

Yes, that would work (and what I originally tested). My assumption with the code is that it was intended for this function to always be inlined but if you'd rather it just be 'static', I am happy to send a v2!

This code is not trying to be that smart, someone just put the extern in there without realizing it. So making it static is the correct fix, so a v2 would be great.

Odds are, almost all other places in the kernel that you hit with this also needs the same fixup, no need to be fancy here :)

thanks,

greg k-h

#4 lore raw
Quoted 61 lines · Greg Kroah-Hartman
Quoted 60 lines · Nathan Chancellor
Quoted 40 lines · Greg Kroah-Hartman
Quoted 39 lines · Nathan Chancellor

When CONFIG_NO_AUTO_INLINE was present in linux-next (which added '-fno-inline-functions' to KBUILD_CFLAGS), an allyesconfig build with Clang failed at the modpost stage:

ERROR: "is_broadcast_mac_addr" [drivers/staging/rtl8723bs/r8723bs.ko] undefined!
ERROR: "is_zero_mac_addr" [drivers/staging/rtl8723bs/r8723bs.ko] undefined!
ERROR: "is_multicast_mac_addr" [drivers/staging/rtl8723bs/r8723bs.ko] undefined!

These functions were marked as extern inline, meaning that if inlining doesn't happen, the function will be undefined, as it is above.

This happens to work with GCC because the '-fno-inline-functions' option respects the __inline attribute so all instances of these functions are inlined as expected and the definition doesn't actually matter. However, with Clang and '-fno-inline-functions', a function has to be marked with the __always_inline attribute to be considered for inlining, which none of these functions are. Clang tries to find the symbol definition elsewhere as it was told and fails, which trickles down to modpost.

To make sure that this code compiles regardless of compiler and make the intention of the code clearer, use 'static __always_inline' to ensure that these functions are always inlined. Some alternative solutions included 'extern __always_inline' or converting these functions to macros (so the preprocessor deals with them) but I would argue this is the more "standard" solution.

---
 drivers/staging/rtl8723bs/include/ieee80211.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/staging/rtl8723bs/include/ieee80211.h +0 -0
index bcc8dfa8e672..959e822315b5 100644
@@ -850,18 +850,18 @@ enum ieee80211_state {
 #define IP_FMT "%pI4"
 #define IP_ARG(x) (x)
 
Quoted 7 lines

drivers/staging/rtl8723bs/include/ieee80211.h enum ieee80211_state { · line 853

Quoted 2 lines
drivers/staging/rtl8723bs/include/ieee80211.h +1 -1
-extern __inline int is_multicast_mac_addr(const u8 *addr)
+static __always_inline int is_multicast_mac_addr(const u8 *addr)

Ick, really? This is in a .h file, the .c file sees this, so why isn't clang picking it up? Worst case it just makes it a "normal" function and doesn't inline it, right?

As I understand it, the meaning of 'extern inline' is basically use this defintion when inlining, otherwise use one from a different file or translation unit. See commit d0a8d9378d16 ("x86/paravirt: Make native_save_fl() extern inline"). These functions don't have any other declaration/definition so when they aren't inlined, they don't exist.

Quoted 4 lines

How about just replacing "extern" with "static", that should solve this, adding "__always_inline" everywhere is not going to be fun and doesn't make any sense.

Quoted 8 lines
Quoted 3 lines

Yes, that would work (and what I originally tested). My assumption with the code is that it was intended for this function to always be inlined but if you'd rather it just be 'static', I am happy to send a v2!

This code is not trying to be that smart, someone just put the extern in there without realizing it. So making it static is the correct fix, so a v2 would be great.

Done!

Quoted 3 lines

Odds are, almost all other places in the kernel that you hit with this also needs the same fixup, no need to be fancy here :)

Thankfully, with arm, arm64, and x86_64, there was only one other place that where that config caused an error:

https://lore.kernel.org/lkml/[email protected]/

Quoted 3 lines

thanks,

greg k-h

Thanks,
Nathan

#5 lore raw
Quoted 73 lines · Nathan Chancellor
Quoted 61 lines · Greg Kroah-Hartman
Quoted 60 lines · Nathan Chancellor
Quoted 40 lines · Greg Kroah-Hartman
Quoted 39 lines · Nathan Chancellor

When CONFIG_NO_AUTO_INLINE was present in linux-next (which added '-fno-inline-functions' to KBUILD_CFLAGS), an allyesconfig build with Clang failed at the modpost stage:

ERROR: "is_broadcast_mac_addr" [drivers/staging/rtl8723bs/r8723bs.ko] undefined!
ERROR: "is_zero_mac_addr" [drivers/staging/rtl8723bs/r8723bs.ko] undefined!
ERROR: "is_multicast_mac_addr" [drivers/staging/rtl8723bs/r8723bs.ko] undefined!

These functions were marked as extern inline, meaning that if inlining doesn't happen, the function will be undefined, as it is above.

This happens to work with GCC because the '-fno-inline-functions' option respects the __inline attribute so all instances of these functions are inlined as expected and the definition doesn't actually matter. However, with Clang and '-fno-inline-functions', a function has to be marked with the __always_inline attribute to be considered for inlining, which none of these functions are. Clang tries to find the symbol definition elsewhere as it was told and fails, which trickles down to modpost.

To make sure that this code compiles regardless of compiler and make the intention of the code clearer, use 'static __always_inline' to ensure that these functions are always inlined. Some alternative solutions included 'extern __always_inline' or converting these functions to macros (so the preprocessor deals with them) but I would argue this is the more "standard" solution.

---
 drivers/staging/rtl8723bs/include/ieee80211.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/staging/rtl8723bs/include/ieee80211.h +0 -0
index bcc8dfa8e672..959e822315b5 100644
@@ -850,18 +850,18 @@ enum ieee80211_state {
 #define IP_FMT "%pI4"
 #define IP_ARG(x) (x)
 
Quoted 7 lines

drivers/staging/rtl8723bs/include/ieee80211.h enum ieee80211_state { · line 853

Quoted 2 lines
drivers/staging/rtl8723bs/include/ieee80211.h +1 -1
-extern __inline int is_multicast_mac_addr(const u8 *addr)
+static __always_inline int is_multicast_mac_addr(const u8 *addr)

Ick, really? This is in a .h file, the .c file sees this, so why isn't clang picking it up? Worst case it just makes it a "normal" function and doesn't inline it, right?

As I understand it, the meaning of 'extern inline' is basically use this defintion when inlining, otherwise use one from a different file or translation unit. See commit d0a8d9378d16 ("x86/paravirt: Make native_save_fl() extern inline"). These functions don't have any other declaration/definition so when they aren't inlined, they don't exist.

Quoted 4 lines

How about just replacing "extern" with "static", that should solve this, adding "__always_inline" everywhere is not going to be fun and doesn't make any sense.

Quoted 8 lines
Quoted 3 lines

Yes, that would work (and what I originally tested). My assumption with the code is that it was intended for this function to always be inlined but if you'd rather it just be 'static', I am happy to send a v2!

This code is not trying to be that smart, someone just put the extern in there without realizing it. So making it static is the correct fix, so a v2 would be great.

Done!

Quoted 8 lines
Quoted 3 lines

Odds are, almost all other places in the kernel that you hit with this also needs the same fixup, no need to be fancy here :)

Thankfully, with arm, arm64, and x86_64, there was only one other place that where that config caused an error:

https://lore.kernel.org/lkml/[email protected]/

Ah, that's good, I think the previous cleanups that clang required where people used "extern inline" for where it wasn't needed at all (no inline function present), made this much simpler.

I'll go queue this up now, thanks

greg k-h