linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/29] modpost: various fixes, cleanups, optimizations
@ 2020-05-17  9:48 Masahiro Yamada
  2020-05-17  9:48 ` [PATCH 01/29] modpost: drop RCS/CVS $Revision handling in MODULE_VERSION() Masahiro Yamada
                   ` (28 more replies)
  0 siblings, 29 replies; 36+ messages in thread
From: Masahiro Yamada @ 2020-05-17  9:48 UTC (permalink / raw)
  To: linux-kbuild; +Cc: Jessica Yu, Masahiro Yamada, Michal Marek, linux-kernel


Masahiro Yamada (29):
  modpost: drop RCS/CVS $Revision handling in MODULE_VERSION()
  modpost: do not call get_modinfo() for vmlinux
  modpost: add read_text_file() and get_line() helpers
  modpost: fix potential mmap'ed file overrun in get_src_version()
  modpost: re-add warning about missing *.mod file
  modpost: avoid false-positive file open error
  modpost: use read_text_file() and get_line() for reading text files
  modpost: remove get_next_text() and make {grab,release_}file static
  kbuild: disallow multi-word in M= or KBUILD_EXTMOD
  modpost: move -T option close to the modpost command
  modpost: pass -N option only for modules modpost
  modpost: move external module options
  modpost: load KBUILD_EXTRA_SYMBOLS files in order
  modpost: track if the symbol origin is a dump file or ELF object
  modpost: allow to pass -i option multiple times remove -e option
  modpost: rename ext_sym_list to dump_list
  modpost: re-add -e to set external_module flag
  modpost: show warning if vmlinux is not found when processing modules
  modpost: show warning if it fails to read symbol dump file
  modpost: generate vmlinux.symvers and reuse it for the second modpost
  modpost: remove -s option
  modpost: remove mod->is_dot_o struct member
  modpost: remove is_vmlinux() call in check_for_{gpl_usage,unused}()
  modpost: add mod->is_vmlinux struct member
  modpost: remove mod->skip struct member
  modpost: set have_vmlinux in new_module()
  modpost: strip .o from modname before calling new_module()
  modpost: remove is_vmlinux() helper
  modpost: change elf_info->size to size_t

 .gitignore               |   1 +
 Makefile                 |  15 +-
 scripts/Makefile.modpost |  29 ++--
 scripts/link-vmlinux.sh  |   2 -
 scripts/mod/modpost.c    | 309 ++++++++++++++++++---------------------
 scripts/mod/modpost.h    |  17 +--
 scripts/mod/sumversion.c | 114 ++++-----------
 7 files changed, 195 insertions(+), 292 deletions(-)

-- 
2.25.1


^ permalink raw reply	[flat|nested] 36+ messages in thread

* [PATCH 01/29] modpost: drop RCS/CVS $Revision handling in MODULE_VERSION()
  2020-05-17  9:48 [PATCH 00/29] modpost: various fixes, cleanups, optimizations Masahiro Yamada
@ 2020-05-17  9:48 ` Masahiro Yamada
  2020-05-17  9:48 ` [PATCH 02/29] modpost: do not call get_modinfo() for vmlinux Masahiro Yamada
                   ` (27 subsequent siblings)
  28 siblings, 0 replies; 36+ messages in thread
From: Masahiro Yamada @ 2020-05-17  9:48 UTC (permalink / raw)
  To: linux-kbuild; +Cc: Jessica Yu, Masahiro Yamada, Michal Marek, linux-kernel

As far as I understood, this code gets rid of '$Revision$' or '$Revision:'
of CVS, RCS or whatever in MODULE_VERSION() tags.

Remove the primeval code.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

 scripts/mod/modpost.c    |  3 --
 scripts/mod/modpost.h    |  4 ---
 scripts/mod/sumversion.c | 66 ----------------------------------------
 3 files changed, 73 deletions(-)

diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index 4d4b979d76be..77e5425759e2 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -2074,9 +2074,6 @@ static void read_symbols(const char *modname)
 		check_sec_ref(mod, modname, &info);
 
 	version = get_modinfo(&info, "version");
-	if (version)
-		maybe_frob_rcs_version(modname, version, info.modinfo,
-				       version - (char *)info.hdr);
 	if (version || (all_versions && !is_vmlinux(modname)))
 		get_src_version(modname, mod->srcversion,
 				sizeof(mod->srcversion)-1);
diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
index 39f6c29fb568..bbaf5cc37bfb 100644
--- a/scripts/mod/modpost.h
+++ b/scripts/mod/modpost.h
@@ -187,10 +187,6 @@ void handle_moddevtable(struct module *mod, struct elf_info *info,
 void add_moddevtable(struct buffer *buf, struct module *mod);
 
 /* sumversion.c */
-void maybe_frob_rcs_version(const char *modfilename,
-			    char *version,
-			    void *modinfo,
-			    unsigned long modinfo_offset);
 void get_src_version(const char *modname, char sum[], unsigned sumlen);
 
 /* from modpost.c */
diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
index 63062024ce0e..f27f22420cbc 100644
--- a/scripts/mod/sumversion.c
+++ b/scripts/mod/sumversion.c
@@ -429,69 +429,3 @@ void get_src_version(const char *modname, char sum[], unsigned sumlen)
 release:
 	release_file(file, len);
 }
-
-static void write_version(const char *filename, const char *sum,
-			  unsigned long offset)
-{
-	int fd;
-
-	fd = open(filename, O_RDWR);
-	if (fd < 0) {
-		warn("changing sum in %s failed: %s\n",
-			filename, strerror(errno));
-		return;
-	}
-
-	if (lseek(fd, offset, SEEK_SET) == (off_t)-1) {
-		warn("changing sum in %s:%lu failed: %s\n",
-			filename, offset, strerror(errno));
-		goto out;
-	}
-
-	if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
-		warn("writing sum in %s failed: %s\n",
-			filename, strerror(errno));
-		goto out;
-	}
-out:
-	close(fd);
-}
-
-static int strip_rcs_crap(char *version)
-{
-	unsigned int len, full_len;
-
-	if (strncmp(version, "$Revision", strlen("$Revision")) != 0)
-		return 0;
-
-	/* Space for version string follows. */
-	full_len = strlen(version) + strlen(version + strlen(version) + 1) + 2;
-
-	/* Move string to start with version number: prefix will be
-	 * $Revision$ or $Revision: */
-	len = strlen("$Revision");
-	if (version[len] == ':' || version[len] == '$')
-		len++;
-	while (isspace(version[len]))
-		len++;
-	memmove(version, version+len, full_len-len);
-	full_len -= len;
-
-	/* Preserve up to next whitespace. */
-	len = 0;
-	while (version[len] && !isspace(version[len]))
-		len++;
-	memmove(version + len, version + strlen(version),
-		full_len - strlen(version));
-	return 1;
-}
-
-/* Clean up RCS-style version numbers. */
-void maybe_frob_rcs_version(const char *modfilename,
-			    char *version,
-			    void *modinfo,
-			    unsigned long version_offset)
-{
-	if (strip_rcs_crap(version))
-		write_version(modfilename, version, version_offset);
-}
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH 02/29] modpost: do not call get_modinfo() for vmlinux
  2020-05-17  9:48 [PATCH 00/29] modpost: various fixes, cleanups, optimizations Masahiro Yamada
  2020-05-17  9:48 ` [PATCH 01/29] modpost: drop RCS/CVS $Revision handling in MODULE_VERSION() Masahiro Yamada
@ 2020-05-17  9:48 ` Masahiro Yamada
  2020-05-17  9:48 ` [PATCH 03/29] modpost: add read_text_file() and get_line() helpers Masahiro Yamada
                   ` (26 subsequent siblings)
  28 siblings, 0 replies; 36+ messages in thread
From: Masahiro Yamada @ 2020-05-17  9:48 UTC (permalink / raw)
  To: linux-kbuild; +Cc: Jessica Yu, Masahiro Yamada, Michal Marek, linux-kernel

The three calls of get_modinfo() ("license", "import_ns", "version")
always return NULL for vmlinux because the built-in module info is
prefixed with __MODULE_INFO_PREFIX.

It is harmless to call get_modinfo(), but there is no point to search
for what apparently does not exist.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

 scripts/mod/modpost.c | 45 +++++++++++++++++++++++--------------------
 1 file changed, 24 insertions(+), 21 deletions(-)

diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index 77e5425759e2..af098d7efc22 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -2014,25 +2014,26 @@ static void read_symbols(const char *modname)
 		mod->skip = 1;
 	}
 
-	license = get_modinfo(&info, "license");
-	if (!license && !is_vmlinux(modname))
-		warn("missing MODULE_LICENSE() in %s\n"
-		     "see include/linux/module.h for "
-		     "more information\n", modname);
-	while (license) {
-		if (license_is_gpl_compatible(license))
-			mod->gpl_compatible = 1;
-		else {
-			mod->gpl_compatible = 0;
-			break;
+	if (!is_vmlinux(modname)) {
+		license = get_modinfo(&info, "license");
+		if (!license)
+			warn("missing MODULE_LICENSE() in %s\n", modname);
+		while (license) {
+			if (license_is_gpl_compatible(license))
+				mod->gpl_compatible = 1;
+			else {
+				mod->gpl_compatible = 0;
+				break;
+			}
+			license = get_next_modinfo(&info, "license", license);
 		}
-		license = get_next_modinfo(&info, "license", license);
-	}
 
-	namespace = get_modinfo(&info, "import_ns");
-	while (namespace) {
-		add_namespace(&mod->imported_namespaces, namespace);
-		namespace = get_next_modinfo(&info, "import_ns", namespace);
+		namespace = get_modinfo(&info, "import_ns");
+		while (namespace) {
+			add_namespace(&mod->imported_namespaces, namespace);
+			namespace = get_next_modinfo(&info, "import_ns",
+						     namespace);
+		}
 	}
 
 	for (sym = info.symtab_start; sym < info.symtab_stop; sym++) {
@@ -2073,10 +2074,12 @@ static void read_symbols(const char *modname)
 	if (!is_vmlinux(modname) || vmlinux_section_warnings)
 		check_sec_ref(mod, modname, &info);
 
-	version = get_modinfo(&info, "version");
-	if (version || (all_versions && !is_vmlinux(modname)))
-		get_src_version(modname, mod->srcversion,
-				sizeof(mod->srcversion)-1);
+	if (!is_vmlinux(modname)) {
+		version = get_modinfo(&info, "version");
+		if (version || all_versions)
+			get_src_version(modname, mod->srcversion,
+					sizeof(mod->srcversion) - 1);
+	}
 
 	parse_elf_finish(&info);
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH 03/29] modpost: add read_text_file() and get_line() helpers
  2020-05-17  9:48 [PATCH 00/29] modpost: various fixes, cleanups, optimizations Masahiro Yamada
  2020-05-17  9:48 ` [PATCH 01/29] modpost: drop RCS/CVS $Revision handling in MODULE_VERSION() Masahiro Yamada
  2020-05-17  9:48 ` [PATCH 02/29] modpost: do not call get_modinfo() for vmlinux Masahiro Yamada
@ 2020-05-17  9:48 ` Masahiro Yamada
  2020-05-19 10:21   ` Peter Zijlstra
  2020-05-17  9:48 ` [PATCH 04/29] modpost: fix potential mmap'ed file overrun in get_src_version() Masahiro Yamada
                   ` (25 subsequent siblings)
  28 siblings, 1 reply; 36+ messages in thread
From: Masahiro Yamada @ 2020-05-17  9:48 UTC (permalink / raw)
  To: linux-kbuild; +Cc: Jessica Yu, Masahiro Yamada, Michal Marek, linux-kernel

modpost uses grab_file() to open a file, but it is not suitable for
a text file because the mmaped file is not terminated by null byte.
Actually, I see some issues for the use of grab_file().

The new helper, read_text_file() loads the whole file content into a
malloc'ed buffer, and appends a null byte. Then, get_line() reads
each line.

To handle text files, I intend to replace as follows:

 grab_file()    -> read_text_file()
 get_new_line() -> get_line()

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

 scripts/mod/modpost.c | 36 ++++++++++++++++++++++++++++++++++++
 scripts/mod/modpost.h |  2 ++
 2 files changed, 38 insertions(+)

diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index af098d7efc22..2c6319f0ce19 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -112,6 +112,42 @@ void *do_nofail(void *ptr, const char *expr)
 	return ptr;
 }
 
+char *read_text_file(const char *filename)
+{
+	struct stat st;
+	int fd;
+	char *buf;
+
+	fd = open(filename, O_RDONLY);
+	if (fd < 0)
+		return NULL;
+
+	if (fstat(fd, &st) < 0)
+		return NULL;
+
+	buf = NOFAIL(malloc(st.st_size + 1));
+
+	if (read(fd, buf, st.st_size) != st.st_size) {
+		free(buf);
+		buf = NULL;
+		goto close;
+	}
+	buf[st.st_size] = '\0';
+close:
+	close(fd);
+
+	return buf;
+}
+
+char *get_line(char **stringp)
+{
+	/* do not return the unwanted extra line at EOF */
+	if (*stringp && **stringp == '\0')
+		return NULL;
+
+	return strsep(stringp, "\n");
+}
+
 /* A list of all modules we processed */
 static struct module *modules;
 
diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
index bbaf5cc37bfb..dfadaa0c01ec 100644
--- a/scripts/mod/modpost.h
+++ b/scripts/mod/modpost.h
@@ -190,6 +190,8 @@ void add_moddevtable(struct buffer *buf, struct module *mod);
 void get_src_version(const char *modname, char sum[], unsigned sumlen);
 
 /* from modpost.c */
+char *read_text_file(const char *filename);
+char *get_line(char **stringp);
 void *grab_file(const char *filename, unsigned long *size);
 char* get_next_line(unsigned long *pos, void *file, unsigned long size);
 void release_file(void *file, unsigned long size);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH 04/29] modpost: fix potential mmap'ed file overrun in get_src_version()
  2020-05-17  9:48 [PATCH 00/29] modpost: various fixes, cleanups, optimizations Masahiro Yamada
                   ` (2 preceding siblings ...)
  2020-05-17  9:48 ` [PATCH 03/29] modpost: add read_text_file() and get_line() helpers Masahiro Yamada
@ 2020-05-17  9:48 ` Masahiro Yamada
  2020-05-17  9:48 ` [PATCH 05/29] modpost: re-add warning about missing *.mod file Masahiro Yamada
                   ` (24 subsequent siblings)
  28 siblings, 0 replies; 36+ messages in thread
From: Masahiro Yamada @ 2020-05-17  9:48 UTC (permalink / raw)
  To: linux-kbuild; +Cc: Jessica Yu, Masahiro Yamada, Michal Marek, linux-kernel

I do not know how reliably this function works, but it seems dangerous
to me, at least.

The function call

    strchr(sources, '\n');

... continues searching until it finds '\n' or it reaches the '\0'
terminator. In other words, 'sources' should be a null-terminated
string.

However, grab_file() just mmaps a file, so 'sources' is not terminated
with null byte. If the file does not contain '\n' at all, strchr() will
go beyond the mmap'ed memory.

Instead, use read_text_file(), which loads the file content into a
malloc'ed buffer, appending null-byte.

Here we are interested only in the first line of *.mod files. Use
get_line() helper to get the first line.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

 scripts/mod/sumversion.c | 27 ++++++++++++---------------
 1 file changed, 12 insertions(+), 15 deletions(-)

diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
index f27f22420cbc..f9aa532d93cf 100644
--- a/scripts/mod/sumversion.c
+++ b/scripts/mod/sumversion.c
@@ -392,40 +392,37 @@ static int parse_source_files(const char *objfile, struct md4_ctx *md)
 /* Calc and record src checksum. */
 void get_src_version(const char *modname, char sum[], unsigned sumlen)
 {
-	void *file;
-	unsigned long len;
+	char *buf, *pos, *firstline;
 	struct md4_ctx md;
-	char *sources, *end, *fname;
+	char *fname;
 	char filelist[PATH_MAX + 1];
 
 	/* objects for a module are listed in the first line of *.mod file. */
 	snprintf(filelist, sizeof(filelist), "%.*smod",
 		 (int)strlen(modname) - 1, modname);
 
-	file = grab_file(filelist, &len);
-	if (!file)
+	buf = read_text_file(filelist);
+	if (!buf)
 		/* not a module or .mod file missing - ignore */
 		return;
 
-	sources = file;
-
-	end = strchr(sources, '\n');
-	if (!end) {
+	pos = buf;
+	firstline = get_line(&pos);
+	if (!firstline) {
 		warn("bad ending versions file for %s\n", modname);
-		goto release;
+		goto free;
 	}
-	*end = '\0';
 
 	md4_init(&md);
-	while ((fname = strsep(&sources, " ")) != NULL) {
+	while ((fname = strsep(&firstline, " "))) {
 		if (!*fname)
 			continue;
 		if (!(is_static_library(fname)) &&
 				!parse_source_files(fname, &md))
-			goto release;
+			goto free;
 	}
 
 	md4_final_ascii(&md, sum, sumlen);
-release:
-	release_file(file, len);
+free:
+	free(buf);
 }
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH 05/29] modpost: re-add warning about missing *.mod file
  2020-05-17  9:48 [PATCH 00/29] modpost: various fixes, cleanups, optimizations Masahiro Yamada
                   ` (3 preceding siblings ...)
  2020-05-17  9:48 ` [PATCH 04/29] modpost: fix potential mmap'ed file overrun in get_src_version() Masahiro Yamada
@ 2020-05-17  9:48 ` Masahiro Yamada
  2020-05-17  9:48 ` [PATCH 06/29] modpost: avoid false-positive file open error Masahiro Yamada
                   ` (23 subsequent siblings)
  28 siblings, 0 replies; 36+ messages in thread
From: Masahiro Yamada @ 2020-05-17  9:48 UTC (permalink / raw)
  To: linux-kbuild; +Cc: Jessica Yu, Masahiro Yamada, Michal Marek, linux-kernel

This reverts 4be40e22233c ("kbuild: do not emit src version warning for
non-modules").

I do not fully understand what that commit addressed, but commit
91341d4b2c19 ("kbuild: introduce new option to enhance section mismatch
analysis") introduced partial section checks by using modpost. built-in.o
was parsed by modpost. Even modules had a problem because *.mod files
were created after the modpost check.

Commit b7dca6dd1e59 ("kbuild: create *.mod with full directory path and
remove MODVERDIR") stopped doing that. Now that modpost is only invoked
after the directory descend, *.mod files should always exist at the
modpost stage. If not, something went wrong, which should be warned.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

 scripts/mod/sumversion.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
index f9aa532d93cf..f9df0b1863f1 100644
--- a/scripts/mod/sumversion.c
+++ b/scripts/mod/sumversion.c
@@ -402,9 +402,11 @@ void get_src_version(const char *modname, char sum[], unsigned sumlen)
 		 (int)strlen(modname) - 1, modname);
 
 	buf = read_text_file(filelist);
-	if (!buf)
-		/* not a module or .mod file missing - ignore */
+	if (!buf) {
+		warn("failed to open %s. cannot calculate checksum\n",
+		     filelist);
 		return;
+	}
 
 	pos = buf;
 	firstline = get_line(&pos);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH 06/29] modpost: avoid false-positive file open error
  2020-05-17  9:48 [PATCH 00/29] modpost: various fixes, cleanups, optimizations Masahiro Yamada
                   ` (4 preceding siblings ...)
  2020-05-17  9:48 ` [PATCH 05/29] modpost: re-add warning about missing *.mod file Masahiro Yamada
@ 2020-05-17  9:48 ` Masahiro Yamada
  2020-05-17  9:48 ` [PATCH 07/29] modpost: use read_text_file() and get_line() for reading text files Masahiro Yamada
                   ` (22 subsequent siblings)
  28 siblings, 0 replies; 36+ messages in thread
From: Masahiro Yamada @ 2020-05-17  9:48 UTC (permalink / raw)
  To: linux-kbuild; +Cc: Jessica Yu, Masahiro Yamada, Michal Marek, linux-kernel

One problem of grab_file() is that it cannot distinguish the following
two cases:

 - I cannot read the file (the file does not exist, or read permission
   is not set)

 - It can read the file, but the file size is zero

This is because grab_file() calls mmap(), which requires the mapped
length is greater than 0. Hence, grab_file() fails for both cases.

If an empty header file were included from a module that requires checksum
calculation, the following warning would be printed:

  WARNING: modpost: could not open ...: Invalid argument

An empty file is a valid source file, so it should not fail.

Use read_text_file() instead. It can read a zero-length file.
Then, parse_file() will succeed with doing nothing.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

 scripts/mod/sumversion.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
index f9df0b1863f1..a1c7b0f4cd5a 100644
--- a/scripts/mod/sumversion.c
+++ b/scripts/mod/sumversion.c
@@ -258,10 +258,12 @@ static int parse_file(const char *fname, struct md4_ctx *md)
 	char *file;
 	unsigned long i, len;
 
-	file = grab_file(fname, &len);
+	file = read_text_file(fname);
 	if (!file)
 		return 0;
 
+	len = strlen(file);
+
 	for (i = 0; i < len; i++) {
 		/* Collapse and ignore \ and CR. */
 		if (file[i] == '\\' && (i+1 < len) && file[i+1] == '\n') {
@@ -287,7 +289,7 @@ static int parse_file(const char *fname, struct md4_ctx *md)
 
 		add_char(file[i], md);
 	}
-	release_file(file, len);
+	free(file);
 	return 1;
 }
 /* Check whether the file is a static library or not */
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH 07/29] modpost: use read_text_file() and get_line() for reading text files
  2020-05-17  9:48 [PATCH 00/29] modpost: various fixes, cleanups, optimizations Masahiro Yamada
                   ` (5 preceding siblings ...)
  2020-05-17  9:48 ` [PATCH 06/29] modpost: avoid false-positive file open error Masahiro Yamada
@ 2020-05-17  9:48 ` Masahiro Yamada
  2020-05-17  9:48 ` [PATCH 08/29] modpost: remove get_next_text() and make {grab,release_}file static Masahiro Yamada
                   ` (21 subsequent siblings)
  28 siblings, 0 replies; 36+ messages in thread
From: Masahiro Yamada @ 2020-05-17  9:48 UTC (permalink / raw)
  To: linux-kbuild; +Cc: Jessica Yu, Masahiro Yamada, Michal Marek, linux-kernel

grab_file() mmaps a file, but it is not so efficient here because
get_next_line() copies every line to the temporary buffer anyway.

read_text_file() and get_line() are simpler. get_line() exploits the
library function strchr().

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

 scripts/mod/modpost.c    | 15 ++++++++-------
 scripts/mod/sumversion.c | 11 ++++++-----
 2 files changed, 14 insertions(+), 12 deletions(-)

diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index 2c6319f0ce19..8021f7e93448 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -2466,15 +2466,16 @@ static void write_if_changed(struct buffer *b, const char *fname)
  **/
 static void read_dump(const char *fname, unsigned int kernel)
 {
-	unsigned long size, pos = 0;
-	void *file = grab_file(fname, &size);
-	char *line;
+	char *buf, *pos, *line;
 
-	if (!file)
+	buf = read_text_file(fname);
+	if (!buf)
 		/* No symbol versions, silently ignore */
 		return;
 
-	while ((line = get_next_line(&pos, file, size))) {
+	pos = buf;
+
+	while ((line = get_line(&pos))) {
 		char *symname, *namespace, *modname, *d, *export;
 		unsigned int crc;
 		struct module *mod;
@@ -2509,10 +2510,10 @@ static void read_dump(const char *fname, unsigned int kernel)
 		sym_set_crc(symname, crc);
 		sym_update_namespace(symname, namespace);
 	}
-	release_file(file, size);
+	free(buf);
 	return;
 fail:
-	release_file(file, size);
+	free(buf);
 	fatal("parse error in symbol dump file\n");
 }
 
diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
index a1c7b0f4cd5a..89c8baefde9d 100644
--- a/scripts/mod/sumversion.c
+++ b/scripts/mod/sumversion.c
@@ -306,9 +306,8 @@ static int is_static_library(const char *objfile)
  * to figure out source files. */
 static int parse_source_files(const char *objfile, struct md4_ctx *md)
 {
-	char *cmd, *file, *line, *dir;
+	char *cmd, *file, *line, *dir, *pos;
 	const char *base;
-	unsigned long flen, pos = 0;
 	int dirlen, ret = 0, check_files = 0;
 
 	cmd = NOFAIL(malloc(strlen(objfile) + sizeof("..cmd")));
@@ -326,14 +325,16 @@ static int parse_source_files(const char *objfile, struct md4_ctx *md)
 	strncpy(dir, objfile, dirlen);
 	dir[dirlen] = '\0';
 
-	file = grab_file(cmd, &flen);
+	file = read_text_file(cmd);
 	if (!file) {
 		warn("could not find %s for %s\n", cmd, objfile);
 		goto out;
 	}
 
+	pos = file;
+
 	/* Sum all files in the same dir or subdirs. */
-	while ((line = get_next_line(&pos, file, flen)) != NULL) {
+	while ((line = get_line(&pos))) {
 		char* p = line;
 
 		if (strncmp(line, "source_", sizeof("source_")-1) == 0) {
@@ -384,7 +385,7 @@ static int parse_source_files(const char *objfile, struct md4_ctx *md)
 	/* Everyone parsed OK */
 	ret = 1;
 out_file:
-	release_file(file, flen);
+	free(file);
 out:
 	free(dir);
 	free(cmd);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH 08/29] modpost: remove get_next_text() and make {grab,release_}file static
  2020-05-17  9:48 [PATCH 00/29] modpost: various fixes, cleanups, optimizations Masahiro Yamada
                   ` (6 preceding siblings ...)
  2020-05-17  9:48 ` [PATCH 07/29] modpost: use read_text_file() and get_line() for reading text files Masahiro Yamada
@ 2020-05-17  9:48 ` Masahiro Yamada
  2020-05-17  9:48 ` [PATCH 09/29] kbuild: disallow multi-word in M= or KBUILD_EXTMOD Masahiro Yamada
                   ` (20 subsequent siblings)
  28 siblings, 0 replies; 36+ messages in thread
From: Masahiro Yamada @ 2020-05-17  9:48 UTC (permalink / raw)
  To: linux-kbuild; +Cc: Jessica Yu, Masahiro Yamada, Michal Marek, linux-kernel

get_next_line() is no longer used. Remove.

grab_file() and release_file() are only used in modpost.c. Make them
static.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

 scripts/mod/modpost.c | 38 ++------------------------------------
 scripts/mod/modpost.h |  3 ---
 2 files changed, 2 insertions(+), 39 deletions(-)

diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index 8021f7e93448..cd3cb781a2e7 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -452,7 +452,7 @@ static void sym_set_crc(const char *name, unsigned int crc)
 	s->crc_valid = 1;
 }
 
-void *grab_file(const char *filename, unsigned long *size)
+static void *grab_file(const char *filename, unsigned long *size)
 {
 	struct stat st;
 	void *map = MAP_FAILED;
@@ -474,41 +474,7 @@ void *grab_file(const char *filename, unsigned long *size)
 	return map;
 }
 
-/**
-  * Return a copy of the next line in a mmap'ed file.
-  * spaces in the beginning of the line is trimmed away.
-  * Return a pointer to a static buffer.
-  **/
-char *get_next_line(unsigned long *pos, void *file, unsigned long size)
-{
-	static char line[4096];
-	int skip = 1;
-	size_t len = 0;
-	signed char *p = (signed char *)file + *pos;
-	char *s = line;
-
-	for (; *pos < size ; (*pos)++) {
-		if (skip && isspace(*p)) {
-			p++;
-			continue;
-		}
-		skip = 0;
-		if (*p != '\n' && (*pos < size)) {
-			len++;
-			*s++ = *p++;
-			if (len > 4095)
-				break; /* Too long, stop */
-		} else {
-			/* End of string */
-			*s = '\0';
-			return line;
-		}
-	}
-	/* End of buffer */
-	return NULL;
-}
-
-void release_file(void *file, unsigned long size)
+static void release_file(void *file, unsigned long size)
 {
 	munmap(file, size);
 }
diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
index dfadaa0c01ec..232a0e11fcaa 100644
--- a/scripts/mod/modpost.h
+++ b/scripts/mod/modpost.h
@@ -192,9 +192,6 @@ void get_src_version(const char *modname, char sum[], unsigned sumlen);
 /* from modpost.c */
 char *read_text_file(const char *filename);
 char *get_line(char **stringp);
-void *grab_file(const char *filename, unsigned long *size);
-char* get_next_line(unsigned long *pos, void *file, unsigned long size);
-void release_file(void *file, unsigned long size);
 
 enum loglevel {
 	LOG_WARN,
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH 09/29] kbuild: disallow multi-word in M= or KBUILD_EXTMOD
  2020-05-17  9:48 [PATCH 00/29] modpost: various fixes, cleanups, optimizations Masahiro Yamada
                   ` (7 preceding siblings ...)
  2020-05-17  9:48 ` [PATCH 08/29] modpost: remove get_next_text() and make {grab,release_}file static Masahiro Yamada
@ 2020-05-17  9:48 ` Masahiro Yamada
  2020-05-17 12:33   ` David Laight
  2020-05-17  9:48 ` [PATCH 10/29] modpost: move -T option close to the modpost command Masahiro Yamada
                   ` (19 subsequent siblings)
  28 siblings, 1 reply; 36+ messages in thread
From: Masahiro Yamada @ 2020-05-17  9:48 UTC (permalink / raw)
  To: linux-kbuild; +Cc: Jessica Yu, Masahiro Yamada, Michal Marek, linux-kernel

$(firstword ...) in scripts/Makefile.modpost was added by commit
3f3fd3c05585 ("[PATCH] kbuild: allow multi-word $M in Makefile.modpost")
to build multiple external module directories.

This feature has been broken for a while. Remove the bitrotten code, and
stop parsing if M or KBUILD_EXTMOD contains multiple words.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

 Makefile                 | 3 +++
 scripts/Makefile.modpost | 2 +-
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/Makefile b/Makefile
index 1915630cc24b..aeb690c692ee 100644
--- a/Makefile
+++ b/Makefile
@@ -218,6 +218,9 @@ ifeq ("$(origin M)", "command line")
   KBUILD_EXTMOD := $(M)
 endif
 
+$(if $(word 2, $(KBUILD_EXTMOD)), \
+	$(error building multiple external modules is not supported))
+
 export KBUILD_CHECKSRC KBUILD_EXTMOD
 
 extmod-prefix = $(if $(KBUILD_EXTMOD),$(KBUILD_EXTMOD)/)
diff --git a/scripts/Makefile.modpost b/scripts/Makefile.modpost
index 957eed6a17a5..b79bf0e30d32 100644
--- a/scripts/Makefile.modpost
+++ b/scripts/Makefile.modpost
@@ -44,7 +44,7 @@ include include/config/auto.conf
 include scripts/Kbuild.include
 
 kernelsymfile := $(objtree)/Module.symvers
-modulesymfile := $(firstword $(KBUILD_EXTMOD))/Module.symvers
+modulesymfile := $(KBUILD_EXTMOD)/Module.symvers
 
 MODPOST = scripts/mod/modpost								\
 	$(if $(CONFIG_MODVERSIONS),-m)							\
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH 10/29] modpost: move -T option close to the modpost command
  2020-05-17  9:48 [PATCH 00/29] modpost: various fixes, cleanups, optimizations Masahiro Yamada
                   ` (8 preceding siblings ...)
  2020-05-17  9:48 ` [PATCH 09/29] kbuild: disallow multi-word in M= or KBUILD_EXTMOD Masahiro Yamada
@ 2020-05-17  9:48 ` Masahiro Yamada
  2020-05-17  9:48 ` [PATCH 11/29] modpost: pass -N option only for modules modpost Masahiro Yamada
                   ` (18 subsequent siblings)
  28 siblings, 0 replies; 36+ messages in thread
From: Masahiro Yamada @ 2020-05-17  9:48 UTC (permalink / raw)
  To: linux-kbuild; +Cc: Jessica Yu, Masahiro Yamada, Michal Marek, linux-kernel

The '-T -' option reads the file list from stdin.

It is clearer to put it close to the piped command.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

 scripts/Makefile.modpost | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/scripts/Makefile.modpost b/scripts/Makefile.modpost
index b79bf0e30d32..da7730a43819 100644
--- a/scripts/Makefile.modpost
+++ b/scripts/Makefile.modpost
@@ -66,7 +66,7 @@ __modpost:
 
 else
 
-MODPOST += $(subst -i,-n,$(filter -i,$(MAKEFLAGS))) -s -T - \
+MODPOST += $(subst -i,-n,$(filter -i,$(MAKEFLAGS))) -s \
 	$(if $(KBUILD_NSDEPS),-d $(MODULES_NSDEPS))
 
 ifeq ($(KBUILD_EXTMOD),)
@@ -88,7 +88,7 @@ modules := $(sort $(shell cat $(MODORDER)))
 # Read out modules.order instead of expanding $(modules) to pass in modpost.
 # Otherwise, allmodconfig would fail with "Argument list too long".
 quiet_cmd_modpost = MODPOST $(words $(modules)) modules
-      cmd_modpost = sed 's/ko$$/o/' $(MODORDER) | $(MODPOST)
+      cmd_modpost = sed 's/ko$$/o/' $(MODORDER) | $(MODPOST) -T -
 
 __modpost:
 	$(call cmd,modpost)
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH 11/29] modpost: pass -N option only for modules modpost
  2020-05-17  9:48 [PATCH 00/29] modpost: various fixes, cleanups, optimizations Masahiro Yamada
                   ` (9 preceding siblings ...)
  2020-05-17  9:48 ` [PATCH 10/29] modpost: move -T option close to the modpost command Masahiro Yamada
@ 2020-05-17  9:48 ` Masahiro Yamada
  2020-05-17  9:48 ` [PATCH 12/29] modpost: move external module options Masahiro Yamada
                   ` (17 subsequent siblings)
  28 siblings, 0 replies; 36+ messages in thread
From: Masahiro Yamada @ 2020-05-17  9:48 UTC (permalink / raw)
  To: linux-kbuild; +Cc: Jessica Yu, Masahiro Yamada, Michal Marek, linux-kernel

The built-in only code is not required to have MODULE_IMPORT_NS() to
use symbols. So, the namespace is not checked for vmlinux(.o).

Do not pass the meaningless -N option to the first pass of modpost.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

 scripts/Makefile.modpost | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/scripts/Makefile.modpost b/scripts/Makefile.modpost
index da7730a43819..bc5561aedb24 100644
--- a/scripts/Makefile.modpost
+++ b/scripts/Makefile.modpost
@@ -53,7 +53,6 @@ MODPOST = scripts/mod/modpost								\
 	$(if $(KBUILD_EXTMOD),$(addprefix -e ,$(KBUILD_EXTRA_SYMBOLS)))			\
 	$(if $(KBUILD_EXTMOD),-o $(modulesymfile))					\
 	$(if $(CONFIG_SECTION_MISMATCH_WARN_ONLY),,-E)					\
-	$(if $(CONFIG_MODULE_ALLOW_MISSING_NAMESPACE_IMPORTS)$(KBUILD_NSDEPS),-N) 	\
 	$(if $(KBUILD_MODPOST_WARN),-w)
 
 ifdef MODPOST_VMLINUX
@@ -66,7 +65,9 @@ __modpost:
 
 else
 
+# modpost options for modules (both in-kernel and external)
 MODPOST += $(subst -i,-n,$(filter -i,$(MAKEFLAGS))) -s \
+	$(if $(CONFIG_MODULE_ALLOW_MISSING_NAMESPACE_IMPORTS)$(KBUILD_NSDEPS),-N) \
 	$(if $(KBUILD_NSDEPS),-d $(MODULES_NSDEPS))
 
 ifeq ($(KBUILD_EXTMOD),)
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH 12/29] modpost: move external module options
  2020-05-17  9:48 [PATCH 00/29] modpost: various fixes, cleanups, optimizations Masahiro Yamada
                   ` (10 preceding siblings ...)
  2020-05-17  9:48 ` [PATCH 11/29] modpost: pass -N option only for modules modpost Masahiro Yamada
@ 2020-05-17  9:48 ` Masahiro Yamada
  2020-05-17  9:48 ` [PATCH 13/29] modpost: load KBUILD_EXTRA_SYMBOLS files in order Masahiro Yamada
                   ` (16 subsequent siblings)
  28 siblings, 0 replies; 36+ messages in thread
From: Masahiro Yamada @ 2020-05-17  9:48 UTC (permalink / raw)
  To: linux-kbuild; +Cc: Jessica Yu, Masahiro Yamada, Michal Marek, linux-kernel

Separate out the external-only code for readability.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

 scripts/Makefile.modpost | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/scripts/Makefile.modpost b/scripts/Makefile.modpost
index bc5561aedb24..8321068abb31 100644
--- a/scripts/Makefile.modpost
+++ b/scripts/Makefile.modpost
@@ -44,14 +44,11 @@ include include/config/auto.conf
 include scripts/Kbuild.include
 
 kernelsymfile := $(objtree)/Module.symvers
-modulesymfile := $(KBUILD_EXTMOD)/Module.symvers
 
 MODPOST = scripts/mod/modpost								\
 	$(if $(CONFIG_MODVERSIONS),-m)							\
 	$(if $(CONFIG_MODULE_SRCVERSION_ALL),-a)					\
-	$(if $(KBUILD_EXTMOD),-i,-o) $(kernelsymfile)					\
-	$(if $(KBUILD_EXTMOD),$(addprefix -e ,$(KBUILD_EXTRA_SYMBOLS)))			\
-	$(if $(KBUILD_EXTMOD),-o $(modulesymfile))					\
+	$(if $(KBUILD_EXTMOD),,-o $(kernelsymfile))					\
 	$(if $(CONFIG_SECTION_MISMATCH_WARN_ONLY),,-E)					\
 	$(if $(KBUILD_MODPOST_WARN),-w)
 
@@ -81,6 +78,13 @@ src := $(obj)
 # Include the module's Makefile to find KBUILD_EXTRA_SYMBOLS
 include $(if $(wildcard $(KBUILD_EXTMOD)/Kbuild), \
              $(KBUILD_EXTMOD)/Kbuild, $(KBUILD_EXTMOD)/Makefile)
+
+# modpost options for external modules
+MODPOST += \
+	-i Module.symvers \
+	$(addprefix -e ,$(KBUILD_EXTRA_SYMBOLS)) \
+	-o $(KBUILD_EXTMOD)/Module.symvers
+
 endif
 
 # find all modules listed in modules.order
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH 13/29] modpost: load KBUILD_EXTRA_SYMBOLS files in order
  2020-05-17  9:48 [PATCH 00/29] modpost: various fixes, cleanups, optimizations Masahiro Yamada
                   ` (11 preceding siblings ...)
  2020-05-17  9:48 ` [PATCH 12/29] modpost: move external module options Masahiro Yamada
@ 2020-05-17  9:48 ` Masahiro Yamada
  2020-05-17  9:48 ` [PATCH 14/29] modpost: track if the symbol origin is a dump file or ELF object Masahiro Yamada
                   ` (15 subsequent siblings)
  28 siblings, 0 replies; 36+ messages in thread
From: Masahiro Yamada @ 2020-05-17  9:48 UTC (permalink / raw)
  To: linux-kbuild; +Cc: Jessica Yu, Masahiro Yamada, Michal Marek, linux-kernel

Currently, modpost reads extra symbol dump files in the reverse order.
If '-e foo -e bar' is given, modpost reads bar, foo, in this order.

This is probably not a big deal, but there is no good reason to reverse
the order. Read files in the given order.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

 scripts/mod/modpost.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index cd3cb781a2e7..dc8f15f10da0 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -2559,8 +2559,8 @@ int main(int argc, char **argv)
 	int opt;
 	int err;
 	int n;
-	struct ext_sym_list *extsym_iter;
 	struct ext_sym_list *extsym_start = NULL;
+	struct ext_sym_list **extsym_iter = &extsym_start;
 
 	while ((opt = getopt(argc, argv, "i:e:mnsT:o:awENd:")) != -1) {
 		switch (opt) {
@@ -2570,11 +2570,9 @@ int main(int argc, char **argv)
 			break;
 		case 'e':
 			external_module = 1;
-			extsym_iter =
-			   NOFAIL(malloc(sizeof(*extsym_iter)));
-			extsym_iter->next = extsym_start;
-			extsym_iter->file = optarg;
-			extsym_start = extsym_iter;
+			*extsym_iter = NOFAIL(calloc(1, sizeof(**extsym_iter)));
+			(*extsym_iter)->file = optarg;
+			extsym_iter = &(*extsym_iter)->next;
 			break;
 		case 'm':
 			modversions = 1;
@@ -2614,10 +2612,12 @@ int main(int argc, char **argv)
 	if (kernel_read)
 		read_dump(kernel_read, 1);
 	while (extsym_start) {
+		struct ext_sym_list *tmp;
+
 		read_dump(extsym_start->file, 0);
-		extsym_iter = extsym_start->next;
+		tmp = extsym_start->next;
 		free(extsym_start);
-		extsym_start = extsym_iter;
+		extsym_start = tmp;
 	}
 
 	while (optind < argc)
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH 14/29] modpost: track if the symbol origin is a dump file or ELF object
  2020-05-17  9:48 [PATCH 00/29] modpost: various fixes, cleanups, optimizations Masahiro Yamada
                   ` (12 preceding siblings ...)
  2020-05-17  9:48 ` [PATCH 13/29] modpost: load KBUILD_EXTRA_SYMBOLS files in order Masahiro Yamada
@ 2020-05-17  9:48 ` Masahiro Yamada
  2020-05-17  9:48 ` [PATCH 15/29] modpost: allow to pass -i option multiple times remove -e option Masahiro Yamada
                   ` (14 subsequent siblings)
  28 siblings, 0 replies; 36+ messages in thread
From: Masahiro Yamada @ 2020-05-17  9:48 UTC (permalink / raw)
  To: linux-kbuild; +Cc: Jessica Yu, Masahiro Yamada, Michal Marek, linux-kernel

The meaning of sym->kernel is obscure; it is set for in-kernel symbols
loaded from Modules.symver. This happens only when we are building
external modules, and it is used to determine whether to dump symbols
to $(KBUILD_EXTMOD)/Modules.symver

It is clearer to remember whether the symbol or module came from a dump
file or ELF object.

This changes the KBUILD_EXTRA_SYMBOLS behavior. Previously, symbols
loaded from KBUILD_EXTRA_SYMBOLS are accumulated into the current
$(KBUILD_EXTMOD)/Modules.symver

Going forward, they will be only used to check symbol references, but
not dumped into the current $(KBUILD_EXTMOD)/Modules.symver. I believe
this makes more sense.

sym->vmlinux will have no user. Remove it too.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

 scripts/mod/modpost.c | 15 +++++----------
 scripts/mod/modpost.h |  1 +
 2 files changed, 6 insertions(+), 10 deletions(-)

diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index dc8f15f10da0..340b88647e94 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -197,9 +197,6 @@ struct symbol {
 	int crc_valid;
 	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
-				    *  (only for external modules) **/
 	unsigned int is_static:1;  /* 1 if symbol is not global */
 	enum export  export;       /* Type of export */
 	char name[];
@@ -431,8 +428,6 @@ static struct symbol *sym_add_exported(const char *name, struct module *mod,
 	}
 
 	s->module = mod;
-	s->vmlinux   = is_vmlinux(mod->name);
-	s->kernel    = 0;
 	s->export    = export;
 	return s;
 }
@@ -2430,7 +2425,7 @@ static void write_if_changed(struct buffer *b, const char *fname)
 /* parse Module.symvers file. line format:
  * 0x12345678<tab>symbol<tab>module<tab>export<tab>namespace
  **/
-static void read_dump(const char *fname, unsigned int kernel)
+static void read_dump(const char *fname)
 {
 	char *buf, *pos, *line;
 
@@ -2469,9 +2464,9 @@ static void read_dump(const char *fname, unsigned int kernel)
 				have_vmlinux = 1;
 			mod = new_module(modname);
 			mod->skip = 1;
+			mod->from_dump = 1;
 		}
 		s = sym_add_exported(symname, mod, export_no(export));
-		s->kernel    = kernel;
 		s->is_static = 0;
 		sym_set_crc(symname, crc);
 		sym_update_namespace(symname, namespace);
@@ -2491,7 +2486,7 @@ static int dump_sym(struct symbol *sym)
 {
 	if (!external_module)
 		return 1;
-	if (sym->vmlinux || sym->kernel)
+	if (sym->module->from_dump)
 		return 0;
 	return 1;
 }
@@ -2610,11 +2605,11 @@ int main(int argc, char **argv)
 	}
 
 	if (kernel_read)
-		read_dump(kernel_read, 1);
+		read_dump(kernel_read);
 	while (extsym_start) {
 		struct ext_sym_list *tmp;
 
-		read_dump(extsym_start->file, 0);
+		read_dump(extsym_start->file);
 		tmp = extsym_start->next;
 		free(extsym_start);
 		extsym_start = tmp;
diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
index 232a0e11fcaa..aaf3c4ad5d60 100644
--- a/scripts/mod/modpost.h
+++ b/scripts/mod/modpost.h
@@ -119,6 +119,7 @@ struct module {
 	const char *name;
 	int gpl_compatible;
 	struct symbol *unres;
+	int from_dump;  /* 1 if module was loaded from *.symver */
 	int seen;
 	int skip;
 	int has_init;
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH 15/29] modpost: allow to pass -i option multiple times remove -e option
  2020-05-17  9:48 [PATCH 00/29] modpost: various fixes, cleanups, optimizations Masahiro Yamada
                   ` (13 preceding siblings ...)
  2020-05-17  9:48 ` [PATCH 14/29] modpost: track if the symbol origin is a dump file or ELF object Masahiro Yamada
@ 2020-05-17  9:48 ` Masahiro Yamada
  2020-05-17  9:48 ` [PATCH 16/29] modpost: rename ext_sym_list to dump_list Masahiro Yamada
                   ` (13 subsequent siblings)
  28 siblings, 0 replies; 36+ messages in thread
From: Masahiro Yamada @ 2020-05-17  9:48 UTC (permalink / raw)
  To: linux-kbuild; +Cc: Jessica Yu, Masahiro Yamada, Michal Marek, linux-kernel

Now that there is no difference in the functionality of -i and -e,
they can be unified.

Make modpost accept the -i option multiple times, then remove -e.

I will reuse -e for a different purpose.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

 scripts/Makefile.modpost | 2 +-
 scripts/mod/modpost.c    | 9 +--------
 2 files changed, 2 insertions(+), 9 deletions(-)

diff --git a/scripts/Makefile.modpost b/scripts/Makefile.modpost
index 8321068abb31..a316095c843c 100644
--- a/scripts/Makefile.modpost
+++ b/scripts/Makefile.modpost
@@ -82,7 +82,7 @@ include $(if $(wildcard $(KBUILD_EXTMOD)/Kbuild), \
 # modpost options for external modules
 MODPOST += \
 	-i Module.symvers \
-	$(addprefix -e ,$(KBUILD_EXTRA_SYMBOLS)) \
+	$(addprefix -i ,$(KBUILD_EXTRA_SYMBOLS)) \
 	-o $(KBUILD_EXTMOD)/Module.symvers
 
 endif
diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index 340b88647e94..d3141b217b57 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -2548,7 +2548,6 @@ int main(int argc, char **argv)
 {
 	struct module *mod;
 	struct buffer buf = { };
-	char *kernel_read = NULL;
 	char *missing_namespace_deps = NULL;
 	char *dump_write = NULL, *files_source = NULL;
 	int opt;
@@ -2557,13 +2556,9 @@ int main(int argc, char **argv)
 	struct ext_sym_list *extsym_start = NULL;
 	struct ext_sym_list **extsym_iter = &extsym_start;
 
-	while ((opt = getopt(argc, argv, "i:e:mnsT:o:awENd:")) != -1) {
+	while ((opt = getopt(argc, argv, "i:mnsT:o:awENd:")) != -1) {
 		switch (opt) {
 		case 'i':
-			kernel_read = optarg;
-			external_module = 1;
-			break;
-		case 'e':
 			external_module = 1;
 			*extsym_iter = NOFAIL(calloc(1, sizeof(**extsym_iter)));
 			(*extsym_iter)->file = optarg;
@@ -2604,8 +2599,6 @@ int main(int argc, char **argv)
 		}
 	}
 
-	if (kernel_read)
-		read_dump(kernel_read);
 	while (extsym_start) {
 		struct ext_sym_list *tmp;
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH 16/29] modpost: rename ext_sym_list to dump_list
  2020-05-17  9:48 [PATCH 00/29] modpost: various fixes, cleanups, optimizations Masahiro Yamada
                   ` (14 preceding siblings ...)
  2020-05-17  9:48 ` [PATCH 15/29] modpost: allow to pass -i option multiple times remove -e option Masahiro Yamada
@ 2020-05-17  9:48 ` Masahiro Yamada
  2020-05-17  9:48 ` [PATCH 17/29] modpost: re-add -e to set external_module flag Masahiro Yamada
                   ` (12 subsequent siblings)
  28 siblings, 0 replies; 36+ messages in thread
From: Masahiro Yamada @ 2020-05-17  9:48 UTC (permalink / raw)
  To: linux-kbuild; +Cc: Jessica Yu, Masahiro Yamada, Michal Marek, linux-kernel

The -i option is used to include Modules.symver as well as files from
$(KBUILD_EXTRA_SYMBOLS).

Make the struct and variable names more generic.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

 scripts/mod/modpost.c | 27 ++++++++++++++-------------
 1 file changed, 14 insertions(+), 13 deletions(-)

diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index d3141b217b57..a5bac158d344 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -2539,8 +2539,8 @@ static void write_namespace_deps_files(const char *fname)
 	free(ns_deps_buf.p);
 }
 
-struct ext_sym_list {
-	struct ext_sym_list *next;
+struct dump_list {
+	struct dump_list *next;
 	const char *file;
 };
 
@@ -2553,16 +2553,17 @@ int main(int argc, char **argv)
 	int opt;
 	int err;
 	int n;
-	struct ext_sym_list *extsym_start = NULL;
-	struct ext_sym_list **extsym_iter = &extsym_start;
+	struct dump_list *dump_read_start = NULL;
+	struct dump_list **dump_read_iter = &dump_read_start;
 
 	while ((opt = getopt(argc, argv, "i:mnsT:o:awENd:")) != -1) {
 		switch (opt) {
 		case 'i':
 			external_module = 1;
-			*extsym_iter = NOFAIL(calloc(1, sizeof(**extsym_iter)));
-			(*extsym_iter)->file = optarg;
-			extsym_iter = &(*extsym_iter)->next;
+			*dump_read_iter =
+				NOFAIL(calloc(1, sizeof(**dump_read_iter)));
+			(*dump_read_iter)->file = optarg;
+			dump_read_iter = &(*dump_read_iter)->next;
 			break;
 		case 'm':
 			modversions = 1;
@@ -2599,13 +2600,13 @@ int main(int argc, char **argv)
 		}
 	}
 
-	while (extsym_start) {
-		struct ext_sym_list *tmp;
+	while (dump_read_start) {
+		struct dump_list *tmp;
 
-		read_dump(extsym_start->file);
-		tmp = extsym_start->next;
-		free(extsym_start);
-		extsym_start = tmp;
+		read_dump(dump_read_start->file);
+		tmp = dump_read_start->next;
+		free(dump_read_start);
+		dump_read_start = tmp;
 	}
 
 	while (optind < argc)
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH 17/29] modpost: re-add -e to set external_module flag
  2020-05-17  9:48 [PATCH 00/29] modpost: various fixes, cleanups, optimizations Masahiro Yamada
                   ` (15 preceding siblings ...)
  2020-05-17  9:48 ` [PATCH 16/29] modpost: rename ext_sym_list to dump_list Masahiro Yamada
@ 2020-05-17  9:48 ` Masahiro Yamada
  2020-05-17  9:48 ` [PATCH 18/29] modpost: show warning if vmlinux is not found when processing modules Masahiro Yamada
                   ` (11 subsequent siblings)
  28 siblings, 0 replies; 36+ messages in thread
From: Masahiro Yamada @ 2020-05-17  9:48 UTC (permalink / raw)
  To: linux-kbuild; +Cc: Jessica Yu, Masahiro Yamada, Michal Marek, linux-kernel

Previously, the -i option had two functions; load a symbol dump file,
and set the external_module flag.

I want to assign a dedicate option for each of them.

Going forward, the -i is used to load a symbol dump file, and the -e
to set the external_module flag.

With this, we will be able to use -i for loading in-kernel symbols.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

 scripts/Makefile.modpost | 1 +
 scripts/mod/modpost.c    | 6 ++++--
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/scripts/Makefile.modpost b/scripts/Makefile.modpost
index a316095c843c..d14143b30b7a 100644
--- a/scripts/Makefile.modpost
+++ b/scripts/Makefile.modpost
@@ -81,6 +81,7 @@ include $(if $(wildcard $(KBUILD_EXTMOD)/Kbuild), \
 
 # modpost options for external modules
 MODPOST += \
+	-e \
 	-i Module.symvers \
 	$(addprefix -i ,$(KBUILD_EXTRA_SYMBOLS)) \
 	-o $(KBUILD_EXTMOD)/Module.symvers
diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index a5bac158d344..b14ecfbfd640 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -2556,10 +2556,12 @@ int main(int argc, char **argv)
 	struct dump_list *dump_read_start = NULL;
 	struct dump_list **dump_read_iter = &dump_read_start;
 
-	while ((opt = getopt(argc, argv, "i:mnsT:o:awENd:")) != -1) {
+	while ((opt = getopt(argc, argv, "ei:mnsT:o:awENd:")) != -1) {
 		switch (opt) {
-		case 'i':
+		case 'e':
 			external_module = 1;
+			break;
+		case 'i':
 			*dump_read_iter =
 				NOFAIL(calloc(1, sizeof(**dump_read_iter)));
 			(*dump_read_iter)->file = optarg;
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH 18/29] modpost: show warning if vmlinux is not found when processing modules
  2020-05-17  9:48 [PATCH 00/29] modpost: various fixes, cleanups, optimizations Masahiro Yamada
                   ` (16 preceding siblings ...)
  2020-05-17  9:48 ` [PATCH 17/29] modpost: re-add -e to set external_module flag Masahiro Yamada
@ 2020-05-17  9:48 ` Masahiro Yamada
  2020-05-17  9:48 ` [PATCH 19/29] modpost: show warning if it fails to read symbol dump file Masahiro Yamada
                   ` (10 subsequent siblings)
  28 siblings, 0 replies; 36+ messages in thread
From: Masahiro Yamada @ 2020-05-17  9:48 UTC (permalink / raw)
  To: linux-kbuild; +Cc: Jessica Yu, Masahiro Yamada, Michal Marek, linux-kernel

check_exports() does not print warnings about unresolved symbols if
vmlinux is missing because there would be too many.

This situation happens when you do 'make modules' from the clean
tree, or compile external modules against a kernel tree that has
not been completely built.

Not checking unresolved symbols is dangerous because you might be
building useless modules. At least it should be noted.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

 scripts/mod/modpost.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index b14ecfbfd640..8150be00e3df 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -2004,8 +2004,6 @@ static void read_symbols(const char *modname)
 
 	mod = new_module(modname);
 
-	/* When there's no vmlinux, don't print warnings about
-	 * unresolved symbols (since there'll be too many ;) */
 	if (is_vmlinux(modname)) {
 		have_vmlinux = 1;
 		mod->skip = 1;
@@ -2617,6 +2615,13 @@ int main(int argc, char **argv)
 	if (files_source)
 		read_symbols_from_files(files_source);
 
+	/*
+	 * When there's no vmlinux, don't print warnings about
+	 * unresolved symbols (since there'll be too many ;)
+	 */
+	if (!have_vmlinux)
+		warn("Symbol info of vmlinux is missing. Unresolved symbol check will be entirely skipped.\n");
+
 	err = 0;
 
 	for (mod = modules; mod; mod = mod->next) {
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH 19/29] modpost: show warning if it fails to read symbol dump file
  2020-05-17  9:48 [PATCH 00/29] modpost: various fixes, cleanups, optimizations Masahiro Yamada
                   ` (17 preceding siblings ...)
  2020-05-17  9:48 ` [PATCH 18/29] modpost: show warning if vmlinux is not found when processing modules Masahiro Yamada
@ 2020-05-17  9:48 ` Masahiro Yamada
  2020-05-17  9:48 ` [PATCH 20/29] modpost: generate vmlinux.symvers and reuse it for the second modpost Masahiro Yamada
                   ` (9 subsequent siblings)
  28 siblings, 0 replies; 36+ messages in thread
From: Masahiro Yamada @ 2020-05-17  9:48 UTC (permalink / raw)
  To: linux-kbuild; +Cc: Jessica Yu, Masahiro Yamada, Michal Marek, linux-kernel

If modpost fails to load a symbol dump file, it cannot check unresolved
symbols, hence module dependency will not be added. Nor CRCs can be added.

Currently, external module builds check only $(objtree)/Module.symvers,
but it should check files specified by KBUILD_EXTRA_SYMBOLS as well.

Print the warnings in modpost. The warning in Makefile is unneeded.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

 Makefile              | 10 +---------
 scripts/mod/modpost.c | 11 +++++++++--
 2 files changed, 10 insertions(+), 11 deletions(-)

diff --git a/Makefile b/Makefile
index aeb690c692ee..27e8a0522a3c 100644
--- a/Makefile
+++ b/Makefile
@@ -1638,17 +1638,9 @@ else # KBUILD_EXTMOD
 # We are always building modules
 KBUILD_MODULES := 1
 
-PHONY += $(objtree)/Module.symvers
-$(objtree)/Module.symvers:
-	@test -e $(objtree)/Module.symvers || ( \
-	echo; \
-	echo "  WARNING: Symbol version dump $(objtree)/Module.symvers"; \
-	echo "           is missing; modules will have no dependencies and modversions."; \
-	echo )
-
 build-dirs := $(KBUILD_EXTMOD)
 PHONY += modules
-modules: descend $(objtree)/Module.symvers
+modules: descend
 	$(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
 
 PHONY += modules_install
diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index 8150be00e3df..ff715623b37e 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -41,6 +41,8 @@ static int sec_mismatch_fatal = 0;
 static int ignore_missing_files;
 /* If set to 1, only warn (instead of error) about missing ns imports */
 static int allow_missing_ns_imports;
+/* Set when at list one dump file is missing */
+static int missing_dump_file;
 
 enum export {
 	export_plain,      export_unused,     export_gpl,
@@ -2428,9 +2430,11 @@ static void read_dump(const char *fname)
 	char *buf, *pos, *line;
 
 	buf = read_text_file(fname);
-	if (!buf)
-		/* No symbol versions, silently ignore */
+	if (!buf) {
+		warn("failed to read '%s'\n", fname);
+		missing_dump_file = 1;
 		return;
+	}
 
 	pos = buf;
 
@@ -2615,6 +2619,9 @@ int main(int argc, char **argv)
 	if (files_source)
 		read_symbols_from_files(files_source);
 
+	if (missing_dump_file)
+		warn("Symbol dump file is missing. Modules may not have dependencies or movversions.\n");
+
 	/*
 	 * When there's no vmlinux, don't print warnings about
 	 * unresolved symbols (since there'll be too many ;)
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH 20/29] modpost: generate vmlinux.symvers and reuse it for the second modpost
  2020-05-17  9:48 [PATCH 00/29] modpost: various fixes, cleanups, optimizations Masahiro Yamada
                   ` (18 preceding siblings ...)
  2020-05-17  9:48 ` [PATCH 19/29] modpost: show warning if it fails to read symbol dump file Masahiro Yamada
@ 2020-05-17  9:48 ` Masahiro Yamada
  2020-05-17  9:48 ` [PATCH 21/29] modpost: remove -s option Masahiro Yamada
                   ` (8 subsequent siblings)
  28 siblings, 0 replies; 36+ messages in thread
From: Masahiro Yamada @ 2020-05-17  9:48 UTC (permalink / raw)
  To: linux-kbuild; +Cc: Jessica Yu, Masahiro Yamada, Michal Marek, linux-kernel

The full build runs modpost twice, first for vmlinux.o and second for
modules.

The first pass dumps all the vmlinux symbols into Module.symvers, but
the second pass parses vmlinux again instead of reusing the dump file,
presumably because it needs to avoid accumulating stale symbols.

Loading symbol info from a dump file is faster than parsing an ELF object.
Besides, modpost deals with various issues to parse vmlinux in the second
pass.

A solution is to make the first pass dumps symbols into a separate file,
vmlinux.symvers. The second pass reads it, and parses module .o files.
The merged symbol information is dumped into Module.symvers as before.

This makes further modpost cleanups possible.

Also, it fixes the problem of 'make vmlinux', which previously overwrote
Module.symvers, throwing away module symbols.

I slightly touched scripts/link-vmlinux.sh so that vmlinux is re-linked
when you cross this commit. Otherwise, vmlinux.symvers would not be
generated.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

 .gitignore               |  1 +
 Makefile                 |  2 +-
 scripts/Makefile.modpost | 11 +++++++----
 scripts/link-vmlinux.sh  |  2 --
 4 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/.gitignore b/.gitignore
index 2258e906f01c..87b9dd8a163b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -56,6 +56,7 @@ modules.order
 /linux
 /vmlinux
 /vmlinux.32
+/vmlinux.symvers
 /vmlinux-gdb.py
 /vmlinuz
 /System.map
diff --git a/Makefile b/Makefile
index 27e8a0522a3c..43988ce4e17e 100644
--- a/Makefile
+++ b/Makefile
@@ -1405,7 +1405,7 @@ endif # CONFIG_MODULES
 # make distclean Remove editor backup files, patch leftover files and the like
 
 # Directories & files removed with 'make clean'
-CLEAN_FILES += include/ksym \
+CLEAN_FILES += include/ksym vmlinux.symvers \
 	       modules.builtin modules.builtin.modinfo modules.nsdeps
 
 # Directories & files removed with 'make mrproper'
diff --git a/scripts/Makefile.modpost b/scripts/Makefile.modpost
index d14143b30b7a..1c597999b6a0 100644
--- a/scripts/Makefile.modpost
+++ b/scripts/Makefile.modpost
@@ -43,17 +43,17 @@ __modpost:
 include include/config/auto.conf
 include scripts/Kbuild.include
 
-kernelsymfile := $(objtree)/Module.symvers
-
 MODPOST = scripts/mod/modpost								\
 	$(if $(CONFIG_MODVERSIONS),-m)							\
 	$(if $(CONFIG_MODULE_SRCVERSION_ALL),-a)					\
-	$(if $(KBUILD_EXTMOD),,-o $(kernelsymfile))					\
 	$(if $(CONFIG_SECTION_MISMATCH_WARN_ONLY),,-E)					\
 	$(if $(KBUILD_MODPOST_WARN),-w)
 
 ifdef MODPOST_VMLINUX
 
+# modpost options for vmlinux.o
+MODPOST += -o vmlinux.symvers
+
 quiet_cmd_modpost = MODPOST vmlinux.o
       cmd_modpost = $(MODPOST) vmlinux.o
 
@@ -68,7 +68,10 @@ MODPOST += $(subst -i,-n,$(filter -i,$(MAKEFLAGS))) -s \
 	$(if $(KBUILD_NSDEPS),-d $(MODULES_NSDEPS))
 
 ifeq ($(KBUILD_EXTMOD),)
-MODPOST += $(wildcard vmlinux)
+
+# modpost options for in-kernel modules
+MODPOST += -i vmlinux.symvers -o Module.symvers
+
 else
 
 # set src + obj - they may be used in the modules's Makefile
diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
index d09ab4afbda4..d5af6be50b50 100755
--- a/scripts/link-vmlinux.sh
+++ b/scripts/link-vmlinux.sh
@@ -218,8 +218,6 @@ on_signals()
 }
 trap on_signals HUP INT QUIT TERM
 
-#
-#
 # Use "make V=1" to debug this script
 case "${KBUILD_VERBOSE}" in
 *1*)
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH 21/29] modpost: remove -s option
  2020-05-17  9:48 [PATCH 00/29] modpost: various fixes, cleanups, optimizations Masahiro Yamada
                   ` (19 preceding siblings ...)
  2020-05-17  9:48 ` [PATCH 20/29] modpost: generate vmlinux.symvers and reuse it for the second modpost Masahiro Yamada
@ 2020-05-17  9:48 ` Masahiro Yamada
  2020-05-17  9:48 ` [PATCH 22/29] modpost: remove mod->is_dot_o struct member Masahiro Yamada
                   ` (7 subsequent siblings)
  28 siblings, 0 replies; 36+ messages in thread
From: Masahiro Yamada @ 2020-05-17  9:48 UTC (permalink / raw)
  To: linux-kbuild; +Cc: Jessica Yu, Masahiro Yamada, Michal Marek, linux-kernel

The -s option was added by commit 8d8d8289df65 ("kbuild: do not do
section mismatch checks on vmlinux in 2nd pass").

Now that the second pass does not parse vmlinux, this option is
unneeded.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

 scripts/Makefile.modpost |  2 +-
 scripts/mod/modpost.c    | 10 ++--------
 2 files changed, 3 insertions(+), 9 deletions(-)

diff --git a/scripts/Makefile.modpost b/scripts/Makefile.modpost
index 1c597999b6a0..67db4bba2d45 100644
--- a/scripts/Makefile.modpost
+++ b/scripts/Makefile.modpost
@@ -63,7 +63,7 @@ __modpost:
 else
 
 # modpost options for modules (both in-kernel and external)
-MODPOST += $(subst -i,-n,$(filter -i,$(MAKEFLAGS))) -s \
+MODPOST += $(subst -i,-n,$(filter -i,$(MAKEFLAGS))) \
 	$(if $(CONFIG_MODULE_ALLOW_MISSING_NAMESPACE_IMPORTS)$(KBUILD_NSDEPS),-N) \
 	$(if $(KBUILD_NSDEPS),-d $(MODULES_NSDEPS))
 
diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index ff715623b37e..c6e1a349421c 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -30,8 +30,6 @@ static int have_vmlinux = 0;
 static int all_versions = 0;
 /* If we are modposting external module set to 1 */
 static int external_module = 0;
-/* Warn about section mismatch in vmlinux if set to 1 */
-static int vmlinux_section_warnings = 1;
 /* Only warn about unresolved symbols */
 static int warn_unresolved = 0;
 /* How a symbol is exported */
@@ -2068,8 +2066,7 @@ static void read_symbols(const char *modname)
 		}
 	}
 
-	if (!is_vmlinux(modname) || vmlinux_section_warnings)
-		check_sec_ref(mod, modname, &info);
+	check_sec_ref(mod, modname, &info);
 
 	if (!is_vmlinux(modname)) {
 		version = get_modinfo(&info, "version");
@@ -2558,7 +2555,7 @@ int main(int argc, char **argv)
 	struct dump_list *dump_read_start = NULL;
 	struct dump_list **dump_read_iter = &dump_read_start;
 
-	while ((opt = getopt(argc, argv, "ei:mnsT:o:awENd:")) != -1) {
+	while ((opt = getopt(argc, argv, "ei:mnT:o:awENd:")) != -1) {
 		switch (opt) {
 		case 'e':
 			external_module = 1;
@@ -2581,9 +2578,6 @@ int main(int argc, char **argv)
 		case 'a':
 			all_versions = 1;
 			break;
-		case 's':
-			vmlinux_section_warnings = 0;
-			break;
 		case 'T':
 			files_source = optarg;
 			break;
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH 22/29] modpost: remove mod->is_dot_o struct member
  2020-05-17  9:48 [PATCH 00/29] modpost: various fixes, cleanups, optimizations Masahiro Yamada
                   ` (20 preceding siblings ...)
  2020-05-17  9:48 ` [PATCH 21/29] modpost: remove -s option Masahiro Yamada
@ 2020-05-17  9:48 ` Masahiro Yamada
  2020-05-17  9:48 ` [PATCH 23/29] modpost: remove is_vmlinux() call in check_for_{gpl_usage,unused}() Masahiro Yamada
                   ` (6 subsequent siblings)
  28 siblings, 0 replies; 36+ messages in thread
From: Masahiro Yamada @ 2020-05-17  9:48 UTC (permalink / raw)
  To: linux-kbuild; +Cc: Jessica Yu, Masahiro Yamada, Michal Marek, linux-kernel

Previously, there were two cases where mod->is_dot_o is unset:

[1] the executable 'vmlinux' in the second pass of modpost
[2] modules loaded by read_dump()

I think [1] was intended usage to distinguish 'vmlinux.o' and 'vmlinux'.
Now that modpost does not parse the executable 'vmlinux', this case
does not happen.

[2] is obscure, maybe a bug. Module.symver stores module paths without
extension. So, none of modules loaded by read_dump() has the .o suffix,
and new_module() unsets ->is_dot_o. Anyway, it is not a big deal because
handle_symbol() is not called for the case.

To sum up, all the parsed ELF files are .o files.

mod->is_dot_o is unneeded.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

 scripts/mod/modpost.c | 14 ++------------
 scripts/mod/modpost.h |  1 -
 2 files changed, 2 insertions(+), 13 deletions(-)

diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index c6e1a349421c..7136bfc8f46a 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -171,10 +171,8 @@ static struct module *new_module(const char *modname)
 	p = NOFAIL(strdup(modname));
 
 	/* strip trailing .o */
-	if (strends(p, ".o")) {
+	if (strends(p, ".o"))
 		p[strlen(p) - 2] = '\0';
-		mod->is_dot_o = 1;
-	}
 
 	/* add to list */
 	mod->name = p;
@@ -702,8 +700,7 @@ static void handle_symbol(struct module *mod, struct elf_info *info,
 	enum export export;
 	const char *name;
 
-	if ((!is_vmlinux(mod->name) || mod->is_dot_o) &&
-	    strstarts(symname, "__ksymtab"))
+	if (strstarts(symname, "__ksymtab"))
 		export = export_from_secname(info, get_secindex(info, sym));
 	else
 		export = export_from_sec(info, get_secindex(info, sym));
@@ -2661,13 +2658,6 @@ int main(int argc, char **argv)
 		struct symbol *s;
 
 		for (s = symbolhash[n]; s; s = s->next) {
-			/*
-			 * Do not check "vmlinux". This avoids the same warnings
-			 * shown twice, and false-positives for ARCH=um.
-			 */
-			if (is_vmlinux(s->module->name) && !s->module->is_dot_o)
-				continue;
-
 			if (s->is_static)
 				warn("\"%s\" [%s] is a static %s\n",
 				     s->name, s->module->name,
diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
index aaf3c4ad5d60..554f02c69ac2 100644
--- a/scripts/mod/modpost.h
+++ b/scripts/mod/modpost.h
@@ -126,7 +126,6 @@ struct module {
 	int has_cleanup;
 	struct buffer dev_table_buf;
 	char	     srcversion[25];
-	int is_dot_o;
 	// Missing namespace dependencies
 	struct namespace_list *missing_namespaces;
 	// Actual imported namespaces
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH 23/29] modpost: remove is_vmlinux() call in check_for_{gpl_usage,unused}()
  2020-05-17  9:48 [PATCH 00/29] modpost: various fixes, cleanups, optimizations Masahiro Yamada
                   ` (21 preceding siblings ...)
  2020-05-17  9:48 ` [PATCH 22/29] modpost: remove mod->is_dot_o struct member Masahiro Yamada
@ 2020-05-17  9:48 ` Masahiro Yamada
  2020-05-17  9:48 ` [PATCH 24/29] modpost: add mod->is_vmlinux struct member Masahiro Yamada
                   ` (5 subsequent siblings)
  28 siblings, 0 replies; 36+ messages in thread
From: Masahiro Yamada @ 2020-05-17  9:48 UTC (permalink / raw)
  To: linux-kbuild; +Cc: Jessica Yu, Masahiro Yamada, Michal Marek, linux-kernel

check_exports() is never called for vmlinux because mod->skip is set
for vmlinux.

Hence, check_for_gpl_usage() and check_for_unused() are not called
for vmlinux, either. is_vmlinux() is always false here.

Remove the is_vmlinux() calls, and hard-code the ".ko" suffix.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

 scripts/mod/modpost.c | 20 ++++++++------------
 1 file changed, 8 insertions(+), 12 deletions(-)

diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index 7136bfc8f46a..4155669a92bd 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -2134,20 +2134,18 @@ void buf_write(struct buffer *buf, const char *s, int len)
 
 static void check_for_gpl_usage(enum export exp, const char *m, const char *s)
 {
-	const char *e = is_vmlinux(m) ?"":".ko";
-
 	switch (exp) {
 	case export_gpl:
-		fatal("GPL-incompatible module %s%s "
-		      "uses GPL-only symbol '%s'\n", m, e, s);
+		fatal("GPL-incompatible module %s.ko uses GPL-only symbol '%s'\n",
+		      m, s);
 		break;
 	case export_unused_gpl:
-		fatal("GPL-incompatible module %s%s "
-		      "uses GPL-only symbol marked UNUSED '%s'\n", m, e, s);
+		fatal("GPL-incompatible module %s.ko uses GPL-only symbol marked UNUSED '%s'\n",
+		      m, s);
 		break;
 	case export_gpl_future:
-		warn("GPL-incompatible module %s%s "
-		      "uses future GPL-only symbol '%s'\n", m, e, s);
+		warn("GPL-incompatible module %s.ko uses future GPL-only symbol '%s'\n",
+		     m, s);
 		break;
 	case export_plain:
 	case export_unused:
@@ -2159,13 +2157,11 @@ static void check_for_gpl_usage(enum export exp, const char *m, const char *s)
 
 static void check_for_unused(enum export exp, const char *m, const char *s)
 {
-	const char *e = is_vmlinux(m) ?"":".ko";
-
 	switch (exp) {
 	case export_unused:
 	case export_unused_gpl:
-		warn("module %s%s "
-		      "uses symbol '%s' marked UNUSED\n", m, e, s);
+		warn("module %s.ko uses symbol '%s' marked UNUSED\n",
+		     m, s);
 		break;
 	default:
 		/* ignore */
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH 24/29] modpost: add mod->is_vmlinux struct member
  2020-05-17  9:48 [PATCH 00/29] modpost: various fixes, cleanups, optimizations Masahiro Yamada
                   ` (22 preceding siblings ...)
  2020-05-17  9:48 ` [PATCH 23/29] modpost: remove is_vmlinux() call in check_for_{gpl_usage,unused}() Masahiro Yamada
@ 2020-05-17  9:48 ` Masahiro Yamada
  2020-05-17  9:48 ` [PATCH 25/29] modpost: remove mod->skip " Masahiro Yamada
                   ` (4 subsequent siblings)
  28 siblings, 0 replies; 36+ messages in thread
From: Masahiro Yamada @ 2020-05-17  9:48 UTC (permalink / raw)
  To: linux-kbuild; +Cc: Jessica Yu, Masahiro Yamada, Michal Marek, linux-kernel

is_vmlinux() is called in several places to check whether the current
module is vmlinux or not.

It is faster and clearer to check mod->is_vmlinux flag.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

 scripts/mod/modpost.c | 19 ++++++++++---------
 scripts/mod/modpost.h |  1 +
 2 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index 4155669a92bd..0df0fc82412d 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -176,6 +176,7 @@ static struct module *new_module(const char *modname)
 
 	/* add to list */
 	mod->name = p;
+	mod->is_vmlinux = is_vmlinux(modname);
 	mod->gpl_compatible = -1;
 	mod->next = modules;
 	modules = mod;
@@ -417,11 +418,11 @@ static struct symbol *sym_add_exported(const char *name, struct module *mod,
 
 	if (!s) {
 		s = new_symbol(name, mod, export);
-	} else if (!external_module || is_vmlinux(s->module->name) ||
+	} else if (!external_module || s->module->is_vmlinux ||
 		   s->module == mod) {
 		warn("%s: '%s' exported twice. Previous export was in %s%s\n",
 		     mod->name, name, s->module->name,
-		     is_vmlinux(s->module->name) ? "" : ".ko");
+		     s->module->is_vmlinux ? "" : ".ko");
 		return s;
 	}
 
@@ -678,7 +679,7 @@ static void handle_modversion(const struct module *mod,
 
 	if (sym->st_shndx == SHN_UNDEF) {
 		warn("EXPORT symbol \"%s\" [%s%s] version generation failed, symbol will not be versioned.\n",
-		     symname, mod->name, is_vmlinux(mod->name) ? "":".ko");
+		     symname, mod->name, mod->is_vmlinux ? "" : ".ko");
 		return;
 	}
 
@@ -2001,12 +2002,12 @@ static void read_symbols(const char *modname)
 
 	mod = new_module(modname);
 
-	if (is_vmlinux(modname)) {
+	if (mod->is_vmlinux) {
 		have_vmlinux = 1;
 		mod->skip = 1;
 	}
 
-	if (!is_vmlinux(modname)) {
+	if (!mod->is_vmlinux) {
 		license = get_modinfo(&info, "license");
 		if (!license)
 			warn("missing MODULE_LICENSE() in %s\n", modname);
@@ -2065,7 +2066,7 @@ static void read_symbols(const char *modname)
 
 	check_sec_ref(mod, modname, &info);
 
-	if (!is_vmlinux(modname)) {
+	if (!mod->is_vmlinux) {
 		version = get_modinfo(&info, "version");
 		if (version || all_versions)
 			get_src_version(modname, mod->srcversion,
@@ -2335,7 +2336,7 @@ static void add_depends(struct buffer *b, struct module *mod)
 	/* Clear ->seen flag of modules that own symbols needed by this. */
 	for (s = mod->unres; s; s = s->next)
 		if (s->module)
-			s->module->seen = is_vmlinux(s->module->name);
+			s->module->seen = s->module->is_vmlinux;
 
 	buf_printf(b, "\n");
 	buf_printf(b, "MODULE_INFO(depends, \"");
@@ -2452,9 +2453,9 @@ static void read_dump(const char *fname)
 			goto fail;
 		mod = find_module(modname);
 		if (!mod) {
-			if (is_vmlinux(modname))
-				have_vmlinux = 1;
 			mod = new_module(modname);
+			if (mod->is_vmlinux)
+				have_vmlinux = 1;
 			mod->skip = 1;
 			mod->from_dump = 1;
 		}
diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
index 554f02c69ac2..ec717ab20b98 100644
--- a/scripts/mod/modpost.h
+++ b/scripts/mod/modpost.h
@@ -120,6 +120,7 @@ struct module {
 	int gpl_compatible;
 	struct symbol *unres;
 	int from_dump;  /* 1 if module was loaded from *.symver */
+	int is_vmlinux;
 	int seen;
 	int skip;
 	int has_init;
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH 25/29] modpost: remove mod->skip struct member
  2020-05-17  9:48 [PATCH 00/29] modpost: various fixes, cleanups, optimizations Masahiro Yamada
                   ` (23 preceding siblings ...)
  2020-05-17  9:48 ` [PATCH 24/29] modpost: add mod->is_vmlinux struct member Masahiro Yamada
@ 2020-05-17  9:48 ` Masahiro Yamada
  2020-05-17  9:48 ` [PATCH 26/29] modpost: set have_vmlinux in new_module() Masahiro Yamada
                   ` (3 subsequent siblings)
  28 siblings, 0 replies; 36+ messages in thread
From: Masahiro Yamada @ 2020-05-17  9:48 UTC (permalink / raw)
  To: linux-kbuild; +Cc: Jessica Yu, Masahiro Yamada, Michal Marek, linux-kernel

The meaning of 'skip' is obscure since it does not explain
"what to skip".

mod->skip is set when it is vmlinux or the module info came from
a dump file.

So, mod->skip is equivalent to (mod->is_vmlinux || mod->from_dump).

For the check in write_namespace_deps_files(), mod->is_vmlinux is
unneeded because the -d option is not passed in the first pass of
modpost.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

 scripts/mod/modpost.c | 9 +++------
 scripts/mod/modpost.h | 1 -
 2 files changed, 3 insertions(+), 7 deletions(-)

diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index 0df0fc82412d..003b6fb2303c 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -2002,10 +2002,8 @@ static void read_symbols(const char *modname)
 
 	mod = new_module(modname);
 
-	if (mod->is_vmlinux) {
+	if (mod->is_vmlinux)
 		have_vmlinux = 1;
-		mod->skip = 1;
-	}
 
 	if (!mod->is_vmlinux) {
 		license = get_modinfo(&info, "license");
@@ -2456,7 +2454,6 @@ static void read_dump(const char *fname)
 			mod = new_module(modname);
 			if (mod->is_vmlinux)
 				have_vmlinux = 1;
-			mod->skip = 1;
 			mod->from_dump = 1;
 		}
 		s = sym_add_exported(symname, mod, export_no(export));
@@ -2517,7 +2514,7 @@ static void write_namespace_deps_files(const char *fname)
 
 	for (mod = modules; mod; mod = mod->next) {
 
-		if (mod->skip || !mod->missing_namespaces)
+		if (mod->from_dump || !mod->missing_namespaces)
 			continue;
 
 		buf_printf(&ns_deps_buf, "%s.ko:", mod->name);
@@ -2622,7 +2619,7 @@ int main(int argc, char **argv)
 	for (mod = modules; mod; mod = mod->next) {
 		char fname[PATH_MAX];
 
-		if (mod->skip)
+		if (mod->is_vmlinux || mod->from_dump)
 			continue;
 
 		buf.pos = 0;
diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
index ec717ab20b98..264c0c51defa 100644
--- a/scripts/mod/modpost.h
+++ b/scripts/mod/modpost.h
@@ -122,7 +122,6 @@ struct module {
 	int from_dump;  /* 1 if module was loaded from *.symver */
 	int is_vmlinux;
 	int seen;
-	int skip;
 	int has_init;
 	int has_cleanup;
 	struct buffer dev_table_buf;
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH 26/29] modpost: set have_vmlinux in new_module()
  2020-05-17  9:48 [PATCH 00/29] modpost: various fixes, cleanups, optimizations Masahiro Yamada
                   ` (24 preceding siblings ...)
  2020-05-17  9:48 ` [PATCH 25/29] modpost: remove mod->skip " Masahiro Yamada
@ 2020-05-17  9:48 ` Masahiro Yamada
  2020-05-17  9:48 ` [PATCH 27/29] modpost: strip .o from modname before calling new_module() Masahiro Yamada
                   ` (2 subsequent siblings)
  28 siblings, 0 replies; 36+ messages in thread
From: Masahiro Yamada @ 2020-05-17  9:48 UTC (permalink / raw)
  To: linux-kbuild; +Cc: Jessica Yu, Masahiro Yamada, Michal Marek, linux-kernel

Set have_vmlinux flag in a single place.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

 scripts/mod/modpost.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index 003b6fb2303c..79622939a6c7 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -181,6 +181,9 @@ static struct module *new_module(const char *modname)
 	mod->next = modules;
 	modules = mod;
 
+	if (mod->is_vmlinux)
+		have_vmlinux = 1;
+
 	return mod;
 }
 
@@ -2002,9 +2005,6 @@ static void read_symbols(const char *modname)
 
 	mod = new_module(modname);
 
-	if (mod->is_vmlinux)
-		have_vmlinux = 1;
-
 	if (!mod->is_vmlinux) {
 		license = get_modinfo(&info, "license");
 		if (!license)
@@ -2452,8 +2452,6 @@ static void read_dump(const char *fname)
 		mod = find_module(modname);
 		if (!mod) {
 			mod = new_module(modname);
-			if (mod->is_vmlinux)
-				have_vmlinux = 1;
 			mod->from_dump = 1;
 		}
 		s = sym_add_exported(symname, mod, export_no(export));
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH 27/29] modpost: strip .o from modname before calling new_module()
  2020-05-17  9:48 [PATCH 00/29] modpost: various fixes, cleanups, optimizations Masahiro Yamada
                   ` (25 preceding siblings ...)
  2020-05-17  9:48 ` [PATCH 26/29] modpost: set have_vmlinux in new_module() Masahiro Yamada
@ 2020-05-17  9:48 ` Masahiro Yamada
  2020-05-17  9:48 ` [PATCH 28/29] modpost: remove is_vmlinux() helper Masahiro Yamada
  2020-05-17  9:48 ` [PATCH 29/29] modpost: change elf_info->size to size_t Masahiro Yamada
  28 siblings, 0 replies; 36+ messages in thread
From: Masahiro Yamada @ 2020-05-17  9:48 UTC (permalink / raw)
  To: linux-kbuild; +Cc: Jessica Yu, Masahiro Yamada, Michal Marek, linux-kernel

new_module() conditionally strips the .o because the modname has .o
suffix when it is called from read_symbols(), but no .o when it is
called from read_dump().

It is clearer to strip .o in read_symbols().

I also used flexible-array for mod->name.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

 scripts/mod/modpost.c | 20 +++++++++++---------
 scripts/mod/modpost.h |  2 +-
 2 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index 79622939a6c7..6669b3ace968 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -164,18 +164,12 @@ static struct module *find_module(const char *modname)
 static struct module *new_module(const char *modname)
 {
 	struct module *mod;
-	char *p;
 
-	mod = NOFAIL(malloc(sizeof(*mod)));
+	mod = NOFAIL(malloc(sizeof(*mod) + strlen(modname) + 1));
 	memset(mod, 0, sizeof(*mod));
-	p = NOFAIL(strdup(modname));
-
-	/* strip trailing .o */
-	if (strends(p, ".o"))
-		p[strlen(p) - 2] = '\0';
 
 	/* add to list */
-	mod->name = p;
+	strcpy(mod->name, modname);
 	mod->is_vmlinux = is_vmlinux(modname);
 	mod->gpl_compatible = -1;
 	mod->next = modules;
@@ -2003,7 +1997,15 @@ static void read_symbols(const char *modname)
 	if (!parse_elf(&info, modname))
 		return;
 
-	mod = new_module(modname);
+	{
+		char *tmp;
+
+		/* strip trailing .o */
+		tmp = NOFAIL(strdup(modname));
+		tmp[strlen(tmp) - 2] = '\0';
+		mod = new_module(tmp);
+		free(tmp);
+	}
 
 	if (!mod->is_vmlinux) {
 		license = get_modinfo(&info, "license");
diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
index 264c0c51defa..1df87d204c9a 100644
--- a/scripts/mod/modpost.h
+++ b/scripts/mod/modpost.h
@@ -116,7 +116,6 @@ struct namespace_list {
 
 struct module {
 	struct module *next;
-	const char *name;
 	int gpl_compatible;
 	struct symbol *unres;
 	int from_dump;  /* 1 if module was loaded from *.symver */
@@ -130,6 +129,7 @@ struct module {
 	struct namespace_list *missing_namespaces;
 	// Actual imported namespaces
 	struct namespace_list *imported_namespaces;
+	char name[];
 };
 
 struct elf_info {
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH 28/29] modpost: remove is_vmlinux() helper
  2020-05-17  9:48 [PATCH 00/29] modpost: various fixes, cleanups, optimizations Masahiro Yamada
                   ` (26 preceding siblings ...)
  2020-05-17  9:48 ` [PATCH 27/29] modpost: strip .o from modname before calling new_module() Masahiro Yamada
@ 2020-05-17  9:48 ` Masahiro Yamada
  2020-05-17  9:48 ` [PATCH 29/29] modpost: change elf_info->size to size_t Masahiro Yamada
  28 siblings, 0 replies; 36+ messages in thread
From: Masahiro Yamada @ 2020-05-17  9:48 UTC (permalink / raw)
  To: linux-kbuild; +Cc: Jessica Yu, Masahiro Yamada, Michal Marek, linux-kernel

Now that is_vmlinux() is called only in new_module(), we can inline
the function call.

modname is the basename with '.o' is stripped. No need to compare it
with 'vmlinux.o'.

vmlinux is always located at the current working directory. No need
to strip the directory path.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

 scripts/mod/modpost.c | 16 +---------------
 1 file changed, 1 insertion(+), 15 deletions(-)

diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index 6669b3ace968..bcab010f09ce 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -90,20 +90,6 @@ static inline bool strends(const char *str, const char *postfix)
 	return strcmp(str + strlen(str) - strlen(postfix), postfix) == 0;
 }
 
-static int is_vmlinux(const char *modname)
-{
-	const char *myname;
-
-	myname = strrchr(modname, '/');
-	if (myname)
-		myname++;
-	else
-		myname = modname;
-
-	return (strcmp(myname, "vmlinux") == 0) ||
-	       (strcmp(myname, "vmlinux.o") == 0);
-}
-
 void *do_nofail(void *ptr, const char *expr)
 {
 	if (!ptr)
@@ -170,7 +156,7 @@ static struct module *new_module(const char *modname)
 
 	/* add to list */
 	strcpy(mod->name, modname);
-	mod->is_vmlinux = is_vmlinux(modname);
+	mod->is_vmlinux = (strcmp(modname, "vmlinux") == 0);
 	mod->gpl_compatible = -1;
 	mod->next = modules;
 	modules = mod;
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH 29/29] modpost: change elf_info->size to size_t
  2020-05-17  9:48 [PATCH 00/29] modpost: various fixes, cleanups, optimizations Masahiro Yamada
                   ` (27 preceding siblings ...)
  2020-05-17  9:48 ` [PATCH 28/29] modpost: remove is_vmlinux() helper Masahiro Yamada
@ 2020-05-17  9:48 ` Masahiro Yamada
  28 siblings, 0 replies; 36+ messages in thread
From: Masahiro Yamada @ 2020-05-17  9:48 UTC (permalink / raw)
  To: linux-kbuild; +Cc: Jessica Yu, Masahiro Yamada, Michal Marek, linux-kernel

Align with the mmap / munmap APIs.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

 scripts/mod/modpost.c | 9 ++++-----
 scripts/mod/modpost.h | 2 +-
 2 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index bcab010f09ce..af5c55d96df3 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -429,7 +429,7 @@ static void sym_set_crc(const char *name, unsigned int crc)
 	s->crc_valid = 1;
 }
 
-static void *grab_file(const char *filename, unsigned long *size)
+static void *grab_file(const char *filename, size_t *size)
 {
 	struct stat st;
 	void *map = MAP_FAILED;
@@ -451,7 +451,7 @@ static void *grab_file(const char *filename, unsigned long *size)
 	return map;
 }
 
-static void release_file(void *file, unsigned long size)
+static void release_file(void *file, size_t size)
 {
 	munmap(file, size);
 }
@@ -507,9 +507,8 @@ static int parse_elf(struct elf_info *info, const char *filename)
 
 	/* Check if file offset is correct */
 	if (hdr->e_shoff > info->size) {
-		fatal("section header offset=%lu in file '%s' is bigger than "
-		      "filesize=%lu\n", (unsigned long)hdr->e_shoff,
-		      filename, info->size);
+		fatal("section header offset=%lu in file '%s' is bigger than filesize=%zu\n",
+		      (unsigned long)hdr->e_shoff, filename, info->size);
 		return 0;
 	}
 
diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
index 1df87d204c9a..efb74dba19e2 100644
--- a/scripts/mod/modpost.h
+++ b/scripts/mod/modpost.h
@@ -133,7 +133,7 @@ struct module {
 };
 
 struct elf_info {
-	unsigned long size;
+	size_t size;
 	Elf_Ehdr     *hdr;
 	Elf_Shdr     *sechdrs;
 	Elf_Sym      *symtab_start;
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 36+ messages in thread

* RE: [PATCH 09/29] kbuild: disallow multi-word in M= or KBUILD_EXTMOD
  2020-05-17  9:48 ` [PATCH 09/29] kbuild: disallow multi-word in M= or KBUILD_EXTMOD Masahiro Yamada
@ 2020-05-17 12:33   ` David Laight
  2020-05-21  3:57     ` Masahiro Yamada
  0 siblings, 1 reply; 36+ messages in thread
From: David Laight @ 2020-05-17 12:33 UTC (permalink / raw)
  To: 'Masahiro Yamada', linux-kbuild
  Cc: Jessica Yu, Michal Marek, linux-kernel

From: Masahiro Yamada
> Sent: 17 May 2020 10:49
> $(firstword ...) in scripts/Makefile.modpost was added by commit
> 3f3fd3c05585 ("[PATCH] kbuild: allow multi-word $M in Makefile.modpost")
> to build multiple external module directories.
> 
> This feature has been broken for a while. Remove the bitrotten code, and
> stop parsing if M or KBUILD_EXTMOD contains multiple words.

ISTR that one of the kernel documentation files says that it is possible
to build multiple modules together in order to avoid 'faffing' with
exported symbol lists.

So the docs need updating to match.

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)


^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH 03/29] modpost: add read_text_file() and get_line() helpers
  2020-05-17  9:48 ` [PATCH 03/29] modpost: add read_text_file() and get_line() helpers Masahiro Yamada
@ 2020-05-19 10:21   ` Peter Zijlstra
  2020-05-20 12:17     ` Masahiro Yamada
  0 siblings, 1 reply; 36+ messages in thread
From: Peter Zijlstra @ 2020-05-19 10:21 UTC (permalink / raw)
  To: Masahiro Yamada; +Cc: linux-kbuild, Jessica Yu, Michal Marek, linux-kernel

On Sun, May 17, 2020 at 06:48:33PM +0900, Masahiro Yamada wrote:

> +char *read_text_file(const char *filename)
> +{
> +	struct stat st;
> +	int fd;
> +	char *buf;
> +
> +	fd = open(filename, O_RDONLY);
> +	if (fd < 0)
> +		return NULL;
> +
> +	if (fstat(fd, &st) < 0)
> +		return NULL;
> +
> +	buf = NOFAIL(malloc(st.st_size + 1));
> +
> +	if (read(fd, buf, st.st_size) != st.st_size) {

Is this sensible coding ? I've always been taught read() can return
early/short for a number of reasons and we must not assume this is an
error.

The 'normal' way to read a file is something like:

	for (;;) {
		ssize_t ret = read(fd, buf + size, st.st_size - size);
		if (ret < 0) {
			free(buf);
			buf = NULL;
			goto close;
		}
		if (!ret)
			break;

		size += ret;
	}

> +		free(buf);
> +		buf = NULL;
> +		goto close;
> +	}
> +	buf[st.st_size] = '\0';
> +close:
> +	close(fd);
> +
> +	return buf;
> +}

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH 03/29] modpost: add read_text_file() and get_line() helpers
  2020-05-19 10:21   ` Peter Zijlstra
@ 2020-05-20 12:17     ` Masahiro Yamada
  2020-05-20 12:29       ` Peter Zijlstra
  0 siblings, 1 reply; 36+ messages in thread
From: Masahiro Yamada @ 2020-05-20 12:17 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: Linux Kbuild mailing list, Jessica Yu, Michal Marek,
	Linux Kernel Mailing List

On Tue, May 19, 2020 at 7:21 PM Peter Zijlstra <peterz@infradead.org> wrote:
>
> On Sun, May 17, 2020 at 06:48:33PM +0900, Masahiro Yamada wrote:
>
> > +char *read_text_file(const char *filename)
> > +{
> > +     struct stat st;
> > +     int fd;
> > +     char *buf;
> > +
> > +     fd = open(filename, O_RDONLY);
> > +     if (fd < 0)
> > +             return NULL;
> > +
> > +     if (fstat(fd, &st) < 0)
> > +             return NULL;
> > +
> > +     buf = NOFAIL(malloc(st.st_size + 1));
> > +
> > +     if (read(fd, buf, st.st_size) != st.st_size) {
>
> Is this sensible coding ? I've always been taught read() can return
> early/short for a number of reasons and we must not assume this is an
> error.
>
> The 'normal' way to read a file is something like:
>
>         for (;;) {
>                 ssize_t ret = read(fd, buf + size, st.st_size - size);
>                 if (ret < 0) {
>                         free(buf);
>                         buf = NULL;
>                         goto close;
>                 }
>                 if (!ret)
>                         break;
>
>                 size += ret;
>         }
>
> > +             free(buf);
> > +             buf = NULL;
> > +             goto close;
> > +     }
> > +     buf[st.st_size] = '\0';
> > +close:
> > +     close(fd);
> > +
> > +     return buf;
> > +}


In theory, I think yes.

But, is it necessary when we know
it is reading a regular file?



The specification [1] says this:

"The value returned may be less than nbyte if the number of bytes
left in the file is less than nbyte, if the read() request was
interrupted by a signal, or if the file is a pipe or FIFO or
special file and has fewer than nbyte bytes immediately available
for reading."


This case does not meet any of 'if ...' parts.

[1] https://pubs.opengroup.org/onlinepubs/000095399/functions/read.html


-- 
Best Regards
Masahiro Yamada

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH 03/29] modpost: add read_text_file() and get_line() helpers
  2020-05-20 12:17     ` Masahiro Yamada
@ 2020-05-20 12:29       ` Peter Zijlstra
  2020-05-23  4:18         ` Masahiro Yamada
  0 siblings, 1 reply; 36+ messages in thread
From: Peter Zijlstra @ 2020-05-20 12:29 UTC (permalink / raw)
  To: Masahiro Yamada
  Cc: Linux Kbuild mailing list, Jessica Yu, Michal Marek,
	Linux Kernel Mailing List

On Wed, May 20, 2020 at 09:17:45PM +0900, Masahiro Yamada wrote:

> The specification [1] says this:
> 
> "The value returned may be less than nbyte if the number of bytes
> left in the file is less than nbyte, if the read() request was
> interrupted by a signal, or if the file is a pipe or FIFO or
> special file and has fewer than nbyte bytes immediately available
> for reading."
> 
> 
> This case does not meet any of 'if ...' parts.

So nobody ever ^Z's their build? I really don't think you can assume
that you'll never get a signal. That's just asking for trouble.

Doing the right thing here is 'trivial', there is absolutely no reason
to not do it.

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH 09/29] kbuild: disallow multi-word in M= or KBUILD_EXTMOD
  2020-05-17 12:33   ` David Laight
@ 2020-05-21  3:57     ` Masahiro Yamada
  0 siblings, 0 replies; 36+ messages in thread
From: Masahiro Yamada @ 2020-05-21  3:57 UTC (permalink / raw)
  To: David Laight; +Cc: linux-kbuild, Jessica Yu, Michal Marek, linux-kernel

On Sun, May 17, 2020 at 9:33 PM David Laight <David.Laight@aculab.com> wrote:
>
> From: Masahiro Yamada
> > Sent: 17 May 2020 10:49
> > $(firstword ...) in scripts/Makefile.modpost was added by commit
> > 3f3fd3c05585 ("[PATCH] kbuild: allow multi-word $M in Makefile.modpost")
> > to build multiple external module directories.
> >
> > This feature has been broken for a while. Remove the bitrotten code, and
> > stop parsing if M or KBUILD_EXTMOD contains multiple words.
>
> ISTR that one of the kernel documentation files says that it is possible
> to build multiple modules together in order to avoid 'faffing' with
> exported symbol lists.
>
> So the docs need updating to match.


Do you remember which doc mentions it?



>         David
>
> -
> Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
> Registration No: 1397386 (Wales)
>


-- 
Best Regards
Masahiro Yamada

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH 03/29] modpost: add read_text_file() and get_line() helpers
  2020-05-20 12:29       ` Peter Zijlstra
@ 2020-05-23  4:18         ` Masahiro Yamada
  0 siblings, 0 replies; 36+ messages in thread
From: Masahiro Yamada @ 2020-05-23  4:18 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: Linux Kbuild mailing list, Jessica Yu, Michal Marek,
	Linux Kernel Mailing List

On Wed, May 20, 2020 at 9:29 PM Peter Zijlstra <peterz@infradead.org> wrote:
>
> On Wed, May 20, 2020 at 09:17:45PM +0900, Masahiro Yamada wrote:
>
> > The specification [1] says this:
> >
> > "The value returned may be less than nbyte if the number of bytes
> > left in the file is less than nbyte, if the read() request was
> > interrupted by a signal, or if the file is a pipe or FIFO or
> > special file and has fewer than nbyte bytes immediately available
> > for reading."
> >
> >
> > This case does not meet any of 'if ...' parts.
>
> So nobody ever ^Z's their build? I really don't think you can assume
> that you'll never get a signal. That's just asking for trouble.
>
> Doing the right thing here is 'trivial', there is absolutely no reason
> to not do it.


In my testing, read() seems robust against ^Z,
but perhaps it might be implementation-defined ?


I think you are right.
We can gain extra safety with a trivial change.

--
Best Regards
Masahiro Yamada

^ permalink raw reply	[flat|nested] 36+ messages in thread

end of thread, other threads:[~2020-05-23  4:19 UTC | newest]

Thread overview: 36+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-17  9:48 [PATCH 00/29] modpost: various fixes, cleanups, optimizations Masahiro Yamada
2020-05-17  9:48 ` [PATCH 01/29] modpost: drop RCS/CVS $Revision handling in MODULE_VERSION() Masahiro Yamada
2020-05-17  9:48 ` [PATCH 02/29] modpost: do not call get_modinfo() for vmlinux Masahiro Yamada
2020-05-17  9:48 ` [PATCH 03/29] modpost: add read_text_file() and get_line() helpers Masahiro Yamada
2020-05-19 10:21   ` Peter Zijlstra
2020-05-20 12:17     ` Masahiro Yamada
2020-05-20 12:29       ` Peter Zijlstra
2020-05-23  4:18         ` Masahiro Yamada
2020-05-17  9:48 ` [PATCH 04/29] modpost: fix potential mmap'ed file overrun in get_src_version() Masahiro Yamada
2020-05-17  9:48 ` [PATCH 05/29] modpost: re-add warning about missing *.mod file Masahiro Yamada
2020-05-17  9:48 ` [PATCH 06/29] modpost: avoid false-positive file open error Masahiro Yamada
2020-05-17  9:48 ` [PATCH 07/29] modpost: use read_text_file() and get_line() for reading text files Masahiro Yamada
2020-05-17  9:48 ` [PATCH 08/29] modpost: remove get_next_text() and make {grab,release_}file static Masahiro Yamada
2020-05-17  9:48 ` [PATCH 09/29] kbuild: disallow multi-word in M= or KBUILD_EXTMOD Masahiro Yamada
2020-05-17 12:33   ` David Laight
2020-05-21  3:57     ` Masahiro Yamada
2020-05-17  9:48 ` [PATCH 10/29] modpost: move -T option close to the modpost command Masahiro Yamada
2020-05-17  9:48 ` [PATCH 11/29] modpost: pass -N option only for modules modpost Masahiro Yamada
2020-05-17  9:48 ` [PATCH 12/29] modpost: move external module options Masahiro Yamada
2020-05-17  9:48 ` [PATCH 13/29] modpost: load KBUILD_EXTRA_SYMBOLS files in order Masahiro Yamada
2020-05-17  9:48 ` [PATCH 14/29] modpost: track if the symbol origin is a dump file or ELF object Masahiro Yamada
2020-05-17  9:48 ` [PATCH 15/29] modpost: allow to pass -i option multiple times remove -e option Masahiro Yamada
2020-05-17  9:48 ` [PATCH 16/29] modpost: rename ext_sym_list to dump_list Masahiro Yamada
2020-05-17  9:48 ` [PATCH 17/29] modpost: re-add -e to set external_module flag Masahiro Yamada
2020-05-17  9:48 ` [PATCH 18/29] modpost: show warning if vmlinux is not found when processing modules Masahiro Yamada
2020-05-17  9:48 ` [PATCH 19/29] modpost: show warning if it fails to read symbol dump file Masahiro Yamada
2020-05-17  9:48 ` [PATCH 20/29] modpost: generate vmlinux.symvers and reuse it for the second modpost Masahiro Yamada
2020-05-17  9:48 ` [PATCH 21/29] modpost: remove -s option Masahiro Yamada
2020-05-17  9:48 ` [PATCH 22/29] modpost: remove mod->is_dot_o struct member Masahiro Yamada
2020-05-17  9:48 ` [PATCH 23/29] modpost: remove is_vmlinux() call in check_for_{gpl_usage,unused}() Masahiro Yamada
2020-05-17  9:48 ` [PATCH 24/29] modpost: add mod->is_vmlinux struct member Masahiro Yamada
2020-05-17  9:48 ` [PATCH 25/29] modpost: remove mod->skip " Masahiro Yamada
2020-05-17  9:48 ` [PATCH 26/29] modpost: set have_vmlinux in new_module() Masahiro Yamada
2020-05-17  9:48 ` [PATCH 27/29] modpost: strip .o from modname before calling new_module() Masahiro Yamada
2020-05-17  9:48 ` [PATCH 28/29] modpost: remove is_vmlinux() helper Masahiro Yamada
2020-05-17  9:48 ` [PATCH 29/29] modpost: change elf_info->size to size_t Masahiro Yamada

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).