如何提取从C code所有的库函数堆栈大小? [英] How to extract stack size of all library functions from c code?

查看:710
本文介绍了如何提取从C code所有的库函数堆栈大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个类似的基准FFT,Dijkstra算法。我想收集所有的库函数和用户定义函数的堆栈大小。 C code是也可用。

I have few benchmarks like fft, dijkstra. I want to collect the stack size of all library functions and user defined functions. C code is also available.

我在管理硬件高速缓存,所以我需要每个小功能的确切堆栈大小,可变的。

I am managing cache in hardware, so i need the exact stack size of each small function, variable.

推荐答案

如果有最近 GCC 在编译可以通过 -fstack使用率标志海湾合作委员会(除了优化的标志,如有的话):

If compiling with a recent GCC you could pass the -fstack-usage flag to gcc (in addition of optimization flags, if any) which:

使得程序的编译器输出的堆栈使用信息,在每个功能的基础。转储的文件名通过附加。苏到auxname的。 auxname从输出文件的名称所产生,如果明确指定,它不是可执行文件,否则它是源文件的基本部分。一个条目由三个字段组成:

Makes the compiler output stack usage information for the program, on a per-function basis. The filename for the dump is made by appending .su to the auxname. auxname is generated from the name of the output file, if explicitly specified and it is not an executable, otherwise it is the basename of the source file. An entry is made up of three fields:

函数的名称。
     字节数。
     一个或多个限定词:静态动态

限定符静态表示函数操纵栈静态:固定字节数分配对函数入口的框架,并在函数出口释放;没有堆栈调整的功能,否则的。第二个字段是一个字节的这个固定数。

The qualifier static means that the function manipulates the stack statically: a fixed number of bytes are allocated for the frame on function entry and released on function exit; no stack adjustments are otherwise made in the function. The second field is this fixed number of bytes.

限定符动态表示函数动态操纵堆栈:除了上述的静态分配,栈调整是在函数体制作,例如推/流行的论点各地函数调用。如果预选赛也present,这些调整量在编译时是有界的,第二个字段是一个上限堆栈所使用的总量的功能。如果不是present,这些调整的量不会在编译时有界,第二个字段只重presents有界的一部分。

The qualifier dynamic means that the function manipulates the stack dynamically: in addition to the static allocation described above, stack adjustments are made in the body of the function, for example to push/pop arguments around function calls. If the qualifier bounded is also present, the amount of these adjustments is bounded at compile time and the second field is an upper bound of the total amount of stack used by the function. If it is not present, the amount of these adjustments is not bounded at compile time and the second field only represents the bounded part.

您也可以通过一个 -Wstack使用率= LEN 的的警示标志,其中:

You could also pass a -Wstack-usage=len warning flag, which:

警告如果一个函数的栈使用量可能比的 LEN 的字节。完成确定堆栈用量的计算是保守的。通过的alloca 分配变长数组或相关构造的任何空间,是由编译器决定是否发出警告时包括在内。

Warn if the stack usage of a function might be larger than len bytes. The computation done to determine the stack usage is conservative. Any space allocated via alloca, variable-length arrays, or related constructs is included by the compiler when determining whether or not to issue a warning.

最后,你可能会考虑使用 MELT 来定制你的目的编译器。例如,你可能会考虑扩大与海湾合作委员会的的MELT扩展仪器动态堆栈使用在每一个你的函数。

At last, you might consider using MELT to customize the compiler for your purposes. For example, you might consider extending GCC with your MELT extension to instrument dynamic stack usage in every of your functions.

当然,如果你想为库相同的信息,则应该从源头code重新编译它们。

Of course, if you want the same information for libraries, you should re-compile them from their source code.

BTW,部分功能堆栈使用,或者一些功能的调用发生时,可能不明确(当然取决于优化参数和目标系统),因为GCC是的有时的能力尾调用优化和功能的内联和/或的在线!):/ /gcc.gnu.org/ml/gcc-help/2009-10/msg00279.html相对=nofollow>功能克隆。此外,一些的 C标准库函数的printf memset的,....)奇迹般地知道这可能会使用一些内部的内置功能对它们进行编译。最后,一​​些软件(以及越来越多的库)与(使用链接时优化编译 -flto ),然后对各功能的堆栈使用并不明确(因为他们往往​​内联)。

BTW, the stack usage of some functions, or of some function calls occurrences, might be ill-defined (and certainly depends upon the optimization flags and the target system), since GCC is sometimes capable of tail call optimizations, and of function inlining (even on functions not qualified inline!) and/or function cloning. Also, some few C standard library functions (printf, memset, ....) are magically known to the compiler which might use some internal builtin functions to compile them. At last, several softwares (and more and more libraries) are compiled with link-time optimizations (using -flto), then the stack usage of individual functions is not well defined (since they are often inlined).

所以,我不知道你的问题作出任何的 precise 的感觉。你可能会改换和激励,完善它。

So I am not sure your question makes any precise sense. You might rephrase it and motivate and improve it.

这篇关于如何提取从C code所有的库函数堆栈大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆