Description
Exercise #7
Complete the dl.c and elf.c programs.
dl.c
- It should use
dlopen(3)anddlsym(3)to open the/lib64/libm.so.6library and get the addresses for thesin()andcos()functions and compute and print the result ofsin(cos(M_PI))whereM_PIis the constant:
#define M_PI 3.14159265358979323846 /* pi */
Your completed program should not in any way be linked against the math library, but should be equivalent to:
#include <stdio.h>
#include <math.h>
int main(void)
{
printf("sin(cos(pi)) = %lf\n", sin(cos(M_PI)));
return 0;
}
elf.c
- This program should print the header information for an ELF object ala:
'
readelf -h <file>'. To do this it should mmap the ELF file into the processes address space (i.e. themapfile()function) and then the map theElf64_Ehdrstructure onto it and print out the information in the same format as thereadelfprogram outputs.