How to find the end address of a function in program C?

The starting address can be obtained from the function name, how to find the final address of the function? I was asked this question in an interview:

Consider the f () function that I wrote, crossed a text section and started writing a neighboring section (data section). How can I deal with this situation? He also added that I should process it using the C code. I should not see the symbol map file and get the address.

+5
source share
4 answers

Using GCC, you can take the label address with an operator &&(yes - &&, not &).
This can be used as follows:

void f(void) {
    printf("Start %p End %p\n", f, &&f_end);
    f_end: return;
}

, - , , .

+5

C , , .

, .

.

, , " ", GetProcAddress, ( ), - , .

, , . , . , thunk.

+2

, C "" .

What you could do is check your binary program and parse character tables, etc.

+1
source

Perhaps your compiler can create a listing file, and your linker can create a map file. This will allow you to see how long a specific function is performed manually. Not sure if you need to determine the size from the C program itself.

0
source

All Articles