Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp3423847rwb; Fri, 16 Dec 2022 14:56:27 -0800 (PST) X-Google-Smtp-Source: AA0mqf6B/43ZykFPzuyIGzczIKNKNov1lJ/7NG3SJGwi1Ink9h+lw85flXW/HnliqXzlWSsF/ycs X-Received: by 2002:a05:6a20:6983:b0:a3:754c:2769 with SMTP id t3-20020a056a20698300b000a3754c2769mr47175126pzk.40.1671231387436; Fri, 16 Dec 2022 14:56:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671231387; cv=none; d=google.com; s=arc-20160816; b=IodjPQWHoc9YYBynX3fAcAU+d0iE1AcbSEynnYXwF193bWERGfuiu1tnhicXWFlG5a dTsWqCu+BsdoMjUU9y1L4olnyk0MTWLV0qo027Nj9GcJAhy037SiLodsZogcrxIyaq4k 3AD2su0BBJQ8RRqNrtrL3raW6oZ8wvRnEvq2Mz77Wt/cRStxPnpUUYSE3945RsqAFhgj rtBZqMDCvaUVH6a75QcjuiR42YZR38pAMPNoOTVwfijr/0xnQDojHRWyMqmLa0UuSkE7 tQyVF+FtmSdJHncEaW8nYFPnO0nF1wG5ShWU3bAF51WgTB6kXsdDyv8+UwkLU02z+fZR 6Bvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=G0/vtfeve/G9ydeke/gLh4oQEre+L13iDXwcfVwzkg8=; b=zw2uxS0fQL2x4AcixQuZV1zdEmqqY/T/TF8dvOHK9YZqSH0zeO+7Bm+xq8iLpox7gL pCe+HYkHcRcIjV1iDKr9AGcrHnp7dqyfM2EwHol0KeptOOeVbBpNODY/yPDoUYPK8zQv TP9V2dRaUstWe8+Tm6C0n86gZWW5F41zJe1f0pPyT1MxMtNv3UCHkIxMx+vb/kivQS+b 3Yz/z7ScfPw0PuGMtCS/dxpI7qon3zbRULWbbxf5Z9XZmGAfvz6CAQtg22slxVbOAmuk kCkouW1cJpGj+KiEDVNg6zswk37fvDy7by1gz57iuCdGWubY+TWL0sPy9ha3iQ2VvY1g Nyqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=XuNwKmwP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w189-20020a6382c6000000b00478972c18c4si3870119pgd.865.2022.12.16.14.56.18; Fri, 16 Dec 2022 14:56:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=XuNwKmwP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230010AbiLPWRg (ORCPT + 68 others); Fri, 16 Dec 2022 17:17:36 -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-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 Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 +#include #include #include @@ -1540,9 +1541,9 @@ void handle_moddevtable(struct module *mod, struct elf_info *info, Elf_Sym *sym, const char *symname) { void *symval; - char *zeros = NULL; - const char *name, *identifier; - unsigned int namelen; + char *zeros = NULL, *modname_str = NULL; + const char *name, *identifier, *modname; + unsigned int namelen, modnamelen; /* We're looking for a section relative symbol */ if (!sym->st_shndx || get_secindex(info, sym) >= info->num_sections) @@ -1552,7 +1553,11 @@ void handle_moddevtable(struct module *mod, struct elf_info *info, if (ELF_ST_TYPE(sym->st_info) != STT_OBJECT) return; - /* 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 = symname + strlen("__mod_"); @@ -1564,8 +1569,29 @@ void handle_moddevtable(struct module *mod, struct elf_info *info, identifier = strstr(name, "__"); if (!identifier) return; + modnamelen = namelen; namelen = identifier - name; + /* In the vmlinuz.o case we want to handle __kmod_ so aliases from + * builtin modules are attributed correctly. + */ + modname = strstr(identifier + 2, "__kmod_"); + if (modname) { + modname += strlen("__kmod_"); + modnamelen -= (modname - name) + strlen("_device_table"); + modname_str = malloc(modnamelen + 1); + /* We don't want to continue if the allocation fails. */ + assert(modname_str); + memcpy(modname_str, modname, modnamelen); + modname_str[modnamelen] = '\0'; + } + + if (modname_str) + modname = modname_str; + else + modname = mod->name; + mod->builtin_name = modname; + /* Handle all-NULL symbols allocated into .bss */ if (info->sechdrs[get_secindex(info, sym)].sh_type & SHT_NOBITS) { zeros = calloc(1, sym->st_size); @@ -1597,6 +1623,9 @@ void handle_moddevtable(struct module *mod, struct elf_info *info, } } free(zeros); + mod->builtin_name = NULL; + if (modname_str) + free(modname_str); } /* 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[]; }; -- 2.37.3