get size of function

Simon s.d.hammett at gmail.com
Wed Aug 31 10:40:39 PDT 2011


On 31/08/2011 15:42, Johannes Pfau wrote:
> Trass3r wrote:
>> Am 31.08.2011, 12:05 Uhr, schrieb maarten van damme
>> <maartenvd1994 at gmail.com>:
>>
>>> Am I sure those functions aren't shift around during optimization?
>>
>> No. It's just an ugly hack and likely to go up in flames.
>> Also what you try could only work with PIC but even then...
>
> That's true, as I already said it for sure is an ugly hack. There's no
> guarantee that the compiler outputs the functions in this order. The
> linker could change the order as well. And if you send this function to
> another process (or even a different machine), you might get even more
> issues (for example some kind of offset calculated by the compiler and
> "hard-coded" into the function could be wrong in the other process).
>
> The Linux kernel does some tricks to store 'dynamic' lists in ELF files.
> For this to work it also needs access to the size of the list. You could
> use a similar approach: You'd have to write your own linker script to
> put your function in an own sections, than output 2 symbols exactly
> before and after the function. But that's a lot of work and I personally
> think that's still an ugly hack. It's used in the Linux kernel however,
> so it has to work.
>
> DMD also uses a similar trick with the _deh_beg and _deh_end symbols,
> maybe dmd does something to make that mechanism less fragile, you could
> look it up in the compiler source.

Then you will run into problems with data execution prevention, so 
you'll have to write OS specific code for each platform to run the code.

The easiest and most portable way to export runnable code is use an 
interpreted language.

After that you could look at llvm, but there's no D interface to that.

All in all, it's a big messy can of worms you are trying to open.

-- 
My enormous talent is exceeded only by my outrageous laziness.
http://www.ssTk.co.uk


More information about the Digitalmars-d-learn mailing list