| 1 | #!/bin/sh |
| 2 | # SPDX-License-Identifier: GPL-2.0-only |
| 3 | |
| 4 | |
| 5 | # Argument 1: Source file to build. |
| 6 | IN="" |
| 7 | |
| 8 | # Extract just the filename for error messages below. |
| 9 | FILE="" |
| 10 | # Extract the function name for error messages below. |
| 11 | FUNC="" |
| 12 | FUNC="" |
| 13 | FUNC="" |
| 14 | # Extract the symbol to test for in build/symbol test below. |
| 15 | WANT="__" |
| 16 | |
| 17 | # Argument 2: Where to write the build log. |
| 18 | OUT="" |
| 19 | |
| 20 | TMP="/..tmp" |
| 21 | |
| 22 | # Argument 3: Path to "nm" tool. |
| 23 | NM="" |
| 24 | |
| 25 | |
| 26 | # Remaining arguments are: $(CC) $(c_flags) |
| 27 | |
| 28 | # Clean up temporary file at exit. |
| 29 | |
| 30 | |
| 31 | } |
| 32 | |
| 33 | |
| 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. |
| 36 | |
| 37 | |
| 38 | status= |
| 39 | # Attempt to build a source that is expected to fail with a specific warning. |
| 40 | if ; then |
| 41 | # If the build succeeds, either the test has failed or the |
| 42 | # 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 ! | ; then |
| 46 | status="warning: unsafe () usage lacked '' symbol in " |
| 47 | fi |
| 48 | else |
| 49 | # 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 ! ; then |
| 55 | status="warning: unsafe () usage lacked '' warning in " |
| 56 | fi |
| 57 | fi |
| 58 | |
| 59 | if [; then |
| 60 | # Report on failure results, including compilation warnings. |
| 61 | | |
| 62 | else |
| 63 | # Report on good results, and save any compilation output to log. |
| 64 | |
| 65 | fi |
| 66 |