From patchwork Tue Oct 15 23:18:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Maurer X-Patchwork-Id: 13837407 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BB9661F80DB for ; Tue, 15 Oct 2024 23:19:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729034383; cv=none; b=KVDpLGqyWH0wZNdYj6CPUi5uQ+l24MGi6zEY0ASfLccRedhVjobpzmYxtjwdq8Amj1B3WX/QK/w6yMoZPeAf76u8itnrbEJEreRYC3zCDbfR/BhXXji9KtvWoJX38hMFegzt20LFE87P1EHIkXBFUWYl6Z0uQKj8o4pnVATVAY4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729034383; c=relaxed/simple; bh=eBJG2rXeVYA/XEzcQYJAZKaNWGCWFxTaGo2H2wh3ljw=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Dz536u0rF9njK9d4qCSbffBFVRpC1wMJlhNSsNgdFq4XkMkf44DpMWxj4K1/72DEs2fem8TSkZ/E2ibI39xleteO2wz1roYNIlOTKTPi55zGXjIFfnQAAH00luUtrevbHrnHhxBa+/QMgDjpNeRjnDYojMXGg3bzS3PvcJh9oE4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--mmaurer.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=HudI9Ysc; arc=none smtp.client-ip=209.85.219.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--mmaurer.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="HudI9Ysc" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e2605ce4276so10733277276.3 for ; Tue, 15 Oct 2024 16:19:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1729034381; x=1729639181; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=kcWYIAwP9b7jjsyrsKEHRrU+6v789OznTVm7Ys3lY5Q=; b=HudI9YscA6FvaCounyUY/VU0lVXBbLKqsQFSi32mPopNM7pInijLK3EUXckBqR0o97 x7kD1rbA+ULIYTt1fjL1YX/l4/Xn3LAY6XT7Kx0sUjSEVBmjiei/4/BlBAKRDUKbp0RB coWHQemMeFQzc9vaUz8QcWmZPsgwg62jEuTr5cVx1bBwPHi3E2D7rmug+2lJ/9dJJkQz XcFZf4Eo6RfI74L88bd7GeUCZF4Vh8Rs3DUlZjW917ZkxbRiIN0ps7wAC5auDZ9cRocN jBGOhuF4T5FoWFhdqraIhqXy5phuyc1FfjdriSLf5I6LGBPGB10/2lpxWYOSVPAhfjhj oGHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729034381; x=1729639181; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=kcWYIAwP9b7jjsyrsKEHRrU+6v789OznTVm7Ys3lY5Q=; b=dwf+ngAxSexZrDd+LIBcJxAczaz8hY2CQUiL2tLAdYjsSSWrQ/+FlZsJ1syFIMdLx4 40fIwSgIkdAkMPmDYsf1Q6lLywiHjZPYCR327xuxyXgBLlw3Dyc+Fg/EBBDIUsSwPQms 9ZiC9dnUmgMZcYH068mp1WcuAAnGrsY/ORRPog8A1Ov3TtMSShIQwGf3KWy2C5c9fF9V RYbd+Svkgr+PRsQDvfbsYnCKfzsikC0qnCmU/Pz2Z0KOeO8Uxjcfm0vmbF5meiMyGPoH gHrK5mx/oCsf7w4zQ+DLJwv+dkh0qFhbz5jORNQhgwDHINfZFWuU19IAXmg1JYWdYnm1 P55Q== X-Forwarded-Encrypted: i=1; AJvYcCUVTjslpD9IsrFIjfv+sDFBEfi8v22hIy7mq/2ADX53TrFFb3yTk9ryPqh0MGMlaMc8XD933TBZ7QLB7KUz@vger.kernel.org X-Gm-Message-State: AOJu0Yzqvc/478nWCZlwuzcYZzckfQxUHd2znTmC1xpvDq0I6TtwWZmf AKO4ctN5TQhUnjJkvKOn0tsoxBY3hUD6rneUCjU49v38B/bDjgg2SUFprZgxfr31NLeHOf6h76L 3YuNX+g== X-Google-Smtp-Source: AGHT+IFGh7T9/sOWrOvku3a83TcqKp+gmz3hSjkGEL/6gT3UKoDIzg6hQ4IXpJdp72DC6zOThRZlztPzdbc9 X-Received: from anyblade.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:1791]) (user=mmaurer job=sendgmr) by 2002:a05:6902:1c3:b0:e28:ee84:e4d8 with SMTP id 3f1490d57ef6-e29783006b4mr1193276.3.1729034380759; Tue, 15 Oct 2024 16:19:40 -0700 (PDT) Date: Tue, 15 Oct 2024 23:18:56 +0000 In-Reply-To: <20241015231925.3854230-1-mmaurer@google.com> Precedence: bulk X-Mailing-List: linux-modules@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241015231925.3854230-1-mmaurer@google.com> X-Mailer: git-send-email 2.47.0.rc1.288.g06298d1525-goog Message-ID: <20241015231925.3854230-2-mmaurer@google.com> Subject: [PATCH v6 1/5] export_report: Rehabilitate script From: Matthew Maurer To: masahiroy@kernel.org, ndesaulniers@google.com, ojeda@kernel.org, gary@garyguo.net, mcgrof@kernel.org, Alex Gaynor Cc: rust-for-linux@vger.kernel.org, linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, neal@gompa.dev, marcan@marcan.st, j@jannau.net, asahi@lists.linux.dev, linux-modules@vger.kernel.org, samitolvanen@google.com, Matthew Maurer , Boqun Feng , " =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= " , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross The `export_report.pl` script was broken [1] a while back due to a code cleanup causing the regex to no longer match. Additionally, it assumes a `modules.order` file containing `.ko` in a build directory with `.mod.c` files. I cannot find when this would have been the case in the history, as normally `.ko` files only appear in `modules.order` in installed modules directories, and those do not contain `.mod.c` files. This patch makes it able to report symbol usage counts for a build tree with modules and MODVERSIONS. Since the rest of this series will change the format of `.mod.c`, this change fixes the script to work correctly against a current build tree. Given that the regex no longer matches the format used in `.mod.c`, it cannot have worked since 2019, so updating this script is purely out of an abundance of caution. I am unsure who uses this script or for what purpose. * modules.order in a build directory uses .o, not .ko files. Allow .o files when parsing modules.order. * The .mod.c format changed [1] how it expressed the section attribute, leading to a regex mismatch. Update it to match modpost.c [1]: https://lore.kernel.org/all/20190909113423.2289-2-yamada.masahiro@socionext.com/ Signed-off-by: Matthew Maurer --- scripts/export_report.pl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/export_report.pl b/scripts/export_report.pl index feb3d5542a62..30b5f7819086 100755 --- a/scripts/export_report.pl +++ b/scripts/export_report.pl @@ -55,6 +55,7 @@ sub collectcfiles { open my $fh, '< modules.order' or die "cannot open modules.order: $!\n"; while (<$fh>) { s/\.ko$/.mod.c/; + s/\.o$/.mod.c/; push (@file, $_) } close($fh); @@ -120,7 +121,7 @@ foreach my $thismod (@allcfiles) { next; } if ($state == 1) { - $state = 2 if ($_ =~ /__attribute__\(\(section\("__versions"\)\)\)/); + $state = 2 if ($_ =~ /__used __section\("__versions"\)/); next; } if ($state == 2) { From patchwork Tue Oct 15 23:18:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Maurer X-Patchwork-Id: 13837408 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5EFD321E3DB for ; Tue, 15 Oct 2024 23:19:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729034392; cv=none; b=GT9lLz++CIuH7vn09ByLdYBVBSqwi1yqHBmrJNDd340Iw/5c32gOziG+SKSbz0WZ+B/8xHrKviORbrp8ENSEbkrVZEvS2hefcWHAEA8yFhUu5g4DXpxdh3i+3TbPibSSkQ14D64guElM/I3MDG3FLq67WhiGAAFEZqTvm0QPjGY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729034392; c=relaxed/simple; bh=EqoiMCMwtXRzYrztphzbbyPQC7yghBAcoUcUTqsjzc0=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=PjEKBl78tk4SiFAKSfBlqqSBxfo29bQ9XlyxN0PrjON2v3GbXApLxZhYeBbpfKXhZWu+/dfWejivA2oFd6SRilOFd19bdVxdB/l5y+P3i4B8G3K+3HkKRGRUSWeZGXfUyqfTnl036IJ9zARmDeFMbrkk71uficPxPUnF3zq3CSM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--mmaurer.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=zngqYdbL; arc=none smtp.client-ip=209.85.128.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--mmaurer.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="zngqYdbL" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6e390b164c7so43866937b3.1 for ; Tue, 15 Oct 2024 16:19:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1729034389; x=1729639189; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=FMSQ/Tp5KquWB/NFr+gBjq3itwue5CA00E66TGsfFAE=; b=zngqYdbLfl0d/a7MD30SgV0RuqONkrAxH2x7WguyJGcVGHh98qOW8Ce/WKbtmuk8Xy 3RW0CobFe0NDu8oS/aqQ3tqRLL/t8yGx/nNwwt1VlIwy6EBOz7CxKRbD5OuR7bdYpvgO 26gB/zkKlvU4Cv+rQtosZVWqMauQ+J8TIRvzbr2ZxQm3ip+5R+yWzOjZirDFjY+gqlaM UQTW8SOSR3SujwSr/5ypfDs3CNf3J9mRK9PyOtKnmsc+G2FG9UPLXYF+UcUnwjHXhbc2 rkMilJyKrpFGe/zY5KVql1KQdJ6jFhQTQxgoEUPwlaCHozwkTDh5nc1CxQ6GI+9wi4PU y4Rg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729034389; x=1729639189; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=FMSQ/Tp5KquWB/NFr+gBjq3itwue5CA00E66TGsfFAE=; b=tgGnhYZvS//8rF9bW63bck9y3gHvN9pb/WjrOn5Ql89L+ZWTPD1Cjyi6XmF349EN7y /kMhCMj2EQ7XrMClMIjq1HbT69QnfPlkJw23LmuSwxH6KU3ZYIelvaF0IWoBm6jwZNuE Ugs5P7QvVHSYQnUxRUHZChUmfiH87s9qR4O6cug3H3UsLt8Yekno+qh03fQRwivInZll qq1sYEioBAjx7bOBSsxI7fCvJlU1HYJD0NSX1ntS5i/PCvBfenoMLW6KcWc9Shzx/4CD fMOQ6O0Us2WAR0zfBD8Ai1SCZn7AZp8bXK2q5EVwVpDX9e9mu1fLDGcPEqrMHXsGtUaY Q0IA== X-Forwarded-Encrypted: i=1; AJvYcCU9U1q+qhuKIAs3K8LLbrY9RCF7zfAN603AYBkhPhaDNdd9YboijZ/e+Ddx1n4ZZgCHMCUUKmO24O0ueBiI@vger.kernel.org X-Gm-Message-State: AOJu0YyAAssjf0J4B2EYaHTTKAC8jbkWhZW1GjrR2DRo8vl+K0/eMihT KvP5DGB70/6HUuJuRGqrmwEnGANUOHre7u7ovyyjzgZYDeeRAmhrphgOZo70GZ2qp/l3tTGqK2n W31P5JA== X-Google-Smtp-Source: AGHT+IGX0icJ1CWivcvNRrA/zojDVZFklRmkCxNQxnPYkIU1lCS12nRY8wVMRxtxvqJKRQSf0gcnC2/QNxRA X-Received: from anyblade.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:1791]) (user=mmaurer job=sendgmr) by 2002:a0d:c405:0:b0:6b2:3ecc:817 with SMTP id 00721157ae682-6e3d41eb817mr246597b3.8.1729034388608; Tue, 15 Oct 2024 16:19:48 -0700 (PDT) Date: Tue, 15 Oct 2024 23:18:57 +0000 In-Reply-To: <20241015231925.3854230-1-mmaurer@google.com> Precedence: bulk X-Mailing-List: linux-modules@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241015231925.3854230-1-mmaurer@google.com> X-Mailer: git-send-email 2.47.0.rc1.288.g06298d1525-goog Message-ID: <20241015231925.3854230-3-mmaurer@google.com> Subject: [PATCH v6 2/5] modules: Support extended MODVERSIONS info From: Matthew Maurer To: masahiroy@kernel.org, ndesaulniers@google.com, ojeda@kernel.org, gary@garyguo.net, mcgrof@kernel.org, Michael Ellerman , Alex Gaynor , Naveen N Rao , Arnd Bergmann , "Mike Rapoport (Microsoft)" , Benjamin Gray Cc: rust-for-linux@vger.kernel.org, linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, neal@gompa.dev, marcan@marcan.st, j@jannau.net, asahi@lists.linux.dev, linux-modules@vger.kernel.org, samitolvanen@google.com, Matthew Maurer , Nicholas Piggin , Christophe Leroy , Madhavan Srinivasan , Petr Pavlu , Daniel Gomez , Boqun Feng , " =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= " , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Andrew Morton , linuxppc-dev@lists.ozlabs.org Adds a new format for MODVERSIONS which stores each field in a separate ELF section. This initially adds support for variable length names, but could later be used to add additional fields to MODVERSIONS in a backwards compatible way if needed. Any new fields will be ignored by old user tooling, unlike the current format where user tooling cannot tolerate adjustments to the format (for example making the name field longer). Since PPC munges its version records to strip leading dots, we reproduce the munging for the new format. Other architectures do not appear to have architecture-specific usage of this information. Signed-off-by: Matthew Maurer --- arch/powerpc/kernel/module_64.c | 23 ++++++++- kernel/module/internal.h | 11 ++++ kernel/module/main.c | 92 ++++++++++++++++++++++++++++++--- kernel/module/version.c | 45 ++++++++++++++++ 4 files changed, 161 insertions(+), 10 deletions(-) diff --git a/arch/powerpc/kernel/module_64.c b/arch/powerpc/kernel/module_64.c index 135960918d14..0f7ef7e7e9d6 100644 --- a/arch/powerpc/kernel/module_64.c +++ b/arch/powerpc/kernel/module_64.c @@ -355,6 +355,23 @@ static void dedotify_versions(struct modversion_info *vers, } } +static void dedotify_ext_version_names(char *str_seq, unsigned long size) +{ + unsigned long out = 0; + unsigned long in; + char last = '\0'; + + for (in = 0; in < size; in++) { + /* Skip one leading dot */ + if (last == '\0' && str_seq[in] == '.') + in++; + last = str_seq[in]; + str_seq[out++] = last; + } + /* Zero the trailing portion of the names table for robustness */ + memset(&str_seq[out], 0, size - out); +} + /* * Undefined symbols which refer to .funcname, hack to funcname. Make .TOC. * seem to be defined (value set later). @@ -424,10 +441,12 @@ int module_frob_arch_sections(Elf64_Ehdr *hdr, me->arch.toc_section = i; if (sechdrs[i].sh_addralign < 8) sechdrs[i].sh_addralign = 8; - } - else if (strcmp(secstrings+sechdrs[i].sh_name,"__versions")==0) + } else if (strcmp(secstrings + sechdrs[i].sh_name, "__versions") == 0) dedotify_versions((void *)hdr + sechdrs[i].sh_offset, sechdrs[i].sh_size); + else if (strcmp(secstrings + sechdrs[i].sh_name, "__version_ext_names") == 0) + dedotify_ext_version_names((void *)hdr + sechdrs[i].sh_offset, + sechdrs[i].sh_size); if (sechdrs[i].sh_type == SHT_SYMTAB) dedotify((void *)hdr + sechdrs[i].sh_offset, diff --git a/kernel/module/internal.h b/kernel/module/internal.h index daef2be83902..59959c21b205 100644 --- a/kernel/module/internal.h +++ b/kernel/module/internal.h @@ -86,6 +86,8 @@ struct load_info { unsigned int vers; unsigned int info; unsigned int pcpu; + unsigned int vers_ext_crc; + unsigned int vers_ext_name; } index; }; @@ -389,6 +391,15 @@ void module_layout(struct module *mod, struct modversion_info *ver, struct kerne struct kernel_symbol *ks, struct tracepoint * const *tp); int check_modstruct_version(const struct load_info *info, struct module *mod); int same_magic(const char *amagic, const char *bmagic, bool has_crcs); +struct modversion_info_ext { + size_t remaining; + const s32 *crc; + const char *name; +}; +void modversion_ext_start(const struct load_info *info, struct modversion_info_ext *ver); +void modversion_ext_advance(struct modversion_info_ext *ver); +#define for_each_modversion_info_ext(ver, info) \ + for (modversion_ext_start(info, &ver); ver.remaining > 0; modversion_ext_advance(&ver)) #else /* !CONFIG_MODVERSIONS */ static inline int check_version(const struct load_info *info, const char *symname, diff --git a/kernel/module/main.c b/kernel/module/main.c index 3db9ff544c09..f5f4ceaef31a 100644 --- a/kernel/module/main.c +++ b/kernel/module/main.c @@ -2072,6 +2072,82 @@ static int elf_validity_cache_index_str(struct load_info *info) return 0; } +/** + * elf_validity_cache_index_versions() - Validate and cache version indices + * @info: Load info to cache version indices in. + * Must have &load_info->sechdrs and &load_info->secstrings populated. + * @flags: Load flags, relevant to suppress version loading, see + * uapi/linux/module.h + * + * If we're ignoring modversions based on @flags, zero all version indices + * and return validity. Othewrise check: + * + * * If "__version_ext_crcs" is present, "__version_ext_names" is present + * * There is a name present for every crc + * + * Then populate: + * + * * &load_info->index.vers + * * &load_info->index.vers_ext_crc + * * &load_info->index.vers_ext_names + * + * if present. + * + * Return: %0 if valid, %-ENOEXEC on failure. + */ +static int elf_validity_cache_index_versions(struct load_info *info, int flags) +{ + unsigned int vers_ext_crc; + unsigned int vers_ext_name; + size_t crc_count; + size_t remaining_len; + size_t name_size; + char *name; + + /* If modversions were suppressed, pretend we didn't find any */ + if (flags & MODULE_INIT_IGNORE_MODVERSIONS) { + info->index.vers = 0; + info->index.vers_ext_crc = 0; + info->index.vers_ext_name = 0; + return 0; + } + + vers_ext_crc = find_sec(info, "__version_ext_crcs"); + vers_ext_name = find_sec(info, "__version_ext_names"); + + /* If we have one field, we must have the other */ + if (!!vers_ext_crc != !!vers_ext_name) { + pr_err("extended version crc+name presence does not match"); + return -ENOEXEC; + } + + /* + * If we have extended version information, we should have the same + * number of entries in every section. + */ + if (vers_ext_crc) { + crc_count = info->sechdrs[vers_ext_crc].sh_size / sizeof(s32); + name = (void *)info->hdr + + info->sechdrs[vers_ext_name].sh_offset; + remaining_len = info->sechdrs[vers_ext_name].sh_size; + + while (crc_count--) { + name_size = strnlen(name, remaining_len) + 1; + if (name_size > remaining_len) { + pr_err("more extended version crcs than names"); + return -ENOEXEC; + } + remaining_len -= name_size; + name += name_size; + } + } + + info->index.vers = find_sec(info, "__versions"); + info->index.vers_ext_crc = vers_ext_crc; + info->index.vers_ext_name = vers_ext_name; + return 0; +} + /** * elf_validity_cache_index() - Resolve, validate, cache section indices * @info: Load info to read from and update. @@ -2086,9 +2162,7 @@ static int elf_validity_cache_index_str(struct load_info *info) * * elf_validity_cache_index_mod() * * elf_validity_cache_index_sym() * * elf_validity_cache_index_str() - * - * If versioning is not suppressed via flags, load the version index from - * a section called "__versions" with no validation. + * * elf_validity_cache_index_versions() * * If CONFIG_SMP is enabled, load the percpu section by name with no * validation. @@ -2111,11 +2185,9 @@ static int elf_validity_cache_index(struct load_info *info, int flags) err = elf_validity_cache_index_str(info); if (err < 0) return err; - - if (flags & MODULE_INIT_IGNORE_MODVERSIONS) - info->index.vers = 0; /* Pretend no __versions section! */ - else - info->index.vers = find_sec(info, "__versions"); + err = elf_validity_cache_index_versions(info, flags); + if (err < 0) + return err; info->index.pcpu = find_pcpusec(info); @@ -2326,6 +2398,10 @@ static int rewrite_section_headers(struct load_info *info, int flags) /* Track but don't keep modinfo and version sections. */ info->sechdrs[info->index.vers].sh_flags &= ~(unsigned long)SHF_ALLOC; + info->sechdrs[info->index.vers_ext_crc].sh_flags &= + ~(unsigned long)SHF_ALLOC; + info->sechdrs[info->index.vers_ext_name].sh_flags &= + ~(unsigned long)SHF_ALLOC; info->sechdrs[info->index.info].sh_flags &= ~(unsigned long)SHF_ALLOC; return 0; diff --git a/kernel/module/version.c b/kernel/module/version.c index 53f43ac5a73e..c246d4087970 100644 --- a/kernel/module/version.c +++ b/kernel/module/version.c @@ -19,11 +19,28 @@ int check_version(const struct load_info *info, unsigned int versindex = info->index.vers; unsigned int i, num_versions; struct modversion_info *versions; + struct modversion_info_ext version_ext; /* Exporting module didn't supply crcs? OK, we're already tainted. */ if (!crc) return 1; + /* If we have extended version info, rely on it */ + if (info->index.vers_ext_crc) { + for_each_modversion_info_ext(version_ext, info) { + if (strcmp(version_ext.name, symname) != 0) + continue; + if (*version_ext.crc == *crc) + return 1; + pr_debug("Found checksum %X vs module %X\n", + *crc, *version_ext.crc); + goto bad_version; + } + pr_warn_once("%s: no extended symbol version for %s\n", + info->name, symname); + return 1; + } + /* No versions at all? modprobe --force does this. */ if (versindex == 0) return try_to_force_load(mod, symname) == 0; @@ -87,6 +104,34 @@ int same_magic(const char *amagic, const char *bmagic, return strcmp(amagic, bmagic) == 0; } +void modversion_ext_start(const struct load_info *info, + struct modversion_info_ext *start) +{ + unsigned int crc_idx = info->index.vers_ext_crc; + unsigned int name_idx = info->index.vers_ext_name; + Elf_Shdr *sechdrs = info->sechdrs; + + /* + * Both of these fields are needed for this to be useful + * Any future fields should be initialized to NULL if absent. + */ + if (crc_idx == 0 || name_idx == 0) { + start->remaining = 0; + return; + } + + start->crc = (const s32 *)sechdrs[crc_idx].sh_addr; + start->name = (const char *)sechdrs[name_idx].sh_addr; + start->remaining = sechdrs[crc_idx].sh_size / sizeof(*start->crc); +} + +void modversion_ext_advance(struct modversion_info_ext *vers) +{ + vers->remaining--; + vers->crc++; + vers->name += strlen(vers->name) + 1; +} + /* * Generate the signature for all relevant module structures here. * If these change, we don't want to try to parse the module. From patchwork Tue Oct 15 23:18:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Maurer X-Patchwork-Id: 13837409 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 61ECA1F80A4 for ; Tue, 15 Oct 2024 23:19:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729034399; cv=none; b=L54yKAJArt0Uo3Q6njGfxiftVLCOaK9NtgsouX+mZIrKgXKf9IEtwKB7pNsR/3cfoLCxjfuz+UiBHOmdW/L3JKdv8jNORPVJ8ucyMe5/9o7nVp32rrjd+g0OuzDVbWygr5fnbRkl18ydQSciwBgLDyoSgLqDVKxzrN5bkcS3Zno= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729034399; c=relaxed/simple; bh=b/Bd5hNVwONQMAMAKZObOat4jqHFnL5FtBWQng4HuQc=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=rNwq9Yi2jP5BQ/T6GIrTiSmehHCUpjhpz9pfniE7BKH5cmn+nGLzSKCmtCdRLwRJAVj1WAXcohb1192vZzb/6UlmL1hUZvFJDCDS5RLyB7nxlKpU9UNC7q+TH4Ph0dHfhlWwjdqSFlAA7e9I420ZW1AtbGdow5lPuWK1/tFqoAQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--mmaurer.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=N1dO/cYJ; arc=none smtp.client-ip=209.85.219.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--mmaurer.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="N1dO/cYJ" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e292a6bdd72so6632005276.0 for ; Tue, 15 Oct 2024 16:19:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1729034396; x=1729639196; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=GMeFuBGaCaHx7HaM28eyKlSyRMkG/ZUOc3U36euZD88=; b=N1dO/cYJgyXeHSEkWZ8PHaXrwa/kRuKQYlwroncJFvpb+qGuZlcqMJw7yzLeY03SXD Tf3MIpwjEaL7rtuiH2HoEPdISP63RqtNsmBauP0fjZ2ytZWbuvDpD+XpeuwdZb7Vel4m rwDhDnugNGydsQ1jb9+y0lEiDpgyAVIil/SrHktcGNRXQXh9H2ygeeMx7bECNdUZQcIj Z7/PWE5YWKimlu0XXydjHhLEDV8BRzdbczjknmDR/oFRbo29BvVQpWyMRCP1FD/p+JoX 38hchTAzzXjhve1pzxwljmTVZxAabLdBO5rZo8/VNAbjcLY+ffYEL/sMO1vvBnP7+C1y Krjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729034396; x=1729639196; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=GMeFuBGaCaHx7HaM28eyKlSyRMkG/ZUOc3U36euZD88=; b=tgZlW83grIQLEJ68zIM+iybrmgmek9ZWe+NCjE6uK6layNFRecw0ymjHv7vJhh2yQj R2tznERT5uYpkXryfgWa7KKZzod+Cp4PRMIF9Ms11VkwLT2aoONpYmYocuWwI6rUoi13 AWz7Xh1Pc5SeNEuoDnwdfCqbA2jl3i5gelABxoNZdq25lrAp1EOVckVuWxeiCEL4MyaX bAOcCNh0ZFD3rj4YGdsAlb4YP22tsx3u4f1dyecTyrPlvCM6+B0tsFuOQye1YNpvlMmH VD/EM0M/lnPY0ZHN2ZlZUZMt1vNeNC/uSUfAA6Kk4Vesf08h6MD6tSovHsJlGp9c06wX 7L+Q== X-Forwarded-Encrypted: i=1; AJvYcCUflh7wewaPRtm784xgCOmXz3Lqz4K7qkqCBwCpoGK9PRZxLgxHJlQOOhdoubW1ueKkVrPsq9ktjX62OOU+@vger.kernel.org X-Gm-Message-State: AOJu0YyHnvDEIII9Tsht4aHSQ9ZKWvlXprneOc4j6XgUdX1v/CqZ3spX Jl7Hx+PPk7nAGhXBfjKKkeibnXvOgrbXByq2Rx7b2OavkLY1/h5U3j2ZwVXCArSHNASPKhGaxap ePijm8g== X-Google-Smtp-Source: AGHT+IHJ/PD4IZdXpfLT+phmwcv6QqIW8I80B2uJZiw7eFoWOINWL5PmPprPbPx3sBWJLPoXxBjkxCvK2VhZ X-Received: from anyblade.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:1791]) (user=mmaurer job=sendgmr) by 2002:a5b:341:0:b0:e29:68a9:8612 with SMTP id 3f1490d57ef6-e29782f4017mr1762276.4.1729034396326; Tue, 15 Oct 2024 16:19:56 -0700 (PDT) Date: Tue, 15 Oct 2024 23:18:58 +0000 In-Reply-To: <20241015231925.3854230-1-mmaurer@google.com> Precedence: bulk X-Mailing-List: linux-modules@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241015231925.3854230-1-mmaurer@google.com> X-Mailer: git-send-email 2.47.0.rc1.288.g06298d1525-goog Message-ID: <20241015231925.3854230-4-mmaurer@google.com> Subject: [PATCH v6 3/5] export_report: Tolerate additional `.mod.c` content From: Matthew Maurer To: masahiroy@kernel.org, ndesaulniers@google.com, ojeda@kernel.org, gary@garyguo.net, mcgrof@kernel.org, Alex Gaynor Cc: rust-for-linux@vger.kernel.org, linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, neal@gompa.dev, marcan@marcan.st, j@jannau.net, asahi@lists.linux.dev, linux-modules@vger.kernel.org, samitolvanen@google.com, Matthew Maurer , Boqun Feng , " =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= " , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross Currently, `export_report.pl` will error out if it sees a hex number not in the context of the original `__versions` array. This adds a "finished" state so that it does not attempt to parse content past the end of the array, and requires the array to be terminated. This is prepwork for the subsequent extended modversions information, which would not be parseable otherwise. Signed-off-by: Matthew Maurer --- scripts/export_report.pl | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/export_report.pl b/scripts/export_report.pl index 30b5f7819086..dcef915405f3 100755 --- a/scripts/export_report.pl +++ b/scripts/export_report.pl @@ -125,6 +125,10 @@ foreach my $thismod (@allcfiles) { next; } if ($state == 2) { + if ( $_ =~ /};/ ) { + $state = 3; + next; + } if ( $_ !~ /0x[0-9a-f]+,/ ) { next; } @@ -134,7 +138,7 @@ foreach my $thismod (@allcfiles) { push(@{$MODULE{$thismod}} , $sym); } } - if ($state != 2) { + if ($state != 3) { warn "WARNING:$thismod is not built with CONFIG_MODVERSIONS enabled\n"; $modversion_warnings++; } From patchwork Tue Oct 15 23:18:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Maurer X-Patchwork-Id: 13837410 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A8CCC1FDFAC for ; Tue, 15 Oct 2024 23:19:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729034402; cv=none; b=jm26cwJKYzPkq/r92Y/Z7pPcjPP+vbVSQ1Draa9CTytX2o1L+XZ6k/6rsUr0MPdjvn6WSVwi2VzmlpatFI2tjKG85iNAGCYdxOFeD/ok2RX5XTlXqvcnpWrPNAV9kixZY5O2SJzhz2hP4evdihC7RiU4SHPCdBtLJr5FzrMFIdw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729034402; c=relaxed/simple; bh=Kp5uggGbEJrPIVkqdlvJVT6U0SCrN+hpDOmeYYUT59w=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=ezVic9Zk4hspmGFarpyDcnBrtOy6zQ1ENJ62Je3w90IFJy8GczaNuG8anlrNzhFqGlqWcJJBCInWEpKjCvBC4reVp1MxUMxWRfv07irrsXQVOw6JE+1dP7hSXsGtHZ0alC8PG7Zikp64aD0nAV/1vdKEsB2qnD4wvKfQc53/V9E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--mmaurer.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Opv7o2Sa; arc=none smtp.client-ip=209.85.128.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--mmaurer.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Opv7o2Sa" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6dbbeee08f0so5807827b3.0 for ; Tue, 15 Oct 2024 16:19:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1729034399; x=1729639199; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=xasC2bG4ku4iDrf29H3XucNRhtvas+BiYTJxtPjY34w=; b=Opv7o2SauZsHkaEOtnSMVkRMJG96RIH4tAde9LPE+Gvy8GL8BKRr9h/3Bh2hqQUTCZ pJlngBMbWusiiFMy3xK+SYUffO5PF1rl0nTdkdUQ1RUtAtxRZY/UYRCc7WUusjtRf2e5 ItIb8CEqxK6GQLQi2tOyWsfT4muWDQF60ANVTYqrZEvRk2AMGIWYp3pyTXxcpj1eSlQk PoqY0MlZO65norjFrQlD8ruoU7ta8RnSO9gV9F3sfe0Fai9GnkuTFfTAWIZO/DWltNZA ZfsZuFPhn19ujZPmQ9RxFBoULvkL5mAwz+p0nRy2LbOL34yQghKKvGvc2k9i5kMfwxTp /vRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729034399; x=1729639199; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=xasC2bG4ku4iDrf29H3XucNRhtvas+BiYTJxtPjY34w=; b=BdU+VdZH4D3KEN7C5sl34l7ts1KHCfuXQSHtT7l1qjeFgQFQocXI9Y2GyeT9u8tnVd j4N0Tq/RTLVnaWSokuN9bM9hRg9sPv3/H36BL1XWZeJ+IwkE24+2Bw9WcKBfP4PPreOt VSMKJK+Qg2xStVcj6/xhzv/D2rabCYzL4ghXjwvZ/hVnQtew6Rr7yj8w3vN1iE2SOBWx SKIseUsjrN27JcTzc7j1U5PSQE+I8Rqo3ApLyUtskAHygihJnpUAITo24rKNwhXxM370 J0Izufh/2ohrcVDOYtYOQfvH5GRyuhZy0ryljxgF/pdkNB/vFK7TRUd8PbUCvfCfgDrX oJ0Q== X-Forwarded-Encrypted: i=1; AJvYcCUS2yuPKNPvQpRTIhwGWuaY2MPiFFWGVXn/SNkDzlweVM/E6bxPuhXMfQky8W29B5aKNiYDpffGcTJCdXO6@vger.kernel.org X-Gm-Message-State: AOJu0Yw5JC00dDKFXCJIEpgs62d73Iu/1+i/0VZVeob1HxNZ/IqvYYdi BoavyltCN44Ti2r4sg2LuqJMM1REuSYvdNVq77cYXEb8qOeiGcvAbymog4oR/QTICalcu0JJMHU cP3J/vg== X-Google-Smtp-Source: AGHT+IEhM7UuM8n6j7x3Tn2NtgtBsdUObL6hxcYJG9U32wvNR7YuZK72mjGGNuHH/96W7Ib7Lctj8rOyPY/w X-Received: from anyblade.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:1791]) (user=mmaurer job=sendgmr) by 2002:a05:690c:3587:b0:68e:8de6:617c with SMTP id 00721157ae682-6e3d3aacfc0mr316117b3.5.1729034398638; Tue, 15 Oct 2024 16:19:58 -0700 (PDT) Date: Tue, 15 Oct 2024 23:18:59 +0000 In-Reply-To: <20241015231925.3854230-1-mmaurer@google.com> Precedence: bulk X-Mailing-List: linux-modules@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241015231925.3854230-1-mmaurer@google.com> X-Mailer: git-send-email 2.47.0.rc1.288.g06298d1525-goog Message-ID: <20241015231925.3854230-5-mmaurer@google.com> Subject: [PATCH v6 4/5] modpost: Produce extended MODVERSIONS information From: Matthew Maurer To: masahiroy@kernel.org, ndesaulniers@google.com, ojeda@kernel.org, gary@garyguo.net, mcgrof@kernel.org, Alex Gaynor Cc: rust-for-linux@vger.kernel.org, linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, neal@gompa.dev, marcan@marcan.st, j@jannau.net, asahi@lists.linux.dev, linux-modules@vger.kernel.org, samitolvanen@google.com, Matthew Maurer , Petr Pavlu , Daniel Gomez , Nathan Chancellor , Nicolas Schier , Boqun Feng , " =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= " , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross Generate both the existing modversions format and the new extended one when running modpost. Presence of this metadata in the final .ko is guarded by CONFIG_EXTENDED_MODVERSIONS. We no longer generate an error on long symbols in modpost if CONFIG_EXTENDED_MODVERSIONS is set, as they can now be appropriately encoded in the extended section. These symbols will be skipped in the previous encoding. An error will still be generated if CONFIG_EXTENDED_MODVERSIONS is not set. Signed-off-by: Matthew Maurer --- kernel/module/Kconfig | 8 ++++++++ scripts/mod/modpost.c | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/kernel/module/Kconfig b/kernel/module/Kconfig index 7c6588148d42..a5de2b7f2758 100644 --- a/kernel/module/Kconfig +++ b/kernel/module/Kconfig @@ -177,6 +177,14 @@ config ASM_MODVERSIONS assembly. This can be enabled only when the target architecture supports it. +config EXTENDED_MODVERSIONS + bool "Extended Module Versioning Support" + depends on MODVERSIONS + help + This enables extended MODVERSIONs support, allowing long symbol + names to be versioned. The most likely reasons you would enable + this are for Rust usage or aggressive LTO configurations. + config MODULE_SRCVERSION_ALL bool "Source checksum for all modules" help diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index 107393a8c48a..d18ff8a1109a 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -1840,15 +1840,56 @@ static void add_versions(struct buffer *b, struct module *mod) continue; } if (strlen(s->name) >= MODULE_NAME_LEN) { +#ifdef CONFIG_EXTENDED_MODVERSIONS + /* this symbol will only be in the extended info */ + continue; +#else error("too long symbol \"%s\" [%s.ko]\n", s->name, mod->name); break; +#endif } buf_printf(b, "\t{ %#8x, \"%s\" },\n", s->crc, s->name); } buf_printf(b, "};\n"); + + buf_printf(b, "#ifdef CONFIG_EXTENDED_MODVERSIONS\n"); + buf_printf(b, "static const s32 ____version_ext_crcs[]\n"); + buf_printf(b, "__used __section(\"__version_ext_crcs\") = {\n"); + list_for_each_entry(s, &mod->unresolved_symbols, list) { + if (!s->module) + continue; + if (!s->crc_valid) { + /* + * We already warned on this when producing the legacy + * modversions table. + */ + continue; + } + buf_printf(b, "\t%#8x,\n", s->crc); + } + buf_printf(b, "};\n"); + + buf_printf(b, "static const char ____version_ext_names[]\n"); + buf_printf(b, "__used __section(\"__version_ext_names\") =\n"); + list_for_each_entry(s, &mod->unresolved_symbols, list) { + if (!s->module) + continue; + if (!s->crc_valid) { + /* + * We already warned on this when producing the legacy + * modversions table. + * We need to skip its name too, as the indexes in + * both tables need to align. + */ + continue; + } + buf_printf(b, "\t\"%s\\0\"\n", s->name); + } + buf_printf(b, ";\n"); + buf_printf(b, "#endif\n"); } static void add_depends(struct buffer *b, struct module *mod) From patchwork Tue Oct 15 23:19:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Maurer X-Patchwork-Id: 13837411 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D35481FDFA9 for ; Tue, 15 Oct 2024 23:20:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729034408; cv=none; b=cxWveWsyMWrPQ6XxPowEI+Kruq0/kOsYJg7VWZAgYXkavKdrD495n/4EZ3+mqz+gMplPXTkE71ZpXOUMdzJutrXqRiiyE1z5gaO2Njy/+jVLNqegIhwfy/yWN9qm+l3Ttm6x08XOMK3fEq1c/zktVPTpdMLn/ZHbDIpTIKks6Zc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729034408; c=relaxed/simple; bh=THSkSo9lSkuxsbYiUqaXJmBiMFSg1TaDfQHynW6LWoM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=aJkPntjS1FH2jL+PacufWar8sjDdUvGqb+Qycb0Vu6bthzbP/ykDy4A7ow/TInbv05WK9rtJDOUlGzzUiQh1B0cc6tCz726bLxM899J9pEvWFGyF+2CRJeG4FPZtmDl0NlXIKU+8kMct/QJ0QZ3qWdbaDiuQIfATu2aAlZOqlLA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--mmaurer.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=DJkd1Qjd; arc=none smtp.client-ip=209.85.128.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--mmaurer.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="DJkd1Qjd" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6e370d76c15so51958317b3.2 for ; Tue, 15 Oct 2024 16:20:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1729034406; x=1729639206; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=y90q7N+0JYvarHeSSS/HcK3d00J7zzbtwQB+DjacdQs=; b=DJkd1Qjd6nfYoALd0SmcygiPVkhCub3F6KQlzJFaGd172PG+zHvYXrDFqdcoFw0l0z tWxJYs8O1wnSlt1nmB4VxN8+fUgqqTfBhiR1l2yEoKMPJWI3W59zpmOEvX9mbskJt5ZT nrBnDIBtqftzCfy78ruvNKuL1ztQTwLC7QLbOMYdZJn13C9pt/W4Vz+YSlZhAJocTjU2 I7+ez/lBvnXV0i12tYHwHherRtEsaIgNIovI3jTloJGbO+ZKEPhTn4o1sBQRHEYouOfd 1rKPDILVBOJjh8HMLJ9xvCghVD5Iw+lGW8VdhR92biWljp6a1fLZNBHKBTb1EBl1NPrF OwyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729034406; x=1729639206; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=y90q7N+0JYvarHeSSS/HcK3d00J7zzbtwQB+DjacdQs=; b=IBnCl00pvjgYsrLL6nMiSs7bMCkqApQ5rjl2UelEEbqaMPrHQnJUi4+NUxi5QylHLC nqUK2uXALixrYgKreWfjkrDkepo6QjXO2pYEmNZus3qZxfUAh0qH0nTu7eBcTIVq1HIw P3RYB5nOkGAD+t6fFHaaLu+yIOI/K0fgiWYsZ9MBytCpHGNXxNaXjmX8f1A3gi6XkqoP MlcsgjTD+I+3DNkr8Ao69wWd5zKBUhmoDfiLqyIqZsa1z37I7ph7vIAoWSch8iXS0Dsk YI/aEHpvcoyZRgBTZiYr9i90IllvzvBAYjgQYZ8LkYA95VSjchNKQx9c+Eb56Y1OwKqE BdXA== X-Forwarded-Encrypted: i=1; AJvYcCWna6KHzXixLk0cAhnhV0lIbVJTVHuKT4KyHErv6EIfW1jnp5dW/jMYmcqOLOyPTe7IDQv4Fs6l0UrTATj6@vger.kernel.org X-Gm-Message-State: AOJu0Ywk0/0AFNjllYKnqoY5t7uhO/t01lzk5SSkkhcojHHmJGoBM8Ib A54YVkkl4eA1oflzBUrlpFVfe/z0uLxQ09UfMc3d9PQCuc6l3bhpqoyJ9a79/2SafVDRKy0hRZe MYfyfdQ== X-Google-Smtp-Source: AGHT+IEl0PoSNMsAIV4NYkV6h7fXXICopbsvroAdggBgvaXcptZB1VvmgZiKvr9u8QtCOHgbZG9OiwkRYgC+ X-Received: from anyblade.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:1791]) (user=mmaurer job=sendgmr) by 2002:a05:690c:9b02:b0:6e2:371f:4afe with SMTP id 00721157ae682-6e3d4194914mr597357b3.4.1729034405979; Tue, 15 Oct 2024 16:20:05 -0700 (PDT) Date: Tue, 15 Oct 2024 23:19:00 +0000 In-Reply-To: <20241015231925.3854230-1-mmaurer@google.com> Precedence: bulk X-Mailing-List: linux-modules@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241015231925.3854230-1-mmaurer@google.com> X-Mailer: git-send-email 2.47.0.rc1.288.g06298d1525-goog Message-ID: <20241015231925.3854230-6-mmaurer@google.com> Subject: [PATCH v6 5/5] export_report: Use new version info format From: Matthew Maurer To: masahiroy@kernel.org, ndesaulniers@google.com, ojeda@kernel.org, gary@garyguo.net, mcgrof@kernel.org, Alex Gaynor Cc: rust-for-linux@vger.kernel.org, linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, neal@gompa.dev, marcan@marcan.st, j@jannau.net, asahi@lists.linux.dev, linux-modules@vger.kernel.org, samitolvanen@google.com, Matthew Maurer , Boqun Feng , " =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= " , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross The new version info format has a superset of symbols in the old format. Since this is a tool for in-tree modules, we don't need to parse the old one with this tool any longer. Even if we build without CONFIG_EXTENDED_MODVERSIONS, these are still in the `.mod.c` file. Their presence in the final module is controlled by conditional compilation inside the at file. Signed-off-by: Matthew Maurer --- scripts/export_report.pl | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/scripts/export_report.pl b/scripts/export_report.pl index dcef915405f3..6a37df6f947f 100755 --- a/scripts/export_report.pl +++ b/scripts/export_report.pl @@ -114,31 +114,29 @@ foreach my $thismod (@allcfiles) { } my $state=0; + # State map: + # 0 - Looking for names + # 1 - Scanning names + # 2 - Done while ( <$module> ) { chomp; if ($state == 0) { - $state = 1 if ($_ =~ /static const struct modversion_info/); + $state = 1 if ($_ =~ /__used __section\("__version_ext_names"\)/); next; } if ($state == 1) { - $state = 2 if ($_ =~ /__used __section\("__versions"\)/); - next; - } - if ($state == 2) { - if ( $_ =~ /};/ ) { - $state = 3; - next; - } - if ( $_ !~ /0x[0-9a-f]+,/ ) { + if ( $_ =~ /;/ ) { + $state = 2; next; } - my $sym = (split /([,"])/,)[4]; + $_ =~ /"(.*)\\0"/; + my $sym = $1; my ($module, $value, $symbol, $gpl) = @{$SYMBOL{$sym}}; $SYMBOL{ $sym } = [ $module, $value+1, $symbol, $gpl]; push(@{$MODULE{$thismod}} , $sym); } } - if ($state != 3) { + if ($state != 2) { warn "WARNING:$thismod is not built with CONFIG_MODVERSIONS enabled\n"; $modversion_warnings++; }