symbol size as function size

Paulo J. Matos pocmatos@gmail.com
Thu Jun 23 16:16:00 GMT 2011


Hi all,

Following a post to gcc mailing list I need help with setting up a 
binutils backend properly.

We currently have a builtin GCC function __function_size that expands 
into a symbol and a function sum would have the assembly code:

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.

Ian told me through the GCC mailing list that adding defining 
DIFF_EXPR_OK should work and I did but it didn't work. My guess is that 
my rudimentary binutils backend is missing something or the version of 
binutils we are using is too old (version 2.17, I know its old but I 
think I am pretty much stuck to it unless you tell me this can't be done 
using this version).

Reiterating my previous thought, I thought that the solution could go 
through generating the additional line:
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).

Any suggestions?

Cheers,
-- 
PMatos



More information about the Binutils mailing list