[RFC 07/31] kbuild: Remove "kmod" prefix from __KBUILD_MODNAME

Josh Poimboeuf posted 31 patches 1 year, 5 months ago
[RFC 07/31] kbuild: Remove "kmod" prefix from __KBUILD_MODNAME
Posted by Josh Poimboeuf 1 year, 5 months ago
Remove the arbitrary "kmod" prefix from __KBUILD_MODNAME and add it back
manually in the __initcall_id() macro.

This makes it more consistent, now __KBUILD_MODNAME is just the
non-stringified version of KBUILD_MODNAME.  It will come in handy for
the upcoming "objtool klp diff".

Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
---
 include/linux/init.h | 3 ++-
 scripts/Makefile.lib | 2 +-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/include/linux/init.h b/include/linux/init.h
index 58cef4c2e59a..b1921f4a7b7e 100644
--- a/include/linux/init.h
+++ b/include/linux/init.h
@@ -206,12 +206,13 @@ extern struct module __this_module;
 
 /* Format: <modname>__<counter>_<line>_<fn> */
 #define __initcall_id(fn)					\
+	__PASTE(kmod_,						\
 	__PASTE(__KBUILD_MODNAME,				\
 	__PASTE(__,						\
 	__PASTE(__COUNTER__,					\
 	__PASTE(_,						\
 	__PASTE(__LINE__,					\
-	__PASTE(_, fn))))))
+	__PASTE(_, fn)))))))
 
 /* Format: __<prefix>__<iid><id> */
 #define __initcall_name(prefix, __iid, id)			\
diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index 9f06f6aaf7fc..8411e3d53938 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -130,7 +130,7 @@ name-fix-token = $(subst $(comma),_,$(subst -,_,$1))
 name-fix = $(call stringify,$(call name-fix-token,$1))
 basename_flags = -DKBUILD_BASENAME=$(call name-fix,$(basetarget))
 modname_flags  = -DKBUILD_MODNAME=$(call name-fix,$(modname)) \
-		 -D__KBUILD_MODNAME=kmod_$(call name-fix-token,$(modname))
+		 -D__KBUILD_MODNAME=$(call name-fix-token,$(modname))
 modfile_flags  = -DKBUILD_MODFILE=$(call stringify,$(modfile))
 
 _c_flags       = $(filter-out $(CFLAGS_REMOVE_$(target-stem).o), \
-- 
2.45.2
Re: [RFC 07/31] kbuild: Remove "kmod" prefix from __KBUILD_MODNAME
Posted by Peter Zijlstra 1 year, 5 months ago
On Mon, Sep 02, 2024 at 08:59:50PM -0700, Josh Poimboeuf wrote:
> Remove the arbitrary "kmod" prefix from __KBUILD_MODNAME and add it back
> manually in the __initcall_id() macro.
> 
> This makes it more consistent, now __KBUILD_MODNAME is just the
> non-stringified version of KBUILD_MODNAME.  It will come in handy for
> the upcoming "objtool klp diff".
> 
> Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
> ---
>  include/linux/init.h | 3 ++-
>  scripts/Makefile.lib | 2 +-
>  2 files changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/include/linux/init.h b/include/linux/init.h
> index 58cef4c2e59a..b1921f4a7b7e 100644
> --- a/include/linux/init.h
> +++ b/include/linux/init.h
> @@ -206,12 +206,13 @@ extern struct module __this_module;
>  
>  /* Format: <modname>__<counter>_<line>_<fn> */
>  #define __initcall_id(fn)					\
> +	__PASTE(kmod_,						\
>  	__PASTE(__KBUILD_MODNAME,				\
>  	__PASTE(__,						\
>  	__PASTE(__COUNTER__,					\
>  	__PASTE(_,						\
>  	__PASTE(__LINE__,					\
> -	__PASTE(_, fn))))))
> +	__PASTE(_, fn)))))))

:-(
Re: [RFC 07/31] kbuild: Remove "kmod" prefix from __KBUILD_MODNAME
Posted by Josh Poimboeuf 1 year, 5 months ago
On Tue, Sep 03, 2024 at 09:58:13AM +0200, Peter Zijlstra wrote:
> On Mon, Sep 02, 2024 at 08:59:50PM -0700, Josh Poimboeuf wrote:
> > Remove the arbitrary "kmod" prefix from __KBUILD_MODNAME and add it back
> > manually in the __initcall_id() macro.
> > 
> > This makes it more consistent, now __KBUILD_MODNAME is just the
> > non-stringified version of KBUILD_MODNAME.  It will come in handy for
> > the upcoming "objtool klp diff".
> > 
> > Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
> > ---
> >  include/linux/init.h | 3 ++-
> >  scripts/Makefile.lib | 2 +-
> >  2 files changed, 3 insertions(+), 2 deletions(-)
> > 
> > diff --git a/include/linux/init.h b/include/linux/init.h
> > index 58cef4c2e59a..b1921f4a7b7e 100644
> > --- a/include/linux/init.h
> > +++ b/include/linux/init.h
> > @@ -206,12 +206,13 @@ extern struct module __this_module;
> >  
> >  /* Format: <modname>__<counter>_<line>_<fn> */
> >  #define __initcall_id(fn)					\
> > +	__PASTE(kmod_,						\
> >  	__PASTE(__KBUILD_MODNAME,				\
> >  	__PASTE(__,						\
> >  	__PASTE(__COUNTER__,					\
> >  	__PASTE(_,						\
> >  	__PASTE(__LINE__,					\
> > -	__PASTE(_, fn))))))
> > +	__PASTE(_, fn)))))))
> 
> :-(

Yeah, I was just keeping the existing format here.

But actually, I strongly prefer it compared to this:

/* Format: <modname>__<counter>_<line>_<fn> */
#define __initcall_id(fn)						\
	__PASTE(kmod_,							\
		__PASTE(__KBUILD_MODNAME,				\
			__PASTE(__,					\
				__PASTE(__COUNTER__,			\
					__PASTE(_,			\
						__PASTE(__LINE__,	\
							__PASTE(_, fn)))))))

That gives headaches.  Sure, the vertically aligned version is a bit
unorthodox but it *much* easier to read if you know how to read it: just
scan down.

And the "Format:" comment at the top clarifies the result.

-- 
Josh
Re: [RFC 07/31] kbuild: Remove "kmod" prefix from __KBUILD_MODNAME
Posted by Peter Zijlstra 1 year, 5 months ago
On Tue, Sep 03, 2024 at 07:11:24PM -0700, Josh Poimboeuf wrote:
> On Tue, Sep 03, 2024 at 09:58:13AM +0200, Peter Zijlstra wrote:
> > On Mon, Sep 02, 2024 at 08:59:50PM -0700, Josh Poimboeuf wrote:
> > > Remove the arbitrary "kmod" prefix from __KBUILD_MODNAME and add it back
> > > manually in the __initcall_id() macro.
> > > 
> > > This makes it more consistent, now __KBUILD_MODNAME is just the
> > > non-stringified version of KBUILD_MODNAME.  It will come in handy for
> > > the upcoming "objtool klp diff".
> > > 
> > > Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
> > > ---
> > >  include/linux/init.h | 3 ++-
> > >  scripts/Makefile.lib | 2 +-
> > >  2 files changed, 3 insertions(+), 2 deletions(-)
> > > 
> > > diff --git a/include/linux/init.h b/include/linux/init.h
> > > index 58cef4c2e59a..b1921f4a7b7e 100644
> > > --- a/include/linux/init.h
> > > +++ b/include/linux/init.h
> > > @@ -206,12 +206,13 @@ extern struct module __this_module;
> > >  
> > >  /* Format: <modname>__<counter>_<line>_<fn> */
> > >  #define __initcall_id(fn)					\
> > > +	__PASTE(kmod_,						\
> > >  	__PASTE(__KBUILD_MODNAME,				\
> > >  	__PASTE(__,						\
> > >  	__PASTE(__COUNTER__,					\
> > >  	__PASTE(_,						\
> > >  	__PASTE(__LINE__,					\
> > > -	__PASTE(_, fn))))))
> > > +	__PASTE(_, fn)))))))
> > 
> > :-(
> 
> Yeah, I was just keeping the existing format here.
> 
> But actually, I strongly prefer it compared to this:
> 
> /* Format: <modname>__<counter>_<line>_<fn> */
> #define __initcall_id(fn)						\
> 	__PASTE(kmod_,							\
> 		__PASTE(__KBUILD_MODNAME,				\
> 			__PASTE(__,					\
> 				__PASTE(__COUNTER__,			\
> 					__PASTE(_,			\
> 						__PASTE(__LINE__,	\
> 							__PASTE(_, fn)))))))
> 
> That gives headaches.  Sure, the vertically aligned version is a bit
> unorthodox but it *much* easier to read if you know how to read it: just
> scan down.
> 
> And the "Format:" comment at the top clarifies the result.

Yeah, I suppose you're right.