I am looking for a way to determine the size (in bytes) of a compiled function.
I did a little research, and on most compilers you can't use sizeof(functionName). I looked at the PE32 headers, and I could only find the address of the entry point listed in there.
When using GCC, I think you could use a linker script, and it seems the info is also contained in the ELF file headers.
However, these solutions only work on Unix. Is there any way to do this in windows? I'm using Visual Studio and was wondering if the linker is capable of such a thing.
Another way to do this would be machinecode analysis (tracking down jmps and ret opcodes; I don't know how reliable this would be), but this seems pretty hard to implement.
EDIT: Several people asked why I want to do this. I do not consider this part of the question, but I want to run some tests with running certain computation-intensive functions on another computer. Nothing more than experimenting, really. I considered it to be a more efficient solution than sending the code and re-compiling every time. (So, maybe the classification as a "XY problem" might be true).
I know that optimization prevents functions to be nice 'blocks' of code, but I think it's possible to avoid this (by using a function pointer or compiler directives: this is how I got the function to be included in the export table when I was trying to extract the function size from the PE data).