6.3.6.4 Arg Nodes
In both the call trees and the call graph itself, you can see functions
listed with the annotation (ARG
) after its name. This implies that the
call to that function at that point in the call graph is made to obtain an argument to
another function. For example, in the following code snippet, the function
input()
is called to obtain an argument value to the function
process()
.
result = process(input(0x7));
For such code, if it were to appear inside the main()
function, the call graph would contain the following.
_main (ROOT)
_input
_process
_input (ARG)
This indicates that main()
calls input()
and main()
also calls process()
, but
input()
is also called as an argument expression to
process()
.
These argument nodes in the graph do not contribute to the overall stack depth usage of the program, but they are important for the creation of the compiled stack. The call depth stack usage of the tree indicated above would only be 1, not 2, even though the argument node function is at an indicated depth of 2. This is because there is no actual reentrancy in terms of an actual call and a return address being stored on the hardware stack.
The compiler must ensure that the parameter area for a function and any of its ‘argument functions’ must be at unique addresses in the compiled stack to avoid data corruption. Note that a function’s return value is also stored in its parameter area; so that must to be considered by the compiler even if there are no parameters. A function’s parameters become ‘active’ before the function is actually called (when the arguments are passed) and its return value location remains ‘active’ after the function has returned (while that return value is being processed).
In terms of data allocation, the compiler assumes a function has been ‘called’ the moment that any of its parameters have been loaded and is still considered ‘called’ up until its return value is no longer required. Thus, the definition for ‘reentrancy’ is much broader when considering data allocation than it is when considering stack call depth.