History log of /linux-master/scripts/mod/sumversion.c
Revision Date Author Comments
# 5d9a16b2 14-Feb-2024 Radek Krejci <radek.krejci@oracle.com>

modpost: trim leading spaces when processing source files list

get_line() does not trim the leading spaces, but the
parse_source_files() expects to get lines with source files paths where
the first space occurs after the file path.

Fixes: 70f30cfe5b89 ("modpost: use read_text_file() and get_line() for reading text files")
Signed-off-by: Radek Krejci <radek.krejci@oracle.com>
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>


# 30daacc5 13-Nov-2022 KaiLong Wang <wangkailong@jari.cn>

modpost: fix array_size.cocci warning

Fix following coccicheck warning:

scripts/mod/sumversion.c:219:48-49: WARNING: Use ARRAY_SIZE
scripts/mod/sumversion.c:156:48-49: WARNING: Use ARRAY_SIZE

Signed-off-by: KaiLong Wang <wangkailong@jari.cn>
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>


# 58e01fca 01-May-2022 Masahiro Yamada <masahiroy@kernel.org>

modpost: use bool type where appropriate

Use 'bool' to clarify that the valid value is true or false.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>


# 22f26f21 06-Apr-2022 Masahiro Yamada <masahiroy@kernel.org>

kbuild: get rid of duplication in *.mod files

It is allowed to add the same objects multiple times to obj-y / obj-m:

obj-y += foo.o foo.o foo.o
obj-m += bar.o bar.o bar.o

It is also allowed to add the same objects multiple times to a composite
module:

obj-m += foo.o
foo-y := foo1.o foo2.o foo2.o foo1.o

This flexibility is useful because the same object might be selected by
different CONFIG options, like this:

obj-m += foo.o
foo-y := foo1.o
foo-$(CONFIG_FOO_X) += foo2.o
foo-$(CONFIG_FOO_Y) += foo2.o

The duplicated objects are omitted at link time. It works naturally in
Makefiles because GNU Make removes duplication in $^ without changing
the order.

It is working well, almost...

A small flaw I notice is, *.mod contains duplication in such a case.

This is probably not a big deal. As far as I know, the only small
problem is scripts/mod/sumversion.c parses the same file multiple
times.

I am fixing this because I plan to reuse *.mod for other purposes,
where the duplication can be problematic.

The code change is quite simple. We already use awk to drop duplicated
lines in modules.order (see cmd_modules_order in the same file).
I copied the code, but changed RS to use spaces as record separators.

I also changed the file format to list one object per line.

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


# 9413e764 06-Apr-2022 Masahiro Yamada <masahiroy@kernel.org>

kbuild: split the second line of *.mod into *.usyms

The *.mod files have two lines; the first line lists the member objects
of the module, and the second line, if CONFIG_TRIM_UNUSED_KSYMS=y, lists
the undefined symbols.

Currently, we generate *.mod after constructing composite modules,
otherwise, we cannot compute the second line. No prerequisite is
required to print the first line.

They are orthogonal. Splitting them into separate commands will ease
further cleanups.

This commit splits the list of undefined symbols out to *.usyms files.

Previously, the list of undefined symbols ended up with a very long
line, but now it has one symbol per line.

Use sed like we did before commit 7d32358be8ac ("kbuild: avoid split
lines in .mod files").

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Reviewed-by: Nicolas Schier <nicolas@fjasle.eu>


# e54dd93a 28-Aug-2021 Masahiro Yamada <masahiroy@kernel.org>

modpost: get the *.mod file path more simply

get_src_version() strips 'o' or 'lto.o' from the end of the object file
path (so, postfixlen is 1 or 5), then adds 'mod'.

If you look at the code closely, mod->name already holds the base path
with the extension stripped.

Most of the code changes made by commit 7ac204b545f2 ("modpost: lto:
strip .lto from module names") was actually unneeded.

sumversion.c does not need strends(), so it can get back local in
modpost.c again.

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


# 7ac204b5 11-Dec-2020 Sami Tolvanen <samitolvanen@google.com>

modpost: lto: strip .lto from module names

With LTO, everything is compiled into LLVM bitcode, so we have to link
each module into native code before modpost. Kbuild uses the .lto.o
suffix for these files, which also ends up in module information. This
change strips the unnecessary .lto suffix from the module name.

Suggested-by: Bill Wendling <morbo@google.com>
Signed-off-by: Sami Tolvanen <samitolvanen@google.com>
Reviewed-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Kees Cook <keescook@chromium.org>
Link: https://lore.kernel.org/r/20201211184633.3213045-11-samitolvanen@google.com


# 70f30cfe 31-May-2020 Masahiro Yamada <masahiroy@kernel.org>

modpost: use read_text_file() and get_line() for reading text files

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().

Going forward, the missing *.symvers or *.cmd is a fatal error.
This should not happen because scripts/Makefile.modpost guards the
-i option files with $(wildcard $(input-symdump)).

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


# 7c8f5662 31-May-2020 Masahiro Yamada <masahiroy@kernel.org>

modpost: avoid false-positive file open error

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

- It 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 for 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.

Going forward, the first case (it cannot read the file) is a fatal
error. If the source file from which an object was compiled is missing,
something went wrong.

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


# f531c1b5 31-May-2020 Masahiro Yamada <masahiroy@kernel.org>

modpost: fix potential mmap'ed file overrun in get_src_version()

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

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.

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.

This also makes missing *.mod file a fatal error.

Commit 4be40e22233c ("kbuild: do not emit src version warning for
non-modules") ignored missing *.mod files.

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.

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


# f6931535 31-May-2020 Masahiro Yamada <masahiroy@kernel.org>

modpost: drop RCS/CVS $Revision handling in MODULE_VERSION()

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>


# 60ae1b19 17-Jul-2019 Masahiro Yamada <yamada.masahiro@socionext.com>

kbuild: remove the first line of *.mod files

The current format of *.mod is like this:

line 1: directory path to the .ko file
line 2: a list of objects linked into this module
line 3: unresolved symbols (only when CONFIG_TRIM_UNUSED_KSYMS=y)

Now that *.mod and *.ko are created in the same directory, the line 1
provides no valuable information. It can be derived by replacing the
extension .mod with .ko. In fact, nobody uses the first line any more.

Cut down the first line.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>


# b7dca6dd 17-Jul-2019 Masahiro Yamada <yamada.masahiro@socionext.com>

kbuild: create *.mod with full directory path and remove MODVERDIR

While descending directories, Kbuild produces objects for modules,
but do not link final *.ko files; it is done in the modpost.

To keep track of modules, Kbuild creates a *.mod file in $(MODVERDIR)
for every module it is building. Some post-processing steps read the
necessary information from *.mod files. This avoids descending into
directories again. This mechanism was introduced in 2003 or so.

Later, commit 551559e13af1 ("kbuild: implement modules.order") added
modules.order. So, we can simply read it out to know all the modules
with directory paths. This is easier than parsing the first line of
*.mod files.

$(MODVERDIR) has a flat directory structure, that is, *.mod files
are named only with base names. This is based on the assumption that
the module name is unique across the tree. This assumption is really
fragile.

Stephen Rothwell reported a race condition caused by a module name
conflict:

https://lkml.org/lkml/2019/5/13/991

In parallel building, two different threads could write to the same
$(MODVERDIR)/*.mod simultaneously.

Non-unique module names are the source of all kind of troubles, hence
commit 3a48a91901c5 ("kbuild: check uniqueness of module names")
introduced a new checker script.

However, it is still fragile in the build system point of view because
this race happens before scripts/modules-check.sh is invoked. If it
happens again, the modpost will emit unclear error messages.

To fix this issue completely, create *.mod with full directory path
so that two threads never attempt to write to the same file.

$(MODVERDIR) is no longer needed.

Since modules with directory paths are listed in modules.order, Kbuild
is still able to find *.mod files without additional descending.

I also killed cmd_secanalysis; scripts/mod/sumversion.c computes MD4 hash
for modules with MODULE_VERSION(). When CONFIG_DEBUG_SECTION_MISMATCH=y,
it occurs not only in the modpost stage, but also during directory
descending, where sumversion.c may parse stale *.mod files. It would emit
'No such file or directory' warning when an object consisting a module is
renamed, or when a single-obj module is turned into a multi-obj module or
vice versa.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Acked-by: Nicolas Pitre <nico@fluxnic.net>


# 9fc34767 22-Mar-2018 Rasmus Villemoes <linux@rasmusvillemoes.dk>

modpost: delete stale comment

Commit 7840fea200cd ("kbuild: Fix computing srcversion for modules")
fixed the comment above parse_source_files to refer to the new source_
line, but left this one behind that could still give the impression that
drivers/net/dummy.c appears in the deps_ variable.

Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>


# bb66fc67 10-Jun-2014 Masahiro Yamada <yamada.m@jp.panasonic.com>

kbuild: trivial - use tabs for code indent where possible

Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
Signed-off-by: Michal Marek <mmarek@suse.cz>


# 849464d1 25-Oct-2013 Kees Cook <keescook@chromium.org>

kbuild: replace unbounded sprintf call in modpost

The modpost tool could overflow its stack buffer if someone was running
with an insane shell environment. Regardless, it's technically a bug,
so this fixes it to truncate the string instead of seg-faulting.

Found by Coverity.

Signed-off-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Michal Marek <mmarek@suse.cz>


# 7840fea2 11-Mar-2011 Michal Marek <mmarek@suse.cz>

kbuild: Fix computing srcversion for modules

Recent change to fixdep:

commit b7bd182176960fdd139486cadb9962b39f8a2b50
Author: Michal Marek <mmarek@suse.cz>
Date: Thu Feb 17 15:13:54 2011 +0100

fixdep: Do not record dependency on the source file itself

changed the format of the *.cmd files without realizing that it is also
used by modpost. Put the path to the source file to the file back, in a
special variable, so that modpost sees all source files when calculating
srcversion for modules.

Reported-and-tested-by: Henrik Rydberg <rydberg@euromail.se>
Signed-off-by: Michal Marek <mmarek@suse.cz>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>


# 7d3392e5 11-Jun-2009 Markus Heidelberg <markus.heidelberg@web.de>

trivial: remove references to non-existent include/linux/config.h

Ignore drivers/staging/ since it is very likely that new drivers
introduce it again.

Signed-off-by: Markus Heidelberg <markus.heidelberg@web.de>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>


# e6e6733e 25-Oct-2008 Ashutosh Naik <ashutosh@chelsio.com>

kbuild: prevent modpost from looking for a .cmd file for a static library linked into a module

This fixes a compile time warning which occurs whenever a static library
is linked into a kernel module. MODPOST tries to look for a
".<modulename>.cmd" file to look for its dependencies, but that file
doesn't exist or get generated for static libraries.

This patch prevents modpost from looking for a .cmd file when a module is
linked with a static library

[akpm@linux-foundation.org: coding-style fixes]
Signed-off-by: Ashutosh Naik <ashutosh.naik@gmail.com>
Cc: Rusty Russell <rusty@rustcorp.com.au>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Sam Ravnborg <sam@ravnborg.org>


# fc31c771 17-May-2007 Mike Frysinger <vapier@gentoo.org>

kbuild: include limits.h in sumversion.c for PATH_MAX

POSIX says limits.h defines PATH_MAX so we should include it (which fixes
compiling on some systems like OS X).

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Sam Ravnborg <sam@ravnborg.org>


# 4be40e22 20-Mar-2007 Sam Ravnborg <sam@ravnborg.org>

kbuild: do not emit src version warning for non-modules

modpost is now called with .o files that are not modules.
So do not warn if there is no corresponding .mod
file listing .o files (in .tmp_versions/).

Signed-off-by: Sam Ravnborg <sam@ravnborg.org>


# 41370d3b 18-Feb-2006 Sam Ravnborg <sam@mars.ravnborg.org>

kbuild: do not segfault in modpost if MODVERDIR is not defined

A combination of calling modpost with option -a and MODVERDIR undefined
caused segmentation fault. So provide a default value and accept the
error messages it generates instead.

Signed-off-by: Sam Ravnborg <sam@ravnborg.org>


# cb80514d 28-Jan-2006 Sam Ravnborg <sam@mars.ravnborg.org>

kbuild: use warn()/fatal() consistent in modpost

modpost.c provides warn() and fatal() - so use them all over the place.

Signed-off-by: Sam Ravnborg <sam@ravnborg.org>


# 61d9cdf2 15-Jul-2005 J.A. Magallon <jamagallon@able.es>

[PATCH] kbuild: signed char fixes for scripts

This time I did not break anything... and they shut up gcc4 ;)

Signed-off-by: Sam Ravnborg <sam@ravnborg.org>


# 1da177e4 16-Apr-2005 Linus Torvalds <torvalds@ppc970.osdl.org>

Linux-2.6.12-rc2

Initial git repository build. I'm not bothering with the full history,
even though we have it. We can create a separate "historical" git
archive of that later if we want to, and in the meantime it's about
3.2GB when imported into git - space that would just make the early
git days unnecessarily complicated, when we don't have a lot of good
infrastructure for it.

Let it rip!