How to find the end address of a function in a C prog?
c
Solution
With GCC, you can take the address of a label, with the `&&` operator (yes - `&&`, not `&`). This can be used as follows:
void f(void) {
printf("Start %p End %p\n", f, &&f_end);
f_end: return;
}
This won't give you exactly the end, because there's some epilogue code after the label, but I think it's good enough for an interview answer.
Problem
Start address can be obtained from the function name, how to find the end address of a function? I have been asked this question in interview: Consider the function f() which i wrote has crossed the text section and started over writing the adjacent section (data section). How can i handle this situation? Also he added that i should handle it through C code. I should not see the symbol map file and get the address.