From patchwork Thu Oct 3 07:58:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 11172263 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 718021709 for ; Thu, 3 Oct 2019 07:59:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4FB0121D81 for ; Thu, 3 Oct 2019 07:59:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=nifty.com header.i=@nifty.com header.b="SzfFwVTm" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728692AbfJCH7a (ORCPT ); Thu, 3 Oct 2019 03:59:30 -0400 Received: from conuserg-11.nifty.com ([210.131.2.78]:59227 "EHLO conuserg-11.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726523AbfJCH7R (ORCPT ); Thu, 3 Oct 2019 03:59:17 -0400 Received: from localhost.localdomain (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-11.nifty.com with ESMTP id x937wTkT007720; Thu, 3 Oct 2019 16:58:30 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-11.nifty.com x937wTkT007720 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1570089510; bh=Ne5AozHKQBV/eN5L7U5RW8n+qn4kZ0PpPgZtYlmXwqs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SzfFwVTmehv9gNGgR1TE+D93JWeJI0/ZGZ0C2AeH6e2XkAyF3tUnI1aDCk3wVcaCA EOcO4fYSej8XhnLNgrg90VBGe7z/Zv+ki/Wia+TcRSOgKSpCl6oG+iuNPpzeWggyTk b8EBuTJEE+jY/i3bKdZnET9RDYhA9zDM3o/bjepQsYJScchVY3owxI2mB87R+8qDPx 0t+Y9LXZdnzB7oxd9traZRR4sqyWx3vblOAAyk5OffgU6tjhWFrocsPE/LSJGhdnwm zF2HLmhZHBZW+aIdcALgxtBxl4cXrPhurmfcvHvm6R7GkdZwQxWVSX4E8KmuS6mpi/ 12l3jabmBktsQ== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: Jessica Yu Cc: Matthias Maennich , Greg Kroah-Hartman , Shaun Ruffell , linux-kbuild@vger.kernel.org, Masahiro Yamada , Martijn Coenen , Michal Marek , Will Deacon , linux-kernel@vger.kernel.org Subject: [PATCH v2 1/6] module: swap the order of symbol.namespace Date: Thu, 3 Oct 2019 16:58:21 +0900 Message-Id: <20191003075826.7478-2-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191003075826.7478-1-yamada.masahiro@socionext.com> References: <20191003075826.7478-1-yamada.masahiro@socionext.com> Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org Currently, EXPORT_SYMBOL_NS(_GPL) constructs the kernel symbol as follows: __ksymtab_SYMBOL.NAMESPACE The sym_extract_namespace() in modpost allocates memory for the part SYMBOL.NAMESPACE when '.' is contained. One problem is that the pointer returned by strdup() is lost because the symbol name will be copied to malloc'ed memory by alloc_symbol(). No one will keep track of the pointer of strdup'ed memory. sym->namespace still points to the NAMESPACE part. So, you can free it with complicated code like this: free(sym->namespace - strlen(sym->name) - 1); It complicates memory free. To fix it elegantly, I swapped the order of the symbol and the namespace as follows: __ksymtab_NAMESPACE.SYMBOL then, simplified sym_extract_namespace() so that it allocates memory only for the NAMESPACE part. I prefer this order because it is intuitive and also matches to major languages. For example, NAMESPACE::NAME in C++, MODULE.NAME in Python. Signed-off-by: Masahiro Yamada Reviewed-by: Matthias Maennich --- Changes in v2: None include/linux/export.h | 4 ++-- scripts/mod/modpost.c | 16 +++++++--------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/include/linux/export.h b/include/linux/export.h index 95f55b7f83a0..0695d4e847d9 100644 --- a/include/linux/export.h +++ b/include/linux/export.h @@ -52,7 +52,7 @@ extern struct module __this_module; __ADDRESSABLE(sym) \ asm(" .section \"___ksymtab" sec "+" #sym "\", \"a\" \n" \ " .balign 4 \n" \ - "__ksymtab_" #sym NS_SEPARATOR #ns ": \n" \ + "__ksymtab_" #ns NS_SEPARATOR #sym ": \n" \ " .long " #sym "- . \n" \ " .long __kstrtab_" #sym "- . \n" \ " .long __kstrtab_ns_" #sym "- . \n" \ @@ -76,7 +76,7 @@ struct kernel_symbol { #else #define __KSYMTAB_ENTRY_NS(sym, sec, ns) \ static const struct kernel_symbol __ksymtab_##sym##__##ns \ - asm("__ksymtab_" #sym NS_SEPARATOR #ns) \ + asm("__ksymtab_" #ns NS_SEPARATOR #sym) \ __attribute__((section("___ksymtab" sec "+" #sym), used)) \ __aligned(sizeof(void *)) \ = { (unsigned long)&sym, __kstrtab_##sym, __kstrtab_ns_##sym } diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index 442d5e2ad688..2c644086c412 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -350,18 +350,16 @@ static enum export export_from_sec(struct elf_info *elf, unsigned int sec) static const char *sym_extract_namespace(const char **symname) { - size_t n; - char *dupsymname; + char *namespace = NULL; + char *ns_separator; - n = strcspn(*symname, "."); - if (n < strlen(*symname) - 1) { - dupsymname = NOFAIL(strdup(*symname)); - dupsymname[n] = '\0'; - *symname = dupsymname; - return dupsymname + n + 1; + ns_separator = strchr(*symname, '.'); + if (ns_separator) { + namespace = NOFAIL(strndup(*symname, ns_separator - *symname)); + *symname = ns_separator + 1; } - return NULL; + return namespace; } /** From patchwork Thu Oct 3 07:58:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 11172255 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 948871709 for ; Thu, 3 Oct 2019 07:59:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 71BA321D81 for ; Thu, 3 Oct 2019 07:59:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=nifty.com header.i=@nifty.com header.b="l10tqUHY" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728178AbfJCH7W (ORCPT ); Thu, 3 Oct 2019 03:59:22 -0400 Received: from conuserg-11.nifty.com ([210.131.2.78]:59228 "EHLO conuserg-11.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728119AbfJCH7R (ORCPT ); Thu, 3 Oct 2019 03:59:17 -0400 Received: from localhost.localdomain (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-11.nifty.com with ESMTP id x937wTkU007720; Thu, 3 Oct 2019 16:58:31 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-11.nifty.com x937wTkU007720 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1570089511; bh=2WkGrobjA1U1dn5ejZfaJgOsN0toyJldJb1G+H1ogM0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=l10tqUHYyIrYc2z8CdUvQAEG+svgnd1dFQ0zv1xeEnjonanZ1TvjAwwVrxl/n3Sw8 5+fGNijQgu7Pu2eIW6tq52e7E+qs1dAZRxWNaYZD6AsYhwL0PB0d/tpXQ3BchFJhMI Snrpr7INlZSTiiBZQZi8JjM0620QSqpsYUi7d7SslcERl5MALc7JwOJ0JDDhZZsx0O 2Uz4uk6GB5SgOAjtEPXxehTKa4uBxMHf52qM2i04OfxMpBjpdzKD8CsG0YeDsum48X UpKnEWtSmAY+nxiZyeLBaGGAgqcVEYs31SRi9CfhBIRY1NzRtq959EQty+n7HP/ZOv 10uEwBTDMyFpQ== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: Jessica Yu Cc: Matthias Maennich , Greg Kroah-Hartman , Shaun Ruffell , linux-kbuild@vger.kernel.org, Masahiro Yamada , Michal Marek , linux-kernel@vger.kernel.org Subject: [PATCH v2 2/6] modpost: fix broken sym->namespace for external module builds Date: Thu, 3 Oct 2019 16:58:22 +0900 Message-Id: <20191003075826.7478-3-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191003075826.7478-1-yamada.masahiro@socionext.com> References: <20191003075826.7478-1-yamada.masahiro@socionext.com> Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org Currently, external module builds produce tons of false-positives: WARNING: module uses symbol from namespace , but does not import it. Here, the part shows a random string. When you build external modules, the symbol info of vmlinux and in-kernel modules are read from $(objtree)/Module.symvers, but read_dump() is buggy in multiple ways: [1] When the modpost is run for vmlinux and in-kernel modules, sym_extract_namespace() allocates memory for the namespace. On the other hand, read_dump() does not, then sym->namespace will point to somewhere in the line buffer of get_next_line(). The data in the buffer will be replaced soon, and sym->namespace will end up with pointing to unrelated data. As a result, check_exports() will show random strings in the warning messages. [2] When there is no namespace, sym_extract_namespace() returns NULL. On the other hand, read_dump() sets namespace to an empty string "". (but, it will be later replaced with unrelated data due to bug [1].) The check_exports() shows a warning unless exp->namespace is NULL, so every symbol read from read_dump() emits the warning, which is mostly false positive. To address [1], sym_add_exported() calls strdup() for s->namespace. The namespace from sym_extract_namespace() must be freed to avoid memory leak. For [2], I changed the if-conditional in check_exports(). This commit also fixes sym_add_exported() to set s->namespace correctly when the symbol is preloaded. Signed-off-by: Masahiro Yamada Reviewed-by: Matthias Maennich Reviewed-by: Shaun Ruffell Tested-by: Shaun Ruffell --- Changes in v2: - Change the approach to deal with ->preloaded scripts/mod/modpost.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index 2c644086c412..936d3ad23c83 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -166,7 +166,7 @@ struct symbol { struct module *module; unsigned int crc; int crc_valid; - const char *namespace; + char *namespace; unsigned int weak:1; unsigned int vmlinux:1; /* 1 if symbol is defined in vmlinux */ unsigned int kernel:1; /* 1 if symbol is from kernel @@ -348,7 +348,7 @@ static enum export export_from_sec(struct elf_info *elf, unsigned int sec) return export_unknown; } -static const char *sym_extract_namespace(const char **symname) +static char *sym_extract_namespace(const char **symname) { char *namespace = NULL; char *ns_separator; @@ -373,7 +373,6 @@ static struct symbol *sym_add_exported(const char *name, const char *namespace, if (!s) { s = new_symbol(name, mod, export); - s->namespace = namespace; } else { if (!s->preloaded) { warn("%s: '%s' exported twice. Previous export was in %s%s\n", @@ -384,6 +383,8 @@ static struct symbol *sym_add_exported(const char *name, const char *namespace, s->module = mod; } } + free(s->namespace); + s->namespace = namespace ? strdup(namespace) : NULL; s->preloaded = 0; s->vmlinux = is_vmlinux(mod->name); s->kernel = 0; @@ -670,7 +671,8 @@ static void handle_modversions(struct module *mod, struct elf_info *info, unsigned int crc; enum export export; bool is_crc = false; - const char *name, *namespace; + const char *name; + char *namespace; if ((!is_vmlinux(mod->name) || mod->is_dot_o) && strstarts(symname, "__ksymtab")) @@ -745,6 +747,7 @@ static void handle_modversions(struct module *mod, struct elf_info *info, name = symname + strlen("__ksymtab_"); namespace = sym_extract_namespace(&name); sym_add_exported(name, namespace, mod, export); + free(namespace); } if (strcmp(symname, "init_module") == 0) mod->has_init = 1; @@ -2193,7 +2196,7 @@ static int check_exports(struct module *mod) else basename = mod->name; - if (exp->namespace) { + if (exp->namespace && exp->namespace[0]) { add_namespace(&mod->required_namespaces, exp->namespace); From patchwork Thu Oct 3 07:58:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 11172259 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 127AB15AB for ; Thu, 3 Oct 2019 07:59:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E5B1221D81 for ; Thu, 3 Oct 2019 07:59:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=nifty.com header.i=@nifty.com header.b="sOufCbPQ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728119AbfJCH70 (ORCPT ); Thu, 3 Oct 2019 03:59:26 -0400 Received: from conuserg-11.nifty.com ([210.131.2.78]:59223 "EHLO conuserg-11.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728061AbfJCH7R (ORCPT ); Thu, 3 Oct 2019 03:59:17 -0400 Received: from localhost.localdomain (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-11.nifty.com with ESMTP id x937wTkV007720; Thu, 3 Oct 2019 16:58:32 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-11.nifty.com x937wTkV007720 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1570089512; bh=120bNVWb/cAQsirkPrw5wuUPD0J6O7LG/eInWnc0GXM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sOufCbPQwtH53jrQ4+SKNS8BTK/E+XQVV/fnQjxwjvk5EUSt/oSWZrt5XQgHu04Yz +dXnPmpBjOZeJgRpfqmsR4OdoiEUmMIzSq/kOO5SoiB1EdqX2XKB3WZxUMamBpaN9v xElB92NZS0pxrpkwlK0EEvIjRMlfaVrXOmATpd+ubKqJUVvc7QEp57uLYEJxzkOqt6 joTmKXLL6IL42K5T511rqnUtMhHiF/HUw/py6SqPqF6uLBzopMEzEEvq4EeKgrHLLn Lf6+lwHVFdpajOGOSHJmWcH+F6yYt5HZK41Ij7ZpZlJJaBSe7jMTKCXvBd9QjsNGU9 N9ehQ6o3sz3FA== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: Jessica Yu Cc: Matthias Maennich , Greg Kroah-Hartman , Shaun Ruffell , linux-kbuild@vger.kernel.org, Masahiro Yamada , Martijn Coenen , Will Deacon , linux-kernel@vger.kernel.org Subject: [PATCH v2 3/6] module: rename __kstrtab_ns_* to __kstrtabns_* to avoid symbol conflict Date: Thu, 3 Oct 2019 16:58:23 +0900 Message-Id: <20191003075826.7478-4-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191003075826.7478-1-yamada.masahiro@socionext.com> References: <20191003075826.7478-1-yamada.masahiro@socionext.com> Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org The module namespace produces __strtab_ns_ symbols to store namespace strings, but it does not guarantee the name uniqueness. This is a potential problem because we have exported symbols starting with "ns_". For example, kernel/capability.c exports the following symbols: EXPORT_SYMBOL(ns_capable); EXPORT_SYMBOL(capable); Assume a situation where those are converted as follows: EXPORT_SYMBOL_NS(ns_capable, some_namespace); EXPORT_SYMBOL_NS(capable, some_namespace); The former expands to "__kstrtab_ns_capable" and "__kstrtab_ns_ns_capable", and the latter to "__kstrtab_capable" and "__kstrtab_ns_capable". Then, we have the duplicated "__kstrtab_ns_capable". To ensure the uniqueness, rename "__kstrtab_ns_*" to "__kstrtabns_*". Signed-off-by: Masahiro Yamada Reviewed-by: Matthias Maennich --- Changes in v2: None include/linux/export.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/linux/export.h b/include/linux/export.h index 0695d4e847d9..621158ecd2e2 100644 --- a/include/linux/export.h +++ b/include/linux/export.h @@ -55,7 +55,7 @@ extern struct module __this_module; "__ksymtab_" #ns NS_SEPARATOR #sym ": \n" \ " .long " #sym "- . \n" \ " .long __kstrtab_" #sym "- . \n" \ - " .long __kstrtab_ns_" #sym "- . \n" \ + " .long __kstrtabns_" #sym "- . \n" \ " .previous \n") #define __KSYMTAB_ENTRY(sym, sec) \ @@ -79,7 +79,7 @@ struct kernel_symbol { asm("__ksymtab_" #ns NS_SEPARATOR #sym) \ __attribute__((section("___ksymtab" sec "+" #sym), used)) \ __aligned(sizeof(void *)) \ - = { (unsigned long)&sym, __kstrtab_##sym, __kstrtab_ns_##sym } + = { (unsigned long)&sym, __kstrtab_##sym, __kstrtabns_##sym } #define __KSYMTAB_ENTRY(sym, sec) \ static const struct kernel_symbol __ksymtab_##sym \ @@ -112,7 +112,7 @@ struct kernel_symbol { /* For every exported symbol, place a struct in the __ksymtab section */ #define ___EXPORT_SYMBOL_NS(sym, sec, ns) \ ___export_symbol_common(sym, sec); \ - static const char __kstrtab_ns_##sym[] \ + static const char __kstrtabns_##sym[] \ __attribute__((section("__ksymtab_strings"), used, aligned(1))) \ = #ns; \ __KSYMTAB_ENTRY_NS(sym, sec, ns) From patchwork Thu Oct 3 07:58:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 11172265 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1276C1709 for ; Thu, 3 Oct 2019 07:59:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E46B9222CA for ; Thu, 3 Oct 2019 07:59:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=nifty.com header.i=@nifty.com header.b="xzpHUKIW" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726523AbfJCH7e (ORCPT ); Thu, 3 Oct 2019 03:59:34 -0400 Received: from conuserg-11.nifty.com ([210.131.2.78]:59224 "EHLO conuserg-11.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727452AbfJCH7Q (ORCPT ); Thu, 3 Oct 2019 03:59:16 -0400 Received: from localhost.localdomain (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-11.nifty.com with ESMTP id x937wTkW007720; Thu, 3 Oct 2019 16:58:32 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-11.nifty.com x937wTkW007720 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1570089513; bh=+2++qHqEb0DqRRYFRDlh3635ELQ/E4mk9ABraUBN90M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xzpHUKIW1Rdb+BGeVOTE9aitZme/b4Cfxbnx0ukpryA73Q4laaIZVJGwNI8EgBL11 m+uKhaOQFaL8e1PwVsafamEH4O56h27AmtxkNtTG6KI0ugDRwCQ7rSRUgK2aQaka0l M/Ph7mbYklGJwrBRwxK4BavnKcTVFXoPN3q6/Dbc3raiAeBUwo68O0yC92D6Mr/lq2 psMYe10UTW5BIQLpX3JB4Zr2JUg5sFAVaP1le7jQz8Cbn9I517yaTTo44qZOfrqqNA JLYFfDsJ/ak3lsxsO5PD+KT3jvexpQIMH8cdcXjE8jyCtEoT5j5IbFnHbJeSXbaDi6 j9JPu7ZbVh3ZA== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: Jessica Yu Cc: Matthias Maennich , Greg Kroah-Hartman , Shaun Ruffell , linux-kbuild@vger.kernel.org, Masahiro Yamada , Michal Marek , linux-kernel@vger.kernel.org Subject: [PATCH v2 4/6] kbuild: fix build error of 'make nsdeps' in clean tree Date: Thu, 3 Oct 2019 16:58:24 +0900 Message-Id: <20191003075826.7478-5-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191003075826.7478-1-yamada.masahiro@socionext.com> References: <20191003075826.7478-1-yamada.masahiro@socionext.com> Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org Running 'make nsdeps' in a clean source tree fails as follows: $ make -s clean; make -s defconfig; make nsdeps [ snip ] awk: fatal: cannot open file `init/modules.order' for reading (No such file or directory) make: *** [Makefile;1307: modules.order] Error 2 make: *** Deleting file 'modules.order' make: *** Waiting for unfinished jobs.... The cause of the error is 'make nsdeps' does not build modules at all. Set KBUILD_MODULES to fix it. Signed-off-by: Masahiro Yamada Reviewed-by: Matthias Maennich --- Changes in v2: None Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 6f54f2f95743..d97f38ad5d9f 100644 --- a/Makefile +++ b/Makefile @@ -616,7 +616,7 @@ endif # in addition to whatever we do anyway. # Just "make" or "make all" shall build modules as well -ifneq ($(filter all _all modules,$(MAKECMDGOALS)),) +ifneq ($(filter all _all modules nsdeps,$(MAKECMDGOALS)),) KBUILD_MODULES := 1 endif From patchwork Thu Oct 3 07:58:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 11172267 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1321515AB for ; Thu, 3 Oct 2019 07:59:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DB52821D81 for ; Thu, 3 Oct 2019 07:59:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=nifty.com header.i=@nifty.com header.b="jy193E1E" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728199AbfJCH7Q (ORCPT ); Thu, 3 Oct 2019 03:59:16 -0400 Received: from conuserg-11.nifty.com ([210.131.2.78]:59231 "EHLO conuserg-11.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728102AbfJCH7Q (ORCPT ); Thu, 3 Oct 2019 03:59:16 -0400 Received: from localhost.localdomain (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-11.nifty.com with ESMTP id x937wTkX007720; Thu, 3 Oct 2019 16:58:33 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-11.nifty.com x937wTkX007720 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1570089514; bh=wNrxE/R+8BhtQOYFz0ZDJvyWIepl6P4okkyZb4m/C9k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jy193E1EhUdZpsYspNUk778eRK2ZGfe0ME/1rRNgBRezcpO6k88unUAKpy7f1GY7i GofB+lD9HSnLmCQqPbH+DSTWMl6v/f/p40yUxZCy9JcTpvQYUaojPr79q+0mzpnFlH UTzuaUtsmoiNLXt3SdW39VfHe5s4EbG+XxYALWvSsj07/GIuxq9/mSqaqtkCK96JRX 0M2qJH0kQyi46sU7ckLgvfjN482vKdWx6z/cDl9CnshicUug6PIlz/vt/f9g0uroyd d5OT0nZXC3nyXygQZPvhYRdUAvT3EAV/oRODmR0+Rr2vn9wHwe0ugZHgz3coWA0J0x lE4hmOcVz6PqA== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: Jessica Yu Cc: Matthias Maennich , Greg Kroah-Hartman , Shaun Ruffell , linux-kbuild@vger.kernel.org, Masahiro Yamada , linux-kernel@vger.kernel.org Subject: [PATCH v2 5/6] nsdeps: fix hashbang of scripts/nsdeps Date: Thu, 3 Oct 2019 16:58:25 +0900 Message-Id: <20191003075826.7478-6-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191003075826.7478-1-yamada.masahiro@socionext.com> References: <20191003075826.7478-1-yamada.masahiro@socionext.com> Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org This script does not use bash-extension. I am guessing this hashbang was copied from scripts/coccicheck, which really uses bash-extension. /bin/sh is enough for this script. Signed-off-by: Masahiro Yamada Reviewed-by: Matthias Maennich --- Changes in v2: None scripts/nsdeps | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/nsdeps b/scripts/nsdeps index ac2b6031dd13..964b7fb8c546 100644 --- a/scripts/nsdeps +++ b/scripts/nsdeps @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh # SPDX-License-Identifier: GPL-2.0 # Linux kernel symbol namespace import generator # From patchwork Thu Oct 3 07:58:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 11172257 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BE25D1902 for ; Thu, 3 Oct 2019 07:59:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9D36B222C2 for ; Thu, 3 Oct 2019 07:59:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=nifty.com header.i=@nifty.com header.b="JkW9JFD3" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728328AbfJCH7R (ORCPT ); Thu, 3 Oct 2019 03:59:17 -0400 Received: from conuserg-11.nifty.com ([210.131.2.78]:59222 "EHLO conuserg-11.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728178AbfJCH7R (ORCPT ); Thu, 3 Oct 2019 03:59:17 -0400 Received: from localhost.localdomain (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-11.nifty.com with ESMTP id x937wTkY007720; Thu, 3 Oct 2019 16:58:34 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-11.nifty.com x937wTkY007720 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1570089514; bh=59eE/rGcp2OFwwXp+ofMwhXaVSnXW6C8LJ8vAqEhBT8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JkW9JFD3WiK28/HG0qiHqAjyVx6xAYXVsr8kJZ1Brp9fIgb20YDB1nxm4XHsG7CzU H9I9whiVaS6vOFtE3y28YTYHxAPWBiyGtdvm6wjPNRr0ZwdZr5tWSsFRZMjZpSXNq9 UJWoUtH+w0F8ip47kjVGCQHmeVk5mn85mbal0ToUwgv8fuwUhF/OldGknyTOC3IH+p 91LewO4WtqsNVD+w7P5Ps6qkXtnofeJ1q7QSJKU2SmhpdL6/7tJwN1Cg9TUX2ovVRH +i5SZARSaLDGDXJo+PoTcI5eJJMUl3r7bP3+EXpCUXnXLUW3PLfByk0gmEt/5jxFtf /n5BF/hn6X18g== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: Jessica Yu Cc: Matthias Maennich , Greg Kroah-Hartman , Shaun Ruffell , linux-kbuild@vger.kernel.org, Masahiro Yamada , linux-kernel@vger.kernel.org Subject: [PATCH v2 6/6] nsdeps: make generated patches independent of locale Date: Thu, 3 Oct 2019 16:58:26 +0900 Message-Id: <20191003075826.7478-7-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191003075826.7478-1-yamada.masahiro@socionext.com> References: <20191003075826.7478-1-yamada.masahiro@socionext.com> Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org scripts/nsdeps automatically generates a patch to add MODULE_IMPORT_NS tags, and what is nicer, it sorts the lines alphabetically with the 'sort' command. However, the output from the 'sort' command depends on locale. For example, I got this: $ { echo usbstorage; echo usb_storage; } | LANG=en_US.UTF-8 sort usbstorage usb_storage $ { echo usbstorage; echo usb_storage; } | LANG=C sort usb_storage usbstorage So, this means people might potentially send different patches. This kind of issue was reported in the past, for example, commit f55f2328bb28 ("kbuild: make sorting initramfs contents independent of locale"). Adding 'LANG=C' is a conventional way of fixing when a deterministic result is desirable. I added 'LANG=C' very close to the 'sort' command since changing locale affects the language of error messages etc. We should respect users' choice as much as possible. Signed-off-by: Masahiro Yamada Reviewed-by: Matthias Maennich --- Changes in v2: - Add more commit log about the locale impact scripts/nsdeps | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/nsdeps b/scripts/nsdeps index 964b7fb8c546..3754dac13b31 100644 --- a/scripts/nsdeps +++ b/scripts/nsdeps @@ -41,7 +41,7 @@ generate_deps() { for source_file in $mod_source_files; do sed '/MODULE_IMPORT_NS/Q' $source_file > ${source_file}.tmp offset=$(wc -l ${source_file}.tmp | awk '{print $1;}') - cat $source_file | grep MODULE_IMPORT_NS | sort -u >> ${source_file}.tmp + cat $source_file | grep MODULE_IMPORT_NS | LANG=C sort -u >> ${source_file}.tmp tail -n +$((offset +1)) ${source_file} | grep -v MODULE_IMPORT_NS >> ${source_file}.tmp if ! diff -q ${source_file} ${source_file}.tmp; then mv ${source_file}.tmp ${source_file}