converting function pointers to/from object pointers

Martin Sebor msebor@gmail.com
Mon Aug 24 20:24:00 GMT 2015


> If the functions are reordered, chances are that clone_region_start and
> clone_region_end would span not all of the required functions and the
> consequence would be that not all of the required code would be copied to RAM
> and non-existing code would be called eventually.
>
> So the question is: how can I ensure the ordering of the functions?

I don't think there is a good way short of writing a cumbersome
linker script.

But I don't think that's the right question to ask (or one that
would lead to a robust solution). I think a better question to
ask is: how can one compute the size of a set of text symbols.
The answer to that is also "by writing a linker script," but
the solution to that problem is much easier than trying to order
all the text symbols. In the linker script for your image, save
the dot address in a symbol, say _start, then let the linker
define all the other symbols using wildcards, and then save
the dot address again, say in _end. The size is then the
difference between _start and _end. To compute the value in
your program simply declare _start and _end as symbols with
the appropriate type (char* or unsigned long) in your program
and compute the difference there (or have the linker do the
math and define/declare _size analogously).

Martin



More information about the Gcc-help mailing list