-
Notifications
You must be signed in to change notification settings - Fork 2
/
genbtf.sh
executable file
·174 lines (147 loc) · 3.01 KB
/
genbtf.sh
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#!/bin/bash
# SPDX-License-Identifier: Apache-2.0
# Copyright (c) 2024 Elastic NV
Script=${0##*/}
function usage
{
echo "usage: $Script path-to-btfhub-archive" 1>&2
exit 1
}
function die {
printf "%s: %s\n" "$Script" "$1" 1>&2
exit 1
}
if [ $# -ne 1 ]; then
usage
fi
Btfhub_path="$1"
Srcs_amd64="
amzn/2/x86_64
amzn/2018/x86_64
centos/7/x86_64
centos/8/x86_64
debian/bullseye/x86_64
debian/9/x86_64
debian/10/x86_64
fedora/24/x86_64
fedora/25/x86_64
fedora/26/x86_64
fedora/27/x86_64
fedora/28/x86_64
fedora/29/x86_64
fedora/30/x86_64
fedora/31/x86_64
ol/7/x86_64
ol/8/x86_64
rhel/7/x86_64
rhel/8/x86_64
sles/12.3
sles/12.5
sles/15.3
ubuntu/16.04/x86_64
ubuntu/18.04/x86_64
ubuntu/20.04/x86_64
"
Srcs_arm64="
amzn/2/arm64
centos/7/arm64
centos/8/arm64
debian/bullseye/arm64
debian/9/arm64
debian/10/arm64
fedora/28/arm64
fedora/29/arm64
fedora/30/arm64
fedora/31/arm64
ol/7/arm64
ol/8/arm64
rhel/7/arm64
rhel/8/arm64
ubuntu/16.04/arm64
ubuntu/18.04/arm64
ubuntu/20.04/arm64
"
# Table of all successfull kernels, so we can create all_btfs[]
typeset -a Good_amd64
typeset -a Good_arm64
typeset -i Total=0
Commit=$(cd "$Btfhub_path" && git rev-parse HEAD)
if [ -z "$Commit" ]; then
exit 1
fi
cat <<EOF
// SPDX-License-Identifier: Apache-2.0
/* Copyright (c) 2024 Elastic NV */
#include "quark.h"
/*
* THIS FILE IS AUTOGENERATED! Resist all urges to ruin its spirit manually!
*
* You can happily generate this through:
* $ make btfhub BTFHUB_ARCHIVE_PATH=/my/path/to/a/btfhub-archive
*
* Grab a beer as this takes some time. It's 3000 files for amd64 only.
*/
EOF
printf "const char *btfhub_archive_commit=\"%s\";\n\n" "$Commit"
function do_arch
{
if [ "$1" = amd64 ]; then
arch=amd64
srcs="$Srcs_amd64"
elif [ "$1" = arm64 ]; then
arch=aarch64
srcs="$Srcs_arm64"
else
die "bad arch"
fi
printf "#ifdef __%s__\n\n" $arch
for s in $srcs; do
distro=${s%/*}
s="$Btfhub_path/$s"
while IFS= read -r -d '' k
do
btf=$(basename "${k%%.tar.xz}")
version="${btf%%.btf}"
tar xf "$k" || die "oh noes"
name=${distro}_${version}
name=$(echo "$name" | tr \\055\\056\\057 _)
if ./quark-btf -g "$btf" "$distro" "$version" 2>/dev/null; then
echo "$name OK" 1>&2
if [ "$1" = amd64 ]; then
Good_amd64+=("$name")
elif [ "$1" = arm64 ]; then
Good_arm64+=("$name")
fi
else
echo "$name FAIL" 1>&2
fi
rm -f "$btf"
Total=$((Total+1))
done < <(find "$s" -name '*.tar.xz' -print0)
# for k in $(find "$s" -name '*.tar.xz'); do
# done
done
printf "#endif /* __%s__ */\n\n" $arch
}
do_arch amd64
do_arch arm64
cat <<EOF
struct quark_btf *all_btfs[] = {
EOF
printf "\n#ifdef __amd64__\n"
for name in "${Good_amd64[@]}"; do
printf "\t&%s,\n" "$name"
done
printf "#endif /* __amd64__ */\n\n"
printf "#ifdef __aarch64__\n"
for name in "${Good_arm64[@]}"; do
printf "\t&%s,\n" "$name"
done
printf "#endif /* __aarch64__ */\n\n"
cat <<EOF
NULL
};
EOF
typeset -i Good_count
Good_count=$((${#Good_amd64[@]} + ${#Good_arm64[@]}))
printf "%d/%d succeeded\n" $Good_count $Total 1>&2