From patchwork Mon Dec 19 20:46:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Allen Webb X-Patchwork-Id: 34768 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp2607475wrn; Mon, 19 Dec 2022 12:47:47 -0800 (PST) X-Google-Smtp-Source: AA0mqf5GPN0C8CZUEodZgytkYwMRo5pqD6u7e++yCS7nhFAdViw4ZB/RYD4J7C10mvmRfGHpo0Sh X-Received: by 2002:a05:6a20:6f89:b0:a5:418:8341 with SMTP id gv9-20020a056a206f8900b000a504188341mr48853825pzb.28.1671482867029; Mon, 19 Dec 2022 12:47:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671482867; cv=none; d=google.com; s=arc-20160816; b=a5seyQ93C0leaPNqBz3C/Osajk1v5uv4xS4UjbkSgMCAvOc7HioO+ikVNr28dLRLLF V9zp7OOPM5Ds3diUlXZ2tqje+J+znBdzaM1SRmUJv9QwV0BrN7L4qUVJq5L3M7XWD2za wK1R5jcj/iNsl+HVB1WPQPZ+jXCYp17JS+RXeXVJV6X+2GZQjNvtHrbEIVQxSqrKTTAs 6+2+xMt7Fks27kuyPZn2xrU1essGXmJDVUS8VHOIOE91MkbROaprut0J7CheBFVfZyDU aYDuWMtj2a5MWjlK05HMXDI3upVdYyyK/qcDCJsEQdXGX57kbRNULEGXHhaC7Z/f/myF h+tQ== 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=VwPD0qy3Fd4MZbZ1UDU3b7vBqkh0mNCuHHOa6+XoRDI=; b=ZfnqMyUVMTlt/ZJVKJ8xvubbiLq6Agvf5kfPi1nzyK9mRUU57HlsvNjLDYb6eraer4 bulKNu8lvl2TUWhERFRR6MBKFXUkVyemeKv5r0IlfHSn/mIvAodaL1pkBaVYoErlyoJT r6XmRZj10MNzdwGaKbT0iDk91chkehQrDIE6e/Cyunnd/Lhd6mGuR8NtBWm4DoUSkKZM D83EXuIYgesNeQX5liZlYZ2u76nTqkdm9US9HZoH1FqApu3Tp98Ai4trmuI+aBAr46kR ffnudlPLIUkSoet7+xLsmQZ1ZRO88nPe+bhW9JyW0YMVDG5no6OLBgKz/Xq0nzgZFsi6 dAQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=IHg6+Gv3; 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 69-20020a621848000000b00537b1bc9683si11139729pfy.36.2022.12.19.12.47.34; Mon, 19 Dec 2022 12:47:46 -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=IHg6+Gv3; 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 S232726AbiLSUqv (ORCPT + 99 others); Mon, 19 Dec 2022 15:46:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57816 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232679AbiLSUq3 (ORCPT ); Mon, 19 Dec 2022 15:46:29 -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 132AF120AA for ; Mon, 19 Dec 2022 12:46:29 -0800 (PST) Received: by mail-io1-xd4a.google.com with SMTP id z200-20020a6bc9d1000000b006e003aecf04so4604074iof.16 for ; Mon, 19 Dec 2022 12:46:29 -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=VwPD0qy3Fd4MZbZ1UDU3b7vBqkh0mNCuHHOa6+XoRDI=; b=IHg6+Gv3Z3EE3ZvZcHJip+nkzkOLPOiU2MKzy/1YcYpE9p6Vhub6QpTm6zYdFvxZSr vC1qM6HZkvMXHTT+cMTj7gfPLbh4je7ixHxoyyvg140Jnt7PtuNZa/gzHBIZu0mFGlrO xMuN+neqE0Hi0oHReaRSt8oJJNWwNmPIBWf1bLJMeuxIFi0pmYzk/xNUsE7lxmECL3R7 uBn0n4KfdsfFsPdhxa1nlscMZwymsK5UbWJ/5vVZB3YDCHIC3qw2ZtfA1WPsacIhO3gM 3KHFxJEAvv3sXEyXU3n2vqq+GuOODnT+XhxWvEySHzaDGW8awt2SSKymYf4TE1MWKB0R PTpQ== 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=VwPD0qy3Fd4MZbZ1UDU3b7vBqkh0mNCuHHOa6+XoRDI=; b=SiKboHW93ui/yiOMobezB9JuvspaB+hirHQNGGohXogzYjbzxpeU6VIXB0bZh7kkJo a6vh2z7oeUvTPqnBEJOXTgQqCiPi7FCHSQRhzaNgG/iWgRq/a8fW9zfxqF5KDy1qmGB9 p5MaYXpBHRVhpEyNw/o56tyXBjmC5f/YgLSy6kNhm+uI+gRykNptT+GPh7TQ1KOGyyDg VvWDh4W9Jj/hKa1Goa+mE05Qj96u6w+ObJk5/F6/zMyNU2JWUPbxXeFhoKT7KT4Gt00k 87ju1/VlzEnvtJptNO+tCAdpZ2L1F3iXfV+IgWUJcGa8QvDghH5k1vL7eXvOuvgm6eR5 wwVg== X-Gm-Message-State: AFqh2koYlAdPKh4v4hQwAhdKE0G4orwRYLOOsSrR5xPg4kNEpCiBd8zF bFdOnPb/eX12L5zYsFxE3x9cTotNYfs6qcE= X-Received: from allenwebb.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:12e8]) (user=allenwebb job=sendgmr) by 2002:a6b:90b:0:b0:6ec:6abf:f5eb with SMTP id t11-20020a6b090b000000b006ec6abff5ebmr225969ioi.91.1671482788508; Mon, 19 Dec 2022 12:46:28 -0800 (PST) Date: Mon, 19 Dec 2022 14:46:14 -0600 In-Reply-To: <20221219204619.2205248-1-allenwebb@google.com> Mime-Version: 1.0 References: <20221219191855.2010466-1-allenwebb@google.com> <20221219204619.2205248-1-allenwebb@google.com> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog Message-ID: <20221219204619.2205248-7-allenwebb@google.com> Subject: [PATCH v9 06/10] 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=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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752410880954012248?= X-GMAIL-MSGID: =?utf-8?q?1752676818585778392?= 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 80d973144fde..e41ff8de7a87 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 1178f40a73f3..34fe5fc0b02c 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[]; };