From patchwork Thu Jun 8 14:24:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 104992 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6358:3046:b0:115:7a1d:dabb with SMTP id p6csp371166rwl; Thu, 8 Jun 2023 07:31:09 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4Ahd4FP7Z+o9ALvm9ff3evVoJlwtP0SozckTHDc3fFaeIfD219q10TfswiBDI8DEustjqV X-Received: by 2002:a17:90a:ab94:b0:259:dd60:d90e with SMTP id n20-20020a17090aab9400b00259dd60d90emr3053221pjq.20.1686234669400; Thu, 08 Jun 2023 07:31:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686234669; cv=none; d=google.com; s=arc-20160816; b=iz314M0g44BGM3jkwW12b3JSCRtZ5vZFDyShyzKfNbD4+mvkY+ZmCFkkScdkP2E4Zi Xpd4bAWbgcZuSqM6i/mcvsS6z4u2Pn3K5QuPrhY9bEmISMVZNDV3a2j+qQ5jkXH50+95 4D37gJ6GE5RJai6TFr+KQlBtP4vlSvGClzXXVDkHUC6+VhqLm9NxlHTLnCvZMmN3A1vZ zivvPOkTd6unbj2KmsruHjcOIeGa0EVwIp/HD3jiFB2fDAWiRVrsvqHzcAiXBS2AVtTc 2CJo1OJKXf8RbwlssJ6KJ8T2PPyjqj0C91/ac6VBmKVjWWAgLRs8g41VleBv5N9zVB1P DGRg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ZnpO8ZpdujYO5wKmgHck2FxfHXtlw9ZSop4Jh7BdS9E=; b=HHQLIJT8hcRpU+CijDRGvTl/b0hvRMerMvez6TEyjMaqWw4lvlnpdwDnmvaL0EAGxQ 4YI6vXBz20R3Dx4jU1QbxLnfkjZAUFGIv7jctv3Yqiem6Ke+5MDE+g3ZZPO6KAk1Me/q YkkXQ+M/fjWgcxajOhcNnRKmw4G53rUPLQDtmyqqZfDMa6YwAXPvLTkWxCCZnyln+mtm 7g+zbn172yuAee7OMQmhlV42Ohp0CgLVXTHHnCJy4y1qIUVU/V4d1PiIl6XlnRTW0ltA yidlv2tVQjqPglHlmcu5BLqJi0hAO2KlDvdF3sVFMAHdtQ/MrzgiC3tgbldeUA94q40H MYhQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="lyb/aRQo"; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a12-20020a17090abe0c00b0025359a570fesi1158320pjs.19.2023.06.08.07.30.54; Thu, 08 Jun 2023 07:31:09 -0700 (PDT) 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=@kernel.org header.s=k20201202 header.b="lyb/aRQo"; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237042AbjFHOZA (ORCPT + 99 others); Thu, 8 Jun 2023 10:25:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55752 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237113AbjFHOYx (ORCPT ); Thu, 8 Jun 2023 10:24:53 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 69ABE30C3; Thu, 8 Jun 2023 07:24:39 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id D62B264E20; Thu, 8 Jun 2023 14:24:38 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0A036C433A0; Thu, 8 Jun 2023 14:24:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686234278; bh=7ZPyZ9apG1M05E0n0MB6gFR/gnPXwymtgzxIDVjhPog=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lyb/aRQonk8gbaoHdI0/Cb4ItgDLwxIK+DRpbx0KcKc6rNJ6Rpj7K2KQKpzmumDnE WdoNs13V76MCdMdX41tTHvhd5gocZxNMJEERi+nfhLvD9G4pTxmLMApimqHyX0L624 t4x+22sxF1nQMKsXUZNPeEion4PCNsIBz8S6PkOgZJ9Qxtcjj2th9w1H4u/onrZWcR YwxVkKN4TQA7V4Fl4JLvBPwXVE6EZ6t49WjXaMMKaPucewyNKER1YTMUKrXUqI2n5k VGJi/w9oqzpuvrSUmQueff5KNiMOeypROw8NYKdqqIjd158V/EnZqu6id2PKTe1LUF 4J3jIFYyTWWcg== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Nathan Chancellor , Nick Desaulniers , Nicolas Schier , linux-um@lists.infradead.org, Masahiro Yamada Subject: [PATCH v7 01/11] Revert "[PATCH] uml: export symbols added by GCC hardened" Date: Thu, 8 Jun 2023 23:24:18 +0900 Message-Id: <20230608142428.256985-2-masahiroy@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230608142428.256985-1-masahiroy@kernel.org> References: <20230608142428.256985-1-masahiroy@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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?1768145204479860895?= X-GMAIL-MSGID: =?utf-8?q?1768145204479860895?= This reverts commit cead61a6717a9873426b08d73a34a325e3546f5d. It exported __stack_smash_handler and __guard, while they may not be defined by anyone. The code *declares* __stack_smash_handler and __guard. It does not create weak symbols. When the stack-protector is disabled, they are left undefined, but yet exported. If a loadable module tries to access non-existing symbols, bad things (a page fault, NULL pointer dereference, etc.) will happen. So, the current code is wrong. If the code were written as follows, it would *define* them as weak symbols so modules would be able to get access to them. void (*__stack_smash_handler)(void *) __attribute__((weak)); EXPORT_SYMBOL(__stack_smash_handler); long __guard __attribute__((weak)); EXPORT_SYMBOL(__guard); In fact, modpost forbids exporting undefined symbols. It shows an error message if it detects such a mistake. ERROR: modpost: "..." [...] was exported without definition Unfortunately, it is checked only when the code is built as modular. The problem described above has been unnoticed for a long time because arch/um/os-Linux/user_syms.c is always built-in. With a planned change in Kbuild, exporting undefined symbols will always result in a build error instead of a run-time error. It is a good thing, but we need to fix the breakage in advance. One fix is to *define* weak symbols as shown above. An alternative is to export them conditionally as follows: #ifdef CONFIG_STACKPROTECTOR extern void __stack_smash_handler(void *); EXPORT_SYMBOL(__stack_smash_handler); external long __guard; EXPORT_SYMBOL(__guard); #endif This is what other architectures do; EXPORT_SYMBOL(__stack_chk_guard) is guarded by #ifdef CONFIG_STACKPROTECTOR. However, adding the #ifdef guard is not sensible because UML cannot enable the stack-protector in the first place! (Please note UML does not select HAVE_STACKPROTECTOR in Kconfig.) So, the code is already broken (and unused) in multiple ways. Just remove. Signed-off-by: Masahiro Yamada Reviewed-by: Nick Desaulniers --- Changes in v7: - New patch arch/um/os-Linux/user_syms.c | 7 ------- 1 file changed, 7 deletions(-) diff --git a/arch/um/os-Linux/user_syms.c b/arch/um/os-Linux/user_syms.c index 9b62a9d352b3..a310ae27b479 100644 --- a/arch/um/os-Linux/user_syms.c +++ b/arch/um/os-Linux/user_syms.c @@ -37,13 +37,6 @@ EXPORT_SYMBOL(vsyscall_ehdr); EXPORT_SYMBOL(vsyscall_end); #endif -/* Export symbols used by GCC for the stack protector. */ -extern void __stack_smash_handler(void *) __attribute__((weak)); -EXPORT_SYMBOL(__stack_smash_handler); - -extern long __guard __attribute__((weak)); -EXPORT_SYMBOL(__guard); - #ifdef _FORTIFY_SOURCE extern int __sprintf_chk(char *str, int flag, size_t len, const char *format); EXPORT_SYMBOL(__sprintf_chk); From patchwork Thu Jun 8 14:24:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 104994 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6358:3046:b0:115:7a1d:dabb with SMTP id p6csp371268rwl; Thu, 8 Jun 2023 07:31:18 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ55HH8p69Gvphjk1HRTIymCuHNejefpr2MAaKZXnn5YF12WzIFij0Xtwe/RNIkEWUIM0u48 X-Received: by 2002:a05:6a00:158d:b0:64d:40e0:5580 with SMTP id u13-20020a056a00158d00b0064d40e05580mr2848012pfk.3.1686234677747; Thu, 08 Jun 2023 07:31:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686234677; cv=none; d=google.com; s=arc-20160816; b=y2IuduIpzxiTk5yJvul2P3G+ykOAoW6Zv62jNcHgEbfq1k3Qr+HqJ9Q4MUlK5WJJyG W7dnEw46af4vVM5nUq12gUdOJok4U6YDi93Ku0wZJ+WQPk8yUmm99m7xHY2ujHB49OQF 9F9E9fnqLE/GBuzEGacT8TiobJ2YvGBYV4IYK7AkfPeJpsmkm/y5Ea6sLqTsp4lpzBP7 HXeos+RO0GXQWDip8fvJlCfJ6Pk+IpYDfHqVyr4IZel8p8fHQQuMYrTgtkmZtiMyWQyr RUXRUDkHqpHvxxV9PX40gI8rxzaXlVsuXsJb/EEh+QwscdW1xwMH2MO401c5GvkOK9ZP Pzsw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=QdmNUIqG7ds7rBdJCsc4wL6l92o8tud4N9bDUyUrmoI=; b=qoJlB3baB820yd47rX9FklczQtHW+lWIe9wICnuD4TZDknn8SIrF04a39DVkvK2K/M Mwwb8lWyUig7mYgw+IAHV8rPnDd8yi346AHLrlMuTKRwchltIzfcYQfnYWDQLaUBwLbY udK+db+p2YyPbxX+6y0b3mFVH2bnmU7+FQR01bTIXEsQeIo+Tn2nfwM4SapAzf2CXm2j T1Txnfeq2dhqW3+6rIroHQfkndaG/M/q5lUabJLsV35plIOINoySDXH4NhoNBi53P5Xp 8Pn4X8v+qgbFlwrM5lYE1PTZZ+q28YsNAMTC5ClXlXzmT8ptscVx4NqCTlGmNBzm6crC ueeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=YIEqPaQT; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z10-20020aa7948a000000b0065a4bc8a998si856914pfk.385.2023.06.08.07.31.02; Thu, 08 Jun 2023 07:31:17 -0700 (PDT) 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=@kernel.org header.s=k20201202 header.b=YIEqPaQT; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237061AbjFHOZD (ORCPT + 99 others); Thu, 8 Jun 2023 10:25:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55716 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237142AbjFHOY4 (ORCPT ); Thu, 8 Jun 2023 10:24:56 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F304D30D6; Thu, 8 Jun 2023 07:24:40 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 85DF764E25; Thu, 8 Jun 2023 14:24:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B05E9C4339E; Thu, 8 Jun 2023 14:24:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686234280; bh=Ly+sWm6TM1FV97DnfVYc+edRAEXC0kuE80+arR4Mn2I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YIEqPaQTLVy0UhU1ANwEfuEfbfEPgIno+/ovrkvx9dnO45qiOUOgsUsy0jl+9Gnhh izr28sadiVKgyl1es0lpCzCTM1+wBX++R7Wo0xkIdY4inVzGOpE945pi/ckygQNpwJ H1kS13OF2pGCT1NrMKtWJj7HhYrZ6iOMBF0tZAYK/keO3xz6XJFbaSq9tA87gkOz0/ Xqu7W0u4tu4GE85hoZP+Eb0S6BC9kNRmPdvobLpSqIyBkeoijjkqtVQlCRLGkr9sO0 izcqZemm2v3L+Zz8NmAwS2k6MKDXYl4vDVhhi/mSSmGdIlZ1k1jfXMVLDhYGJdAOti RLXebP6yE/j0g== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Nathan Chancellor , Nick Desaulniers , Nicolas Schier , linux-um@lists.infradead.org, Masahiro Yamada Subject: [PATCH v7 02/11] modpost: pass struct module pointer to check_section_mismatch() Date: Thu, 8 Jun 2023 23:24:19 +0900 Message-Id: <20230608142428.256985-3-masahiroy@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230608142428.256985-1-masahiroy@kernel.org> References: <20230608142428.256985-1-masahiroy@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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?1768145212972204122?= X-GMAIL-MSGID: =?utf-8?q?1768145212972204122?= The next commit will use it. Signed-off-by: Masahiro Yamada Reviewed-by: Nick Desaulniers --- scripts/mod/modpost.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index 8decf04633bc..403ba4d923f5 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -1211,7 +1211,7 @@ static void default_mismatch_handler(const char *modname, struct elf_info *elf, } } -static void check_section_mismatch(const char *modname, struct elf_info *elf, +static void check_section_mismatch(struct module *mod, struct elf_info *elf, Elf_Sym *sym, unsigned int fsecndx, const char *fromsec, Elf_Addr faddr, Elf_Addr taddr) @@ -1222,7 +1222,7 @@ static void check_section_mismatch(const char *modname, struct elf_info *elf, if (!mismatch) return; - default_mismatch_handler(modname, elf, mismatch, sym, + default_mismatch_handler(mod->name, elf, mismatch, sym, fsecndx, fromsec, faddr, tosec, taddr); } @@ -1406,7 +1406,7 @@ static int addend_mips_rel(struct elf_info *elf, Elf_Shdr *sechdr, Elf_Rela *r) #define R_LARCH_SUB32 55 #endif -static void section_rela(const char *modname, struct elf_info *elf, +static void section_rela(struct module *mod, struct elf_info *elf, Elf_Shdr *sechdr) { Elf_Rela *rela; @@ -1452,12 +1452,12 @@ static void section_rela(const char *modname, struct elf_info *elf, break; } - check_section_mismatch(modname, elf, elf->symtab_start + r_sym, + check_section_mismatch(mod, elf, elf->symtab_start + r_sym, fsecndx, fromsec, r.r_offset, r.r_addend); } } -static void section_rel(const char *modname, struct elf_info *elf, +static void section_rel(struct module *mod, struct elf_info *elf, Elf_Shdr *sechdr) { Elf_Rel *rel; @@ -1507,7 +1507,7 @@ static void section_rel(const char *modname, struct elf_info *elf, fatal("Please add code to calculate addend for this architecture\n"); } - check_section_mismatch(modname, elf, elf->symtab_start + r_sym, + check_section_mismatch(mod, elf, elf->symtab_start + r_sym, fsecndx, fromsec, r.r_offset, r.r_addend); } } @@ -1524,19 +1524,19 @@ static void section_rel(const char *modname, struct elf_info *elf, * to find all references to a section that reference a section that will * be discarded and warns about it. **/ -static void check_sec_ref(const char *modname, struct elf_info *elf) +static void check_sec_ref(struct module *mod, struct elf_info *elf) { int i; Elf_Shdr *sechdrs = elf->sechdrs; /* Walk through all sections */ for (i = 0; i < elf->num_sections; i++) { - check_section(modname, elf, &elf->sechdrs[i]); + check_section(mod->name, elf, &elf->sechdrs[i]); /* We want to process only relocation sections and not .init */ if (sechdrs[i].sh_type == SHT_RELA) - section_rela(modname, elf, &elf->sechdrs[i]); + section_rela(mod, elf, &elf->sechdrs[i]); else if (sechdrs[i].sh_type == SHT_REL) - section_rel(modname, elf, &elf->sechdrs[i]); + section_rel(mod, elf, &elf->sechdrs[i]); } } @@ -1707,7 +1707,7 @@ static void read_symbols(const char *modname) sym_get_data(&info, sym)); } - check_sec_ref(modname, &info); + check_sec_ref(mod, &info); if (!mod->is_vmlinux) { version = get_modinfo(&info, "version"); From patchwork Thu Jun 8 14:24:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 104993 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6358:3046:b0:115:7a1d:dabb with SMTP id p6csp371260rwl; Thu, 8 Jun 2023 07:31:16 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4pX/aiYr4/kxEisb3Ev114EAyr1080jnNxlzXvtlfzRjqjvVqPoYvsrZLF1oraaJ9ScB8H X-Received: by 2002:a17:902:854c:b0:1ac:61ad:d6bd with SMTP id d12-20020a170902854c00b001ac61add6bdmr3894002plo.65.1686234676147; Thu, 08 Jun 2023 07:31:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686234676; cv=none; d=google.com; s=arc-20160816; b=Ngd6Q374Rjn+BtDySYtJaH8NK7RGG6IxXiO0GbjZtiB0rXC0qMX5Vc4fXJu+4aq7JN Yz9RHgcK31Pv8R3cPjaHXMEuSPLKFrLUMoJv/JZyagxP4pYEm2sE3Y3wwTE0AN5VwAt8 UwT1uFgnwf3snkEVUz4DYMNgdPLraQ8rhJpksAisMtK25ZbIPpadJuKGb81Gy9zThvFp oSCTHNVytbd3n4QfWkAwi0yIyYBE3i9izIhS48dJDfXr4zu7xCo1VPF3sCphpQAiHhtA 2WajafvNq/bAJg7XKeXDr4f9xYXr1FBhGxrT1rcUsV7P4w3tKewcIc7bGy+QQCS01OkF RhaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ldQff2w6SeM18C/zlkJJZCZcP4SlzfYG9UBFVgBwZ40=; b=WA6D6etxS7PundQZkLHyKq8pPbz7eob84P4zaF6a4AEL26ptj4nRaaPx0xf+ftqobp SbzBGSRIX3RJOzT2UawGuPyEJspk9uGIKUSRZQuCkBTQrQm0Q8EhKRBeMsBkrFL9nDKy lWVzN8T43VKLLPs1NMk2G2C/sQo9vNQlWOGawbKy+lFTf14JnRA3KQLdZo02fKzkmPge a/loTzeoNURUZtiLz+iK+H80xetxkOOAi9bKPcRJJnFa4XfpjiBxJqJir0PQsIIOoPB6 Pt3IzE1/7omyWmvnsPsax+WNLOG36fTbZ2+jgMdWxGvKZDkVbbCu98OVezAIv88h/9fq /WIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=XCJyXjNj; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f17-20020a170902ce9100b0019f3064da41si1141021plg.383.2023.06.08.07.31.01; Thu, 08 Jun 2023 07:31:16 -0700 (PDT) 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=@kernel.org header.s=k20201202 header.b=XCJyXjNj; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237105AbjFHOZL (ORCPT + 99 others); Thu, 8 Jun 2023 10:25:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55894 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237055AbjFHOZA (ORCPT ); Thu, 8 Jun 2023 10:25:00 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0168A30DD; Thu, 8 Jun 2023 07:24:42 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 61DD064E27; Thu, 8 Jun 2023 14:24:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 60A72C4339C; Thu, 8 Jun 2023 14:24:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686234281; bh=fcVg7m3OxQE1Vq5Z9XkAx3enXfNCHUcC8HCKQ1k3KWE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XCJyXjNjrlGAuWlB6EqZViuczuO6KeGMeA5YSA2SmMLRCmZ2EHvGKOdWuX0R5HuBi tn07oqGTDNHbKk+mDvg80ylubcluSmMI9wlbxjJ4SzzjdnJJO8FEMcGrJEurlP/6Dh 0gP9ipDtZ3trz6LA6yfwGXkHU+2scdrvKHnupg2bHp/PFOuiXWWUHkpG/L/SOwMetI FUZppKoDhBhkgoT1hs/yYzQQqjgzwZf/TDHUBR+4ag1EfvU2qAtrAS27OmwW5t7srC lJwHK7XPXldv9tXkd6R9FPosuC5/F0loH0L6UnS8SffISGeevDHvj48wM8Gss08hvb 6qQJLfDhUoKPQ== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Nathan Chancellor , Nick Desaulniers , Nicolas Schier , linux-um@lists.infradead.org, Masahiro Yamada Subject: [PATCH v7 03/11] kbuild: generate KSYMTAB entries by modpost Date: Thu, 8 Jun 2023 23:24:20 +0900 Message-Id: <20230608142428.256985-4-masahiroy@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230608142428.256985-1-masahiroy@kernel.org> References: <20230608142428.256985-1-masahiroy@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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?1768145211587698393?= X-GMAIL-MSGID: =?utf-8?q?1768145211587698393?= Commit 7b4537199a4a ("kbuild: link symbol CRCs at final link, removing CONFIG_MODULE_REL_CRCS") made modpost output CRCs in the same way whether the EXPORT_SYMBOL() is placed in *.c or *.S. For further cleanups, this commit applies a similar approach to the entire data structure of EXPORT_SYMBOL(). The EXPORT_SYMBOL() compilation is split into two stages. When a source file is compiled, EXPORT_SYMBOL() is converted into a dummy symbol in the .export_symbol section. For example, EXPORT_SYMBOL(foo); EXPORT_SYMBOL_NS_GPL(bar, BAR_NAMESPACE); will be encoded into the following assembly code: .section ".export_symbol","a" __export_symbol__foo: .asciz "" .balign 4 .long foo - . .previous .section ".export_symbol","a" __export_symbol_gpl_bar: .asciz "BAR_NAMESPACE" .balign 4 .long bar - . .previous They are mere markers to tell modpost the name, license, and namespace of the symbols. They will be dropped from the final vmlinux and modules because the *(.export_symbol) will go into /DISCARD/ in the linker script. Then, modpost extracts all the information about EXPORT_SYMBOL() from the .export_symbol section, and generates the final C code: KSYMTAB_FUNC(foo, "", ""); KSYMTAB_FUNC(bar, "_gpl", "BAR_NAMESPACE"); KSYMTAB_FUNC() (or KSYMTAB_DATA() if it is data) is expanded to struct kernel_symbol that will be linked to the vmlinux or a module. With this change, EXPORT_SYMBOL() works in the same way for *.c and *.S files, providing the following benefits. [1] Deprecate EXPORT_DATA_SYMBOL() In the old days, EXPORT_SYMBOL() was only available in C files. To export a symbol in *.S, EXPORT_SYMBOL() was placed in a separate *.c file. arch/arm/kernel/armksyms.c is one example written in the classic manner. Commit 22823ab419d8 ("EXPORT_SYMBOL() for asm") removed this limitation. Since then, EXPORT_SYMBOL() can be placed close to the symbol definition in *.S files. It was a nice improvement. However, as that commit mentioned, you need to use EXPORT_DATA_SYMBOL() for data objects on some architectures. In the new approach, modpost checks symbol's type (STT_FUNC or not), and outputs KSYMTAB_FUNC() or KSYMTAB_DATA() accordingly. There are only two users of EXPORT_DATA_SYMBOL: EXPORT_DATA_SYMBOL_GPL(empty_zero_page) (arch/ia64/kernel/head.S) EXPORT_DATA_SYMBOL(ia64_ivt) (arch/ia64/kernel/ivt.S) They are transformed as follows and output into .vmlinux.export.c KSYMTAB_DATA(empty_zero_page, "_gpl", ""); KSYMTAB_DATA(ia64_ivt, "", ""); The other EXPORT_SYMBOL users in ia64 assembly are output as KSYMTAB_FUNC(). EXPORT_DATA_SYMBOL() is now deprecated. [2] merge and There are two similar header implementations: include/linux/export.h for .c files include/asm-generic/export.h for .S files Ideally, the functionality should be consistent between them, but they tend to diverge. Commit 8651ec01daed ("module: add support for symbol namespaces.") did not support the namespace for *.S files. This commit shifts the essential implementation part to C, which supports EXPORT_SYMBOL_NS() for *.S files. and will remain as a wrapper of for a while. They will be removed after #include directives are all replaced with #include . [3] Implement CONFIG_TRIM_UNUSED_KSYMS in one-pass algorithm (by a later commit) When CONFIG_TRIM_UNUSED_KSYMS is enabled, Kbuild recursively traverses the directory tree to determine which EXPORT_SYMBOL to trim. If an EXPORT_SYMBOL turns out to be unused by anyone, Kbuild begins the second traverse, where some source files are recompiled with their EXPORT_SYMBOL() tuned into a no-op. We can do this better now; modpost can selectively emit KSYMTAB entries that are really used by modules. Signed-off-by: Masahiro Yamada Reviewed-by: Nick Desaulniers --- Changes in v7: - Fix sparse warning reported by 0day bot https://lore.kernel.org/linux-kbuild/202305280830.Rj5ltc9M-lkp@intel.com/ Changes in v6: - Fix build error on UML Changes in v5: - Fix build error on ARM Changes in v4: - Version 3 did not work if a same name symbol exists in a different compilation unit Fix it. Changes in v3: - Move struct kernel_symbol to kernel/module/internal.h Changes in v2: - Use KSYMTAB_FUNC and KSYMTAB_DATA for functions and data, respectively This distinction is needed for ia64. arch/ia64/include/asm/Kbuild | 1 + arch/ia64/include/asm/export.h | 3 - include/asm-generic/export.h | 84 ++----------------------- include/asm-generic/vmlinux.lds.h | 1 + include/linux/export-internal.h | 49 +++++++++++++++ include/linux/export.h | 98 ++++++++++------------------- include/linux/pm.h | 8 +-- kernel/module/internal.h | 12 ++++ scripts/Makefile.build | 8 +-- scripts/check-local-export | 4 +- scripts/mod/modpost.c | 100 ++++++++++++++++++++---------- scripts/mod/modpost.h | 1 + 12 files changed, 179 insertions(+), 190 deletions(-) delete mode 100644 arch/ia64/include/asm/export.h diff --git a/arch/ia64/include/asm/Kbuild b/arch/ia64/include/asm/Kbuild index aefae2efde9f..33733245f42b 100644 --- a/arch/ia64/include/asm/Kbuild +++ b/arch/ia64/include/asm/Kbuild @@ -1,6 +1,7 @@ # SPDX-License-Identifier: GPL-2.0 generated-y += syscall_table.h generic-y += agp.h +generic-y += export.h generic-y += kvm_para.h generic-y += mcs_spinlock.h generic-y += vtime.h diff --git a/arch/ia64/include/asm/export.h b/arch/ia64/include/asm/export.h deleted file mode 100644 index ad18c6583252..000000000000 --- a/arch/ia64/include/asm/export.h +++ /dev/null @@ -1,3 +0,0 @@ -/* EXPORT_DATA_SYMBOL != EXPORT_SYMBOL here */ -#define KSYM_FUNC(name) @fptr(name) -#include diff --git a/include/asm-generic/export.h b/include/asm-generic/export.h index 5e4b1f2369d2..0ae9f38a904c 100644 --- a/include/asm-generic/export.h +++ b/include/asm-generic/export.h @@ -3,86 +3,12 @@ #define __ASM_GENERIC_EXPORT_H /* - * This comment block is used by fixdep. Please do not remove. - * - * When CONFIG_MODVERSIONS is changed from n to y, all source files having - * EXPORT_SYMBOL variants must be re-compiled because genksyms is run as a - * side effect of the *.o build rule. + * and are deprecated. + * Please include directly. */ +#include -#ifndef KSYM_FUNC -#define KSYM_FUNC(x) x -#endif -#ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS -#define KSYM_ALIGN 4 -#elif defined(CONFIG_64BIT) -#define KSYM_ALIGN 8 -#else -#define KSYM_ALIGN 4 -#endif - -.macro __put, val, name -#ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS - .long \val - ., \name - ., 0 -#elif defined(CONFIG_64BIT) - .quad \val, \name, 0 -#else - .long \val, \name, 0 -#endif -.endm - -/* - * note on .section use: we specify progbits since usage of the "M" (SHF_MERGE) - * section flag requires it. Use '%progbits' instead of '@progbits' since the - * former apparently works on all arches according to the binutils source. - */ - -.macro ___EXPORT_SYMBOL name,val,sec -#if defined(CONFIG_MODULES) && !defined(__DISABLE_EXPORTS) - .section ___ksymtab\sec+\name,"a" - .balign KSYM_ALIGN -__ksymtab_\name: - __put \val, __kstrtab_\name - .previous - .section __ksymtab_strings,"aMS",%progbits,1 -__kstrtab_\name: - .asciz "\name" - .previous -#endif -.endm - -#if defined(CONFIG_TRIM_UNUSED_KSYMS) - -#include -#include - -.macro __ksym_marker sym - .section ".discard.ksym","a" -__ksym_marker_\sym: - .previous -.endm - -#define __EXPORT_SYMBOL(sym, val, sec) \ - __ksym_marker sym; \ - __cond_export_sym(sym, val, sec, __is_defined(__KSYM_##sym)) -#define __cond_export_sym(sym, val, sec, conf) \ - ___cond_export_sym(sym, val, sec, conf) -#define ___cond_export_sym(sym, val, sec, enabled) \ - __cond_export_sym_##enabled(sym, val, sec) -#define __cond_export_sym_1(sym, val, sec) ___EXPORT_SYMBOL sym, val, sec -#define __cond_export_sym_0(sym, val, sec) /* nothing */ - -#else -#define __EXPORT_SYMBOL(sym, val, sec) ___EXPORT_SYMBOL sym, val, sec -#endif - -#define EXPORT_SYMBOL(name) \ - __EXPORT_SYMBOL(name, KSYM_FUNC(name),) -#define EXPORT_SYMBOL_GPL(name) \ - __EXPORT_SYMBOL(name, KSYM_FUNC(name), _gpl) -#define EXPORT_DATA_SYMBOL(name) \ - __EXPORT_SYMBOL(name, name,) -#define EXPORT_DATA_SYMBOL_GPL(name) \ - __EXPORT_SYMBOL(name, name,_gpl) +#define EXPORT_DATA_SYMBOL(name) EXPORT_SYMBOL(name) +#define EXPORT_DATA_SYMBOL_GPL(name) EXPORT_SYMBOL_GPL(name) #endif diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h index d1f57e4868ed..e65d55e8819c 100644 --- a/include/asm-generic/vmlinux.lds.h +++ b/include/asm-generic/vmlinux.lds.h @@ -1006,6 +1006,7 @@ PATCHABLE_DISCARDS \ *(.discard) \ *(.discard.*) \ + *(.export_symbol) \ *(.modinfo) \ /* ld.bfd warns about .gnu.version* even when not emitted */ \ *(.gnu.version*) \ diff --git a/include/linux/export-internal.h b/include/linux/export-internal.h index fe7e6ba918f1..1c849db953a5 100644 --- a/include/linux/export-internal.h +++ b/include/linux/export-internal.h @@ -10,6 +10,55 @@ #include #include +#if defined(CONFIG_HAVE_ARCH_PREL32_RELOCATIONS) +/* + * relative reference: this reduces the size by half on 64-bit architectures, + * and eliminates the need for absolute relocations that require runtime + * processing on relocatable kernels. + */ +#define __KSYM_REF(sym) ".long " #sym "- ." +#elif defined(CONFIG_64BIT) +#define __KSYM_REF(sym) ".quad " #sym +#else +#define __KSYM_REF(sym) ".long " #sym +#endif + +/* + * For every exported symbol, do the following: + * + * - Put the name of the symbol and namespace (empty string "" for none) in + * __ksymtab_strings. + * - Place a struct kernel_symbol entry in the __ksymtab section. + * + * Note on .section use: we specify progbits since usage of the "M" (SHF_MERGE) + * section flag requires it. Use '%progbits' instead of '@progbits' since the + * former apparently works on all arches according to the binutils source. + */ +#define __KSYMTAB(name, sym, sec, ns) \ + asm(" .section \"__ksymtab_strings\",\"aMS\",%progbits,1" "\n" \ + "__kstrtab_" #name ":" "\n" \ + " .asciz \"" #name "\"" "\n" \ + "__kstrtabns_" #name ":" "\n" \ + " .asciz \"" ns "\"" "\n" \ + " .previous" "\n" \ + " .section \"___ksymtab" sec "+" #name "\", \"a\"" "\n" \ + " .balign 4" "\n" \ + "__ksymtab_" #name ":" "\n" \ + __KSYM_REF(sym) "\n" \ + __KSYM_REF(__kstrtab_ ##name) "\n" \ + __KSYM_REF(__kstrtabns_ ##name) "\n" \ + " .previous" "\n" \ + ) + +#ifdef CONFIG_IA64 +#define KSYM_FUNC(name) @fptr(name) +#else +#define KSYM_FUNC(name) name +#endif + +#define KSYMTAB_FUNC(name, sec, ns) __KSYMTAB(name, KSYM_FUNC(name), sec, ns) +#define KSYMTAB_DATA(name, sec, ns) __KSYMTAB(name, name, sec, ns) + #define SYMBOL_CRC(sym, crc, sec) \ asm(".section \"___kcrctab" sec "+" #sym "\",\"a\"" "\n" \ "__crc_" #sym ":" "\n" \ diff --git a/include/linux/export.h b/include/linux/export.h index 3f31ced0d977..529435a821c0 100644 --- a/include/linux/export.h +++ b/include/linux/export.h @@ -2,6 +2,7 @@ #ifndef _LINUX_EXPORT_H #define _LINUX_EXPORT_H +#include #include /* @@ -28,72 +29,31 @@ extern struct module __this_module; #else #define THIS_MODULE ((struct module *)0) #endif +#endif /* __ASSEMBLY__ */ -#ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS -#include -/* - * Emit the ksymtab entry as a pair of relative references: this reduces - * the size by half on 64-bit architectures, and eliminates the need for - * absolute relocations that require runtime processing on relocatable - * kernels. - */ -#define __KSYMTAB_ENTRY(sym, sec) \ - __ADDRESSABLE(sym) \ - asm(" .section \"___ksymtab" sec "+" #sym "\", \"a\" \n" \ - " .balign 4 \n" \ - "__ksymtab_" #sym ": \n" \ - " .long " #sym "- . \n" \ - " .long __kstrtab_" #sym "- . \n" \ - " .long __kstrtabns_" #sym "- . \n" \ - " .previous \n") - -struct kernel_symbol { - int value_offset; - int name_offset; - int namespace_offset; -}; -#else -#define __KSYMTAB_ENTRY(sym, sec) \ - static const struct kernel_symbol __ksymtab_##sym \ - __attribute__((section("___ksymtab" sec "+" #sym), used)) \ - __aligned(sizeof(void *)) \ - = { (unsigned long)&sym, __kstrtab_##sym, __kstrtabns_##sym } - -struct kernel_symbol { - unsigned long value; - const char *name; - const char *namespace; -}; -#endif +#define ____EXPORT_SYMBOL(sym, license, ns) \ + .section ".export_symbol","a" ; \ + __export_symbol_##license##_##sym: ; \ + .asciz ns ; \ + .balign 4 ; \ + .long sym - . ; \ + .previous #ifdef __GENKSYMS__ #define ___EXPORT_SYMBOL(sym, sec, ns) __GENKSYMS_EXPORT_SYMBOL(sym) +#elif defined(__ASSEMBLY__) + +#define ___EXPORT_SYMBOL(sym, license, ns) \ + ____EXPORT_SYMBOL(sym, license, ns) + #else -/* - * For every exported symbol, do the following: - * - * - Put the name of the symbol and namespace (empty string "" for none) in - * __ksymtab_strings. - * - Place a struct kernel_symbol entry in the __ksymtab section. - * - * note on .section use: we specify progbits since usage of the "M" (SHF_MERGE) - * section flag requires it. Use '%progbits' instead of '@progbits' since the - * former apparently works on all arches according to the binutils source. - */ -#define ___EXPORT_SYMBOL(sym, sec, ns) \ - extern typeof(sym) sym; \ - extern const char __kstrtab_##sym[]; \ - extern const char __kstrtabns_##sym[]; \ - asm(" .section \"__ksymtab_strings\",\"aMS\",%progbits,1 \n" \ - "__kstrtab_" #sym ": \n" \ - " .asciz \"" #sym "\" \n" \ - "__kstrtabns_" #sym ": \n" \ - " .asciz \"" ns "\" \n" \ - " .previous \n"); \ - __KSYMTAB_ENTRY(sym, sec) +#define ___EXPORT_SYMBOL(sym, license, ns) \ + extern typeof(sym) sym; \ + __ADDRESSABLE(sym) \ + asm(__stringify(____EXPORT_SYMBOL(sym, license, ns))) #endif @@ -117,9 +77,21 @@ struct kernel_symbol { * from the $(NM) output (see scripts/gen_ksymdeps.sh). These symbols are * discarded in the final link stage. */ + +#ifdef __ASSEMBLY__ + +#define __ksym_marker(sym) \ + .section ".discard.ksym","a" ; \ +__ksym_marker_##sym: ; \ + .previous + +#else + #define __ksym_marker(sym) \ static int __ksym_marker_##sym[0] __section(".discard.ksym") __used +#endif + #define __EXPORT_SYMBOL(sym, sec, ns) \ __ksym_marker(sym); \ __cond_export_sym(sym, sec, ns, __is_defined(__KSYM_##sym)) @@ -147,11 +119,9 @@ struct kernel_symbol { #define _EXPORT_SYMBOL(sym, sec) __EXPORT_SYMBOL(sym, sec, "") #endif -#define EXPORT_SYMBOL(sym) _EXPORT_SYMBOL(sym, "") -#define EXPORT_SYMBOL_GPL(sym) _EXPORT_SYMBOL(sym, "_gpl") -#define EXPORT_SYMBOL_NS(sym, ns) __EXPORT_SYMBOL(sym, "", __stringify(ns)) -#define EXPORT_SYMBOL_NS_GPL(sym, ns) __EXPORT_SYMBOL(sym, "_gpl", __stringify(ns)) - -#endif /* !__ASSEMBLY__ */ +#define EXPORT_SYMBOL(sym) _EXPORT_SYMBOL(sym,) +#define EXPORT_SYMBOL_GPL(sym) _EXPORT_SYMBOL(sym,gpl) +#define EXPORT_SYMBOL_NS(sym, ns) __EXPORT_SYMBOL(sym,, __stringify(ns)) +#define EXPORT_SYMBOL_NS_GPL(sym, ns) __EXPORT_SYMBOL(sym,gpl, __stringify(ns)) #endif /* _LINUX_EXPORT_H */ diff --git a/include/linux/pm.h b/include/linux/pm.h index 035d9649eba4..aabb6bd8f89e 100644 --- a/include/linux/pm.h +++ b/include/linux/pm.h @@ -388,10 +388,10 @@ const struct dev_pm_ops name = { \ #define EXPORT_PM_FN_NS_GPL(name, ns) #endif -#define EXPORT_DEV_PM_OPS(name) _EXPORT_DEV_PM_OPS(name, "", "") -#define EXPORT_GPL_DEV_PM_OPS(name) _EXPORT_DEV_PM_OPS(name, "_gpl", "") -#define EXPORT_NS_DEV_PM_OPS(name, ns) _EXPORT_DEV_PM_OPS(name, "", #ns) -#define EXPORT_NS_GPL_DEV_PM_OPS(name, ns) _EXPORT_DEV_PM_OPS(name, "_gpl", #ns) +#define EXPORT_DEV_PM_OPS(name) _EXPORT_DEV_PM_OPS(name,, "") +#define EXPORT_GPL_DEV_PM_OPS(name) _EXPORT_DEV_PM_OPS(name,gpl, "") +#define EXPORT_NS_DEV_PM_OPS(name, ns) _EXPORT_DEV_PM_OPS(name,, #ns) +#define EXPORT_NS_GPL_DEV_PM_OPS(name, ns) _EXPORT_DEV_PM_OPS(name,gpl, #ns) /* * Use this if you want to use the same suspend and resume callbacks for suspend diff --git a/kernel/module/internal.h b/kernel/module/internal.h index dc7b0160c480..c8b7b4dcf782 100644 --- a/kernel/module/internal.h +++ b/kernel/module/internal.h @@ -32,6 +32,18 @@ /* Maximum number of characters written by module_flags() */ #define MODULE_FLAGS_BUF_SIZE (TAINT_FLAGS_COUNT + 4) +struct kernel_symbol { +#ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS + int value_offset; + int name_offset; + int namespace_offset; +#else + unsigned long value; + const char *name; + const char *namespace; +#endif +}; + extern struct mutex module_mutex; extern struct list_head modules; diff --git a/scripts/Makefile.build b/scripts/Makefile.build index 9f94fc83f086..6bf026a304e4 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -161,7 +161,7 @@ quiet_cmd_cc_o_c = CC $(quiet_modtag) $@ ifdef CONFIG_MODVERSIONS # When module versioning is enabled the following steps are executed: # o compile a .o from .c -# o if .o doesn't contain a __ksymtab version, i.e. does +# o if .o doesn't contain a __export_symbol*, i.e. does # not export symbols, it's done. # o otherwise, we calculate symbol versions using the good old # genksyms on the preprocessed source and dump them into the .cmd file. @@ -169,7 +169,7 @@ ifdef CONFIG_MODVERSIONS # be compiled and linked to the kernel and/or modules. gen_symversions = \ - if $(NM) $@ 2>/dev/null | grep -q __ksymtab; then \ + if $(NM) $@ 2>/dev/null | grep -q '__export_symbol_[^_]*_'; then \ $(call cmd_gensymtypes_$(1),$(KBUILD_SYMTYPES),$(@:.o=.symtypes)) \ >> $(dot-target).cmd; \ fi @@ -340,9 +340,7 @@ $(obj)/%.ll: $(src)/%.rs FORCE cmd_gensymtypes_S = \ { echo "\#include " ; \ echo "\#include " ; \ - $(CPP) $(a_flags) $< | \ - grep "\<___EXPORT_SYMBOL\>" | \ - sed 's/.*___EXPORT_SYMBOL[[:space:]]*\([a-zA-Z0-9_]*\)[[:space:]]*,.*/EXPORT_SYMBOL(\1);/' ; } | \ + $(NM) $@ | sed -n 's/.*__export_symbol_[^_]*_\(.*\)/EXPORT_SYMBOL(\1);/p' ; } | \ $(CPP) -D__GENKSYMS__ $(c_flags) -xc - | $(genksyms) quiet_cmd_cc_symtypes_S = SYM $(quiet_modtag) $@ diff --git a/scripts/check-local-export b/scripts/check-local-export index f90b5a9c67b3..969a313b9299 100755 --- a/scripts/check-local-export +++ b/scripts/check-local-export @@ -46,9 +46,9 @@ BEGIN { { symbol_types[$3]=$2 } # append the exported symbol to the array -($3 ~ /^__ksymtab_/) { +($3 ~ /^__export_symbol_(gpl)?_.*/) { export_symbols[i] = $3 - sub(/^__ksymtab_/, "", export_symbols[i]) + sub(/^__export_symbol_(gpl)?_/, "", export_symbols[i]) i++ } diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index 403ba4d923f5..0ae6c9c5bdf6 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -217,6 +217,7 @@ struct symbol { unsigned int crc; bool crc_valid; bool weak; + bool is_func; bool is_gpl_only; /* exported by EXPORT_SYMBOL_GPL */ char name[]; }; @@ -533,6 +534,8 @@ static int parse_elf(struct elf_info *info, const char *filename) fatal("%s has NOBITS .modinfo\n", filename); info->modinfo = (void *)hdr + sechdrs[i].sh_offset; info->modinfo_len = sechdrs[i].sh_size; + } else if (!strcmp(secname, ".export_symbol")) { + info->export_symbol_secndx = i; } if (sechdrs[i].sh_type == SHT_SYMTAB) { @@ -655,18 +658,6 @@ static void handle_symbol(struct module *mod, struct elf_info *info, ELF_ST_BIND(sym->st_info) == STB_WEAK); break; default: - /* All exported symbols */ - if (strstarts(symname, "__ksymtab_")) { - const char *name, *secname; - - name = symname + strlen("__ksymtab_"); - secname = sec_name(info, get_secindex(info, sym)); - - if (strstarts(secname, "___ksymtab_gpl+")) - sym_add_exported(name, mod, true); - else if (strstarts(secname, "___ksymtab+")) - sym_add_exported(name, mod, false); - } if (strcmp(symname, "init_module") == 0) mod->has_init = true; if (strcmp(symname, "cleanup_module") == 0) @@ -848,7 +839,6 @@ enum mismatch { XXXEXIT_TO_SOME_EXIT, ANY_INIT_TO_ANY_EXIT, ANY_EXIT_TO_ANY_INIT, - EXPORT_TO_INIT_EXIT, EXTABLE_TO_NON_TEXT, }; @@ -920,12 +910,6 @@ static const struct sectioncheck sectioncheck[] = { .bad_tosec = { INIT_SECTIONS, NULL }, .mismatch = ANY_INIT_TO_ANY_EXIT, }, -/* Do not export init/exit functions or data */ -{ - .fromsec = { "___ksymtab*", NULL }, - .bad_tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL }, - .mismatch = EXPORT_TO_INIT_EXIT, -}, { .fromsec = { "__ex_table", NULL }, /* If you're adding any new black-listed sections in here, consider @@ -1180,10 +1164,6 @@ static void default_mismatch_handler(const char *modname, struct elf_info *elf, warn("%s: section mismatch in reference: %s (section: %s) -> %s (section: %s)\n", modname, fromsym, fromsec, tosym, tosec); break; - case EXPORT_TO_INIT_EXIT: - warn("%s: EXPORT_SYMBOL used for init/exit symbol: %s (section: %s)\n", - modname, tosym, tosec); - break; case EXTABLE_TO_NON_TEXT: warn("%s(%s+0x%lx): Section mismatch in reference to the %s:%s\n", modname, fromsec, (long)faddr, tosec, tosym); @@ -1211,14 +1191,69 @@ static void default_mismatch_handler(const char *modname, struct elf_info *elf, } } +static void check_export_symbol(struct module *mod, struct elf_info *elf, + Elf_Addr faddr, const char *secname, + Elf_Sym *sym) +{ + const char *label_name, *name, *prefix; + Elf_Sym *label; + struct symbol *s; + bool is_gpl; + + label = find_fromsym(elf, faddr, elf->export_symbol_secndx); + label_name = sym_name(elf, label); + + name = sym_name(elf, sym); + + if (strstarts(label_name, "__export_symbol_gpl_")) { + prefix = "__export_symbol_gpl_"; + is_gpl = true; + } else if (strstarts(label_name, "__export_symbol__")) { + prefix = "__export_symbol__"; + is_gpl = false; + } else { + error("%s: .export_symbol section contains strange symbol '%s'\n", + mod->name, label_name); + return; + } + + if (strcmp(label_name + strlen(prefix), name)) { + error("%s: .export_symbol section references '%s', but it does not seem to be an export symbol\n", + mod->name, name); + return; + } + + s = sym_add_exported(name, mod, is_gpl); + sym_update_namespace(name, sym_get_data(elf, label)); + + /* + * We need to be aware whether we are exporting a function or + * a data on some architectures. + */ + s->is_func = (ELF_ST_TYPE(sym->st_info) == STT_FUNC); + + if (match(secname, PATTERNS(INIT_SECTIONS))) + error("%s: %s: EXPORT_SYMBOL used for init symbol. Remove __init or EXPORT_SYMBOL.\n", + mod->name, name); + else if (match(secname, PATTERNS(EXIT_SECTIONS))) + error("%s: %s: EXPORT_SYMBOL used for exit symbol. Remove __exit or EXPORT_SYMBOL.\n", + mod->name, name); +} + static void check_section_mismatch(struct module *mod, struct elf_info *elf, Elf_Sym *sym, unsigned int fsecndx, const char *fromsec, Elf_Addr faddr, Elf_Addr taddr) { const char *tosec = sec_name(elf, get_secindex(elf, sym)); - const struct sectioncheck *mismatch = section_mismatch(fromsec, tosec); + const struct sectioncheck *mismatch; + if (elf->export_symbol_secndx == fsecndx) { + check_export_symbol(mod, elf, faddr, tosec, sym); + return; + } + + mismatch = section_mismatch(fromsec, tosec); if (!mismatch) return; @@ -1698,15 +1733,6 @@ static void read_symbols(const char *modname) handle_moddevtable(mod, &info, sym, symname); } - for (sym = info.symtab_start; sym < info.symtab_stop; sym++) { - symname = remove_dot(info.strtab + sym->st_name); - - /* Apply symbol namespaces from __kstrtabns_ entries. */ - if (strstarts(symname, "__kstrtabns_")) - sym_update_namespace(symname + strlen("__kstrtabns_"), - sym_get_data(&info, sym)); - } - check_sec_ref(mod, &info); if (!mod->is_vmlinux) { @@ -1890,6 +1916,14 @@ static void add_exported_symbols(struct buffer *buf, struct module *mod) { struct symbol *sym; + /* generate struct for exported symbols */ + buf_printf(buf, "\n"); + list_for_each_entry(sym, &mod->exported_symbols, list) + buf_printf(buf, "KSYMTAB_%s(%s, \"%s\", \"%s\");\n", + sym->is_func ? "FUNC" : "DATA", sym->name, + sym->is_gpl_only ? "_gpl" : "", + sym->namespace ?: ""); + if (!modversions) return; diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h index b1e2d95f8047..dfdb9484e325 100644 --- a/scripts/mod/modpost.h +++ b/scripts/mod/modpost.h @@ -137,6 +137,7 @@ struct elf_info { Elf_Shdr *sechdrs; Elf_Sym *symtab_start; Elf_Sym *symtab_stop; + unsigned int export_symbol_secndx; /* .export_symbol section */ char *strtab; char *modinfo; unsigned int modinfo_len; From patchwork Thu Jun 8 14:24:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 104999 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6358:3046:b0:115:7a1d:dabb with SMTP id p6csp380325rwl; Thu, 8 Jun 2023 07:45:35 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7SJtEasi66tMCKJN/e4Sx/fpshdEfXHobgN6tIFtVizevbaP41W4oK4LuQZEiuZpf92HRS X-Received: by 2002:a17:90a:fb43:b0:255:5a5e:df38 with SMTP id iq3-20020a17090afb4300b002555a5edf38mr5248108pjb.33.1686235535341; Thu, 08 Jun 2023 07:45:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686235535; cv=none; d=google.com; s=arc-20160816; b=PashvNAz2F3ltFDy9e8iraWyBxvjI9I5StPepFuZUTkEMJ/Vz11P/bsWgpQL8zDa0H 9H46T9W87HPXjRyWjMCYOC/6KHDRWvb5ji2wy437jcDwgphiom3RWp020zS22uPEwkuR UNA5K1+loDZZuJxhczWHGOq3cebG844VC7XDk74UhfydL3KgEeufO4G1cyN6deyQLVcf 0JQXsX43IwFYdRQXD0waEaqkC2AHDS1b63EZgtLQsOuuN1KsC5a1tKkEGYAdmGo5mBD1 KIKC+m8Kd6imacV4YWI2GwlkoukZxKWUeMl544uID2ejbjF7rROdwe0YpDlGv7kHAHjU gygQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=TWDB1iG+Vl7JVhdRPzBQ/TqB7/5hDO2ShXQK+OWx/pU=; b=GXqs8xf5IIRG6P3JUjOzRMwHxURkJNUNuSnRmBSN/P6gFwwFhfMkzkyGG6DC57GH5k dsXDJnG/+wHgFHpF0klppB0wPjCEuUdzc/J9ydORi+supYbXmEDcy72UCvquzN2jI6K/ Bz3VUye68p5p2es7iiIn36MsbQuaBUfohttlplahcHgdo7IhHOS6E2LtqdNTUAl5blUp 9rrRJDwy9guwwL7gj+GhcgW1RLgGWigdwwpB3bNciOw2CfcSLia3JJ4Mz7RImhGpuwxQ 0qSAJrPgVNFWytNlw/Mg9yzJ5vEkxRpeeKDdFB03chzFulI/ORcALRa01ACzyFzeGwDG YPQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=cKuOBnr9; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ev13-20020a17090aeacd00b0025687c5af36si2846407pjb.115.2023.06.08.07.45.21; Thu, 08 Jun 2023 07:45:35 -0700 (PDT) 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=@kernel.org header.s=k20201202 header.b=cKuOBnr9; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237098AbjFHOZI (ORCPT + 99 others); Thu, 8 Jun 2023 10:25:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55758 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237023AbjFHOY7 (ORCPT ); Thu, 8 Jun 2023 10:24:59 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8DD332D59; Thu, 8 Jun 2023 07:24:44 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 22C0364DEE; Thu, 8 Jun 2023 14:24:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 452D2C433D2; Thu, 8 Jun 2023 14:24:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686234283; bh=zr+yJCwaIX4mMIACmjYkguIW6MMvumzYzdZSlBPO+AQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cKuOBnr9Iq/1ae8awIyi/rOQLVs36xIlGEDNSNCiE6fBszHLVJvysXTelpQ5LsXAW MtquvFidmwc2giAJVjsa0GgMwyk9V5vR669ZCsa4Rc30HYQwzLfbn2+BRfYcl21i8z yjvG/0wjaNEVXQcb0QLmCy5NVbCBcxJ/Vkk7FhTkKOnr2CULRqZuRSkMWSgepQPZt3 JGhrSSoHWzF4vTDpC7kyT9H7xUaFGxj+a/YGjV7Lrh8Nxd0x14wx9UvTOP/JQ4x11M XFBkU26jb/qTgPwi5mRmv6/GWfilsfZ6hbCM2gp2kL96h4YwPRQfWWPan8NjBlg9R3 uXek3TDhjeBWA== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Nathan Chancellor , Nick Desaulniers , Nicolas Schier , linux-um@lists.infradead.org, Masahiro Yamada Subject: [PATCH v7 04/11] ia64,export.h: replace EXPORT_DATA_SYMBOL* with EXPORT_SYMBOL* Date: Thu, 8 Jun 2023 23:24:21 +0900 Message-Id: <20230608142428.256985-5-masahiroy@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230608142428.256985-1-masahiroy@kernel.org> References: <20230608142428.256985-1-masahiroy@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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?1768146112361493931?= X-GMAIL-MSGID: =?utf-8?q?1768146112361493931?= With the previous refactoring, you can always use EXPORT_SYMBOL*. Replace two instances in ia64, then remove EXPORT_DATA_SYMBOL*. Signed-off-by: Masahiro Yamada Reviewed-by: Nick Desaulniers --- arch/ia64/kernel/head.S | 2 +- arch/ia64/kernel/ivt.S | 2 +- include/asm-generic/export.h | 3 --- 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/arch/ia64/kernel/head.S b/arch/ia64/kernel/head.S index f22469f1c1fc..c096500590e9 100644 --- a/arch/ia64/kernel/head.S +++ b/arch/ia64/kernel/head.S @@ -170,7 +170,7 @@ RestRR: \ __PAGE_ALIGNED_DATA .global empty_zero_page -EXPORT_DATA_SYMBOL_GPL(empty_zero_page) +EXPORT_SYMBOL_GPL(empty_zero_page) empty_zero_page: .skip PAGE_SIZE diff --git a/arch/ia64/kernel/ivt.S b/arch/ia64/kernel/ivt.S index d6d4229b28db..7a418e324d30 100644 --- a/arch/ia64/kernel/ivt.S +++ b/arch/ia64/kernel/ivt.S @@ -87,7 +87,7 @@ .align 32768 // align on 32KB boundary .global ia64_ivt - EXPORT_DATA_SYMBOL(ia64_ivt) + EXPORT_SYMBOL(ia64_ivt) ia64_ivt: ///////////////////////////////////////////////////////////////////////////////////////// // 0x0000 Entry 0 (size 64 bundles) VHPT Translation (8,20,47) diff --git a/include/asm-generic/export.h b/include/asm-generic/export.h index 0ae9f38a904c..570cd4da7210 100644 --- a/include/asm-generic/export.h +++ b/include/asm-generic/export.h @@ -8,7 +8,4 @@ */ #include -#define EXPORT_DATA_SYMBOL(name) EXPORT_SYMBOL(name) -#define EXPORT_DATA_SYMBOL_GPL(name) EXPORT_SYMBOL_GPL(name) - #endif From patchwork Thu Jun 8 14:24:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 105001 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6358:3046:b0:115:7a1d:dabb with SMTP id p6csp382675rwl; Thu, 8 Jun 2023 07:49:27 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ47CCPwUQ8c6EhmQ54Jz0+6+UiztvxM+4eIdo/8D0EGyt7Ytfcizb4YQcYTm5JyLQEB1FPC X-Received: by 2002:a17:903:1d1:b0:1af:e10f:ba96 with SMTP id e17-20020a17090301d100b001afe10fba96mr3013348plh.1.1686235767441; Thu, 08 Jun 2023 07:49:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686235767; cv=none; d=google.com; s=arc-20160816; b=WUKIf+Sqi6GZz7PHc0yQBFR1ViPW/ofHXgPt744PBdbayunampyuHTkzp7PIwwIPkz 0c2Ww6MksviSaPWmx6BsYzC3+IDIY3yD1qZvRSwPf+7g5w7jr9baXfxIzdLL+VxqAl5g wzHJXcsAFmaDKUt4f0OsMT2OuxeqhpW2ach9tYStclhbO3Of3h4ZroK/Ra+FwmRVgPjB YQBVTf+57ex0rHr8c3ZkB17s3tjWDzWF5RRYDXhlv2P3SAppRaqpH89P5ESjUidoKbOW 2VOz6UqpurzS2jy7yRDIMQPzDUe9hfXqS9EHerWdj9UxVPLmCkXU5nBZWZKRqVpVdcoN jEcQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=SE1VLziysS6f2yMU44qrO1OuFIos4c01BA9yvD4QRL4=; b=uYM3MB2LWG3YpJbVzkjSaityVu90WI5rBJlOvESBpkWWtz74l1RZIaMD2+SAN+7Oul rixZYvPYrfmA+aAAcje7FVBGFm5UbaYfSFU+OVkUNQgQZ6+PhP0MlO8oR0SnLBbf7dTB dS2L1YWqprYdsewiUDd2zp6axzxdTc44Jgk+cPms8dr8iIeQU7GBqh5VLP3Zmts+O3Gu 1R1qkqRxVgcZbqdYzmXlPgjrV32KAH4VA2x0TY7g3i6IXPektRdOnEXkZjUXWc+eHoXF 7UDmQFrAhoqyp9nlz/RnWZg7baLmjHBCL3Rrdjyv8h8BL1TgJzAcA0OFCMy3vTC1V2dB jVgA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=f5eyupyt; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id la6-20020a170902fa0600b001b0f727bc35si1145773plb.157.2023.06.08.07.49.14; Thu, 08 Jun 2023 07:49:27 -0700 (PDT) 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=@kernel.org header.s=k20201202 header.b=f5eyupyt; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237209AbjFHOZ1 (ORCPT + 99 others); Thu, 8 Jun 2023 10:25:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56004 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237059AbjFHOZI (ORCPT ); Thu, 8 Jun 2023 10:25:08 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 901472D71; Thu, 8 Jun 2023 07:24:51 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id C6DA164E17; Thu, 8 Jun 2023 14:24:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EED04C4339E; Thu, 8 Jun 2023 14:24:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686234285; bh=wDZYNwqiVuH0V8gWt3bQO0dgJiIU1kJv/naJ4wK8eyk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=f5eyupytjMru7y+zKUf+neYzJmNN/qDO1yks3ibrmWIyBDDfHdmEMPqrYbXFoFRml v4TPOg+NVeepAQ1LJ6RVR7SLOICOQX/jjZJcdkdTiQmC8iNB+OpHFL0zLOWYqZul1/ Q0Ly5ObC4xq67L546vHmIP0i6cxu7vfIMochFxeJPeT3C2XSvLfO9KGd6DY29ox1mb YvYgTXPTmh8OaTNxbFNY+/5HBoNxoOlwFPT6JPlv2dx5kfTPf/WU+inMIqbgbzOfp5 MrSn9fanDBshrjHHZnrj08MUM2hZr+ZGS37CBpsF2ci09sxbD85hP87bqjm4q2RU1B pOiNv7OmW3usg== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Nathan Chancellor , Nick Desaulniers , Nicolas Schier , linux-um@lists.infradead.org, Masahiro Yamada Subject: [PATCH v7 05/11] modpost: check static EXPORT_SYMBOL* by modpost again Date: Thu, 8 Jun 2023 23:24:22 +0900 Message-Id: <20230608142428.256985-6-masahiroy@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230608142428.256985-1-masahiroy@kernel.org> References: <20230608142428.256985-1-masahiroy@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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?1768146356314533883?= X-GMAIL-MSGID: =?utf-8?q?1768146356314533883?= Commit 31cb50b5590f ("kbuild: check static EXPORT_SYMBOL* by script instead of modpost") moved the static EXPORT_SYMBOL* check from the mostpost to a shell script because I thought it must be checked per compilation unit to avoid false negatives. I came up with an idea to do this in modpost, against combined ELF files. The relocation entries in ELF will find the correct exported symbol even if there exist symbols with the same name in different compilation units. Again, the same sample code. Makefile: obj-y += foo1.o foo2.o foo1.c: #include static void foo(void) {} EXPORT_SYMBOL(foo); foo2.c: void foo(void) {} Then, modpost can catch it correctly. MODPOST Module.symvers ERROR: modpost: vmlinux: local symbol 'foo' was exported Signed-off-by: Masahiro Yamada Reviewed-by: Nick Desaulniers --- (no changes since v6) Changes in v6: - Make the symbol name in the warning more precise scripts/Makefile.build | 4 --- scripts/check-local-export | 70 -------------------------------------- scripts/mod/modpost.c | 7 ++++ 3 files changed, 7 insertions(+), 74 deletions(-) delete mode 100755 scripts/check-local-export diff --git a/scripts/Makefile.build b/scripts/Makefile.build index 6bf026a304e4..bd4123795299 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -220,8 +220,6 @@ cmd_gen_ksymdeps = \ $(CONFIG_SHELL) $(srctree)/scripts/gen_ksymdeps.sh $@ >> $(dot-target).cmd endif -cmd_check_local_export = $(srctree)/scripts/check-local-export $@ - ifneq ($(findstring 1, $(KBUILD_EXTRA_WARN)),) cmd_warn_shared_object = $(if $(word 2, $(modname-multi)),$(warning $(kbuild-file): $*.o is added to multiple modules: $(modname-multi))) endif @@ -229,7 +227,6 @@ endif define rule_cc_o_c $(call cmd_and_fixdep,cc_o_c) $(call cmd,gen_ksymdeps) - $(call cmd,check_local_export) $(call cmd,checksrc) $(call cmd,checkdoc) $(call cmd,gen_objtooldep) @@ -241,7 +238,6 @@ endef define rule_as_o_S $(call cmd_and_fixdep,as_o_S) $(call cmd,gen_ksymdeps) - $(call cmd,check_local_export) $(call cmd,gen_objtooldep) $(call cmd,gen_symversions_S) $(call cmd,warn_shared_object) diff --git a/scripts/check-local-export b/scripts/check-local-export deleted file mode 100755 index 969a313b9299..000000000000 --- a/scripts/check-local-export +++ /dev/null @@ -1,70 +0,0 @@ -#!/bin/sh -# SPDX-License-Identifier: GPL-2.0-only -# -# Copyright (C) 2022 Masahiro Yamada -# Copyright (C) 2022 Owen Rafferty -# -# Exit with error if a local exported symbol is found. -# EXPORT_SYMBOL should be used for global symbols. - -set -e -pid=$$ - -# If there is no symbol in the object, ${NM} (both GNU nm and llvm-nm) shows -# 'no symbols' diagnostic (but exits with 0). It is harmless and hidden by -# '2>/dev/null'. However, it suppresses real error messages as well. Add a -# hand-crafted error message here. -# -# TODO: -# Use --quiet instead of 2>/dev/null when we upgrade the minimum version of -# binutils to 2.37, llvm to 13.0.0. -# Then, the following line will be simpler: -# { ${NM} --quiet ${1} || kill 0; } | - -{ ${NM} ${1} 2>/dev/null || { echo "${0}: ${NM} failed" >&2; kill $pid; } } | -${AWK} -v "file=${1}" ' -BEGIN { - i = 0 -} - -# Skip the line if the number of fields is less than 3. -# -# case 1) -# For undefined symbols, the first field (value) is empty. -# The outout looks like this: -# " U _printk" -# It is unneeded to record undefined symbols. -# -# case 2) -# For Clang LTO, llvm-nm outputs a line with type t but empty name: -# "---------------- t" -!length($3) { - next -} - -# save (name, type) in the associative array -{ symbol_types[$3]=$2 } - -# append the exported symbol to the array -($3 ~ /^__export_symbol_(gpl)?_.*/) { - export_symbols[i] = $3 - sub(/^__export_symbol_(gpl)?_/, "", export_symbols[i]) - i++ -} - -END { - exit_code = 0 - for (j = 0; j < i; ++j) { - name = export_symbols[j] - # nm(3) says "If lowercase, the symbol is usually local" - if (symbol_types[name] ~ /[a-z]/) { - printf "%s: error: local symbol %s was exported\n", - file, name | "cat 1>&2" - exit_code = 1 - } - } - - exit exit_code -}' - -exit $? diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index 0ae6c9c5bdf6..a3185ee6ec1a 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -1217,6 +1217,13 @@ static void check_export_symbol(struct module *mod, struct elf_info *elf, return; } + if (ELF_ST_BIND(sym->st_info) != STB_GLOBAL && + ELF_ST_BIND(sym->st_info) != STB_WEAK) { + error("%s: local symbol '%s' was exported\n", mod->name, + label_name + strlen(prefix)); + return; + } + if (strcmp(label_name + strlen(prefix), name)) { error("%s: .export_symbol section references '%s', but it does not seem to be an export symbol\n", mod->name, name); From patchwork Thu Jun 8 14:24:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 105000 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6358:3046:b0:115:7a1d:dabb with SMTP id p6csp380615rwl; Thu, 8 Jun 2023 07:46:00 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5DwZ91aJr8ncBjuwhtFF/3h5hePRLBE6h1zHhwfx8n7ZlYp/vGAuXh6U90shMFUtmnpvKp X-Received: by 2002:a05:6a20:8e19:b0:10c:1378:f2ae with SMTP id y25-20020a056a208e1900b0010c1378f2aemr3337527pzj.46.1686235560367; Thu, 08 Jun 2023 07:46:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686235560; cv=none; d=google.com; s=arc-20160816; b=Iih5gjTtTpr/cPctuhqd6cTVLNVaVj3pZocN6GXBLV95rO5oYPk9OHRsVMDVkZKDov 7kiH0LuuPHdCK4IMaph5i3Kl9UE642mJluheBJjEtq6WPxHwETo+gG1F0VU7Xc37tIAH +BcMUu932MwSe/FiPJE+p38cjA8D/9200HTEa8XZXnuynAuJsbRjaPyaWhO62ns7YMlu QIjrFv3Tmn/Yf1VeMJLj4tziUTBAfJ7wPdtx3kP+XWNtARzbwUOw7qUE0bI9vfEWZq4a SERhgR8edF4bNbj0yCYxLcwD8S1YuafCjUXLhIPUhOI/smNaG041iim+zd5qwjHth0L/ zDzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=X4Z8PeZ7UOfRvHfPPKV9T3Z6LgQays0r4cx3yEjrbQg=; b=r9JAvz4AGM8KYrhNf8rPUT+aRbRYSg+3ooygyATI7RU05tS9pIW6GwFMLRN5oFaDC/ enghvjW0dtwtmCwLGKYlzYPlsZwwoepCsCvIUUKZ5to5tcT1INw/xTgLgIT6BGYVQ6ct frTYUg+P63/iGtouWmBgWXcQzVzi/cTFC8KT0T+7M1HgIM6xbqNtjaVdzlVqLAXceYyH +6J/CM1HYuj/U1dxCOjrFY6bGFJCsGUVrEJ+meL8MgrxHahaUvDwgFDNqcJFbDx3iG4u QRr5dYlVOSOyZLOYz1kZoHljpsrfm69JXk2KEatqIIhNPBrRw2F6/Ul4gyXuD7NankNi qhwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=VLIntpql; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r14-20020aa7988e000000b0064490c20e80si950333pfl.59.2023.06.08.07.45.47; Thu, 08 Jun 2023 07:46:00 -0700 (PDT) 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=@kernel.org header.s=k20201202 header.b=VLIntpql; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237155AbjFHOZW (ORCPT + 99 others); Thu, 8 Jun 2023 10:25:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55992 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237092AbjFHOZH (ORCPT ); Thu, 8 Jun 2023 10:25:07 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 901CA30C7; Thu, 8 Jun 2023 07:24:51 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 764D764E28; Thu, 8 Jun 2023 14:24:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9D7A8C4339C; Thu, 8 Jun 2023 14:24:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686234286; bh=WxsbZJQWaT5jCsrdDCJG6B1Ekj8QHp6BWQx+hm3BcWA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VLIntpqlzV0PbXTunOMMpYAbiC5B7RzbxYYbqvwtEwLaTiLF7ZmPeFO95GFKba0Jn VDBNtT3wUnFHvkz15AIr0Ai5TNfHAI/lbUuC+c4mNVdJBdWb5Iqe4xdGRMiRdfLo/1 CRns73rILLWLvRiOL6YgKsthMyMgWdYkt8g3fOp8AP1k9KuD7dXbxiWSzXY4krmNMt zMtu3NkGpcWa+uORL5M3NxCMz4lchkYojjnC73CKuXufUnMCicLrLynGbKgrjrqMNm q7Gqju5e7XwhWorTDS7a7oRqX0fWkmVJ1N7umFCs3hUp6ZztOGcG9pkYU1XPr4McHa J+eAPcqHWH8Vw== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Nathan Chancellor , Nick Desaulniers , Nicolas Schier , linux-um@lists.infradead.org, Masahiro Yamada Subject: [PATCH v7 06/11] modpost: squash sym_update_namespace() into sym_add_exported() Date: Thu, 8 Jun 2023 23:24:23 +0900 Message-Id: <20230608142428.256985-7-masahiroy@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230608142428.256985-1-masahiroy@kernel.org> References: <20230608142428.256985-1-masahiroy@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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?1768146138743839238?= X-GMAIL-MSGID: =?utf-8?q?1768146138743839238?= Pass a set of the name, license, and namespace to sym_add_exported(). sym_update_namespace() is unneeded. Signed-off-by: Masahiro Yamada Reviewed-by: Nick Desaulniers --- scripts/mod/modpost.c | 27 ++++----------------------- 1 file changed, 4 insertions(+), 23 deletions(-) diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index a3185ee6ec1a..4b0a009de0fb 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -355,26 +355,8 @@ static const char *sec_name(const struct elf_info *info, unsigned int secindex) #define strstarts(str, prefix) (strncmp(str, prefix, strlen(prefix)) == 0) -static void sym_update_namespace(const char *symname, const char *namespace) -{ - struct symbol *s = find_symbol(symname); - - /* - * That symbol should have been created earlier and thus this is - * actually an assertion. - */ - if (!s) { - error("Could not update namespace(%s) for symbol %s\n", - namespace, symname); - return; - } - - free(s->namespace); - s->namespace = namespace[0] ? NOFAIL(strdup(namespace)) : NULL; -} - static struct symbol *sym_add_exported(const char *name, struct module *mod, - bool gpl_only) + bool gpl_only, const char *namespace) { struct symbol *s = find_symbol(name); @@ -387,6 +369,7 @@ static struct symbol *sym_add_exported(const char *name, struct module *mod, s = alloc_symbol(name); s->module = mod; s->is_gpl_only = gpl_only; + s->namespace = namespace[0] ? NOFAIL(strdup(namespace)) : NULL; list_add_tail(&s->list, &mod->exported_symbols); hash_add_symbol(s); @@ -1230,8 +1213,7 @@ static void check_export_symbol(struct module *mod, struct elf_info *elf, return; } - s = sym_add_exported(name, mod, is_gpl); - sym_update_namespace(name, sym_get_data(elf, label)); + s = sym_add_exported(name, mod, is_gpl, sym_get_data(elf, label)); /* * We need to be aware whether we are exporting a function or @@ -2174,9 +2156,8 @@ static void read_dump(const char *fname) mod = new_module(modname, strlen(modname)); mod->from_dump = true; } - s = sym_add_exported(symname, mod, gpl_only); + s = sym_add_exported(symname, mod, gpl_only, namespace); sym_set_crc(s, crc); - sym_update_namespace(symname, namespace); } free(buf); return; From patchwork Thu Jun 8 14:24:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 105002 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6358:3046:b0:115:7a1d:dabb with SMTP id p6csp382676rwl; Thu, 8 Jun 2023 07:49:27 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5R45VgjYFiyzpHOJp2ABKKJXmnhjAVhotiLSWWl6VWA6IuEqf6LGXbpBws/LQti1c1x+19 X-Received: by 2002:a17:902:e5c5:b0:1b0:5ce9:adc7 with SMTP id u5-20020a170902e5c500b001b05ce9adc7mr2609962plf.28.1686235767628; Thu, 08 Jun 2023 07:49:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686235767; cv=none; d=google.com; s=arc-20160816; b=qzSaYrmptGVDSzXm5WKknirpKK9a/vXF2+eRmyRsLS3y2yt33q/4OTVgTYShKClQuS 4NJxRS9kT63x/Mc6XlKYXNnHeBH5OTA4mafteexyszUomwcuZ7SJ9r+uq0xa8QY2nKHQ IwEQj0dH5+3bgtY+ZP1C3sAJTqCZDMKsHyDJK6gv5JoJV1IyaAbapmpgRlZCosD9UCO0 fRJyJJGWx0209JfHnaor7q32p0Bu5Azgz1U/AqOUnWf7Q0GTRFhK9Sv1MmstVL0iqvg8 PlWmZ55vN0G1ME2hE7lZ5KbrFGbxPCLSkKRSR5BFkg/uGswdjmZGcN5XU5M9XeJebaOd eOzQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=bB6JjFtJ5iki5iTIcuNeCfgWlmLsVWt8weVIA5Nt5G8=; b=Yk0+/4bBG0SKmAHYLKI5wPqMvskyvOzWoPAMtNDshc6iJb3G+FGLh51FbTp0dbUqkc Jguz9BtF50kCwuHnWTtYzcaXIYNNdvAkKxMkYIMc6/WE1Bma/kFYC7hZLb0A6e8NbXRn /IKdvbYH2iNAPKIke8DwSWZCfFPsYl4QP6/LKMVpBagK96IfdjxzICaxOJ6VxILSsPWc cxv2wSjLrUA3Vzxk/APvqCVN2f5gdE4RWiis5T0bidfN7fuXGhnZRgSkLFt0RBkfT/5R vQgFQMNh8bUP5/qoJFN6cP1KChvXESgzO6A/+pSRq7rmtLJGMHndKL5vcF99aXaHZSdl S6tw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="E/ppkNpU"; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id jg9-20020a17090326c900b001b25c006fbcsi1177662plb.99.2023.06.08.07.49.14; Thu, 08 Jun 2023 07:49:27 -0700 (PDT) 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=@kernel.org header.s=k20201202 header.b="E/ppkNpU"; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237239AbjFHOZc (ORCPT + 99 others); Thu, 8 Jun 2023 10:25:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56014 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237097AbjFHOZI (ORCPT ); Thu, 8 Jun 2023 10:25:08 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7E6202D6A; Thu, 8 Jun 2023 07:24:53 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 2C75264E2B; Thu, 8 Jun 2023 14:24:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 52D36C4339E; Thu, 8 Jun 2023 14:24:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686234288; bh=Ap3GuMqINZf2WdIT1xsNL1OzEvsLgkbr6RhrjaSFN2U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=E/ppkNpUa1T5/FB+OZN82dq2UDzQIyU5Cbo8U3TTO4UUNzBPXl51gEj6FYXPHd0C0 B8fBUUD/WnNo6CND5zxE7A91YlNR8D75vEQqCmvaXDREUZMvckx6QEyeAr2D8LRUg6 mTEF3tCzZrWR/Bz+RWDK09Bl8RxWyDtiAseu46h6FEXk+pM2XpyEbH01OEkUhVaYt3 N6AWER4bq6Z6hZwWxZc4TOIfkzhSS9PaCantt/xrBbkDTIhgc/96+WPERBmKn2RSCz ItV8rK4Zh871ZfPPMNhWASgocY09hJn0uporPngp75NKd2+x//eEWrcaAry+aGCdFy ehyl0GtZu4Lag== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Nathan Chancellor , Nick Desaulniers , Nicolas Schier , linux-um@lists.infradead.org, Masahiro Yamada Subject: [PATCH v7 07/11] modpost: use null string instead of NULL pointer for default namespace Date: Thu, 8 Jun 2023 23:24:24 +0900 Message-Id: <20230608142428.256985-8-masahiroy@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230608142428.256985-1-masahiroy@kernel.org> References: <20230608142428.256985-1-masahiroy@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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?1768146356094387387?= X-GMAIL-MSGID: =?utf-8?q?1768146356094387387?= The default namespace is the null string, "". When set, the null string "" is converted to NULL: s->namespace = namespace[0] ? NOFAIL(strdup(namespace)) : NULL; When printed, the NULL pointer is get back to the null string: sym->namespace ?: "" This saves 1 byte memory allocated for "", but loses the readability. In kernel-space, we strive to save memory, but modpost is a userspace tool used to build the kernel. On modern systems, such small piece of memory is not a big deal. Handle the namespace string as is. Signed-off-by: Masahiro Yamada Reviewed-by: Nick Desaulniers --- scripts/mod/modpost.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index 4b0a009de0fb..7044b257424a 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -300,6 +300,13 @@ static bool contains_namespace(struct list_head *head, const char *namespace) { struct namespace_list *list; + /* + * The default namespace is null string "", which is always implicitly + * contained. + */ + if (!namespace[0]) + return true; + list_for_each_entry(list, head, list) { if (!strcmp(list->namespace, namespace)) return true; @@ -369,7 +376,7 @@ static struct symbol *sym_add_exported(const char *name, struct module *mod, s = alloc_symbol(name); s->module = mod; s->is_gpl_only = gpl_only; - s->namespace = namespace[0] ? NOFAIL(strdup(namespace)) : NULL; + s->namespace = NOFAIL(strdup(namespace)); list_add_tail(&s->list, &mod->exported_symbols); hash_add_symbol(s); @@ -1823,8 +1830,7 @@ static void check_exports(struct module *mod) else basename = mod->name; - if (exp->namespace && - !contains_namespace(&mod->imported_namespaces, exp->namespace)) { + if (!contains_namespace(&mod->imported_namespaces, exp->namespace)) { modpost_log(allow_missing_ns_imports ? LOG_WARN : LOG_ERROR, "module %s uses symbol %s from namespace %s, but does not import it.\n", basename, exp->name, exp->namespace); @@ -1910,8 +1916,7 @@ static void add_exported_symbols(struct buffer *buf, struct module *mod) list_for_each_entry(sym, &mod->exported_symbols, list) buf_printf(buf, "KSYMTAB_%s(%s, \"%s\", \"%s\");\n", sym->is_func ? "FUNC" : "DATA", sym->name, - sym->is_gpl_only ? "_gpl" : "", - sym->namespace ?: ""); + sym->is_gpl_only ? "_gpl" : "", sym->namespace); if (!modversions) return; @@ -2179,7 +2184,7 @@ static void write_dump(const char *fname) buf_printf(&buf, "0x%08x\t%s\t%s\tEXPORT_SYMBOL%s\t%s\n", sym->crc, sym->name, mod->name, sym->is_gpl_only ? "_GPL" : "", - sym->namespace ?: ""); + sym->namespace); } } write_buf(&buf, fname); From patchwork Thu Jun 8 14:24:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 104996 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6358:3046:b0:115:7a1d:dabb with SMTP id p6csp372060rwl; Thu, 8 Jun 2023 07:32:27 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5/LzDRUXhNREh8siezF2fFXZgr3mwBLz/p5iLHU3YTa77X3OZ6p2p5R2gKhB1npVvRhIvh X-Received: by 2002:a05:6a20:e30a:b0:10c:1b38:c8a4 with SMTP id nb10-20020a056a20e30a00b0010c1b38c8a4mr3480566pzb.31.1686234747269; Thu, 08 Jun 2023 07:32:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686234747; cv=none; d=google.com; s=arc-20160816; b=vNLY7ySTzgW8lumxnf1GhOZ7xEEbg6WDwTYpN579ldRjfeu7pdhPDgNXcfoEeE9+Z+ 6/raEa4sKnV4ULSHlbN1quJb3Kf++RcIdnXprvqNDJHvDQzJPBHgKTG30u8a9beaeAu1 f33fYPasYzWfrjZ/ghfOhMl4iO/YiP4GSeotknea/AZ2O6RZ/OZDpJM8fjw4WQHOWMeH 9LCzml+lbjhrn5d6f9sWw2YcnRQSuZjirla3JeAI2hzmTwKH4+fDl1soq683rrPKaK8k QzWxXz4Jhlboy9XgJi7zeTegbI9rhpF0aA5HNkc3wt9ClfcNTXhC1w4tdnN1TxHfPATG lNNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=G8A52Mib9poilAIUqfL9dPV2vGxCPiBEqeHMEbth200=; b=oSSsMldHchYvOGMxSRNCdXHO5RBIxoBmPSUXTBZ/pN+vXOhXB/PwPCMZm+CuF1zDg4 8OqXVd28+Cf5RTe/uYkKretgHoWvr88OjhrsEwFha5utrJ7L9uTX8d2+vv/xaG67CW5u MyZ/HP04F4n0R8YtYnCxTkxoco80t43Vt04fd+ceU7AQe6m9u+rwRcvb7zga7tq2Dt3P p+6773+vn+YumzO3MvOTvFr42rNNDs7fzJ6CW9n+SpJDs5B66wO2bVZQ6eDe0fytuCft BQtzWMfnFJVp3CpEJCuMK9+0t14oGrikjBgLrjJ6kIcmOE54jIfNiUKArvcn1QCGykeg U7XQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=aDrzABN4; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o6-20020a639206000000b00542924cbf7bsi1109554pgd.233.2023.06.08.07.32.13; Thu, 08 Jun 2023 07:32:27 -0700 (PDT) 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=@kernel.org header.s=k20201202 header.b=aDrzABN4; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237226AbjFHOZp (ORCPT + 99 others); Thu, 8 Jun 2023 10:25:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55990 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237055AbjFHOZT (ORCPT ); Thu, 8 Jun 2023 10:25:19 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 86AA72D6D; Thu, 8 Jun 2023 07:24:53 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 00CB264E24; Thu, 8 Jun 2023 14:24:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 02FCEC4339C; Thu, 8 Jun 2023 14:24:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686234290; bh=qcicbV837KRbyMP5gmDj3wUkOUHHrxpok8WGKzsveZM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aDrzABN41EpliMrSXlazMcWzKxwu+n1ff2rWlcl1LlBtUoeXKbnLM8XEQXZkFhXNC hbzQn88AM+WR/SA8HCcKp8Tebze+yUMcXBMDJguWf85PKgTSckjjPWEhKDNBCQ98lQ Oa9cu0+LkPbyQ7gO0v020b3kUHZP8YA42euliXRIdzOsY2asF7v0qQ2JqeGCHOifCO iuUohdTICposjnSkDOOD4MZ1Z7/SxMiJBe505eUk5H39U0TSw8I1b/uS1oocbphC1H 64Fge4Y7oANv1JpVAmGWUsdKQJo5x5vHHG78wlvMImeWgWb5qyJ8vkmLZ0WpF4lvrU gj5NbaUnE1P4w== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Nathan Chancellor , Nick Desaulniers , Nicolas Schier , linux-um@lists.infradead.org, Masahiro Yamada Subject: [PATCH v7 08/11] kbuild: implement CONFIG_TRIM_UNUSED_KSYMS without recursion Date: Thu, 8 Jun 2023 23:24:25 +0900 Message-Id: <20230608142428.256985-9-masahiroy@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230608142428.256985-1-masahiroy@kernel.org> References: <20230608142428.256985-1-masahiroy@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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?1768145286401458606?= X-GMAIL-MSGID: =?utf-8?q?1768145286401458606?= When CONFIG_TRIM_UNUSED_KSYMS is enabled, Kbuild recursively traverses the directory tree to determine which EXPORT_SYMBOL to trim. If an EXPORT_SYMBOL turns out to be unused by anyone, Kbuild begins the second traverse, where some source files are recompiled with their EXPORT_SYMBOL() tuned into a no-op. Linus stated negative opinions about this slowness in commits: - 5cf0fd591f2e ("Kbuild: disable TRIM_UNUSED_KSYMS option") - a555bdd0c58c ("Kbuild: enable TRIM_UNUSED_KSYMS again, with some guarding") We can do this better now. The final data structures of EXPORT_SYMBOL are generated by the modpost stage, so modpost can selectively emit KSYMTAB entries that are really used by modules. Commit f73edc8951b2 ("kbuild: unify two modpost invocations") is another ground-work to do this in a one-pass algorithm. With the list of modules, modpost sets sym->used if it is used by a module. modpost emits KSYMTAB only for symbols with sym->used==true. BTW, Nicolas explained why the trimming was implemented with recursion: https://lore.kernel.org/all/2o2rpn97-79nq-p7s2-nq5-8p83391473r@syhkavp.arg/ Actually, we never achieved that level of optimization where the chain reaction of trimming comes into play because: - CONFIG_LTO_CLANG cannot remove any unused symbols - CONFIG_LD_DEAD_CODE_DATA_ELIMINATION is enabled only for vmlinux, but not modules If deeper trimming is required, we need to revisit this, but I guess that is unlikely to happen. Signed-off-by: Masahiro Yamada --- Changes in v7: - Remove *.usyms Changes in v5: - Clean up more .gitignore | 2 - Makefile | 22 ++--------- include/linux/export.h | 67 +++++----------------------------- scripts/Makefile.build | 15 +------- scripts/Makefile.modpost | 7 ++++ scripts/adjust_autoksyms.sh | 73 ------------------------------------- scripts/basic/fixdep.c | 3 +- scripts/gen_autoksyms.sh | 62 ------------------------------- scripts/gen_ksymdeps.sh | 30 --------------- scripts/mod/modpost.c | 54 ++++++++++++++++++++++++--- scripts/remove-stale-files | 4 ++ 11 files changed, 75 insertions(+), 264 deletions(-) delete mode 100755 scripts/adjust_autoksyms.sh delete mode 100755 scripts/gen_autoksyms.sh delete mode 100755 scripts/gen_ksymdeps.sh diff --git a/.gitignore b/.gitignore index 7f86e0837909..c3ce78ca20d2 100644 --- a/.gitignore +++ b/.gitignore @@ -51,7 +51,6 @@ *.symversions *.tab.[ch] *.tar -*.usyms *.xz *.zst Module.symvers @@ -112,7 +111,6 @@ modules.order # /include/config/ /include/generated/ -/include/ksym/ /arch/*/include/generated/ # stgit generated dirs diff --git a/Makefile b/Makefile index f836936fb4d8..cc3fe09c4dec 100644 --- a/Makefile +++ b/Makefile @@ -1193,28 +1193,12 @@ endif export KBUILD_VMLINUX_LIBS export KBUILD_LDS := arch/$(SRCARCH)/kernel/vmlinux.lds -# Recurse until adjust_autoksyms.sh is satisfied -PHONY += autoksyms_recursive ifdef CONFIG_TRIM_UNUSED_KSYMS # For the kernel to actually contain only the needed exported symbols, # we have to build modules as well to determine what those symbols are. -# (this can be evaluated only once include/config/auto.conf has been included) KBUILD_MODULES := 1 - -autoksyms_recursive: $(build-dir) modules.order - $(Q)$(CONFIG_SHELL) $(srctree)/scripts/adjust_autoksyms.sh \ - "$(MAKE) -f $(srctree)/Makefile autoksyms_recursive" endif -autoksyms_h := $(if $(CONFIG_TRIM_UNUSED_KSYMS), include/generated/autoksyms.h) - -quiet_cmd_autoksyms_h = GEN $@ - cmd_autoksyms_h = mkdir -p $(dir $@); \ - $(CONFIG_SHELL) $(srctree)/scripts/gen_autoksyms.sh $@ - -$(autoksyms_h): - $(call cmd,autoksyms_h) - # '$(AR) mPi' needs 'T' to workaround the bug of llvm-ar <= 14 quiet_cmd_ar_vmlinux.a = AR $@ cmd_ar_vmlinux.a = \ @@ -1223,7 +1207,7 @@ quiet_cmd_ar_vmlinux.a = AR $@ $(AR) mPiT $$($(AR) t $@ | sed -n 1p) $@ $$($(AR) t $@ | grep -F -f $(srctree)/scripts/head-object-list.txt) targets += vmlinux.a -vmlinux.a: $(KBUILD_VMLINUX_OBJS) scripts/head-object-list.txt autoksyms_recursive FORCE +vmlinux.a: $(KBUILD_VMLINUX_OBJS) scripts/head-object-list.txt FORCE $(call if_changed,ar_vmlinux.a) PHONY += vmlinux_o @@ -1279,7 +1263,7 @@ scripts: scripts_basic scripts_dtc PHONY += prepare archprepare archprepare: outputmakefile archheaders archscripts scripts include/config/kernel.release \ - asm-generic $(version_h) $(autoksyms_h) include/generated/utsrelease.h \ + asm-generic $(version_h) include/generated/utsrelease.h \ include/generated/compile.h include/generated/autoconf.h remove-stale-files prepare0: archprepare @@ -2039,7 +2023,7 @@ clean: $(clean-dirs) -o -name '*.dtb.S' -o -name '*.dtbo.S' \ -o -name '*.dt.yaml' \ -o -name '*.dwo' -o -name '*.lst' \ - -o -name '*.su' -o -name '*.mod' -o -name '*.usyms' \ + -o -name '*.su' -o -name '*.mod' \ -o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \ -o -name '*.lex.c' -o -name '*.tab.[ch]' \ -o -name '*.asn1.[ch]' \ diff --git a/include/linux/export.h b/include/linux/export.h index 529435a821c0..fed2e5717461 100644 --- a/include/linux/export.h +++ b/include/linux/export.h @@ -31,7 +31,7 @@ extern struct module __this_module; #endif #endif /* __ASSEMBLY__ */ -#define ____EXPORT_SYMBOL(sym, license, ns) \ +#define ___EXPORT_SYMBOL(sym, license, ns) \ .section ".export_symbol","a" ; \ __export_symbol_##license##_##sym: ; \ .asciz ns ; \ @@ -39,24 +39,6 @@ extern struct module __this_module; .long sym - . ; \ .previous -#ifdef __GENKSYMS__ - -#define ___EXPORT_SYMBOL(sym, sec, ns) __GENKSYMS_EXPORT_SYMBOL(sym) - -#elif defined(__ASSEMBLY__) - -#define ___EXPORT_SYMBOL(sym, license, ns) \ - ____EXPORT_SYMBOL(sym, license, ns) - -#else - -#define ___EXPORT_SYMBOL(sym, license, ns) \ - extern typeof(sym) sym; \ - __ADDRESSABLE(sym) \ - asm(__stringify(____EXPORT_SYMBOL(sym, license, ns))) - -#endif - #if !defined(CONFIG_MODULES) || defined(__DISABLE_EXPORTS) /* @@ -66,50 +48,21 @@ extern struct module __this_module; */ #define __EXPORT_SYMBOL(sym, sec, ns) -#elif defined(CONFIG_TRIM_UNUSED_KSYMS) +#elif defined(__GENKSYMS__) -#include +#define __EXPORT_SYMBOL(sym, sec, ns) __GENKSYMS_EXPORT_SYMBOL(sym) -/* - * For fine grained build dependencies, we want to tell the build system - * about each possible exported symbol even if they're not actually exported. - * We use a symbol pattern __ksym_marker_ that the build system filters - * from the $(NM) output (see scripts/gen_ksymdeps.sh). These symbols are - * discarded in the final link stage. - */ +#elif defined(__ASSEMBLY__) -#ifdef __ASSEMBLY__ - -#define __ksym_marker(sym) \ - .section ".discard.ksym","a" ; \ -__ksym_marker_##sym: ; \ - .previous +#define __EXPORT_SYMBOL(sym, license, ns) \ + ___EXPORT_SYMBOL(sym, license, ns) #else -#define __ksym_marker(sym) \ - static int __ksym_marker_##sym[0] __section(".discard.ksym") __used - -#endif - -#define __EXPORT_SYMBOL(sym, sec, ns) \ - __ksym_marker(sym); \ - __cond_export_sym(sym, sec, ns, __is_defined(__KSYM_##sym)) -#define __cond_export_sym(sym, sec, ns, conf) \ - ___cond_export_sym(sym, sec, ns, conf) -#define ___cond_export_sym(sym, sec, ns, enabled) \ - __cond_export_sym_##enabled(sym, sec, ns) -#define __cond_export_sym_1(sym, sec, ns) ___EXPORT_SYMBOL(sym, sec, ns) - -#ifdef __GENKSYMS__ -#define __cond_export_sym_0(sym, sec, ns) __GENKSYMS_EXPORT_SYMBOL(sym) -#else -#define __cond_export_sym_0(sym, sec, ns) /* nothing */ -#endif - -#else - -#define __EXPORT_SYMBOL(sym, sec, ns) ___EXPORT_SYMBOL(sym, sec, ns) +#define __EXPORT_SYMBOL(sym, license, ns) \ + extern typeof(sym) sym; \ + __ADDRESSABLE(sym) \ + asm(__stringify(___EXPORT_SYMBOL(sym, license, ns))) #endif /* CONFIG_MODULES */ diff --git a/scripts/Makefile.build b/scripts/Makefile.build index bd4123795299..7e1b9ed178e8 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -82,7 +82,7 @@ ifdef need-builtin targets-for-builtin += $(obj)/built-in.a endif -targets-for-modules := $(foreach x, o mod $(if $(CONFIG_TRIM_UNUSED_KSYMS), usyms), \ +targets-for-modules := $(foreach x, o mod, \ $(patsubst %.o, %.$x, $(filter %.o, $(obj-m)))) ifdef need-modorder @@ -215,18 +215,12 @@ is-standard-object = $(if $(filter-out y%, $(OBJECT_FILES_NON_STANDARD_$(basetar $(obj)/%.o: objtool-enabled = $(if $(is-standard-object),$(if $(delay-objtool),$(is-single-obj-m),y)) -ifdef CONFIG_TRIM_UNUSED_KSYMS -cmd_gen_ksymdeps = \ - $(CONFIG_SHELL) $(srctree)/scripts/gen_ksymdeps.sh $@ >> $(dot-target).cmd -endif - ifneq ($(findstring 1, $(KBUILD_EXTRA_WARN)),) cmd_warn_shared_object = $(if $(word 2, $(modname-multi)),$(warning $(kbuild-file): $*.o is added to multiple modules: $(modname-multi))) endif define rule_cc_o_c $(call cmd_and_fixdep,cc_o_c) - $(call cmd,gen_ksymdeps) $(call cmd,checksrc) $(call cmd,checkdoc) $(call cmd,gen_objtooldep) @@ -237,7 +231,6 @@ endef define rule_as_o_S $(call cmd_and_fixdep,as_o_S) - $(call cmd,gen_ksymdeps) $(call cmd,gen_objtooldep) $(call cmd,gen_symversions_S) $(call cmd,warn_shared_object) @@ -256,12 +249,6 @@ cmd_mod = printf '%s\n' $(call real-search, $*.o, .o, -objs -y -m) | \ $(obj)/%.mod: FORCE $(call if_changed,mod) -# List module undefined symbols -cmd_undefined_syms = $(NM) $< | sed -n 's/^ *U //p' > $@ - -$(obj)/%.usyms: $(obj)/%.o FORCE - $(call if_changed,undefined_syms) - quiet_cmd_cc_lst_c = MKLST $@ cmd_cc_lst_c = $(CC) $(c_flags) -g -c -o $*.o $< && \ $(CONFIG_SHELL) $(srctree)/scripts/makelst $*.o \ diff --git a/scripts/Makefile.modpost b/scripts/Makefile.modpost index 074e27c0c140..65133fcdd5b8 100644 --- a/scripts/Makefile.modpost +++ b/scripts/Makefile.modpost @@ -91,6 +91,13 @@ targets += .vmlinux.objs .vmlinux.objs: vmlinux.a $(KBUILD_VMLINUX_LIBS) FORCE $(call if_changed,vmlinux_objs) +ifdef CONFIG_TRIM_UNUSED_KSYMS +ksym-wl := $(CONFIG_UNUSED_KSYMS_WHITELIST) +ksym-wl := $(if $(filter-out /%, $(ksym-wl)),$(srctree)/)$(ksym-wl) +modpost-args += -t $(addprefix -u, $(ksym-wl)) +modpost-deps += $(ksym-wl) +endif + ifeq ($(wildcard vmlinux.o),) missing-input := vmlinux.o output-symdump := modules-only.symvers diff --git a/scripts/adjust_autoksyms.sh b/scripts/adjust_autoksyms.sh deleted file mode 100755 index f1b5ac818411..000000000000 --- a/scripts/adjust_autoksyms.sh +++ /dev/null @@ -1,73 +0,0 @@ -#!/bin/sh -# SPDX-License-Identifier: GPL-2.0-only - -# Script to update include/generated/autoksyms.h and dependency files -# -# Copyright: (C) 2016 Linaro Limited -# Created by: Nicolas Pitre, January 2016 -# - -# Update the include/generated/autoksyms.h file. -# -# For each symbol being added or removed, the corresponding dependency -# file's timestamp is updated to force a rebuild of the affected source -# file. All arguments passed to this script are assumed to be a command -# to be exec'd to trigger a rebuild of those files. - -set -e - -cur_ksyms_file="include/generated/autoksyms.h" -new_ksyms_file="include/generated/autoksyms.h.tmpnew" - -info() { - if [ "$quiet" != "silent_" ]; then - printf " %-7s %s\n" "$1" "$2" - fi -} - -info "CHK" "$cur_ksyms_file" - -# Use "make V=1" to debug this script. -case "$KBUILD_VERBOSE" in -*1*) - set -x - ;; -esac - -# Generate a new symbol list file -$CONFIG_SHELL $srctree/scripts/gen_autoksyms.sh --modorder "$new_ksyms_file" - -# Extract changes between old and new list and touch corresponding -# dependency files. -changed=$( -count=0 -sort "$cur_ksyms_file" "$new_ksyms_file" | uniq -u | -sed -n 's/^#define __KSYM_\(.*\) 1/\1/p' | -while read sympath; do - if [ -z "$sympath" ]; then continue; fi - depfile="include/ksym/${sympath}" - mkdir -p "$(dirname "$depfile")" - touch "$depfile" - # Filesystems with coarse time precision may create timestamps - # equal to the one from a file that was very recently built and that - # needs to be rebuild. Let's guard against that by making sure our - # dep files are always newer than the first file we created here. - while [ ! "$depfile" -nt "$new_ksyms_file" ]; do - touch "$depfile" - done - echo $((count += 1)) -done | tail -1 ) -changed=${changed:-0} - -if [ $changed -gt 0 ]; then - # Replace the old list with tne new one - old=$(grep -c "^#define __KSYM_" "$cur_ksyms_file" || true) - new=$(grep -c "^#define __KSYM_" "$new_ksyms_file" || true) - info "KSYMS" "symbols: before=$old, after=$new, changed=$changed" - info "UPD" "$cur_ksyms_file" - mv -f "$new_ksyms_file" "$cur_ksyms_file" - # Then trigger a rebuild of affected source files - exec $@ -else - rm -f "$new_ksyms_file" -fi diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c index fa562806c2be..84b6efa849f4 100644 --- a/scripts/basic/fixdep.c +++ b/scripts/basic/fixdep.c @@ -246,8 +246,7 @@ static void *read_file(const char *filename) /* Ignore certain dependencies */ static int is_ignored_file(const char *s, int len) { - return str_ends_with(s, len, "include/generated/autoconf.h") || - str_ends_with(s, len, "include/generated/autoksyms.h"); + return str_ends_with(s, len, "include/generated/autoconf.h"); } /* Do not parse these files */ diff --git a/scripts/gen_autoksyms.sh b/scripts/gen_autoksyms.sh deleted file mode 100755 index 12bcfae940ee..000000000000 --- a/scripts/gen_autoksyms.sh +++ /dev/null @@ -1,62 +0,0 @@ -#!/bin/sh -# SPDX-License-Identifier: GPL-2.0-only - -# Create an autoksyms.h header file from the list of all module's needed symbols -# as recorded in *.usyms files and the user-provided symbol whitelist. - -set -e - -# Use "make V=1" to debug this script. -case "$KBUILD_VERBOSE" in -*1*) - set -x - ;; -esac - -read_modorder= - -if [ "$1" = --modorder ]; then - shift - read_modorder=1 -fi - -output_file="$1" - -needed_symbols= - -# Special case for modversions (see modpost.c) -if grep -q "^CONFIG_MODVERSIONS=y$" include/config/auto.conf; then - needed_symbols="$needed_symbols module_layout" -fi - -ksym_wl=$(sed -n 's/^CONFIG_UNUSED_KSYMS_WHITELIST=\(.*\)$/\1/p' include/config/auto.conf) -if [ -n "$ksym_wl" ]; then - [ "${ksym_wl}" != "${ksym_wl#/}" ] || ksym_wl="$abs_srctree/$ksym_wl" - if [ ! -f "$ksym_wl" ] || [ ! -r "$ksym_wl" ]; then - echo "ERROR: '$ksym_wl' whitelist file not found" >&2 - exit 1 - fi -fi - -# Generate a new ksym list file with symbols needed by the current -# set of modules. -cat > "$output_file" << EOT -/* - * Automatically generated file; DO NOT EDIT. - */ - -EOT - -{ - [ -n "${read_modorder}" ] && sed 's/o$/usyms/' modules.order | xargs cat - echo "$needed_symbols" - [ -n "$ksym_wl" ] && cat "$ksym_wl" -} | sed -e 's/ /\n/g' | sed -n -e '/^$/!p' | -# Remove the dot prefix for ppc64; symbol names with a dot (.) hold entry -# point addresses. -sed -e 's/^\.//' | -sort -u | -# Ignore __this_module. It's not an exported symbol, and will be resolved -# when the final .ko's are linked. -grep -v '^__this_module$' | -sed -e 's/\(.*\)/#define __KSYM_\1 1/' >> "$output_file" diff --git a/scripts/gen_ksymdeps.sh b/scripts/gen_ksymdeps.sh deleted file mode 100755 index 8ee533f33659..000000000000 --- a/scripts/gen_ksymdeps.sh +++ /dev/null @@ -1,30 +0,0 @@ -#!/bin/sh -# SPDX-License-Identifier: GPL-2.0 - -set -e - -# List of exported symbols -# -# If the object has no symbol, $NM warns 'no symbols'. -# Suppress the stderr. -# TODO: -# Use -q instead of 2>/dev/null when we upgrade the minimum version of -# binutils to 2.37, llvm to 13.0.0. -ksyms=$($NM $1 2>/dev/null | sed -n 's/.*__ksym_marker_\(.*\)/\1/p') - -if [ -z "$ksyms" ]; then - exit 0 -fi - -echo -echo "ksymdeps_$1 := \\" - -for s in $ksyms -do - printf ' $(wildcard include/ksym/%s) \\\n' "$s" -done - -echo -echo "$1: \$(ksymdeps_$1)" -echo -echo "\$(ksymdeps_$1):" diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index 7044b257424a..decb7d23ef9f 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -35,6 +35,9 @@ static bool warn_unresolved; static int sec_mismatch_count; static bool sec_mismatch_warn_only = true; +/* Trim EXPORT_SYMBOLs that are unused by in-tree modules */ +static bool trim_unused_exports; + /* ignore missing files */ static bool ignore_missing_files; /* If set to 1, only warn (instead of error) about missing ns imports */ @@ -219,6 +222,7 @@ struct symbol { bool weak; bool is_func; bool is_gpl_only; /* exported by EXPORT_SYMBOL_GPL */ + bool used; /* there exists a user of this symbol */ char name[]; }; @@ -1820,6 +1824,7 @@ static void check_exports(struct module *mod) continue; } + exp->used = true; s->module = exp->module; s->crc_valid = exp->crc_valid; s->crc = exp->crc; @@ -1843,6 +1848,23 @@ static void check_exports(struct module *mod) } } +static void handle_white_list_exports(const char *white_list) +{ + char *buf, *p, *name; + + buf = read_text_file(white_list); + p = buf; + + while ((name = strsep(&p, "\n"))) { + struct symbol *sym = find_symbol(name); + + if (sym) + sym->used = true; + } + + free(buf); +} + static void check_modname_len(struct module *mod) { const char *mod_name; @@ -1913,10 +1935,14 @@ static void add_exported_symbols(struct buffer *buf, struct module *mod) /* generate struct for exported symbols */ buf_printf(buf, "\n"); - list_for_each_entry(sym, &mod->exported_symbols, list) + list_for_each_entry(sym, &mod->exported_symbols, list) { + if (trim_unused_exports && !sym->used) + continue; + buf_printf(buf, "KSYMTAB_%s(%s, \"%s\", \"%s\");\n", sym->is_func ? "FUNC" : "DATA", sym->name, sym->is_gpl_only ? "_gpl" : "", sym->namespace); + } if (!modversions) return; @@ -1924,6 +1950,9 @@ static void add_exported_symbols(struct buffer *buf, struct module *mod) /* record CRCs for exported symbols */ buf_printf(buf, "\n"); list_for_each_entry(sym, &mod->exported_symbols, list) { + if (trim_unused_exports && !sym->used) + continue; + if (!sym->crc_valid) warn("EXPORT symbol \"%s\" [%s%s] version generation failed, symbol will not be versioned.\n" "Is \"%s\" prototyped in ?\n", @@ -2087,9 +2116,6 @@ static void write_mod_c_file(struct module *mod) char fname[PATH_MAX]; int ret; - check_modname_len(mod); - check_exports(mod); - add_header(&buf, mod); add_exported_symbols(&buf, mod); add_versions(&buf, mod); @@ -2223,12 +2249,13 @@ int main(int argc, char **argv) { struct module *mod; char *missing_namespace_deps = NULL; + char *unused_exports_white_list = NULL; char *dump_write = NULL, *files_source = NULL; int opt; LIST_HEAD(dump_lists); struct dump_list *dl, *dl2; - while ((opt = getopt(argc, argv, "ei:mnT:o:aWwENd:")) != -1) { + while ((opt = getopt(argc, argv, "ei:mnTt:o:auWwENd:")) != -1) { switch (opt) { case 'e': external_module = true; @@ -2253,6 +2280,12 @@ int main(int argc, char **argv) case 'T': files_source = optarg; break; + case 't': + trim_unused_exports = true; + break; + case 'u': + unused_exports_white_list = optarg; + break; case 'W': extra_warn = true; break; @@ -2285,6 +2318,17 @@ int main(int argc, char **argv) if (files_source) read_symbols_from_files(files_source); + list_for_each_entry(mod, &modules, list) { + if (mod->from_dump || mod->is_vmlinux) + continue; + + check_modname_len(mod); + check_exports(mod); + } + + if (unused_exports_white_list) + handle_white_list_exports(unused_exports_white_list); + list_for_each_entry(mod, &modules, list) { if (mod->from_dump) continue; diff --git a/scripts/remove-stale-files b/scripts/remove-stale-files index 7f432900671a..f3659ea0335b 100755 --- a/scripts/remove-stale-files +++ b/scripts/remove-stale-files @@ -33,3 +33,7 @@ rm -f rust/target.json rm -f scripts/bin2c rm -f .scmversion + +rm -rf include/ksym + +find . -name '*.usyms' | xargs rm -f From patchwork Thu Jun 8 14:24:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 104995 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6358:3046:b0:115:7a1d:dabb with SMTP id p6csp371778rwl; Thu, 8 Jun 2023 07:32:02 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ554xFTTsolLtQ0PilOSqdAf00KZ5wYlD2NBPpIq4zZYe8rvVz8NHEfnCYRsCT94Gi6GYrX X-Received: by 2002:aa7:88c7:0:b0:662:5146:c77a with SMTP id k7-20020aa788c7000000b006625146c77amr6238245pff.31.1686234722068; Thu, 08 Jun 2023 07:32:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686234722; cv=none; d=google.com; s=arc-20160816; b=I5eS8m9vXnCmhcC4PFCgz2swimWNlLrE9Eq6gxMQ++CtLl/vPCF2zIkxFa0P24n6yS yqkGwabvkeAk2ocm80c70FEijFpICtMzaEVCmK5rGztxeuiqPp+dwwuojB2GFtyM3ykM 7Yg9UkkA80Bxw2hz1OvMn2Nc5PkoUUZvyO2rEXo/8JsteYz9aLm1Z5zm8MJi3OWqAA0H cub6VulVZOXm+al6yYxff6Ua80xd6+xQ+KqNH06ScYwcWc/VsrguYno0JHw8XlMexUIy xe0z4g/RbT5bmh0g7sxz1EnyRXM2eycaPzAEboFZVrTA9JVYVjogjRQWgNQmgspmfyIs Si/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=CLU+N21DaoDDLVtsp37fZmw5n26cyBqveLXzBDKPSFY=; b=fujxRZtVzw6abrmHHxltUZL8XIwVkBi4SyoA09IU+dX5r3voC1FdLZojRmH+EKGqVv MLyuPijHs1wCd5+6eFCXmEQv2CS6e0aSyHm95jRijcapURS85aCIvSlX6BWpXlQFYg/M t1QTh6FGQmNv5q4JKOiQcOck/UR9AA8+dU/71iPn17A7Tyt7MvXc+9PaQvf0YpQUz3za ep8IEdXD1l58hC9stREa0YhEvNdvUHd++N8jZqBNNzsQwbKPEMDcr6WibP1J6F1mohdl sI6//vKegvbba8Ok6rKNLbuImw7E7wQ7tl+hjGRSLcisIqWIdg4hIl4Q5g5lrXNIMSWJ j5mg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=n9JMO6Pp; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z10-20020aa7948a000000b0065a4bc8a998si856914pfk.385.2023.06.08.07.31.43; Thu, 08 Jun 2023 07:32:02 -0700 (PDT) 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=@kernel.org header.s=k20201202 header.b=n9JMO6Pp; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237188AbjFHOZh (ORCPT + 99 others); Thu, 8 Jun 2023 10:25:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56026 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236123AbjFHOZI (ORCPT ); Thu, 8 Jun 2023 10:25:08 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 55730198B; Thu, 8 Jun 2023 07:24:56 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id A371B64E1C; Thu, 8 Jun 2023 14:24:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D15FEC4339E; Thu, 8 Jun 2023 14:24:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686234292; bh=Tv49Wx2718uLurHeG8QRHYpB10Ur4mWH5TKdeB3r3Yo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=n9JMO6Pph34Rul/bfEipZsbH/IK6Vox1G/S4T29o1Wdi1nNe+QJlnzU4XJXkJYaIU nXfgGK/UyA4YVJmbYJ44YArzehdxORxGisVHczcGaz0lIW3qW/dtx3ycnuCzS4pELe xFxXjmKvLEQEHikSZ2h/6rqc2svxRMTZgD8MOChvOba2vOvZFjJcC7pogYoiih3mgl Al0swWVPGXkhliC/ypfGNWBzsnXVVghT4vwZ78cxfGKMw56aQQa61B7qAvki7CV0Ip ChWRSB4I/5XU6X5FQBKJkndAouaia2AOmZX50T0FsZIj1I4d2U8w7k4bSMidCpL3ih 5p5Oc9kuO/ZnA== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Nathan Chancellor , Nick Desaulniers , Nicolas Schier , linux-um@lists.infradead.org, Masahiro Yamada Subject: [PATCH v7 09/11] modpost: merge two similar section mismatch warnings Date: Thu, 8 Jun 2023 23:24:26 +0900 Message-Id: <20230608142428.256985-10-masahiroy@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230608142428.256985-1-masahiroy@kernel.org> References: <20230608142428.256985-1-masahiroy@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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?1768145259877298097?= X-GMAIL-MSGID: =?utf-8?q?1768145259877298097?= In case of section mismatch, modpost shows slightly different messages. For extable section mismatch: "%s(%s+0x%lx): Section mismatch in reference to the %s:%s\n" For the other cases: "%s: section mismatch in reference: %s (section: %s) -> %s (section: %s)\n" They are similar. Merge them. Signed-off-by: Masahiro Yamada Reviewed-by: Nick Desaulniers --- scripts/mod/modpost.c | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index decb7d23ef9f..85df3f3ba9ee 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -1147,21 +1147,10 @@ static void default_mismatch_handler(const char *modname, struct elf_info *elf, sec_mismatch_count++; - switch (mismatch->mismatch) { - case TEXT_TO_ANY_INIT: - case DATA_TO_ANY_INIT: - case TEXTDATA_TO_ANY_EXIT: - case XXXINIT_TO_SOME_INIT: - case XXXEXIT_TO_SOME_EXIT: - case ANY_INIT_TO_ANY_EXIT: - case ANY_EXIT_TO_ANY_INIT: - warn("%s: section mismatch in reference: %s (section: %s) -> %s (section: %s)\n", - modname, fromsym, fromsec, tosym, tosec); - break; - case EXTABLE_TO_NON_TEXT: - warn("%s(%s+0x%lx): Section mismatch in reference to the %s:%s\n", - modname, fromsec, (long)faddr, tosec, tosym); + warn("%s: section mismatch in reference: %s (section: %s) -> %s (section: %s)\n", + modname, fromsym, fromsec, tosym, tosec); + if (mismatch->mismatch == EXTABLE_TO_NON_TEXT) { if (match(tosec, mismatch->bad_tosec)) fatal("The relocation at %s+0x%lx references\n" "section \"%s\" which is black-listed.\n" @@ -1181,7 +1170,6 @@ static void default_mismatch_handler(const char *modname, struct elf_info *elf, else error("%s+0x%lx references non-executable section '%s'\n", fromsec, (long)faddr, tosec); - break; } } From patchwork Thu Jun 8 14:24:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 104997 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6358:3046:b0:115:7a1d:dabb with SMTP id p6csp372893rwl; Thu, 8 Jun 2023 07:33:40 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7+LkcG9/aBcaL7eRpoQQ798zuRtT4Zeuy+CADmc5a55JVrW6vQPV+5kWaE5rERx5RSOxEQ X-Received: by 2002:a17:903:1207:b0:1aa:feca:b616 with SMTP id l7-20020a170903120700b001aafecab616mr7523730plh.65.1686234820014; Thu, 08 Jun 2023 07:33:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686234820; cv=none; d=google.com; s=arc-20160816; b=BGdGW1RD96mSONytRjK9DqJJmxgrF09MogjgeV43IfJxUg2ozirnqnC2MD5mCDNOk8 wLX2CN7yuNmr6m+LUOEhDuWoCB416cZrCLAVNuWAeYtt8hisLazGhBC9JQyiW3vTOZ3C OnUruuPDjOmzzMvdSpq8fAGLaJ7kmy2g+r39nK69RThjBhpZhClUaW4skgD1cIjhZQOo v40RISC9cxULWfuqT/Hfr23B06mnh6zmd/pDksgvYHtX2S3RUhzEIk7ZSK/QESUj/8l+ j043HTQIfAv3pTpfSp6q8+eCgWz8DBhyN5KThfkzbIZwwdo/WFzTafmPk3LkqrMdOK61 AsZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=InusXyno0XCVa+JZeOC3BOs6Sn0eGeJe2re8Vwwg5t4=; b=SUl95gZbHmfxyLypf7KeKHDV+qr1oBnPLO3EoclEiBYzZMaO8ZUPHtdpyEKsuvpfgg 4Wj9+Bu/wlEUc3P1j/wvZ9OOyoiipG7rxXKntILGQmt5B+uh0JDT+vAdbwbxxpALmCbO TwpEYnSVWF/w15+rGXGjpXLT6vqNPEVBEBv8LY+AR26r8z0VpAWoq2zlwuYx6Lzx5xdF q5ApRHEPPEhxmuq4D93XgLPYHCY1ffNmtBcuJZ3E7g69d+C0OwyVBiaZLkv/ZjEnaX2t 9w+DB1dFkjcUhtCzb2R4Dw/fRoQ7XllJHscLLdDgDcAlrM8VF5KwX1Wjqeo2QRRHGGKL iCxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Tq32c9BM; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u17-20020a17090341d100b001b053ea9bc0si1147575ple.469.2023.06.08.07.33.24; Thu, 08 Jun 2023 07:33:39 -0700 (PDT) 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=@kernel.org header.s=k20201202 header.b=Tq32c9BM; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237059AbjFHOZj (ORCPT + 99 others); Thu, 8 Jun 2023 10:25:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55964 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236568AbjFHOZS (ORCPT ); Thu, 8 Jun 2023 10:25:18 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5D51D1FCC; Thu, 8 Jun 2023 07:24:56 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 5B3A564E21; Thu, 8 Jun 2023 14:24:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 81F59C4339C; Thu, 8 Jun 2023 14:24:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686234293; bh=iWuNSLxO6q6HZETxHyJL7TfXVCdA5aUkY9bgnycApiw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Tq32c9BM1jBz7n3OZOSVEKvK8CIw2f30Sc5jMXaFZuSj9ggqikMCPqn7VTj54d8A6 L7W6koyjYkTKWhvPAWAoB/DocpdbNRQmVt7Fb6QgmxXrdv5SFvwiXuL8uKm4M62mOT ftmyEiKKgMoxx1KrVuv7D09woIaGiWylwqoFWcfa8po12eMQYGGODmx4Jjd6AOO2NB jSFXVIwXS9dQM2AZy4hv9NMyrdZJnf8ZNCUki98sFcLHqDAtcH/nZ5J+a1tDBs1jx9 tN8MNU+VTiPXxDdZ/fUbebfIXPo80i69iWmxuCBkpsXXS1BIcMPA9IbSAXXAVIrTsq kp5GlTS6jU7DQ== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Nathan Chancellor , Nick Desaulniers , Nicolas Schier , linux-um@lists.infradead.org, Masahiro Yamada Subject: [PATCH v7 10/11] modpost: show offset from symbol for section mismatch warnings Date: Thu, 8 Jun 2023 23:24:27 +0900 Message-Id: <20230608142428.256985-11-masahiroy@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230608142428.256985-1-masahiroy@kernel.org> References: <20230608142428.256985-1-masahiroy@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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?1768145362702135881?= X-GMAIL-MSGID: =?utf-8?q?1768145362702135881?= Currently, modpost only shows the symbol names and section names, so it repeats the same message if there are multiple relocations in the same symbol. It is common the relocation spans across multiple instructions. It is better to show the offset from the symbol. Signed-off-by: Masahiro Yamada Reviewed-by: Nick Desaulniers --- scripts/mod/modpost.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index 85df3f3ba9ee..40967ed816df 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -1147,8 +1147,8 @@ static void default_mismatch_handler(const char *modname, struct elf_info *elf, sec_mismatch_count++; - warn("%s: section mismatch in reference: %s (section: %s) -> %s (section: %s)\n", - modname, fromsym, fromsec, tosym, tosec); + warn("%s: section mismatch in reference: %s+0x%x (section: %s) -> %s (section: %s)\n", + modname, fromsym, (unsigned int)(faddr - from->st_value), fromsec, tosym, tosec); if (mismatch->mismatch == EXTABLE_TO_NON_TEXT) { if (match(tosec, mismatch->bad_tosec)) From patchwork Thu Jun 8 14:24:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 105005 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6358:3046:b0:115:7a1d:dabb with SMTP id p6csp394256rwl; Thu, 8 Jun 2023 08:05:47 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ71l11siA7RR8SdnS4SVTDRUpU+pSxnd669coPLpY9Lr8/twbeBfVMObVQESBpIFNxWAn6m X-Received: by 2002:a05:6a00:2d8e:b0:65b:a187:d433 with SMTP id fb14-20020a056a002d8e00b0065ba187d433mr9696852pfb.6.1686236747424; Thu, 08 Jun 2023 08:05:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686236747; cv=none; d=google.com; s=arc-20160816; b=H2Jbk5yyk3IFYLtbqhvTDBN3+n6dptY9toyuMV14/QWskBtaLYLaJe1CZ7S3BH6qW0 Acqv/fHQJO0KhYHFI+9NBfsj9+xHD3/ibysAWsg5GljScTvdQ0UgoUPvuRSgU8N6KZye UrbjxxbNKJc3uJlSdyyY6jzLySmGnr/d3/UIJOg5LQXtnlZbhFa7Idg+ZTMK2hO+WiMt DuATnpt4v180ClN/fZGW0yvqmyeQFRGkc+OzRQUMsX43ETJkIR6AzLM0KCraWsuE34no DC5+yaoK1cNiot4Yx/xz6zMQLOGLJ+QH0OlVd7DTVdlZcuk1EYFnY0IMU3RotiXQQAVh B2Tw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=WezBxe1rRPuSw67OVRYPRvBWfOVY/JEZduYcFRonXDs=; b=H824BAQbJXw5dVi9IVpoMBqUcXchbq/1ebTIW+B7ladGe2xSNCQvGGGiMtftKc6r5C 7r6qqDNEwQk3tcuL3odaGbg+OMoXbSEQa2bAB1eDw3pIAaOfviZzaHpGdAPnImz1jQnr xlIbZM+Jt63KlpMwtcyJmvlks0GyRKheqsP646fMm5fLndc6AeeJaT96U+ejKUw8PgPW 3yrJ7sTOyUQ3Y9vsFKpeivBzQyHOt5TS/lgYuwdJEizqylUNmMr/WArnayDIbsjiLNxk l8yb/f0xPmcLKKUPOAedn2gXaPaSKSRQpE+oKVjoQfW2cjlzolK0cRgHnZe0QW3CoNZL 7nTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ntFv6gYK; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a28-20020a63705c000000b005250c235984si1118998pgn.860.2023.06.08.08.05.27; Thu, 08 Jun 2023 08:05:47 -0700 (PDT) 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=@kernel.org header.s=k20201202 header.b=ntFv6gYK; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237352AbjFHOZs (ORCPT + 99 others); Thu, 8 Jun 2023 10:25:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56324 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237112AbjFHOZT (ORCPT ); Thu, 8 Jun 2023 10:25:19 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 056112D59; Thu, 8 Jun 2023 07:25:00 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 0E30B64E2A; Thu, 8 Jun 2023 14:24:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 32260C433D2; Thu, 8 Jun 2023 14:24:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686234295; bh=W7P3iG4O3YjGApyRwNtiWKX5Kq+VmGX8uTvW8Ums99c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ntFv6gYKlgbdRwOlDg1ZciYIhnPhN2Yth0zSMBh1rlXZK4/QWKEvGYg1VqYJU7Q7Y 7kPowQgOC8uSdSuIVTPw8oBH0M1YSfJjTwNZPmE3GP7hQP++wMeo+yIOFshXSfOxWM kmEdw4koner4TpL3XNp9u65JUDy2+93IeydEtbqQ6qHjVK+wsFMWA8O6UX3h4NtYdx NHVPrlm87C9dMQoa0JsB8wSfS0xHgoDuGdYQKSt4dq7x2V5PMg5WMimbx42hWDuqHX ibVrSlp+cCQLo4yDl8Ecy3T+AR9+MhywHQsT3hKNrWQiJ0Gz/6hniiRPANFG6WcLxk Fh0DE3EZ2xB+Q== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Nathan Chancellor , Nick Desaulniers , Nicolas Schier , linux-um@lists.infradead.org, Masahiro Yamada Subject: [PATCH v7 11/11] linux/export.h: rename 'sec' argument to 'license' Date: Thu, 8 Jun 2023 23:24:28 +0900 Message-Id: <20230608142428.256985-12-masahiroy@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230608142428.256985-1-masahiroy@kernel.org> References: <20230608142428.256985-1-masahiroy@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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?1768147383875079142?= X-GMAIL-MSGID: =?utf-8?q?1768147383875079142?= Now, EXPORT_SYMBOL() is populated in two stages. In the first stage, all of EXPORT_SYMBOL/EXPORT_SYMBOL_GPL go into the same section, .export_symbol. 'sec' does not make sense any more. Rename it to 'license'. Signed-off-by: Masahiro Yamada Reviewed-by: Nick Desaulniers --- Changes in v7: - New patch include/linux/export.h | 8 ++++---- include/linux/pm.h | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/include/linux/export.h b/include/linux/export.h index fed2e5717461..b411fdb88720 100644 --- a/include/linux/export.h +++ b/include/linux/export.h @@ -46,11 +46,11 @@ extern struct module __this_module; * be reused in other execution contexts such as the UEFI stub or the * decompressor. */ -#define __EXPORT_SYMBOL(sym, sec, ns) +#define __EXPORT_SYMBOL(sym, license, ns) #elif defined(__GENKSYMS__) -#define __EXPORT_SYMBOL(sym, sec, ns) __GENKSYMS_EXPORT_SYMBOL(sym) +#define __EXPORT_SYMBOL(sym, license, ns) __GENKSYMS_EXPORT_SYMBOL(sym) #elif defined(__ASSEMBLY__) @@ -67,9 +67,9 @@ extern struct module __this_module; #endif /* CONFIG_MODULES */ #ifdef DEFAULT_SYMBOL_NAMESPACE -#define _EXPORT_SYMBOL(sym, sec) __EXPORT_SYMBOL(sym, sec, __stringify(DEFAULT_SYMBOL_NAMESPACE)) +#define _EXPORT_SYMBOL(sym, license) __EXPORT_SYMBOL(sym, license, __stringify(DEFAULT_SYMBOL_NAMESPACE)) #else -#define _EXPORT_SYMBOL(sym, sec) __EXPORT_SYMBOL(sym, sec, "") +#define _EXPORT_SYMBOL(sym, license) __EXPORT_SYMBOL(sym, license, "") #endif #define EXPORT_SYMBOL(sym) _EXPORT_SYMBOL(sym,) diff --git a/include/linux/pm.h b/include/linux/pm.h index aabb6bd8f89e..1810d776e84a 100644 --- a/include/linux/pm.h +++ b/include/linux/pm.h @@ -375,14 +375,14 @@ const struct dev_pm_ops name = { \ } #ifdef CONFIG_PM -#define _EXPORT_DEV_PM_OPS(name, sec, ns) \ +#define _EXPORT_DEV_PM_OPS(name, license, ns) \ const struct dev_pm_ops name; \ - __EXPORT_SYMBOL(name, sec, ns); \ + __EXPORT_SYMBOL(name, license, ns); \ const struct dev_pm_ops name #define EXPORT_PM_FN_GPL(name) EXPORT_SYMBOL_GPL(name) #define EXPORT_PM_FN_NS_GPL(name, ns) EXPORT_SYMBOL_NS_GPL(name, ns) #else -#define _EXPORT_DEV_PM_OPS(name, sec, ns) \ +#define _EXPORT_DEV_PM_OPS(name, license, ns) \ static __maybe_unused const struct dev_pm_ops __static_##name #define EXPORT_PM_FN_GPL(name) #define EXPORT_PM_FN_NS_GPL(name, ns)