[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20250502131547.GD4198@noisy.programming.kicks-ass.net>
Date: Fri, 2 May 2025 15:15:47 +0200
From: Peter Zijlstra <peterz@...radead.org>
To: mcgrof@...nel.org
Cc: x86@...nel.org, hpa@...or.com, petr.pavlu@...e.com,
samitolvanen@...gle.com, da.gomez@...sung.com, masahiroy@...nel.org,
nathan@...nel.org, nicolas@...sle.eu, linux-kernel@...r.kernel.org,
linux-modules@...r.kernel.org, linux-kbuild@...r.kernel.org,
hch@...radead.org, gregkh@...uxfoundation.org,
Sean Christopherson <seanjc@...gle.com>
Subject: Re: [PATCH -v2 6/7] module: Account for the build time module name
mangling
On Mon, Dec 02, 2024 at 03:59:52PM +0100, Peter Zijlstra wrote:
> Sean noted that scripts/Makefile.lib:name-fix-token rule will mangle
> the module name with s/-/_/g.
>
> Since this happens late in the build, only the kernel needs to bother
> with this, the modpost tool still sees the original name.
>
> Reported-by: Sean Christopherson <seanjc@...gle.com>
> Signed-off-by: Peter Zijlstra (Intel) <peterz@...radead.org>
> ---
> kernel/module/main.c | 26 +++++++++++++++++++++++++-
> 1 file changed, 25 insertions(+), 1 deletion(-)
>
> --- a/kernel/module/main.c
> +++ b/kernel/module/main.c
> @@ -1062,6 +1062,30 @@ static char *get_modinfo(const struct lo
> }
>
> /*
> + * Like strncmp(), except s/-/_/g as per scripts/Makefile.lib:name-fix-token rule.
> + */
> +static int mod_strncmp(const char *str_a, const char *str_b, size_t n)
> +{
> + for (int i = 0; i < n; i++) {
> + char a = str_a[i];
> + char b = str_b[i];
> + int d;
> +
> + if (a == '-') a = '_';
> + if (b == '-') b = '_';
> +
> + d = a - b;
> + if (d)
> + return d;
> +
> + if (!a)
> + break;
> + }
> +
> + return 0;
> +}
> +
> +/*
> * @namespace ~= "MODULE_foo-*,bar", match @modname to 'foo-*' or 'bar'
> */
> static bool verify_module_namespace(const char *namespace, const char *modname)
> @@ -1086,7 +1110,7 @@ static bool verify_module_namespace(cons
> if (*sep)
> sep++;
>
> - if (strncmp(namespace, modname, len) == 0 && (glob || len == modlen))
> + if (mod_strncmp(namespace, modname, len) == 0 && (glob || len == modlen))
> return true;
Note that this is going to be a pain if we use glob_match(), because
then either all the patterns must already use '[-_]', or we need to
dynamically rewrite the glob.
Neither really appeals to me much.
Best to keep it simple.
Powered by blists - more mailing lists