diff options
author | Joel Fernandes (Google) <joel@joelfernandes.org> | 2019-05-15 17:35:51 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2019-05-24 14:16:01 -0400 |
commit | f7b101d33046a837c2aa4526cef28a3c785d7af2 (patch) | |
tree | 50756746345f4a6ba56994e823d5f60681eb662d /kernel/gen_kheaders.sh | |
parent | a188339ca5a396acc588e5851ed7e19f66b0ebd9 (diff) |
kheaders: Move from proc to sysfs
The kheaders archive consisting of the kernel headers used for compiling
bpf programs is in /proc. However there is concern that moving it here
will make it permanent. Let us move it to /sys/kernel as discussed [1].
[1] https://lore.kernel.org/patchwork/patch/1067310/#1265969
Suggested-by: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Joel Fernandes (Google) <joel@joelfernandes.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'kernel/gen_kheaders.sh')
-rwxr-xr-x | kernel/gen_kheaders.sh | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/kernel/gen_kheaders.sh b/kernel/gen_kheaders.sh new file mode 100755 index 000000000000..581b83534587 --- /dev/null +++ b/kernel/gen_kheaders.sh | |||
@@ -0,0 +1,89 @@ | |||
1 | #!/bin/bash | ||
2 | # SPDX-License-Identifier: GPL-2.0 | ||
3 | |||
4 | # This script generates an archive consisting of kernel headers | ||
5 | # for CONFIG_IKHEADERS. | ||
6 | set -e | ||
7 | spath="$(dirname "$(readlink -f "$0")")" | ||
8 | kroot="$spath/.." | ||
9 | outdir="$(pwd)" | ||
10 | tarfile=$1 | ||
11 | cpio_dir=$outdir/$tarfile.tmp | ||
12 | |||
13 | # Script filename relative to the kernel source root | ||
14 | # We add it to the archive because it is small and any changes | ||
15 | # to this script will also cause a rebuild of the archive. | ||
16 | sfile="$(realpath --relative-to $kroot "$(readlink -f "$0")")" | ||
17 | |||
18 | src_file_list=" | ||
19 | include/ | ||
20 | arch/$SRCARCH/include/ | ||
21 | $sfile | ||
22 | " | ||
23 | |||
24 | obj_file_list=" | ||
25 | include/ | ||
26 | arch/$SRCARCH/include/ | ||
27 | " | ||
28 | |||
29 | # Support incremental builds by skipping archive generation | ||
30 | # if timestamps of files being archived are not changed. | ||
31 | |||
32 | # This block is useful for debugging the incremental builds. | ||
33 | # Uncomment it for debugging. | ||
34 | # iter=1 | ||
35 | # if [ ! -f /tmp/iter ]; then echo 1 > /tmp/iter; | ||
36 | # else; iter=$(($(cat /tmp/iter) + 1)); fi | ||
37 | # find $src_file_list -type f | xargs ls -lR > /tmp/src-ls-$iter | ||
38 | # find $obj_file_list -type f | xargs ls -lR > /tmp/obj-ls-$iter | ||
39 | |||
40 | # include/generated/compile.h is ignored because it is touched even when none | ||
41 | # of the source files changed. This causes pointless regeneration, so let us | ||
42 | # ignore them for md5 calculation. | ||
43 | pushd $kroot > /dev/null | ||
44 | src_files_md5="$(find $src_file_list -type f | | ||
45 | grep -v "include/generated/compile.h" | | ||
46 | xargs ls -lR | md5sum | cut -d ' ' -f1)" | ||
47 | popd > /dev/null | ||
48 | obj_files_md5="$(find $obj_file_list -type f | | ||
49 | grep -v "include/generated/compile.h" | | ||
50 | xargs ls -lR | md5sum | cut -d ' ' -f1)" | ||
51 | |||
52 | if [ -f $tarfile ]; then tarfile_md5="$(md5sum $tarfile | cut -d ' ' -f1)"; fi | ||
53 | if [ -f kernel/kheaders.md5 ] && | ||
54 | [ "$(cat kernel/kheaders.md5|head -1)" == "$src_files_md5" ] && | ||
55 | [ "$(cat kernel/kheaders.md5|head -2|tail -1)" == "$obj_files_md5" ] && | ||
56 | [ "$(cat kernel/kheaders.md5|tail -1)" == "$tarfile_md5" ]; then | ||
57 | exit | ||
58 | fi | ||
59 | |||
60 | if [ "${quiet}" != "silent_" ]; then | ||
61 | echo " GEN $tarfile" | ||
62 | fi | ||
63 | |||
64 | rm -rf $cpio_dir | ||
65 | mkdir $cpio_dir | ||
66 | |||
67 | pushd $kroot > /dev/null | ||
68 | for f in $src_file_list; | ||
69 | do find "$f" ! -name "*.cmd" ! -name ".*"; | ||
70 | done | cpio --quiet -pd $cpio_dir | ||
71 | popd > /dev/null | ||
72 | |||
73 | # The second CPIO can complain if files already exist which can | ||
74 | # happen with out of tree builds. Just silence CPIO for now. | ||
75 | for f in $obj_file_list; | ||
76 | do find "$f" ! -name "*.cmd" ! -name ".*"; | ||
77 | done | cpio --quiet -pd $cpio_dir >/dev/null 2>&1 | ||
78 | |||
79 | # Remove comments except SDPX lines | ||
80 | find $cpio_dir -type f -print0 | | ||
81 | xargs -0 -P8 -n1 perl -pi -e 'BEGIN {undef $/;}; s/\/\*((?!SPDX).)*?\*\///smg;' | ||
82 | |||
83 | tar -Jcf $tarfile -C $cpio_dir/ . > /dev/null | ||
84 | |||
85 | echo "$src_files_md5" > kernel/kheaders.md5 | ||
86 | echo "$obj_files_md5" >> kernel/kheaders.md5 | ||
87 | echo "$(md5sum $tarfile | cut -d ' ' -f1)" >> kernel/kheaders.md5 | ||
88 | |||
89 | rm -rf $cpio_dir | ||