This program is used to do static stack analysis on C source code to determine the maximum stack space used by each function. Source must be compiled using gcc with a number of special flags (see below for details)
-c
, -fdump-rtl-dfinish
and -fstack-usage
gcc -c -fdump-rtl-dfinish -fstack-usage main.c my_library.c other.c
wcs.py
Note: When running wcs.py
the current working directory must contain all the relevant input files.
gcc
. The script directly calls the utility function readelf
. readelf
probably
resides in in the same folder as the gcc executable on your system.The script will search the current directory for sets of files with the names <name>.o
, <name>.su
and <name>.c.<id>.dfinish
. If all three are found the script will calculate the worst case stack for every function in the translation unit <name>.c
. The value of <id>
depends on the version of GCC you use and is auto-detected by the script. In gcc 5.3.1, for example, the value of <id>
is 270r
.
See the usage section for information about how to generate these files.
The scripts also look in files ending with *.msu. These files should contain a whitespace delimited table with function names in the first column, and a decimal integer with the worst case stack usage in the second line
my_function 20
do_something 120
__exit 144
Every line must contain a function / stack pair (empty lines are not permitted). These files can be useful for specifying the worst case stack for functions for which the c-source is not available but the stack usage is known by other means such as inspecting the assembly or run-time testing.
The script will output a list of functions in a table with the following columns:
unbounded
.unbounded:
. Consider adding a manual stack usage file, for better predictions.*.c
source. Calls to compiled libraries (e.g. libc.a) or to assembly functions will result in unbounded
(e.g. unknown) stack usage.The script has no way to detect situations 2 and 3. In the presence of these conditions the script will still complete successfully. Use caution.
readelf
. This should improve compatibility.multiple declarations
error