[Bug middle-end/12285] Add sizeof_function functionality
mkgnu at gmx dot net
gcc-bugzilla@gcc.gnu.org
Fri Sep 19 09:52:00 GMT 2003
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12285
------- Additional Comments From mkgnu at gmx dot net 2003-09-19 06:55 -------
> If your target is ELF, then there is already function size info in the
> ELF symbol table. Try objdump -t executable. The first number is an
> address, the second number is the size of the symbol.
I am trying to get the size of a function compiled for the linux kernel, inside
the kernel. I need the function size info present during runtime.
> The compiler doesn't have enough info to compute function sizes. It has
>to defer it to the assembler by putting a laberl after the function end
>and then subtracting labels. This is what we do to get the ELF symbol
Which is precisely what I'm faking using macros.
> table size info. The only way to get this info back into C code would
> be to store it in a variable somewhere, but since the value is already
> in the symbol table, it would be wasteful to have a second copy of it.
You said "since the value is already in the symbol table". What do you mean ? Is
the symbol table available during runtime ? The value is not present in a binary
image (contained in a 4 byte variable). The value may be computed using
information contained in an ELF image. Right ?
What I need then is a C extension that will have the same effect as adding a
label at the end of the function (which I manually have to do with macros) and
computing that size during assembly time. The space allocated for that in memory
would be an unsigned long (4 bytes). During assembly time when the exact size is
computed, it can be filled in.
> If you are trying to copy functions around, you probably need to be
> looking at ELF headers anyways, so getting the info from there shouldn't
> be too much trouble.
I am looking to generate and modify code during runtime, and I need a way to
know where a function starts and ends. There's a starting label. But no ending
label. I faked my way around that using macros for just a few functions, but I
need a systematic way of always having that information available during runtime
for all functions.
Are you suggesting that I put together a script that objdumps every .o file in
order to get function sizes, and that generates a .asm with global variables for
all possible function names that I should have declared as externs in the
original .[cS] files ? That sounds inefficient since I then have a huge
collection of variables I may not use, but nevertheless interesting. Hmm...maybe
declare those as static so they only get linked in the final kernel image if used ?
Would this be a way of adding symbol table information in a binary file that are
accessible during runtime ?
More information about the Gcc-bugs
mailing list