brintos

brintos / linux-shallow public Read only

0
0
Text · 2.2 KiB · c2688ab Raw
67 lines · bash
1#!/bin/sh2# SPDX-License-Identifier: GPL-2.0-only3set -e4 5# Argument 1: Source file to build.6IN="$1"7shift8# Extract just the filename for error messages below.9FILE="${IN##*/}"10# Extract the function name for error messages below.11FUNC="${FILE#*-}"12FUNC="${FUNC%%-*}"13FUNC="${FUNC%%.*}"14# Extract the symbol to test for in build/symbol test below.15WANT="__${FILE%%-*}"16 17# Argument 2: Where to write the build log.18OUT="$1"19shift20TMP="${OUT}.tmp"21 22# Argument 3: Path to "nm" tool.23NM="$1"24shift25 26# Remaining arguments are: $(CC) $(c_flags)27 28# Clean up temporary file at exit.29__cleanup() {30	rm -f "$TMP"31}32trap __cleanup EXIT33 34# Function names in warnings are wrapped in backticks under UTF-8 locales.35# Run the commands with LANG=C so that grep output will not change.36export LANG=C37 38status=39# Attempt to build a source that is expected to fail with a specific warning.40if "$@" -Werror -c "$IN" -o "$OUT".o 2> "$TMP" ; then41	# If the build succeeds, either the test has failed or the42	# warning may only happen at link time (Clang). In that case,43	# make sure the expected symbol is unresolved in the symbol list.44	# If so, FORTIFY is working for this case.45	if ! $NM -A "$OUT".o | grep -m1 "\bU ${WANT}$" >>"$TMP" ; then46		status="warning: unsafe ${FUNC}() usage lacked '$WANT' symbol in $IN"47	fi48else49	# If the build failed, check for the warning in the stderr.50	# GCC:51	# ./include/linux/fortify-string.h:316:25: error: call to '__write_overflow_field' declared with attribute warning: detected write beyond size of field (1st parameter); maybe use struct_group()? [-Werror=attribute-warning]52	# Clang 14:53	# ./include/linux/fortify-string.h:316:4: error: call to __write_overflow_field declared with 'warning' attribute: detected write beyond size of field (1st parameter); maybe use struct_group()? [-Werror,-Wattribute-warning]54	if ! grep -Eq -m1 "error: call to .?\b${WANT}\b.?" "$TMP" ; then55		status="warning: unsafe ${FUNC}() usage lacked '$WANT' warning in $IN"56	fi57fi58 59if [ -n "$status" ]; then60	# Report on failure results, including compilation warnings.61	echo "$status" | tee "$OUT" >&262else63	# Report on good results, and save any compilation output to log.64	echo "ok: unsafe ${FUNC}() usage correctly detected with '$WANT' in $IN" >"$OUT"65fi66cat "$TMP" >>"$OUT"67