1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
|
#!/bin/bash -efu
# SPDX-License-Identifier: GPL-2.0-only
#
# Generate defines based on kernel having
# some symbols declared
#
# Copyright (C) 2019-2021 <abc@openwall.com>
#
export LANG=C LC_ALL=C LC_MESSAGES=C LC_CTYPE=C
fatal() {
echo "Error: $*" >&2
exit 1
}
eval $(grep ^KDIR Makefile | tr -d ' ')
[ "$KDIR" ] || fatal "KDIR is not found"
WD=cc-test-build
mkdir -p $WD
cd ./$WD || fatal "cannot cd to $WD"
# args: HAVE_SUMBOL symbol include
kbuild_test_compile() {
local cmd
cat > test.c
echo obj-m = test.o > Makefile
cmd="make -s -B -C $KDIR M=$PWD modules"
echo "$cmd" > log
if $cmd >> log 2>&1; then
echo " declared" >&2
[ "$2" ] && echo "// $2 is declared ${3:+in <$3>}"
echo "#define HAVE_$1"
echo
else
echo " undeclared" >&2
echo "#undef HAVE_$1"
echo "// ${2:-symbol} is undeclared${3:+ in <$3>}."
echo "// Compile:"
sed "s/^/\/\/ /" test.c
echo "// Output:"
sed "s/^/\/\/ /" log
echo
if ! egrep -q 'has no member named|undeclared|storage size of .* isn.t known|No such file or directory' log; then
echo "Error: unexpected error from compiler" >&2
cat log >&2
echo >&2
exit 3
fi
fi
}
# Test that symbol is defined.
kbuild_test_symbol() {
echo -n "Test symbol $* " >&2
kbuild_test_compile ${1^^} $1 ${2-} <<-EOF
#include <linux/module.h>
${2:+#include <$2>}
MODULE_LICENSE("GPL");
void *test = $1;
EOF
}
# Test that struct is defined.
kbuild_test_struct() {
echo -n "Test struct $* " >&2
kbuild_test_compile ${1^^} "struct $1" ${2-} <<-EOF
#include <linux/module.h>
${2:+#include <$2>}
MODULE_LICENSE("GPL");
struct $1 test;
EOF
}
# Test that struct have member
kbuild_test_member() {
echo -n "Test member $* " >&2
structname=${1%.*}
member=${1#*.}
def=${1^^}
def=${def//./_}
kbuild_test_compile $def "struct $1" ${2-} <<-EOF
#include <linux/module.h>
${2:+#include <$2>}
MODULE_LICENSE("GPL");
typeof(((struct $structname*)0)->$member) test;
EOF
}
echo "// Autogenerated for $KDIR"
echo
# helpers introduced in 613dbd95723aee7abd16860745691b6c7bda20dc
kbuild_test_symbol xt_family linux/netfilter_ipv4/ip_tables.h
kbuild_test_struct timeval linux/ktime.h
# 97a32539b9568 proc: convert everything to "struct proc_ops"
# d56c0d45f0e27 proc: decouple proc from VFS with "struct proc_ops"
kbuild_test_struct proc_ops linux/proc_fs.h
# No since v5.1, but present in CentOS-8's 4.18.0-227
kbuild_test_symbol synchronize_sched linux/rcupdate.h
# Fails on 3.10.0-957.10.1.el7.x86_64
kbuild_test_symbol nf_bridge_info_get linux/netfilter_bridge.h
# Stumbled on 5.9
kbuild_test_struct vlan_dev_priv linux/if_vlan.h
# b86c0e6429da ("netfilter: ecache: prepare for event notifier merge")
kbuild_test_member nf_ct_event_notifier.ct_event net/netfilter/nf_conntrack_ecache.h
echo "// End of compat_def.h"
cd $OLDPWD
rm -rf $WD
# debug output for Travis
if [ -z "${PWD/*travis*}" ]; then
cat compat_def.h >&2
fi
|