![]() |
|
|||
0001 #!/bin/sh 0002 # SPDX-License-Identifier: GPL-2.0-only 0003 set -e 0004 0005 # Argument 1: Source file to build. 0006 IN="$1" 0007 shift 0008 # Extract just the filename for error messages below. 0009 FILE="${IN##*/}" 0010 # Extract the function name for error messages below. 0011 FUNC="${FILE#*-}" 0012 FUNC="${FUNC%%-*}" 0013 FUNC="${FUNC%%.*}" 0014 # Extract the symbol to test for in build/symbol test below. 0015 WANT="__${FILE%%-*}" 0016 0017 # Argument 2: Where to write the build log. 0018 OUT="$1" 0019 shift 0020 TMP="${OUT}.tmp" 0021 0022 # Argument 3: Path to "nm" tool. 0023 NM="$1" 0024 shift 0025 0026 # Remaining arguments are: $(CC) $(c_flags) 0027 0028 # Clean up temporary file at exit. 0029 __cleanup() { 0030 rm -f "$TMP" 0031 } 0032 trap __cleanup EXIT 0033 0034 # Function names in warnings are wrapped in backticks under UTF-8 locales. 0035 # Run the commands with LANG=C so that grep output will not change. 0036 export LANG=C 0037 0038 status= 0039 # Attempt to build a source that is expected to fail with a specific warning. 0040 if "$@" -Werror -c "$IN" -o "$OUT".o 2> "$TMP" ; then 0041 # If the build succeeds, either the test has failed or the 0042 # warning may only happen at link time (Clang). In that case, 0043 # make sure the expected symbol is unresolved in the symbol list. 0044 # If so, FORTIFY is working for this case. 0045 if ! $NM -A "$OUT".o | grep -m1 "\bU ${WANT}$" >>"$TMP" ; then 0046 status="warning: unsafe ${FUNC}() usage lacked '$WANT' symbol in $IN" 0047 fi 0048 else 0049 # If the build failed, check for the warning in the stderr. 0050 # GCC: 0051 # ./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] 0052 # Clang 14: 0053 # ./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] 0054 if ! grep -Eq -m1 "error: call to .?\b${WANT}\b.?" "$TMP" ; then 0055 status="warning: unsafe ${FUNC}() usage lacked '$WANT' warning in $IN" 0056 fi 0057 fi 0058 0059 if [ -n "$status" ]; then 0060 # Report on failure results, including compilation warnings. 0061 echo "$status" | tee "$OUT" >&2 0062 else 0063 # Report on good results, and save any compilation output to log. 0064 echo "ok: unsafe ${FUNC}() usage correctly detected with '$WANT' in $IN" >"$OUT" 0065 fi 0066 cat "$TMP" >>"$OUT"
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.1.0 LXR engine. The LXR team |
![]() ![]() |