genoffset.sh: stop using a temporary file

Instead, use a here document for the input. This allows us to run the
while loop in the main script so we can build the list of asserts in
a shell variable. We then print out the list of asserts at the end of
the loop.

Reviewed by:	imp
Sponsored by:	Netflix
Differential Revision:	https://reviews.freebsd.org/D42407
This commit is contained in:
Jonathan T. Looney 2023-11-16 15:02:32 +00:00
parent a592812327
commit accfb4cc93

View file

@ -35,16 +35,13 @@ usage()
work()
(
local last off x1 x2 x3 struct field type lastoff lasttype
local last off x1 x2 x3 struct field type lastoff lasttype asserts
echo "#ifndef _OFFSET_INC_"
echo "#define _OFFSET_INC_"
echo "#if !defined(GENOFFSET) && (!defined(KLD_MODULE) || defined(KLD_TIED))"
last=
temp=$(mktemp -d genoffset.XXXXXXXXXX)
trap "rm -rf ${temp}" EXIT
# Note: we need to print symbol values in decimal so the numeric sort works
${NM:='nm'} ${NMFLAGS} -t d "$1" | grep __assym_offset__ | sed -e 's/__/ /g' | sort -k 4 -k 1 -n |
asserts=
while read off x1 x2 struct field type x3; do
off=$(echo "$off" | sed -E 's/^0+//')
if [ "$last" != "$struct" ]; then
@ -60,12 +57,14 @@ work()
printf "%b" "\t${type}\t${field};\n"
lastoff="$off"
lasttype="$type"
echo "_SA(${struct}, ${field}, ${off});" >> "$temp/asserts"
done
asserts="${asserts}_SA(${struct}, ${field}, ${off});\n"
done <<EOT
$(${NM:='nm'} ${NMFLAGS} -t d "$1" | grep __assym_offset__ | sed -e 's/__/ /g' | sort -k 4 -k 1 -n)
EOT
echo "};"
echo "#define _SA(s,f,o) _Static_assert(__builtin_offsetof(struct s ## _lite, f) == o, \\"
printf '\t"struct "#s"_lite field "#f" not at offset "#o)\n'
cat "$temp/asserts"
echo -e "${asserts}\c"
echo "#undef _SA"
echo "#endif"
echo "#endif"