This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: symbol size as function size
- From: Alan Modra <amodra at gmail dot com>
- To: "Paulo J. Matos" <pocmatos at gmail dot com>
- Cc: binutils at sources dot redhat dot com
- Date: Fri, 24 Jun 2011 12:01:49 +0930
- Subject: Re: symbol size as function size
- References: <itvosh$96k$1@dough.gmane.org>
On Thu, Jun 23, 2011 at 05:16:16PM +0100, Paulo J. Matos wrote:
> sum:
> ... // CODE FOR SUM
> .global __size_of_sum
> .equ __size_of_sum, .-sum
>
> __size_of_sum would then be used as a symbol containing the size in
> words of sum.
>
> The problem with the current setup is that as sets the value of
> __size_of_sum and when it is relaxed at link time, the size tends to
> decrease so the final value of __size_of_sum is wrong.
There isn't any provision for this sort of caper in current binutils
as far as I'm aware. You're really asking for a special class of
symbol, which the linker relaxation functions must adjust. If your
__size_of_sum were local and not emitted to the object symbol table
then you possibly could emit a special relocation on uses of
__size_of_sum that used the size of the function after relaxing.
> sum:
> ... // CODE FOR SUM
> .global __size_of_sum
> .size sum, .-sum
> .equ __size_of_sum, <reference to size of symbol sum>
>
> Then in the linker relaxation function for my backend, modify the
> size of symbol sum according to the relaxation. I guess the missing
> piece in this is a way in assembler to refer to the size of symbol
> sum (this would be code generated by gcc).
Again, this boils down to the same thing, needed a special class of
symbol. If I were implementing this feature I would not use global
symbols containing size info. Instead
a) Invent an assembler syntax that allows access to ELF symbol size,
"sum@size" perhaps. (I'm assuming this is ELF only.) "sum" would
not even need to be a defined symbol, it could be external.
b) Arrange for the assembler to emit a relocation on uses of
"sum@size", R_XXX_SIZE against symbol "sum".
c) Teach the linker relaxation functions to update ELF symbol size,
and add processing of the new relocation.
--
Alan Modra
Australia Development Lab, IBM