From patchwork Fri Jun 10 18:32:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 12877911 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2CE55C433EF for ; Fri, 10 Jun 2022 18:34:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346713AbiFJSeu (ORCPT ); Fri, 10 Jun 2022 14:34:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42214 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349791AbiFJSeh (ORCPT ); Fri, 10 Jun 2022 14:34:37 -0400 Received: from conuserg-12.nifty.com (conuserg-12.nifty.com [210.131.2.79]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1F3FF3A1A3; Fri, 10 Jun 2022 11:34:35 -0700 (PDT) Received: from grover.sesame (133-32-177-133.west.xps.vectant.ne.jp [133.32.177.133]) (authenticated) by conuserg-12.nifty.com with ESMTP id 25AIX5TM020882; Sat, 11 Jun 2022 03:33:06 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-12.nifty.com 25AIX5TM020882 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1654885987; bh=dWrkbZ/zCsAQbt1ylsfirph76FCDu7eUxy+/dh5/pjo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EKhRJEaK3gX99ziov/rjxAhmo76ZnId9lzn3GpSIVc9AK8OtHMiqQlPqRY40Pll4s wPGEtZv/GV70FNdJiqwh3lmynNvSm0E9xw0JWIqYuZ5G/Nitx5ImpaWkpMy/SNwCuu fgIptFOsTMpS7zg0mm5qo19VSDSOLLICqmTAz6eJ/TKufDm1ReBHEh4Ks4qMtgfRKb +lVoSCyxyjesKMHD760+vQ7DQ8tz4LkG5iQsoUaCcPn4vSIfndOU3RN9u/kLRy9R/3 NsCKJl97GxHzhgDQF7Sv3Oj9zAW8OtcQVEieSvGoP32j2EOJs9sFsE8tYvwF4zgWDY N7ouJ1/AOlGFg== X-Nifty-SrcIP: [133.32.177.133] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Al Viro , Nicolas Pitre , Luis Chamberlain , linux-modules@vger.kernel.org, Ard Biesheuvel , Masahiro Yamada , Nick Desaulniers , Alessio Igor Bogani , Michal Marek , Rusty Russell , linux-kernel@vger.kernel.org Subject: [PATCH 1/7] modpost: fix section mismatch check for exported init/exit sections Date: Sat, 11 Jun 2022 03:32:30 +0900 Message-Id: <20220610183236.1272216-2-masahiroy@kernel.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220610183236.1272216-1-masahiroy@kernel.org> References: <20220610183236.1272216-1-masahiroy@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: Since commit f02e8a6596b7 ("module: Sort exported symbols"), EXPORT_SYMBOL* is placed in the individual section ___ksymtab(_gpl)+ (3 leading underscores instead of 2). Since then, modpost cannot detect the bad combination of EXPORT_SYMBOL and __init/__exit. Fix the .fromsec field. Fixes: f02e8a6596b7 ("module: Sort exported symbols") Signed-off-by: Masahiro Yamada Reviewed-by: Nick Desaulniers --- scripts/mod/modpost.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index 29d5a841e215..620dc8c4c814 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -980,7 +980,7 @@ static const struct sectioncheck sectioncheck[] = { }, /* Do not export init/exit functions or data */ { - .fromsec = { "__ksymtab*", NULL }, + .fromsec = { "___ksymtab*", NULL }, .bad_tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL }, .mismatch = EXPORT_TO_INIT_EXIT, .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL }, From patchwork Fri Jun 10 18:32:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 12877909 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 26457C433EF for ; Fri, 10 Jun 2022 18:34:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348475AbiFJSed (ORCPT ); Fri, 10 Jun 2022 14:34:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347734AbiFJSeZ (ORCPT ); Fri, 10 Jun 2022 14:34:25 -0400 Received: from conuserg-12.nifty.com (conuserg-12.nifty.com [210.131.2.79]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DA62339BB3; Fri, 10 Jun 2022 11:34:22 -0700 (PDT) Received: from grover.sesame (133-32-177-133.west.xps.vectant.ne.jp [133.32.177.133]) (authenticated) by conuserg-12.nifty.com with ESMTP id 25AIX5TN020882; Sat, 11 Jun 2022 03:33:07 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-12.nifty.com 25AIX5TN020882 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1654885988; bh=3IE60WW7Xg7rXgGuszZsJXuJ1I7EaTrx4m8Z7Lvb9no=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=a4OGGuQgrOyh6Q06Etn1eXD9vw6HbiLwvEQt96iq2c4KxGUtZOgtQbhhtIkIr3w7v pDQylld6dBNBrlBOLaspZ1cRyqQVuOKem3friZXlyymxTGZKKXLtM46m2IbG40bvQe PlHrf7mSsuVmFbgUuQvYPrrqMT8fXCP2/WBLZvXVG4eT2/Z9zxYE1mM3li9wL0J+lq /xWy8C3v4vGd6YZmeYeWv6qBkeqV5IofvuK963O04bBofuWLeZcmGS1h6QYvukFPSD eHKTpvbL62fDpvnG5c5BkO8I3g9+yaFRrpcdxhZ4cgeBKlCN0KsEBZPG2c7y/nYOc+ WUFYCVH6E3MOA== X-Nifty-SrcIP: [133.32.177.133] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Al Viro , Nicolas Pitre , Luis Chamberlain , linux-modules@vger.kernel.org, Ard Biesheuvel , Masahiro Yamada , Michal Marek , Nick Desaulniers , linux-kernel@vger.kernel.org Subject: [PATCH 2/7] modpost: put get_secindex() call inside sec_name() Date: Sat, 11 Jun 2022 03:32:31 +0900 Message-Id: <20220610183236.1272216-3-masahiroy@kernel.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220610183236.1272216-1-masahiroy@kernel.org> References: <20220610183236.1272216-1-masahiroy@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: There are 5 callsites of sec_name(). In all the places, sec_name() is used together with get_secindex(). So, it is simpler to merge two function calls sec_name(elf, get_secindex(elf, sym)) into one call: sec_name_of_symbol(elf, sym) While I was here, I also inserted this array range check: if (secindex >= info->num_sections) return ""; This will make the code robust against info->sechdrs[] overrun. sym->st_shndx is 2 bytes (for both 32 and 64 bit systems), and the range 0xff00..0xffff is reserved for special sections. For example, a symbol specifies an absolute value, sym->st_shndx==0xfff1. get_secindex() remaps it to 0xfffffff1. There is no corresponding section header for such special sections. The existing code does not hit this issue, but it is better to check the array range. Signed-off-by: Masahiro Yamada Reviewed-by: Nick Desaulniers --- scripts/mod/modpost.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index 620dc8c4c814..b9f2a040f185 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -339,8 +339,19 @@ static const char *sech_name(const struct elf_info *info, Elf_Shdr *sechdr) sechdr->sh_name); } -static const char *sec_name(const struct elf_info *info, int secindex) +static const char *sec_name_of_symbol(const struct elf_info *info, + const Elf_Sym *sym) { + unsigned int secindex = get_secindex(info, sym); + + /* + * If sym->st_shndx is within the special section range, get_secindex() + * will remapit to a big number. + * Bail out here, otherwise info->sechdrs[secindex] would overrun. + */ + if (secindex >= info->num_sections) + return ""; + return sech_name(info, &info->sechdrs[secindex]); } @@ -649,7 +660,7 @@ static void handle_symbol(struct module *mod, struct elf_info *info, const char *name, *secname; name = symname + strlen("__ksymtab_"); - secname = sec_name(info, get_secindex(info, sym)); + secname = sec_name_of_symbol(info, sym); if (strstarts(secname, "___ksymtab_gpl+")) sym_add_exported(name, mod, true); @@ -1217,7 +1228,7 @@ static Elf_Sym *find_elf_symbol2(struct elf_info *elf, Elf_Addr addr, if (is_shndx_special(sym->st_shndx)) continue; - symsec = sec_name(elf, get_secindex(elf, sym)); + symsec = sec_name_of_symbol(elf, sym); if (strcmp(symsec, sec) != 0) continue; if (!is_valid_name(elf, sym)) @@ -1457,7 +1468,7 @@ static void default_mismatch_handler(const char *modname, struct elf_info *elf, if (strstarts(fromsym, "reference___initcall")) return; - tosec = sec_name(elf, get_secindex(elf, sym)); + tosec = sec_name_of_symbol(elf, sym); to = find_elf_symbol(elf, r->r_addend, sym); tosym = sym_name(elf, to); @@ -1559,7 +1570,7 @@ static void extable_mismatch_handler(const char* modname, struct elf_info *elf, Elf_Rela* r, Elf_Sym* sym, const char *fromsec) { - const char* tosec = sec_name(elf, get_secindex(elf, sym)); + const char *tosec = sec_name_of_symbol(elf, sym); sec_mismatch_count++; @@ -1593,7 +1604,7 @@ static void extable_mismatch_handler(const char* modname, struct elf_info *elf, static void check_section_mismatch(const char *modname, struct elf_info *elf, Elf_Rela *r, Elf_Sym *sym, const char *fromsec) { - const char *tosec = sec_name(elf, get_secindex(elf, sym)); + const char *tosec = sec_name_of_symbol(elf, sym); const struct sectioncheck *mismatch = section_mismatch(fromsec, tosec); if (mismatch) { From patchwork Fri Jun 10 18:32:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 12877910 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7E9C4CCA47B for ; Fri, 10 Jun 2022 18:34:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349774AbiFJSeg (ORCPT ); Fri, 10 Jun 2022 14:34:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42214 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347795AbiFJSea (ORCPT ); Fri, 10 Jun 2022 14:34:30 -0400 Received: from conuserg-12.nifty.com (conuserg-12.nifty.com [210.131.2.79]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B1D653A1A3; Fri, 10 Jun 2022 11:34:27 -0700 (PDT) Received: from grover.sesame (133-32-177-133.west.xps.vectant.ne.jp [133.32.177.133]) (authenticated) by conuserg-12.nifty.com with ESMTP id 25AIX5TO020882; Sat, 11 Jun 2022 03:33:08 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-12.nifty.com 25AIX5TO020882 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1654885989; bh=HEwC5qQLGU6iwdawow2rUytQpyuI29TJNHOwoo9etdw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jWVbY0CGm5jgBd5rV5hVu48+jkw0esp9pqKKgclXXUe4JOAalCAk8ruhzd8mrA6/a PJY45T8U7DeYaEM4/AqCE8A9ljkI3qLoOR+wldok9iuLPXXLh67gzt4RdoGAIVzzxG 6kViYJsuift6VcXNTzr8QGZhUS4VP3IKF0owAVfMp4DaArYtbj3aPglBniV+ivRAJY Ym/GkBdbXt+XF/wyBUYxs0JFJje2E3m1aMCE7QHS4tgP9wrNLqLGsJ+2bCmPFiAfqd lHkSV08d7z2CUC40RCcqIUwtTvFknGRlS56smNcrcEDc6BqZOx1ETXOnazdjkJjHX/ Ghcp9LLXZEHew== X-Nifty-SrcIP: [133.32.177.133] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Al Viro , Nicolas Pitre , Luis Chamberlain , linux-modules@vger.kernel.org, Ard Biesheuvel , Masahiro Yamada , Arnd Bergmann , Michal Marek , Nick Desaulniers , linux-arch@vger.kernel.org, linux-ia64@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/7] kbuild: generate struct kernel_symbol by modpost Date: Sat, 11 Jun 2022 03:32:32 +0900 Message-Id: <20220610183236.1272216-4-masahiroy@kernel.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220610183236.1272216-1-masahiroy@kernel.org> References: <20220610183236.1272216-1-masahiroy@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: Commit 7b4537199a4a ("kbuild: link symbol CRCs at final link, removing CONFIG_MODULE_REL_CRCS") made the module versioning implementation arch-agnostic; now all the version CRCs are generated by modpost as C code whether the EXPORT_SYMBOL() is placed in *.c or *.S. Doing similar for the entire data structure of EXPORT_SYMBOL() makes further cleanups possible. This commit splits EXPORT_SYMBOL() compilation into two stages. When a source file is compiled, EXPORT_SYMBOL() is converted into a dummy symbol in the .discard.export_symbol section. For example, EXPORT_SYMBOL(foo); EXPORT_SYMBOL_NS_GPL(bar, BAR_NAMESPACE); will be expanded into the following assembly code: .section .discard.export_symbol __export_symbol.foo: .asciz "" .previous .section .discard.export_symbol __export_symbol_gpl.bar: .asciz "BAR_NAMESPACE" .previous They are just markers to tell modpost the name, license, and namespace of the symbols. They will be dropped from the final vmlinux and modules because the section name starts with ".discard.". Then, modpost extracts all the information of EXPORT_SYMBOL() from the .discard.export_symbol section, then generates C code: KSYMTAB_ENTRY(foo, "", ""); KSYMTAB_ENTRY(bar, "_gpl", "BAR_NAMESPACE"); KSYMTAB_ENTRY() 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 assembly code, EXPORT_SYMBOL() was placed in a separate file. arch/arm/kernel/armksyms.c is one example written in the old fashion. 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. For example, commit e007c53397ac ("ia64: move exports to definitions") moved EXPORT_SYMBOL(ia64_ivt) to a .S file, but it resulted in EXPORT_DATA_SYMBOL(). In the new approach, struct kernel_symbol is populated in C. You can always use EXPORT_SYMBOL(). 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 part to C. EXPORT_SYMBOL_NS() is now supported for .S files. and will remain as a wrapper of for a while. They will be removed after #include directives are all replaced. [3] Implement CONFIG_TRIM_UNUSED_KSYMS in one-pass (planned) CONFIG_TRIM_UNUSED_KSYMS works by recursively traversing the directory tree. If an EXPORT_SYMBOL turns out to be unused by anyone, the source file is recompiled, making the EXPORT_SYMBOL() a no-op. Linus did not like this slowness. See: - 5cf0fd591f2e ("Kbuild: disable TRIM_UNUSED_KSYMS option") - a555bdd0c58c ("Kbuild: enable TRIM_UNUSED_KSYMS again, with some guarding") We can do this better now; modpost can selectively emit KSYMTAB_ENTRY's that are really referenced by modules. 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 making the directory traverse one-pass is presumably the right way to go. Signed-off-by: Masahiro Yamada --- arch/ia64/include/asm/Kbuild | 1 + arch/ia64/include/asm/export.h | 3 - include/asm-generic/export.h | 84 ++-------------------------- include/linux/export-internal.h | 44 +++++++++++++++ include/linux/export.h | 97 +++++++++++---------------------- kernel/module/internal.h | 12 ++++ kernel/module/main.c | 1 - scripts/Makefile.build | 8 +-- scripts/check-local-export | 4 +- scripts/mod/modpost.c | 85 +++++++++++++++++------------ scripts/mod/modpost.h | 1 + 11 files changed, 151 insertions(+), 189 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 f994c1daf9d4..fc998339c405 100644 --- a/arch/ia64/include/asm/Kbuild +++ b/arch/ia64/include/asm/Kbuild @@ -1,5 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 generated-y += syscall_table.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/linux/export-internal.h b/include/linux/export-internal.h index c2b1d4fd5987..b491ee482947 100644 --- a/include/linux/export-internal.h +++ b/include/linux/export-internal.h @@ -14,4 +14,48 @@ #define SYMBOL_CRC(sym, crc, sec) \ u32 __section("___kcrctab" sec "+" #sym) __used __crc_##sym = crc +#ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS +/* + * 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) \ + 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") +#else +#define __KSYMTAB_ENTRY(sym, sec) \ + asm(" .section \"___ksymtab" sec "+" #sym "\", \"a\" \n" \ + "__ksymtab_" #sym ": \n" \ + " .long " #sym " \n" \ + " .long __kstrtab_" #sym " \n" \ + " .long __kstrtabns_" #sym " \n" \ + " .previous \n") +#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_ENTRY(sym, sec, ns) \ + 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) + #endif /* __LINUX_EXPORT_INTERNAL_H__ */ diff --git a/include/linux/export.h b/include/linux/export.h index 3f31ced0d977..0c71577cf8bb 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,28 @@ extern struct module __this_module; #else #define THIS_MODULE ((struct module *)0) #endif - -#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 +#endif /* __ASSEMBLY__ */ #ifdef __GENKSYMS__ #define ___EXPORT_SYMBOL(sym, sec, ns) __GENKSYMS_EXPORT_SYMBOL(sym) +#elif defined(__ASSEMBLY__) + +#define ___EXPORT_SYMBOL(sym, sec, ns) \ + .section .discard.export_symbol ; \ + __export_symbol##sec##.sym: ; \ + .asciz ns ; \ + .previous + #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, sec, ns) \ + __ADDRESSABLE(sym) \ + asm(".section .discard.export_symbol \n" \ + "__export_symbol" #sec "." #sym ": \n" \ + ".asciz " "\"" ns "\"" " \n" \ + ".previous \n") #endif @@ -117,9 +74,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 +116,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/kernel/module/internal.h b/kernel/module/internal.h index bc5507ab8450..a362905ed24c 100644 --- a/kernel/module/internal.h +++ b/kernel/module/internal.h @@ -36,6 +36,18 @@ # define strict_align(X) (X) #endif +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/kernel/module/main.c b/kernel/module/main.c index fed58d30725d..e2ed87de6977 100644 --- a/kernel/module/main.c +++ b/kernel/module/main.c @@ -6,7 +6,6 @@ #define INCLUDE_VERMAGIC -#include #include #include #include diff --git a/scripts/Makefile.build b/scripts/Makefile.build index 1f01ac65c0cd..8848e465ba25 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -164,7 +164,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. @@ -172,7 +172,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 @@ -288,9 +288,7 @@ $(obj)/%.lst: $(src)/%.c 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 da745e2743b7..2e83e0498d4f 100755 --- a/scripts/check-local-export +++ b/scripts/check-local-export @@ -34,8 +34,8 @@ do symbol_types[${name}]=${type} # append the exported symbol to the array - if [[ ${name} == __ksymtab_* ]]; then - export_symbols+=(${name#__ksymtab_}) + if [[ ${name} == __export_symbol*.* ]]; then + export_symbols+=(${name#*.}) fi # If there is no symbol in the object, ${NM} (both GNU nm and llvm-nm) diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index b9f2a040f185..f738dddde7b8 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -533,6 +533,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, ".discard.export_symbol")) { + info->export_symbol_sec = i; } if (sechdrs[i].sh_type == SHT_SYMTAB) { @@ -655,17 +657,20 @@ 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; + if (sym->st_shndx == info->export_symbol_sec) { + const char *name; - name = symname + strlen("__ksymtab_"); - secname = sec_name_of_symbol(info, sym); - - if (strstarts(secname, "___ksymtab_gpl+")) + if (strstarts(symname, "__export_symbol_gpl.")) { + name = symname + strlen("__export_symbol_gpl."); sym_add_exported(name, mod, true); - else if (strstarts(secname, "___ksymtab+")) + sym_update_namespace(name, sym_get_data(info, sym)); + } else if (strstarts(symname, "__export_symbol.")) { + name = symname + strlen("__export_symbol."); sym_add_exported(name, mod, false); + sym_update_namespace(name, sym_get_data(info, sym)); + } + + break; } if (strcmp(symname, "init_module") == 0) mod->has_init = true; @@ -877,7 +882,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, }; @@ -989,13 +993,6 @@ static const struct sectioncheck sectioncheck[] = { .mismatch = ANY_INIT_TO_ANY_EXIT, .symbol_white_list = { NULL }, }, -/* Do not export init/exit functions or data */ -{ - .fromsec = { "___ksymtab*", NULL }, - .bad_tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL }, - .mismatch = EXPORT_TO_INIT_EXIT, - .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL }, -}, { .fromsec = { "__ex_table", NULL }, /* If you're adding any new black-listed sections in here, consider @@ -1435,15 +1432,6 @@ static void report_sec_mismatch(const char *modname, free(prl_from); free(prl_to); break; - case EXPORT_TO_INIT_EXIT: - prl_to = sec2annotation(tosec); - fprintf(stderr, - "The symbol %s is exported and annotated %s\n" - "Fix this by removing the %sannotation of %s " - "or drop the export.\n", - tosym, prl_to, prl_to, tosym); - free(prl_to); - break; case EXTABLE_TO_NON_TEXT: fatal("There's a special handler for this mismatch type, " "we should never get here."); @@ -1830,6 +1818,36 @@ static void section_rel(const char *modname, struct elf_info *elf, } } +static void check_sec_for_export_symbols(struct module *mod, struct elf_info *elf) +{ + static const char *const init_or_exit_sections[] = { + INIT_SECTIONS, + EXIT_SECTIONS, + NULL + }; + Elf_Sym *sym; + + for (sym = elf->symtab_start; sym < elf->symtab_stop; sym++) { + const char *symname = sym_name(elf, sym); + const char *secname; + char *annotate; + + if (!sym_find_with_module(symname, mod)) + continue; /* This is not an exported symbol */ + + secname = sec_name_of_symbol(elf, sym); + + if (!match(secname, init_or_exit_sections)) + continue; /* OK, this is not __init or __exit */ + + annotate = sec2annotation(secname); + + error("%s: exported and annotated %s. Remove %s or EXPORT_SYMBOL.\n", + symname, annotate, annotate); + free(annotate); + } +} + /** * A module includes a number of sections that are discarded * either when loaded or when used as built-in. @@ -2016,16 +2034,8 @@ 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(modname, &info); + check_sec_for_export_symbols(mod, &info); if (!mod->is_vmlinux) { version = get_modinfo(&info, "version"); @@ -2208,6 +2218,13 @@ 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_ENTRY(%s, \"%s\", \"%s\");\n", + 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 044bdfb894b7..ae59417a9df9 100644 --- a/scripts/mod/modpost.h +++ b/scripts/mod/modpost.h @@ -139,6 +139,7 @@ struct elf_info { Elf_Shdr *sechdrs; Elf_Sym *symtab_start; Elf_Sym *symtab_stop; + unsigned int export_symbol_sec; /* .discard.export_symbol section */ char *strtab; char *modinfo; unsigned int modinfo_len; From patchwork Fri Jun 10 18:32:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 12877907 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3D255C433EF for ; Fri, 10 Jun 2022 18:33:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232547AbiFJSdv (ORCPT ); Fri, 10 Jun 2022 14:33:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38842 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346477AbiFJSdv (ORCPT ); Fri, 10 Jun 2022 14:33:51 -0400 Received: from conuserg-12.nifty.com (conuserg-12.nifty.com [210.131.2.79]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 57ACD39141; Fri, 10 Jun 2022 11:33:48 -0700 (PDT) Received: from grover.sesame (133-32-177-133.west.xps.vectant.ne.jp [133.32.177.133]) (authenticated) by conuserg-12.nifty.com with ESMTP id 25AIX5TP020882; Sat, 11 Jun 2022 03:33:09 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-12.nifty.com 25AIX5TP020882 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1654885990; bh=ebV4+gRnFFeyUFcz5wz1eB/flTewuR25JCfy/TcRt2U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lg+lHyyBfli8Rd6bqhWTKnNmE1mIhzuyPRYKkjtgHHTLnFwO0jzJL3wggaX8iu0t5 rFhUYu9IfjG0mmDQl1SPIleRHAAAlqWiziwvhRg7GMGApx+DjsGNhOlJCcyYhrSdii 5o9RJT7YK0E0Vp+BtKQ8ocHJYr8FXy8Q97zIin/xHK1CyF57hoEfJi5UmvBfZC0pI4 CNyfwPAiV2dztxbYqq5ohhm79uIIZfGaA6JCLj/BLrgf7mWuOaB8Ey0F7COoVJd8gw 6YdMudxvmCwisssEIbxpM/AjxfQpDnes5smSSKPZplDvlrIrO8up/gpJdl6H4PwN1r +WzkKXrVjBW9Q== X-Nifty-SrcIP: [133.32.177.133] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Al Viro , Nicolas Pitre , Luis Chamberlain , linux-modules@vger.kernel.org, Ard Biesheuvel , Masahiro Yamada , Arnd Bergmann , linux-arch@vger.kernel.org, linux-ia64@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 4/7] ia64,export.h: replace EXPORT_DATA_SYMBOL* with EXPORT_SYMBOL* Date: Sat, 11 Jun 2022 03:32:33 +0900 Message-Id: <20220610183236.1272216-5-masahiroy@kernel.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220610183236.1272216-1-masahiroy@kernel.org> References: <20220610183236.1272216-1-masahiroy@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: With the previous refactoring, you no longer need to know whether the exported symbol is a function or a data. Replace two instances in ia64, then remove EXPORT_DATA_SYMBOL*. Signed-off-by: Masahiro Yamada --- 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 Fri Jun 10 18:32:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 12877908 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8A1A0C433EF for ; Fri, 10 Jun 2022 18:34:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346894AbiFJSeR (ORCPT ); Fri, 10 Jun 2022 14:34:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40946 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241313AbiFJSeR (ORCPT ); Fri, 10 Jun 2022 14:34:17 -0400 Received: from conuserg-12.nifty.com (conuserg-12.nifty.com [210.131.2.79]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6B9A039141; Fri, 10 Jun 2022 11:34:10 -0700 (PDT) Received: from grover.sesame (133-32-177-133.west.xps.vectant.ne.jp [133.32.177.133]) (authenticated) by conuserg-12.nifty.com with ESMTP id 25AIX5TQ020882; Sat, 11 Jun 2022 03:33:10 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-12.nifty.com 25AIX5TQ020882 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1654885991; bh=lUG0NgnACAHHS74el4oK5OBZvnr8gUW/ueE3VkEfAzE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TVkm43y1fPNy7bHuIMWG7DrGnrIceHzV6X1lU6v4ZL9E8/NLc7HBlXBUmeLQSrcTf O4tu6f8AtUkuDszRKWhXvE0+QRT6oE0/veGNGFRrDsUZYuV6Lr7pmYLf/Wqn2HVRO9 /uLwGVNVsIKmT6fFuBQYzixM4f7RTMTIOfJNPDpVRIDtmNUddZISqgXF3Rb2Zro+0S KgX2+FF1wYwZg1gcIs8+lU+S9Ogy8K1keaZFccyqirv+3YTgnx1yvi9KiMC3oB1xRP on3+vNDPgO4kDl5oexNjxh1Ct/6vJSvmFKERWW6G5SrufMm+6fcg+kF8C3InAgdmXL xBLUSPmhkWKNw== X-Nifty-SrcIP: [133.32.177.133] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Al Viro , Nicolas Pitre , Luis Chamberlain , linux-modules@vger.kernel.org, Ard Biesheuvel , Masahiro Yamada , Andy Whitcroft , Dwaipayan Ray , Joe Perches , Lukas Bulwahn , linux-kernel@vger.kernel.org Subject: [PATCH 5/7] checkpatch: warn if is included Date: Sat, 11 Jun 2022 03:32:34 +0900 Message-Id: <20220610183236.1272216-6-masahiroy@kernel.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220610183236.1272216-1-masahiroy@kernel.org> References: <20220610183236.1272216-1-masahiroy@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: With the previous refactoring, - is a wrapper of - is a wrapper of My hope is to replace #include --> #include for all *.S files. For now, adding a warning in the checkpatch. Signed-off-by: Masahiro Yamada --- scripts/checkpatch.pl | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 503e8abbb2c1..f824d690a565 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -3753,6 +3753,13 @@ sub process { "Avoid using '.L' prefixed local symbol names for denoting a range of code via 'SYM_*_START/END' annotations; see Documentation/asm-annotations.rst\n" . $herecurr); } +# warn if is included. +# is a wrapper of . Please include directly. + if ($tree && $rawline =~ m{^.\s*\#\s*include\s*\}) { + WARN("INCLUDE_LINUX_EXPORT", + "Please include instead of \n" . $herecurr); + } + # check we are in a valid source file C or perl if not then ignore this hunk next if ($realfile !~ /\.(h|c|pl|dtsi|dts)$/); From patchwork Fri Jun 10 18:32:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 12877913 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C262AC43334 for ; Fri, 10 Jun 2022 18:35:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350363AbiFJSfU (ORCPT ); Fri, 10 Jun 2022 14:35:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42440 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350035AbiFJSet (ORCPT ); Fri, 10 Jun 2022 14:34:49 -0400 Received: from conuserg-12.nifty.com (conuserg-12.nifty.com [210.131.2.79]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 178373A5F6; Fri, 10 Jun 2022 11:34:38 -0700 (PDT) Received: from grover.sesame (133-32-177-133.west.xps.vectant.ne.jp [133.32.177.133]) (authenticated) by conuserg-12.nifty.com with ESMTP id 25AIX5TR020882; Sat, 11 Jun 2022 03:33:11 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-12.nifty.com 25AIX5TR020882 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1654885992; bh=vdyCFoDb1ktlDMZ2of2KXWKno1vYYdppHQg9jC75LS4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RtKFZesTY2BntPapYcA7z3ne5NUz2dyrQ9mUBt83jiBraUQDCYGyQF84rID/7AkEV 9XicUZ8jbgdXXXY0R+zSI2R1oDBv6SNdRAfrH18SflVQESgMpYfmeOJ36qHFzpO+sb k2P/d3yB8T42swzLopLjX5bH/ElEWBPAQpL6s3Z4X4cLo6HSd1j4z8oC3Ed2opBhTS e8ru/LMQaiY20MKlKXNYo9Zx2xAetdiBGOxetVCPP/bKRJwgWFOCeTK72pEaQi4ryT 4SB3shJnXidH3XHlRJ36xtdTNYIjnypMKV4SQPYXWs3CkBkPIwyYHRQtFxOkgEeyVB VlhVU6U1VcnSg== X-Nifty-SrcIP: [133.32.177.133] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Al Viro , Nicolas Pitre , Luis Chamberlain , linux-modules@vger.kernel.org, Ard Biesheuvel , Masahiro Yamada , Michal Marek , Nick Desaulniers , linux-kernel@vger.kernel.org Subject: [PATCH 6/7] modpost: merge sym_update_namespace() into sym_add_exported() Date: Sat, 11 Jun 2022 03:32:35 +0900 Message-Id: <20220610183236.1272216-7-masahiroy@kernel.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220610183236.1272216-1-masahiroy@kernel.org> References: <20220610183236.1272216-1-masahiroy@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: 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 | 41 +++++++++-------------------------------- 1 file changed, 9 insertions(+), 32 deletions(-) diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index f738dddde7b8..0db2cbb74a2a 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -357,26 +357,8 @@ static const char *sec_name_of_symbol(const struct elf_info *info, #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); @@ -389,6 +371,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); @@ -658,17 +641,12 @@ static void handle_symbol(struct module *mod, struct elf_info *info, break; default: if (sym->st_shndx == info->export_symbol_sec) { - const char *name; - - if (strstarts(symname, "__export_symbol_gpl.")) { - name = symname + strlen("__export_symbol_gpl."); - sym_add_exported(name, mod, true); - sym_update_namespace(name, sym_get_data(info, sym)); - } else if (strstarts(symname, "__export_symbol.")) { - name = symname + strlen("__export_symbol."); - sym_add_exported(name, mod, false); - sym_update_namespace(name, sym_get_data(info, sym)); - } + if (strstarts(symname, "__export_symbol_gpl.")) + sym_add_exported(symname + strlen("__export_symbol_gpl."), + mod, true, sym_get_data(info, sym)); + else if (strstarts(symname, "__export_symbol.")) + sym_add_exported(symname + strlen("__export_symbol."), + mod, false, sym_get_data(info, sym)); break; } @@ -2470,9 +2448,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 Fri Jun 10 18:32:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 12877912 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 39283C43334 for ; Fri, 10 Jun 2022 18:35:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350284AbiFJSfR (ORCPT ); Fri, 10 Jun 2022 14:35:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42758 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347795AbiFJSer (ORCPT ); Fri, 10 Jun 2022 14:34:47 -0400 Received: from conuserg-12.nifty.com (conuserg-12.nifty.com [210.131.2.79]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 165063A5C7; Fri, 10 Jun 2022 11:34:38 -0700 (PDT) Received: from grover.sesame (133-32-177-133.west.xps.vectant.ne.jp [133.32.177.133]) (authenticated) by conuserg-12.nifty.com with ESMTP id 25AIX5TS020882; Sat, 11 Jun 2022 03:33:12 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-12.nifty.com 25AIX5TS020882 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1654885992; bh=Fv4Q2sQU9/jGRzTAgd2r3B6fBk4S6c2Z53z5KaB5G4o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zfczt2NaxLXAYn3OGPGpV6wFMUIu/m80wEWYFsaxM/S5uFGRFQ6O89+xGr1tOfYuy vo6Llz4Romdo1QylXEvMULly0QGTjRm1mMATFSVxsnAGZOOfix9T3SSGStb8iHYfRj tX8OlJcBk5E9XLgafJ04nlTrRYAiHP+pEFubun4vM8NihUwanoO3MZPZj4aMA7rEuk Uk0VRqv+RYi/6kxiG++sqYpDiK5p0ope/uODBcjZQ063s4meH/RWTpUZA4e3iNTlSP O6+BVb4nwQj6+4sDeTeekpZQSFz9VwAbakRvxO1+F6h/pFnAW996aBg4BmFtZlzt4G BhsgcuKfnErgg== X-Nifty-SrcIP: [133.32.177.133] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Al Viro , Nicolas Pitre , Luis Chamberlain , linux-modules@vger.kernel.org, Ard Biesheuvel , Masahiro Yamada , Michal Marek , Nick Desaulniers , linux-kernel@vger.kernel.org Subject: [PATCH 7/7] modpost: use null string instead of NULL pointer for default namespace Date: Sat, 11 Jun 2022 03:32:36 +0900 Message-Id: <20220610183236.1272216-8-masahiroy@kernel.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220610183236.1272216-1-masahiroy@kernel.org> References: <20220610183236.1272216-1-masahiroy@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: 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 | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index 0db2cbb74a2a..5a1785645943 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -296,6 +296,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; @@ -371,7 +378,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); @@ -2117,8 +2124,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); @@ -2201,7 +2207,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_ENTRY(%s, \"%s\", \"%s\");\n", sym->name, sym->is_gpl_only ? "_gpl" : "", - sym->namespace ?: ""); + sym->namespace); if (!modversions) return; @@ -2471,7 +2477,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);