2016-01-27 10:50:18 +08:00
|
|
|
#!/bin/sh
|
2019-06-04 16:11:33 +08:00
|
|
|
# SPDX-License-Identifier: GPL-2.0-only
|
2016-01-27 10:50:18 +08:00
|
|
|
|
|
|
|
# Script to create/update include/generated/autoksyms.h and dependency files
|
|
|
|
#
|
|
|
|
# Copyright: (C) 2016 Linaro Limited
|
|
|
|
# Created by: Nicolas Pitre, January 2016
|
|
|
|
#
|
|
|
|
|
|
|
|
# Create/update the include/generated/autoksyms.h file from the list
|
2019-07-17 14:17:58 +08:00
|
|
|
# of all module's needed symbols as recorded on the second line of *.mod files.
|
2016-01-27 10:50:18 +08:00
|
|
|
#
|
|
|
|
# For each symbol being added or removed, the corresponding dependency
|
|
|
|
# file's timestamp is updated to force a rebuild of the affected source
|
|
|
|
# file. All arguments passed to this script are assumed to be a command
|
|
|
|
# to be exec'd to trigger a rebuild of those files.
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
cur_ksyms_file="include/generated/autoksyms.h"
|
|
|
|
new_ksyms_file="include/generated/autoksyms.h.tmpnew"
|
|
|
|
|
|
|
|
info() {
|
|
|
|
if [ "$quiet" != "silent_" ]; then
|
|
|
|
printf " %-7s %s\n" "$1" "$2"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
info "CHK" "$cur_ksyms_file"
|
|
|
|
|
|
|
|
# Use "make V=1" to debug this script.
|
|
|
|
case "$KBUILD_VERBOSE" in
|
|
|
|
*1*)
|
|
|
|
set -x
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
# We need access to CONFIG_ symbols
|
2019-03-08 13:49:10 +08:00
|
|
|
. include/config/auto.conf
|
2016-01-27 10:50:18 +08:00
|
|
|
|
|
|
|
# Generate a new ksym list file with symbols needed by the current
|
|
|
|
# set of modules.
|
|
|
|
cat > "$new_ksyms_file" << EOT
|
|
|
|
/*
|
|
|
|
* Automatically generated file; DO NOT EDIT.
|
|
|
|
*/
|
|
|
|
|
|
|
|
EOT
|
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>
2019-07-17 14:17:57 +08:00
|
|
|
sed 's/ko$/mod/' modules.order |
|
2019-07-17 14:17:58 +08:00
|
|
|
xargs -n1 sed -n -e '2{s/ /\n/g;/^$/!p;}' -- |
|
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>
2019-07-17 14:17:57 +08:00
|
|
|
sort -u |
|
|
|
|
sed -e 's/\(.*\)/#define __KSYM_\1 1/' >> "$new_ksyms_file"
|
2016-01-27 10:50:18 +08:00
|
|
|
|
|
|
|
# Special case for modversions (see modpost.c)
|
|
|
|
if [ -n "$CONFIG_MODVERSIONS" ]; then
|
|
|
|
echo "#define __KSYM_module_layout 1" >> "$new_ksyms_file"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Extract changes between old and new list and touch corresponding
|
|
|
|
# dependency files.
|
|
|
|
changed=$(
|
|
|
|
count=0
|
|
|
|
sort "$cur_ksyms_file" "$new_ksyms_file" | uniq -u |
|
|
|
|
sed -n 's/^#define __KSYM_\(.*\) 1/\1/p' | tr "A-Z_" "a-z/" |
|
|
|
|
while read sympath; do
|
|
|
|
if [ -z "$sympath" ]; then continue; fi
|
2018-03-16 15:37:14 +08:00
|
|
|
depfile="include/ksym/${sympath}.h"
|
2016-01-27 10:50:18 +08:00
|
|
|
mkdir -p "$(dirname "$depfile")"
|
|
|
|
touch "$depfile"
|
2018-03-16 04:56:20 +08:00
|
|
|
# Filesystems with coarse time precision may create timestamps
|
|
|
|
# equal to the one from a file that was very recently built and that
|
|
|
|
# needs to be rebuild. Let's guard against that by making sure our
|
|
|
|
# dep files are always newer than the first file we created here.
|
|
|
|
while [ ! "$depfile" -nt "$new_ksyms_file" ]; do
|
|
|
|
touch "$depfile"
|
|
|
|
done
|
2016-01-27 10:50:18 +08:00
|
|
|
echo $((count += 1))
|
|
|
|
done | tail -1 )
|
|
|
|
changed=${changed:-0}
|
|
|
|
|
|
|
|
if [ $changed -gt 0 ]; then
|
|
|
|
# Replace the old list with tne new one
|
|
|
|
old=$(grep -c "^#define __KSYM_" "$cur_ksyms_file" || true)
|
|
|
|
new=$(grep -c "^#define __KSYM_" "$new_ksyms_file" || true)
|
|
|
|
info "KSYMS" "symbols: before=$old, after=$new, changed=$changed"
|
|
|
|
info "UPD" "$cur_ksyms_file"
|
|
|
|
mv -f "$new_ksyms_file" "$cur_ksyms_file"
|
|
|
|
# Then trigger a rebuild of affected source files
|
|
|
|
exec $@
|
|
|
|
else
|
|
|
|
rm -f "$new_ksyms_file"
|
|
|
|
fi
|