Basically, I am trying to find a reliable way to get the length of a C function in bytes.
A few people suggest using the address of the function and the address of another function directly following it. I don't want to use this method, as I don't believe it is reliable. The compiler could move things around, and it just seems a bit hack-ish.
The solution I have come up with is to use two labels at the start and the end of a function. I have declared the lables with:
__asm__ __volatile__("func_start/end:");
Now, my problem is, I am having trouble getting the address of these labels put back into a variable in C.
Here is some code that I have already tried:
unsigned int addr, len;
__asm__ __volatile__("mov $func_start, %[address]\n\t"\
"mov $func_end, %[length]\n\t"\
: [address]"=r"(addr), [length]"=r"(len));
__asm__ __volatile__("mov %0, $func_start \n\t"\
"mov %1, $func_end\n\t"\
: "=r"(addr), "=r"(len));
Both of these examples give the error "ARM register expected" during compilation. As I am not very experienced with ARM assembly (let alone x86), I'm not sure what's wrong. I have tried to port the following x86 code to ARM:
__asm__ __volatile__("movl $enc_start, %0\n\t"\
"movl $enc_end, %1\n\t"\
: "=r"(addr), "=r"(len));
I'm obviously doing something wrong here. I would greatly appreciate it if someone could explain what I'm doing wrong. I've been stuck on this for a few weeks now. Thanks!