blob: 212ba45595d3556cd8c945cc065dbefa6135966e [file] [log] [blame]
Nicolas Pitre23121ca2016-01-26 21:50:18 -05001#!/bin/sh
Thomas Gleixnerd2912cb2019-06-04 10:11:33 +02002# SPDX-License-Identifier: GPL-2.0-only
Nicolas Pitre23121ca2016-01-26 21:50:18 -05003
4# Script to create/update include/generated/autoksyms.h and dependency files
5#
6# Copyright: (C) 2016 Linaro Limited
7# Created by: Nicolas Pitre, January 2016
8#
Nicolas Pitre23121ca2016-01-26 21:50:18 -05009
10# Create/update the include/generated/autoksyms.h file from the list
Masahiro Yamada60ae1b12019-07-17 15:17:58 +090011# of all module's needed symbols as recorded on the second line of *.mod files.
Nicolas Pitre23121ca2016-01-26 21:50:18 -050012#
13# For each symbol being added or removed, the corresponding dependency
14# file's timestamp is updated to force a rebuild of the affected source
15# file. All arguments passed to this script are assumed to be a command
16# to be exec'd to trigger a rebuild of those files.
17
18set -e
19
20cur_ksyms_file="include/generated/autoksyms.h"
21new_ksyms_file="include/generated/autoksyms.h.tmpnew"
22
23info() {
24 if [ "$quiet" != "silent_" ]; then
25 printf " %-7s %s\n" "$1" "$2"
26 fi
27}
28
29info "CHK" "$cur_ksyms_file"
30
31# Use "make V=1" to debug this script.
32case "$KBUILD_VERBOSE" in
33*1*)
34 set -x
35 ;;
36esac
37
38# We need access to CONFIG_ symbols
Masahiro Yamada94cf8ac2019-03-08 14:49:10 +090039. include/config/auto.conf
Nicolas Pitre23121ca2016-01-26 21:50:18 -050040
Quentin Perret1518c632020-02-28 17:20:13 +000041ksym_wl=/dev/null
42if [ -n "$CONFIG_UNUSED_KSYMS_WHITELIST" ]; then
43 # Use 'eval' to expand the whitelist path and check if it is relative
44 eval ksym_wl="$CONFIG_UNUSED_KSYMS_WHITELIST"
45 [ "${ksym_wl}" != "${ksym_wl#/}" ] || ksym_wl="$abs_srctree/$ksym_wl"
46 if [ ! -f "$ksym_wl" ] || [ ! -r "$ksym_wl" ]; then
47 echo "ERROR: '$ksym_wl' whitelist file not found" >&2
48 exit 1
49 fi
50fi
51
Nicolas Pitre23121ca2016-01-26 21:50:18 -050052# Generate a new ksym list file with symbols needed by the current
53# set of modules.
54cat > "$new_ksyms_file" << EOT
55/*
56 * Automatically generated file; DO NOT EDIT.
57 */
58
59EOT
Masahiro Yamadab7dca6d2019-07-17 15:17:57 +090060sed 's/ko$/mod/' modules.order |
Masahiro Yamada60ae1b12019-07-17 15:17:58 +090061xargs -n1 sed -n -e '2{s/ /\n/g;/^$/!p;}' -- |
Quentin Perret1518c632020-02-28 17:20:13 +000062cat - "$ksym_wl" |
Masahiro Yamadab7dca6d2019-07-17 15:17:57 +090063sort -u |
64sed -e 's/\(.*\)/#define __KSYM_\1 1/' >> "$new_ksyms_file"
Nicolas Pitre23121ca2016-01-26 21:50:18 -050065
66# Special case for modversions (see modpost.c)
67if [ -n "$CONFIG_MODVERSIONS" ]; then
68 echo "#define __KSYM_module_layout 1" >> "$new_ksyms_file"
69fi
70
71# Extract changes between old and new list and touch corresponding
72# dependency files.
73changed=$(
74count=0
75sort "$cur_ksyms_file" "$new_ksyms_file" | uniq -u |
76sed -n 's/^#define __KSYM_\(.*\) 1/\1/p' | tr "A-Z_" "a-z/" |
77while read sympath; do
78 if [ -z "$sympath" ]; then continue; fi
Masahiro Yamadafbfa9be2018-03-16 16:37:14 +090079 depfile="include/ksym/${sympath}.h"
Nicolas Pitre23121ca2016-01-26 21:50:18 -050080 mkdir -p "$(dirname "$depfile")"
81 touch "$depfile"
Nicolas Pitre825d4872018-03-15 16:56:20 -040082 # Filesystems with coarse time precision may create timestamps
83 # equal to the one from a file that was very recently built and that
84 # needs to be rebuild. Let's guard against that by making sure our
85 # dep files are always newer than the first file we created here.
86 while [ ! "$depfile" -nt "$new_ksyms_file" ]; do
87 touch "$depfile"
88 done
Nicolas Pitre23121ca2016-01-26 21:50:18 -050089 echo $((count += 1))
90done | tail -1 )
91changed=${changed:-0}
92
93if [ $changed -gt 0 ]; then
94 # Replace the old list with tne new one
95 old=$(grep -c "^#define __KSYM_" "$cur_ksyms_file" || true)
96 new=$(grep -c "^#define __KSYM_" "$new_ksyms_file" || true)
97 info "KSYMS" "symbols: before=$old, after=$new, changed=$changed"
98 info "UPD" "$cur_ksyms_file"
99 mv -f "$new_ksyms_file" "$cur_ksyms_file"
100 # Then trigger a rebuild of affected source files
101 exec $@
102else
103 rm -f "$new_ksyms_file"
104fi