Question: a. In which segments of the executable are a, b, s, and func stored? Use the command readelf -hSs out to verify your solution. Locate

 a. In which segments of the executable are a, b, s,

a. In which segments of the executable are a, b, s, and func stored? Use the command readelf -hSs out to verify your solution. Locate each object in the symbol table (.symtab) and match the section index given in the Ndx column with the section headers. Hint: The compiler may have renamed s to s.n with n being some decimal number to prevent name clashes.

b. In which address space segments do r and *parg (the value (int) that parg points to) reside, respecively, when executing the program?

c. Where is the return value of func() placed? Verify you solution by disassembling the executable with objdump -Sd out and finding the epilogue of func().

d. What shared libraries are needed by out? Use the tool ldd to list all library dependencies. /lib64/ld-linux-x86-64.so.2 is the 64-bit ELF dynamic linker/loader, responsible for resolving library dependencies, loading them into the address space of the process and performing the dynamic linking. What purpose does each of the other libraries serve?

Consider the following C program that does some random computations. Download the source code of the program gcc with the following command line: gcc -g main.c func.c -o out You should now have an executable file called out. main.c: #include #include "func.h" func.c: const int a = 42; int b = 1; int main() { int *parg, result; int func(int *parg) { static int s = 0; int r; parg = (int*)malloc(sizeof(int)); if (parg == NULL) exit(1); *parg = 10; result = func(parg); free (parg); if (s == 0) { r = *parg + a; s = 1; } else { r = *parg + b; b++; } return result; } func.h: int func(int *parg); return r; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!