[PATCH -v2 7/7] module: Provide EXPORT_SYMBOL_GPL_FOR() helper

Peter Zijlstra posted 7 patches 1 year, 2 months ago
Only 6 patches received!
There is a newer version of this series
[PATCH -v2 7/7] module: Provide EXPORT_SYMBOL_GPL_FOR() helper
Posted by Peter Zijlstra 1 year, 2 months ago

Requested-by: Masahiro Yamada <masahiroy@kernel.org>
Requested-by: Christoph Hellwig <hch@infradead.org>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
---
 include/linux/export.h |   26 ++++++++++++++++++++------
 1 file changed, 20 insertions(+), 6 deletions(-)

--- a/include/linux/export.h
+++ b/include/linux/export.h
@@ -24,11 +24,23 @@
 	.long sym
 #endif
 
-#define ___EXPORT_SYMBOL(sym, license, ns)		\
+/*
+ * LLVM intregrated assembler refuses to merge adjacent string literals (like
+ * C and GNU-as) and chokes on:
+ *
+ *   .asciz "MODULE_" "kvm" ;
+ *
+ * As would be generated when using EXPORT_SYMBOL_GPL_FOR(foo, "kvm"), use
+ * varargs to assemble it like so:
+ *
+ *   .ascii "MODULE_", "kvm", "\0" ;
+ *
+ */
+#define ___EXPORT_SYMBOL(sym, license, ns...)		\
 	.section ".export_symbol","a"		ASM_NL	\
 	__export_symbol_##sym:			ASM_NL	\
 		.asciz license			ASM_NL	\
-		.asciz ns			ASM_NL	\
+		.ascii ns, "\0"			ASM_NL	\
 		__EXPORT_SYMBOL_REF(sym)	ASM_NL	\
 	.previous
 
@@ -39,20 +51,20 @@
  * be reused in other execution contexts such as the UEFI stub or the
  * decompressor.
  */
-#define __EXPORT_SYMBOL(sym, license, ns)
+#define __EXPORT_SYMBOL(sym, license, ns...)
 
 #elif defined(__GENKSYMS__)
 
-#define __EXPORT_SYMBOL(sym, license, ns)	__GENKSYMS_EXPORT_SYMBOL(sym)
+#define __EXPORT_SYMBOL(sym, license, ns...)	__GENKSYMS_EXPORT_SYMBOL(sym)
 
 #elif defined(__ASSEMBLY__)
 
-#define __EXPORT_SYMBOL(sym, license, ns) \
+#define __EXPORT_SYMBOL(sym, license, ns...) \
 	___EXPORT_SYMBOL(sym, license, ns)
 
 #else
 
-#define __EXPORT_SYMBOL(sym, license, ns)			\
+#define __EXPORT_SYMBOL(sym, license, ns...)			\
 	extern typeof(sym) sym;					\
 	__ADDRESSABLE(sym)					\
 	asm(__stringify(___EXPORT_SYMBOL(sym, license, ns)))
@@ -70,4 +82,6 @@
 #define EXPORT_SYMBOL_NS(sym, ns)	__EXPORT_SYMBOL(sym, "", ns)
 #define EXPORT_SYMBOL_NS_GPL(sym, ns)	__EXPORT_SYMBOL(sym, "GPL", ns)
 
+#define EXPORT_SYMBOL_GPL_FOR(sym, mods) __EXPORT_SYMBOL(sym, "GPL", "MODULE_", mods)
+
 #endif /* _LINUX_EXPORT_H */
Re: [PATCH -v2 7/7] module: Provide EXPORT_SYMBOL_GPL_FOR() helper
Posted by Masahiro Yamada 1 year ago
On Tue, Dec 3, 2024 at 12:11 AM Peter Zijlstra <peterz@infradead.org> wrote:
>

Commit description is needed.


[bikeshed]
Perhaps, I slightly prefer EXPORT_SYMBOL_GPL_FOR_MODULES().




>
> -#define ___EXPORT_SYMBOL(sym, license, ns)             \
> +/*
> + * LLVM intregrated assembler refuses to merge adjacent string literals (like

 "intregrated"  is a typo.




> + * C and GNU-as) and chokes on:
> + *
> + *   .asciz "MODULE_" "kvm" ;
> + *
> + * As would be generated when using EXPORT_SYMBOL_GPL_FOR(foo, "kvm"), use
> + * varargs to assemble it like so:
> + *
> + *   .ascii "MODULE_", "kvm", "\0" ;


But, you do not need  comma separators, right?



The following less-invasive diff worked for me with LLVM=1.



diff --git a/include/linux/export.h b/include/linux/export.h
index a8c23d945634..546279f4d0c2 100644
--- a/include/linux/export.h
+++ b/include/linux/export.h
@@ -24,11 +24,17 @@
        .long sym
 #endif

+/*
+ * LLVM integrated assembler can merge adjacent string literals (like
+ * C and GNU-as) passed to '.ascii', but not to '.asciz' and chokes on:
+ *
+ *   .asciz "MODULE_" "kvm" ;
+ */
 #define ___EXPORT_SYMBOL(sym, license, ns)             \
        .section ".export_symbol","a"           ASM_NL  \
        __export_symbol_##sym:                  ASM_NL  \
                .asciz license                  ASM_NL  \
-               .asciz ns                       ASM_NL  \
+               .ascii ns "\0"                  ASM_NL  \
                __EXPORT_SYMBOL_REF(sym)        ASM_NL  \
        .previous

@@ -85,4 +91,6 @@
 #define EXPORT_SYMBOL_NS(sym, ns)      __EXPORT_SYMBOL(sym, "", ns)
 #define EXPORT_SYMBOL_NS_GPL(sym, ns)  __EXPORT_SYMBOL(sym, "GPL", ns)

+#define EXPORT_SYMBOL_GPL_FOR(sym, mods) __EXPORT_SYMBOL(sym, "GPL",
"MODULE_" mods)
+






-- 
Best Regards
Masahiro Yamada