From nobody Wed Sep 17 18:08:34 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DE8A2C4332F for ; Fri, 16 Dec 2022 22:17:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229744AbiLPWR3 (ORCPT ); Fri, 16 Dec 2022 17:17:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49224 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229731AbiLPWRX (ORCPT ); Fri, 16 Dec 2022 17:17:23 -0500 Received: from mail-io1-xd4a.google.com (mail-io1-xd4a.google.com [IPv6:2607:f8b0:4864:20::d4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CF1DE2A252 for ; Fri, 16 Dec 2022 14:17:20 -0800 (PST) Received: by mail-io1-xd4a.google.com with SMTP id r25-20020a6bfc19000000b006e002cb217fso2026380ioh.2 for ; Fri, 16 Dec 2022 14:17:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=QIkoHfPVoGJGQCXWyZmF+mudK9y7JC4uGfB+VF9vmAA=; b=DPM862br1ksx4WgfZPPdueiIQnI6WvqPmGTG1MgLblwtuOlS7D2+IHQhAHJWXU9iNG j4RxkkFEM0HoFL3kqNsdC+IJMWBTwI8W6+Ta5PvZplSXceS8nTDmbx2x+33J5oD92OFT g77b5zdEyCeTgxNQQFcZA/XalLB+/1uF5YTqvBjiIxsFzKG/Km8FlFj84+FnuoT0LMow HT2aw6HDm83sOt0XTM+xnEBPzPFUkRx+tiHqOWVrRF/4zSEfTDSIW0wZe/YA3+3tJQA8 F7V6Z8l7ZANhHSadRJglbkKVcT0i88Xi5gRe00KnPx6R6+C1xOoBUsZ+idFieWINkCzf aXbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=QIkoHfPVoGJGQCXWyZmF+mudK9y7JC4uGfB+VF9vmAA=; b=swHBLyhoTTIPjGvzs6ZWTGUg4jQsdLEJ8yHU6S5ToXoArDdBDnCuOll6qfPDAfuNlF XZeZ5o8CYkHCzhDfKSo3zLj0iHSWZNUR+C9iHqj8riUMNJ2XjwaQkdmImnoLm2BR0EFQ aVFlAKpJaJqA9JFzvgm1gJyxDXmkeb01iisLIP/fuoi8D7G0qLUaOJ0dYpn7z7ZpAU5n WcGJDXPb64Omz9FaTOj2SKmO4cydWpY+U2ZbJ6SZCJJrz8nxfW/JCEY9+RWPfkVDZXbk cLxR7pDoGEURhbfCQXeIC1KqNuR19tiSBzg7Asi3ddfOpWSg6fTJ+nc8LQJCefEl1M8+ zjcg== X-Gm-Message-State: ANoB5pl1m5hBtTciKG/Syt5ltmKFAgYIzQ7Yl5mU3LlD39wIpCrvoyvp b3ptlqUmOyqtuJteXUZDlWhfqJSYCtaNUSs= X-Google-Smtp-Source: AA0mqf6TfmBK0Mx/g4QE2FH2JCuQ34V+4c+rpIqMat7imN4HKSMjxbOfVMuq9+IWftjxtKMRD5QngzlpEPjmoOk= X-Received: from allenwebb.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:12e8]) (user=allenwebb job=sendgmr) by 2002:a5d:9e4a:0:b0:6de:42ff:d96b with SMTP id i10-20020a5d9e4a000000b006de42ffd96bmr34882896ioi.58.1671229040270; Fri, 16 Dec 2022 14:17:20 -0800 (PST) Date: Fri, 16 Dec 2022 16:16:59 -0600 In-Reply-To: <20221216221703.294683-1-allenwebb@google.com> Mime-Version: 1.0 References: <20221216221703.294683-1-allenwebb@google.com> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog Message-ID: <20221216221703.294683-2-allenwebb@google.com> Subject: [PATCH v7 1/5] module.h: MODULE_DEVICE_TABLE for built-in modules From: Allen Webb To: "linux-modules@vger.kernel.org" , "linux-usb@vger.kernel.org" , "linux-kernel@vger.kernel.org" Cc: Luis Chamberlain , Greg Kroah-Hartman , "Rafael J. Wysocki" , Allen Webb Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Implement MODULE_DEVICE_TABLE for build-in modules to make it possible to generate a builtin.alias file to complement modules.alias. Signed-off-by: Allen Webb --- include/linux/module.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/include/linux/module.h b/include/linux/module.h index ec61fb53979a9..49e4019393127 100644 --- a/include/linux/module.h +++ b/include/linux/module.h @@ -243,7 +243,15 @@ extern void cleanup_module(void); extern typeof(name) __mod_##type##__##name##_device_table \ __attribute__ ((unused, alias(__stringify(name)))) #else /* !MODULE */ -#define MODULE_DEVICE_TABLE(type, name) +/* The names may not be unique for built-in modules, so include the module= name + * to guarantee uniqueness. + */ +#define MODULE_DEVICE_TABLE(type, name) \ +extern void *CONCATENATE( \ + CONCATENATE(__mod_##type##__##name##__, \ + __KBUILD_MODNAME), \ + _device_table) \ + __attribute__ ((unused, alias(__stringify(name)))) #endif =20 /* Version of form [:][-]. --=20 2.37.3 From nobody Wed Sep 17 18:08:34 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AFF8FC3DA78 for ; Fri, 16 Dec 2022 22:17:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230018AbiLPWRh (ORCPT ); Fri, 16 Dec 2022 17:17:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49248 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229996AbiLPWRX (ORCPT ); Fri, 16 Dec 2022 17:17:23 -0500 Received: from mail-io1-xd49.google.com (mail-io1-xd49.google.com [IPv6:2607:f8b0:4864:20::d49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2716727DC9 for ; Fri, 16 Dec 2022 14:17:23 -0800 (PST) Received: by mail-io1-xd49.google.com with SMTP id n10-20020a6b590a000000b006e03471b3eeso2016715iob.11 for ; Fri, 16 Dec 2022 14:17:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=G0/vtfeve/G9ydeke/gLh4oQEre+L13iDXwcfVwzkg8=; b=XuNwKmwPpNlfKES3zcBJOF59W0eZv2AMPYDbfitG7Ycy+a7Q8uZ5QCspwLjWD88r4N qNEl4O2mUAUamEUPN2f4xsKafyXL5LRghVfKvYYYkihHNyh/fjFCWr4roR2GazK/JIPT SD0xAPysuyXz0C/a5JxcHcz76ur05fNnHe53fXhRx15SQ1eGnqGenRPXKcBwY0enWofR 0fWkGOzlCjCBHavz7gOEclKO4CHaxd3tBdECRyE7nciqto1C2kIiHJfMhdsEv1Do0QJA m9iI/5kMYVVHZ8qMSWC4P15VHtu//B+FQXkpMrwUaM80OPXVP/RSbuK8Wyw+OnrTevgz 4m6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=G0/vtfeve/G9ydeke/gLh4oQEre+L13iDXwcfVwzkg8=; b=dsHX3SmPY0oK4BTEFmV02Cn9HVyEt00YNBeoWHeB7M+CbH2izfyxsvX9HxaocRqnYT mujQ64rGYWpY4ivRoeS9l02iKFAwibKqf46WMiK78OPYN7NRd5cQPts13cBqXZgH2s5w cyUlGbJHiTjiM9S2TZP26hGaKP73LxIohsBjTmgcA8wiBQ6sy0UjGcbOimzNzRq8w37N 4NDcPfHxjSEVpLo2CMRLHwoVY7gdVA7qpkcuUumYmxVE+u+8/QEpXSZI07xILeFAxcRV fG5UwDviumBudjKtNosIRh1cNV/j2IbeDU7lEbC+ObkUujsy4k0amQFDbGgs5T7UlYBo FJ1A== X-Gm-Message-State: ANoB5pnarsxGNMgL5fMW9O8RT0ncy7Pcoc1y169JiJFkemfBcLg85kLP s4mBI+Oub60HzvLv7mj16u8ya36FZ1hZcyY= X-Google-Smtp-Source: AA0mqf4UC/atAEdUb3Vl1JsfM1S7LbbKzn42gA1tVwXLOEl9Tg/CF2eeuhJLDOljn5iQSGJpHZxlAN8xlh4egrw= X-Received: from allenwebb.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:12e8]) (user=allenwebb job=sendgmr) by 2002:a05:6602:2bf0:b0:6e2:c12d:571e with SMTP id d16-20020a0566022bf000b006e2c12d571emr4547416ioy.32.1671229042549; Fri, 16 Dec 2022 14:17:22 -0800 (PST) Date: Fri, 16 Dec 2022 16:17:00 -0600 In-Reply-To: <20221216221703.294683-1-allenwebb@google.com> Mime-Version: 1.0 References: <20221216221703.294683-1-allenwebb@google.com> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog Message-ID: <20221216221703.294683-3-allenwebb@google.com> Subject: [PATCH v7 2/5] modpost: Track module name for built-in modules From: Allen Webb To: "linux-modules@vger.kernel.org" , "linux-usb@vger.kernel.org" , "linux-kernel@vger.kernel.org" Cc: Luis Chamberlain , Greg Kroah-Hartman , "Rafael J. Wysocki" , Allen Webb Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Keep track of the module name when processing match table symbols. Signed-off-by: Allen Webb --- scripts/mod/file2alias.c | 37 +++++++++++++++++++++++++++++++++---- scripts/mod/modpost.h | 1 + 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c index 80d973144fded..458e41ae0f5f1 100644 --- a/scripts/mod/file2alias.c +++ b/scripts/mod/file2alias.c @@ -28,6 +28,7 @@ typedef Elf64_Addr kernel_ulong_t; #include #endif =20 +#include #include #include =20 @@ -1540,9 +1541,9 @@ void handle_moddevtable(struct module *mod, struct el= f_info *info, Elf_Sym *sym, const char *symname) { void *symval; - char *zeros =3D NULL; - const char *name, *identifier; - unsigned int namelen; + char *zeros =3D NULL, *modname_str =3D NULL; + const char *name, *identifier, *modname; + unsigned int namelen, modnamelen; =20 /* We're looking for a section relative symbol */ if (!sym->st_shndx || get_secindex(info, sym) >=3D info->num_sections) @@ -1552,7 +1553,11 @@ void handle_moddevtable(struct module *mod, struct e= lf_info *info, if (ELF_ST_TYPE(sym->st_info) !=3D STT_OBJECT) return; =20 - /* All our symbols are of form __mod____device_table. */ + /* All our symbols are either of form + * __mod____device_table + * or + * __mod_____kmod__device_table + */ if (strncmp(symname, "__mod_", strlen("__mod_"))) return; name =3D symname + strlen("__mod_"); @@ -1564,8 +1569,29 @@ void handle_moddevtable(struct module *mod, struct e= lf_info *info, identifier =3D strstr(name, "__"); if (!identifier) return; + modnamelen =3D namelen; namelen =3D identifier - name; =20 + /* In the vmlinuz.o case we want to handle __kmod_ so aliases from + * builtin modules are attributed correctly. + */ + modname =3D strstr(identifier + 2, "__kmod_"); + if (modname) { + modname +=3D strlen("__kmod_"); + modnamelen -=3D (modname - name) + strlen("_device_table"); + modname_str =3D malloc(modnamelen + 1); + /* We don't want to continue if the allocation fails. */ + assert(modname_str); + memcpy(modname_str, modname, modnamelen); + modname_str[modnamelen] =3D '\0'; + } + + if (modname_str) + modname =3D modname_str; + else + modname =3D mod->name; + mod->builtin_name =3D modname; + /* Handle all-NULL symbols allocated into .bss */ if (info->sechdrs[get_secindex(info, sym)].sh_type & SHT_NOBITS) { zeros =3D calloc(1, sym->st_size); @@ -1597,6 +1623,9 @@ void handle_moddevtable(struct module *mod, struct el= f_info *info, } } free(zeros); + mod->builtin_name =3D NULL; + if (modname_str) + free(modname_str); } =20 /* Now add out buffered information to the generated C source */ diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h index 1178f40a73f3d..34fe5fc0b02cb 100644 --- a/scripts/mod/modpost.h +++ b/scripts/mod/modpost.h @@ -128,6 +128,7 @@ struct module { struct list_head missing_namespaces; // Actual imported namespaces struct list_head imported_namespaces; + const char *builtin_name; char name[]; }; =20 --=20 2.37.3 From nobody Wed Sep 17 18:08:34 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C6AA5C4332F for ; Fri, 16 Dec 2022 22:17:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230037AbiLPWRr (ORCPT ); Fri, 16 Dec 2022 17:17:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49246 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230002AbiLPWRZ (ORCPT ); Fri, 16 Dec 2022 17:17:25 -0500 Received: from mail-io1-xd4a.google.com (mail-io1-xd4a.google.com [IPv6:2607:f8b0:4864:20::d4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 60B402A95F for ; Fri, 16 Dec 2022 14:17:24 -0800 (PST) Received: by mail-io1-xd4a.google.com with SMTP id n10-20020a6b590a000000b006e03471b3eeso2016733iob.11 for ; Fri, 16 Dec 2022 14:17:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=H+RvplB5wkPH74MUb1wifMfzO8M5nZWLX+/SXGO5TdI=; b=q0b1jj9NvHbp3f43Na/217O79cCxnY5MMJB+tmd2m4a9KAMjYiB8BlpdORdqG+ungW 8rKFadTJM54bK/kumgRMVr1Yguw7JF71Hv3soXH7RaMR95ECsBNUxxq3e1WOSa+u2OI1 1Y6ix2z7qAGh4XvWq0HnpSOSARb3/Zy5jlbl3nwZp6nIH3KtoMlRZXkF8EBLJGK7iYWk 6niD7L0/pqfwMKn3UasRrTUGL8l+xEQJlvmdC1bwnoLHzUAGDpruXScii9m9DKrMoHDk /aWSB5puTi6SOEntsCfF2g/caz7oOkEyWLgRdcovsvqwpdvh1ZMq8KbdiMvYVh3WCVC5 RcdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=H+RvplB5wkPH74MUb1wifMfzO8M5nZWLX+/SXGO5TdI=; b=zMSa/gwC3ub2Upy36e7IPjXm0IU0g6Q5O4fs3jzrb2/zT52ZdR7DBer7VbHBsfSF+y x4mPnKHPtaIqMGXR2vJ/s1AfU9sUcDUk+4T1g4S1LdG5A72zjOgKKwsLpnAsgHIF+IUL VFGwzTlv2DR2odvkoZsbiVyYkTrKzfrtghGLEd+F21TzRq7TDTmRNArmkbDnbjCyTzhw J/nMtiM6FMY+OeAtoVkSIZ08TrYWRCTZnA9I1AEncMxUBu0kCt8oOmNhr6e7nHLCtmxa 5t1/eH4mFeETQmB1hn8BrHRsjKg3mzeSIfquT6bDunoi1mXGC4CXFKT2FomHqLa90xZM x7Ig== X-Gm-Message-State: AFqh2krf2WY7bJ4muvopHOsxuTakRvBWj9T88NUPnNekG7VW9mtA1Iqu TgWY95Xadt0rQcgKtRnC/ym7M4BxR6eHm2g= X-Google-Smtp-Source: AMrXdXu/b3LbN3BaGO2amr3yvcbAu+UGbScQX6evGCe9lTPh9LFkZJroFCZzUk59lwh7ey7DgjWZfjQ4rBqCa6A= X-Received: from allenwebb.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:12e8]) (user=allenwebb job=sendgmr) by 2002:a6b:4415:0:b0:6e6:279:2e74 with SMTP id r21-20020a6b4415000000b006e602792e74mr235776ioa.10.1671229043653; Fri, 16 Dec 2022 14:17:23 -0800 (PST) Date: Fri, 16 Dec 2022 16:17:01 -0600 In-Reply-To: <20221216221703.294683-1-allenwebb@google.com> Mime-Version: 1.0 References: <20221216221703.294683-1-allenwebb@google.com> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog Message-ID: <20221216221703.294683-4-allenwebb@google.com> Subject: [PATCH v7 3/5] modpost: Add -b option for emitting built-in aliases From: Allen Webb To: "linux-modules@vger.kernel.org" , "linux-usb@vger.kernel.org" , "linux-kernel@vger.kernel.org" Cc: Luis Chamberlain , Greg Kroah-Hartman , "Rafael J. Wysocki" , Allen Webb Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This adds an unimplemented command line flag for writing the built-in aliases to a file. Signed-off-by: Allen Webb --- scripts/mod/modpost.c | 23 +++++++++++++++++++++-- scripts/mod/modpost.h | 1 + 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index 2c80da0220c32..845f157d69ebc 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -2165,6 +2165,19 @@ static void write_if_changed(struct buffer *b, const= char *fname) write_buf(b, fname); } =20 +/* Write the builtin aliases to the specified file. */ +static void write_builtin(const char *fname) +{ + struct buffer buf =3D { }; + struct module *mod; + + list_for_each_entry(mod, &modules, list) { + buf_write(&buf, mod->modalias_buf.p, mod->modalias_buf.pos); + } + write_if_changed(&buf, fname); + free(buf.p); +} + static void write_vmlinux_export_c_file(struct module *mod) { struct buffer buf =3D { }; @@ -2321,13 +2334,16 @@ int main(int argc, char **argv) { struct module *mod; char *missing_namespace_deps =3D NULL; - char *dump_write =3D NULL, *files_source =3D NULL; + char *builtin_write =3D NULL, *dump_write =3D NULL, *files_source =3D NUL= L; int opt; LIST_HEAD(dump_lists); struct dump_list *dl, *dl2; =20 - while ((opt =3D getopt(argc, argv, "ei:mnT:o:awENd:")) !=3D -1) { + while ((opt =3D getopt(argc, argv, "b:ei:mnT:o:awENd:")) !=3D -1) { switch (opt) { + case 'b': + builtin_write =3D optarg; + break; case 'e': external_module =3D true; break; @@ -2390,6 +2406,9 @@ int main(int argc, char **argv) write_mod_c_file(mod); } =20 + if (builtin_write) + write_builtin(builtin_write); + if (missing_namespace_deps) write_namespace_deps_files(missing_namespace_deps); =20 diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h index 34fe5fc0b02cb..c55a6aeb46bfd 100644 --- a/scripts/mod/modpost.h +++ b/scripts/mod/modpost.h @@ -123,6 +123,7 @@ struct module { bool has_init; bool has_cleanup; struct buffer dev_table_buf; + struct buffer modalias_buf; char srcversion[25]; // Missing namespace dependencies struct list_head missing_namespaces; --=20 2.37.3 From nobody Wed Sep 17 18:08:34 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 86563C4332F for ; Fri, 16 Dec 2022 22:17:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230051AbiLPWRv (ORCPT ); Fri, 16 Dec 2022 17:17:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49294 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229957AbiLPWR0 (ORCPT ); Fri, 16 Dec 2022 17:17:26 -0500 Received: from mail-io1-xd4a.google.com (mail-io1-xd4a.google.com [IPv6:2607:f8b0:4864:20::d4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3969127917 for ; Fri, 16 Dec 2022 14:17:25 -0800 (PST) Received: by mail-io1-xd4a.google.com with SMTP id a14-20020a6b660e000000b006bd37975cdfso2027071ioc.10 for ; Fri, 16 Dec 2022 14:17:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=XLvu9YuJyEq4PpXLboWGHlPW5BtXq8Iaz4s/vCpOC+c=; b=e3ljpji6ioK1JmswqGeMT59i8kwd6MfvqxyKihoCalO46QZMcp+qNJ22Sa/dWGHS61 hQt7Dcyt5iYvhfhIxS1m6bBXl92EiA703yaQJ6fsCkkgwyVN8osyFtrUyR75cY1ZUBA9 krWROrvfwpL/5grEcfPSXdqmcM6dLMUIEz9IZngi0SPq+C6F/bm6m4UDENUlS2E+UW89 HiSgi2UX07+CfWBK1m25AL8+Q+DKbt6diCGA6Yp0haO7lrWhf5tptnK3ipFVWLh448Gr ED8NdLMYqYqRdSeDeVmHP83G0e6eHTb+aniw1W2rC2ClRLHS3O47uYwiwaLCj8BxeZq1 s4gQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=XLvu9YuJyEq4PpXLboWGHlPW5BtXq8Iaz4s/vCpOC+c=; b=oDT+8asFkeNAmqxhl5uUjTb5309j5kkoEtdFu6oVEpWbc9Td3H4CpoT6LTS55yuzYB JHpoh6iH8SiaIfDGBL7PoGuYhl4InADiRbUzM2yUr7spC0zMtD1LFnHhvqjwrCivJXYO o/2vWWIDlYJ3/wH2dR0MnlPpZzV+ZwY4GDxS2KDdgKOM1U9dSaa3+8YOOEve3wxKfeh8 gi6svlPJZMIpuY5Sez6jalBUJS8qcX32vy9EmsyXrKQhLw4iT/m+EXk+PwlYS08NXEp5 XGz6NjqP/5fHJ+iDAT2fZxTYRUc4SVdJrkZ9b7JfOSWtj44UJ+Ewgj5gUFy2jCALLx+3 lvhQ== X-Gm-Message-State: ANoB5pny3So0zOqGSNzkDFGXdOn/KclMi8XEbN7utcU+jgy9UDDiKxcu LtmpXyVwEBdiO2ulq2zwrGYMqM+Dn972zI4= X-Google-Smtp-Source: AA0mqf4gCzt7wLDqWtd7vb4p1P/T/LZD/uBz6gdqr23QFQNqjiefKT1o/c05gLYraaBcQacntRWFHfpND37EPes= X-Received: from allenwebb.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:12e8]) (user=allenwebb job=sendgmr) by 2002:a5e:8c10:0:b0:6e3:102d:4826 with SMTP id n16-20020a5e8c10000000b006e3102d4826mr1519940ioj.123.1671229044644; Fri, 16 Dec 2022 14:17:24 -0800 (PST) Date: Fri, 16 Dec 2022 16:17:02 -0600 In-Reply-To: <20221216221703.294683-1-allenwebb@google.com> Mime-Version: 1.0 References: <20221216221703.294683-1-allenwebb@google.com> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog Message-ID: <20221216221703.294683-5-allenwebb@google.com> Subject: [PATCH v7 4/5] file2alias.c: Implement builtin.alias generation From: Allen Webb To: "linux-modules@vger.kernel.org" , "linux-usb@vger.kernel.org" , "linux-kernel@vger.kernel.org" Cc: Luis Chamberlain , Greg Kroah-Hartman , "Rafael J. Wysocki" , Allen Webb Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This populates the mod->modalias_buf with aliases for built-in modules when modpost is run against vmlinuz.o. Signed-off-by: Allen Webb --- scripts/mod/file2alias.c | 55 +++++++++++++++++++++++++++------------- 1 file changed, 38 insertions(+), 17 deletions(-) diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c index 458e41ae0f5f1..8ed08154b3d81 100644 --- a/scripts/mod/file2alias.c +++ b/scripts/mod/file2alias.c @@ -232,6 +232,8 @@ static void do_usb_entry(void *symval, add_wildcard(alias); buf_printf(&mod->dev_table_buf, "MODULE_ALIAS(\"%s\");\n", alias); + if (mod->builtin_name) + buf_printf(&mod->modalias_buf, "alias %s %s\n", alias, mod->builtin_name= ); } =20 /* Handles increment/decrement of BCD formatted integers */ @@ -376,9 +378,13 @@ static void do_of_entry_multi(void *symval, struct mod= ule *mod) *tmp =3D '_'; =20 buf_printf(&mod->dev_table_buf, "MODULE_ALIAS(\"%s\");\n", alias); + if (mod->builtin_name) + buf_printf(&mod->modalias_buf, "alias %s %s\n", alias, mod->builtin_name= ); strcat(alias, "C"); add_wildcard(alias); buf_printf(&mod->dev_table_buf, "MODULE_ALIAS(\"%s\");\n", alias); + if (mod->builtin_name) + buf_printf(&mod->modalias_buf, "alias %s %s\n", alias, mod->builtin_name= ); } =20 static void do_of_table(void *symval, unsigned long size, @@ -610,12 +616,18 @@ static void do_pnp_device_entry(void *symval, unsigne= d long size, =20 buf_printf(&mod->dev_table_buf, "MODULE_ALIAS(\"pnp:d%s*\");\n", *id); + if (mod->builtin_name) + buf_printf(&mod->modalias_buf, "alias pnp:d%s* %s\n", + *id, mod->builtin_name); =20 /* fix broken pnp bus lowercasing */ for (j =3D 0; j < sizeof(acpi_id); j++) acpi_id[j] =3D toupper((*id)[j]); buf_printf(&mod->dev_table_buf, "MODULE_ALIAS(\"acpi*:%s:*\");\n", acpi_id); + if (mod->builtin_name) + buf_printf(&mod->modalias_buf, "alias acpi*:%s:* %s\n", + acpi_id, mod->builtin_name); } } =20 @@ -662,19 +674,25 @@ static void do_pnp_card_entries(void *symval, unsigne= d long size, } =20 /* add an individual alias for every device entry */ - if (!dup) { - char acpi_id[PNP_ID_LEN]; - int k; - - buf_printf(&mod->dev_table_buf, - "MODULE_ALIAS(\"pnp:d%s*\");\n", id); - - /* fix broken pnp bus lowercasing */ - for (k =3D 0; k < sizeof(acpi_id); k++) - acpi_id[k] =3D toupper(id[k]); - buf_printf(&mod->dev_table_buf, - "MODULE_ALIAS(\"acpi*:%s:*\");\n", acpi_id); - } + if (dup) + continue; + char acpi_id[PNP_ID_LEN]; + int k; + + buf_printf(&mod->dev_table_buf, + "MODULE_ALIAS(\"pnp:d%s*\");\n", id); + if (mod->builtin_name) + buf_printf(&mod->modalias_buf, "alias pnp:d%s* %s\n", + id, mod->builtin_name); + + /* fix broken pnp bus lowercasing */ + for (k =3D 0; k < sizeof(acpi_id); k++) + acpi_id[k] =3D toupper(id[k]); + buf_printf(&mod->dev_table_buf, + "MODULE_ALIAS(\"acpi*:%s:*\");\n", acpi_id); + if (mod->builtin_name) + buf_printf(&mod->modalias_buf, "alias acpi*:%s:* %s\n", + acpi_id, mod->builtin_name); } } } @@ -1476,10 +1494,13 @@ static void do_table(void *symval, unsigned long si= ze, size -=3D id_size; =20 for (i =3D 0; i < size; i +=3D id_size) { - if (do_entry(mod->name, symval+i, alias)) { - buf_printf(&mod->dev_table_buf, - "MODULE_ALIAS(\"%s\");\n", alias); - } + if (!do_entry(mod->name, symval + i, alias)) + continue; + buf_printf(&mod->dev_table_buf, "MODULE_ALIAS(\"%s\");\n", alias); + if (!mod->builtin_name) + continue; + buf_printf(&mod->modalias_buf, "alias %s %s\n", alias, + mod->builtin_name); } } =20 --=20 2.37.3 From nobody Wed Sep 17 18:08:34 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C0159C4332F for ; Fri, 16 Dec 2022 22:17:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229718AbiLPWR4 (ORCPT ); Fri, 16 Dec 2022 17:17:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49378 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229883AbiLPWRd (ORCPT ); Fri, 16 Dec 2022 17:17:33 -0500 Received: from mail-ot1-x349.google.com (mail-ot1-x349.google.com [IPv6:2607:f8b0:4864:20::349]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 748B42A703 for ; Fri, 16 Dec 2022 14:17:26 -0800 (PST) Received: by mail-ot1-x349.google.com with SMTP id bq2-20020a056830388200b00672e4a07168so2000988otb.2 for ; Fri, 16 Dec 2022 14:17:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=iIc91OoDv/mBPCGHIucL2csPnIlsRLcBZ/NTNtcT38Q=; b=hAoT5MIAnuQSmqmxxyxbUJFAq8kFycgaIH3Rd2PXnLLgq4zV8nNoyOLPpXnYFa90MJ S/Y97RfYpDzWFWmFoI7ftgkP5qIXUmtQycstRGSutXYJQNRXpI+/tA5cXZ4MkpqC8m9h cdSrO4eoWj8H2mN8FnnHxk2Rf2m10M6jdxzt54kh/QZlJFj+8othZIIk4iBw9mv518Wa 1nQCSs5NUtfc0KkQN4P1EoPdmiYOe5KUsMZcNEYfChG0LL7SEfTDyV6SdUUiun7x6Vqh z6UcYgV6HizryvFbeMJ1FomnoFuWgB4DkUC10Huv6lBsxzb6LQvZYjqwm7y4dJedWs6M eNug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=iIc91OoDv/mBPCGHIucL2csPnIlsRLcBZ/NTNtcT38Q=; b=UFywerS2bClcFx2k94TlqM5nbAIm4GgKrlQ3F3KmcEYrvtjJiHYUkpPPgurX9eP4xF s6GkA9NxQrEOVTQRhVZmd9FcCEoEDulW1mll69QyMsfQla+TuCV1ZD5jWzvi+3OmFyM+ pKoDQAACv/l521NZpicUZNAiXNPNZe0CwFbz9Aadg/dAw7K1tB2A7bY17D8Rdu/TqL+b YZ/lYLZq5PU2eLrDLjlnDjRsH+KBGzGLsEkcoGymQOdd1W0objT3qeGRu33m/JHJE95m vK5C3+IdRw9dsvDpG34xlvUY5zveSXHg29Wl9sknTNPxDxpv/PkODbQlyhaY+ZDxVjd6 KtKA== X-Gm-Message-State: AFqh2ko0KOfRhezVrTv1ngqTHDBNfY44WLQY2K9wt3w1r4LkyoXbUtMP L01TLtONLbHWLAV19SxyufeQ4u2prtJGaoc= X-Google-Smtp-Source: AA0mqf71zNbvpxkSmqWDhizcNttRiDlQ6M7Uz0HofAn4JFHR2CcqiiSdNsVRzV138EW1X7bnH1CHA4hsEUcea+s= X-Received: from allenwebb.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:12e8]) (user=allenwebb job=sendgmr) by 2002:a05:6870:6b8d:b0:143:53aa:5813 with SMTP id ms13-20020a0568706b8d00b0014353aa5813mr717884oab.161.1671229045721; Fri, 16 Dec 2022 14:17:25 -0800 (PST) Date: Fri, 16 Dec 2022 16:17:03 -0600 In-Reply-To: <20221216221703.294683-1-allenwebb@google.com> Mime-Version: 1.0 References: <20221216221703.294683-1-allenwebb@google.com> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog Message-ID: <20221216221703.294683-6-allenwebb@google.com> Subject: [PATCH v7 5/5] build: Add modules.builtin.alias From: Allen Webb To: "linux-modules@vger.kernel.org" , "linux-usb@vger.kernel.org" , "linux-kernel@vger.kernel.org" Cc: Luis Chamberlain , Greg Kroah-Hartman , "Rafael J. Wysocki" , Allen Webb Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Generate modules.builtin.alias using modpost and install it with the modules. Signed-off-by: Allen Webb --- .gitignore | 1 + Makefile | 1 + scripts/Makefile.modpost | 17 ++++++++++++++++- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 47229f98b327b..40a90bca89641 100644 --- a/.gitignore +++ b/.gitignore @@ -67,6 +67,7 @@ modules.order /System.map /Module.markers /modules.builtin +/modules.builtin.alias /modules.builtin.modinfo /modules.nsdeps =20 diff --git a/Makefile b/Makefile index 78525ebea8762..572f364f40538 100644 --- a/Makefile +++ b/Makefile @@ -1558,6 +1558,7 @@ __modinst_pre: fi @sed 's:^:kernel/:' modules.order > $(MODLIB)/modules.order @cp -f modules.builtin $(MODLIB)/ + @cp -f modules.builtin.alias $(MODLIB)/ @cp -f $(objtree)/modules.builtin.modinfo $(MODLIB)/ =20 endif # CONFIG_MODULES diff --git a/scripts/Makefile.modpost b/scripts/Makefile.modpost index e41dee64d429c..94c1d66c7769a 100644 --- a/scripts/Makefile.modpost +++ b/scripts/Makefile.modpost @@ -15,6 +15,7 @@ # 2) modpost is then used to # 3) create one .mod.c file per module # 4) create one Module.symvers file with CRC for all exported symbols +# 5) create modules.builtin.alias the aliases for built-in modules =20 # Step 3 is used to place certain information in the module's ELF # section, including information such as: @@ -51,6 +52,21 @@ ifneq ($(findstring i,$(filter-out --%,$(MAKEFLAGS))),) modpost-args +=3D -n endif =20 +vmlinux.o-if-present :=3D $(wildcard vmlinux.o) +ifneq ($(vmlinux.o-if-present),) +output-builtin.alias :=3D modules.builtin.alias +modpost-args +=3D -b .modules.builtin.alias.in +.modules.builtin.alias.in: $(output-symdump) + @# Building $(output-symdump) generates .modules.builtin.alias.in as a + @# side effect. + @[ -e $@ ] || $(MODPOST) -b .modules.builtin.alias.in $(vmlinux.o-if-pres= ent) + +$(output-builtin.alias): .modules.builtin.alias.in + sort -o $@ $^ + +__modpost: $(output-builtin.alias) +endif + ifeq ($(KBUILD_EXTMOD),) =20 # Generate the list of in-tree objects in vmlinux @@ -78,7 +94,6 @@ targets +=3D .vmlinux.objs .vmlinux.objs: vmlinux.a $(KBUILD_VMLINUX_LIBS) FORCE $(call if_changed,vmlinux_objs) =20 -vmlinux.o-if-present :=3D $(wildcard vmlinux.o) output-symdump :=3D vmlinux.symvers =20 ifdef KBUILD_MODULES --=20 2.37.3