From patchwork Mon Dec 19 19:18:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Allen Webb X-Patchwork-Id: 34722 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp2572769wrn; Mon, 19 Dec 2022 11:21:31 -0800 (PST) X-Google-Smtp-Source: AA0mqf5HM2QfbZfVzpLWTF9La7lCy8FhTDdo8vAouoovW5rj3BzyS4o2jW7JorvIH5QES5kZOZc/ X-Received: by 2002:a17:907:d68c:b0:7c1:72ef:7220 with SMTP id wf12-20020a170907d68c00b007c172ef7220mr28165409ejc.72.1671477691561; Mon, 19 Dec 2022 11:21:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671477691; cv=none; d=google.com; s=arc-20160816; b=GP0Ct1KA69Q+iyPInXrmd04YLTteZKGVKBa27/uO6551iw79dUQspH11VD9nFxaSFA F6dc9icpsX4B0KvkG1Pp4xek8kHHhqzFBkqcTPEs1lZQ+7zBHjIWmgS73WhdZRYLDyIe uoxJCyT6c+0sUIR2CcwI6seVmjE2KU5hPSwFUfSqfMEqO1mdU0EPu2CJvg+yzXOSr3I4 4dOJf+HNae24PWyEeQlKLAK8duZdc2pXU29+PsnWFBE7RdNrK6CaA60ftpw4cppH28C4 ziI3SIy/oNd93YHSNIP8IEGaJ5mzlYmDNad+mnFSjdpJW2X7zelyKUA7aG6NwZYDwTbs Df3w== 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=QPz4DVz3tZDZwOVeqeTus3Hhdj8ABoJzZwaMAiF7Nxg=; b=BPNeME/CR+P29Gu5jZtH1sG8CY98i2D5PtO3f9f2Z4JTbkyDHF/+vbNFHFHGXjPbCX Rw6GDxKZPtvUfxp33CritFDS9JQL6OHzggFszgRU/mfIiYxMAztn/GEQgzN/7irs4UPw GMRoxz0VNw4EbMomtaEeblT4BZTJEFA0zHlRFx9FrtYTneP0Hg7E0EGTvDBqioVWd5na 9CGsoYICw6GwPq4eupKAm4D8L3JfIOHBXXB0xI3WIpS6HdEY5wMyOl35ZwikIUAtuCvr +VoZ/fPWObVc5x1oqr1kw9PMSgsltgtkH5QltW+j4BhUBYAinykuSnFglR6AfOD00A4I oshQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=HmQ2kiym; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cd19-20020a170906b35300b007c177f0064dsi7933869ejb.972.2022.12.19.11.21.08; Mon, 19 Dec 2022 11:21:31 -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=HmQ2kiym; 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 S232734AbiLSTTg (ORCPT + 99 others); Mon, 19 Dec 2022 14:19:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44248 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232248AbiLSTTG (ORCPT ); Mon, 19 Dec 2022 14:19:06 -0500 Received: from mail-il1-x149.google.com (mail-il1-x149.google.com [IPv6:2607:f8b0:4864:20::149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8989812D29 for ; Mon, 19 Dec 2022 11:19:05 -0800 (PST) Received: by mail-il1-x149.google.com with SMTP id o10-20020a056e02102a00b003006328df7bso7082766ilj.17 for ; Mon, 19 Dec 2022 11:19:05 -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=QPz4DVz3tZDZwOVeqeTus3Hhdj8ABoJzZwaMAiF7Nxg=; b=HmQ2kiymwOL9kUhLxZJM5G/ssb7viDDO+nKpbR8v8lfSPSJVTzx9nWNNUPPmk32ot4 AYAQGLqdfd2uQnxuJeTBLLzf9JIUunUmXYjXMZVs5D4iEcx0gZ3qiZuPD68M8OmMfX1D P25V4wPBj0wABkx5DUwHuZHIeo8TuT+lW/YpcHxZa2FbT4yAra6jb7zi784dg0mGYxxz dZzJRLxKZAVI9t9aVegiOumN+hBaZLIEEn0DtpTYJVec+5fYEaRFt1C0qlB4Ere3GNiO T4FDM93EieTv4NNVjwjxXEfgriNZTNAPXWacGUOFzKucVaFUUv2EgcDK8276jLq9SkjG Mjjg== 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=QPz4DVz3tZDZwOVeqeTus3Hhdj8ABoJzZwaMAiF7Nxg=; b=nubUZOhmvcTqBoX+j/T0ymwX/W0hJB8cKHw6+jBAm76QiBeG2XvEEvwd0KqhpxvCMC YXC6cQVxwiZiYJCnBOg68HhLlgEV6B1jdnM7VOwJbzoxBmPH5idoU4xFTnOmwLq1PXvf KYewZ9HaOHpPwJ3BorCkT7LnMnAQUoDkv6aKH/ePa5RkDRPWUsWPYOkz1ojnb0yTKR+d x/BxTWmKd/KgHO3QIkpWT079h4WYFlQatl/hWX6rofJ4Ff5Hh9slW4w8Qkrtd4d8leJh rg1T0YRDictz+Dz7H0sIMhWE+pm1EJQh9BoNY1TlgQSBNrYJ8KtM+c0MuUnM/hyitFKQ c4hA== X-Gm-Message-State: ANoB5pnXBzV08L/YAHAfuDIJBIqR5IZ+kpYKS5bClCTK2VA0GxgnNEr3 roYCemiYn8jk/Mod1ozQ3aK4yYO6RzF9nJo= X-Received: from allenwebb.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:12e8]) (user=allenwebb job=sendgmr) by 2002:a6b:fb06:0:b0:6e0:c4d:65e2 with SMTP id h6-20020a6bfb06000000b006e00c4d65e2mr10765676iog.30.1671477545287; Mon, 19 Dec 2022 11:19:05 -0800 (PST) Date: Mon, 19 Dec 2022 13:18:52 -0600 In-Reply-To: <20221219191855.2010466-1-allenwebb@google.com> Mime-Version: 1.0 References: <20221216221703.294683-1-allenwebb@google.com> <20221219191855.2010466-1-allenwebb@google.com> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog Message-ID: <20221219191855.2010466-7-allenwebb@google.com> Subject: [PATCH v8 6/9] 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 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=ham 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752410880954012248?= X-GMAIL-MSGID: =?utf-8?q?1752671391802898586?= Keep track of the module name when processing match table symbols. Signed-off-by: Allen Webb --- scripts/mod/file2alias.c | 39 +++++++++++++++++++++++++++++++++++---- scripts/mod/modpost.h | 1 + 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c index 80d973144fded..e41ff8de7a876 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,12 @@ 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 +1570,30 @@ 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 +1625,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[]; };