I want to access the data segment of a c program. I found a working solution for Linux: Where are the symbols etext ,edata and end defined?
But the solution proposed for MacOS is not working for me. I have the following code:
#include <stdio.h>
#include <stdlib.h>
#include <mach-o/getsect.h>
int i;
int main(int argc, char *argv[])
{
printf("%p\n", &i);
printf(" program text (etext) %p\n", (void*)get_etext());
printf(" initialized data (edata) %10p\n", (void*)get_edata());
printf(" uninitialized data (end) %p\n", (void*)get_end());
exit(EXIT_SUCCESS);
}
Which outputs:
0x10c35b038
program text (etext) 0x100000ee6
initialized data (edata) 0x0
uninitialized data (end) 0x100003000
The address of i
is not between etext
and end
. And edata
seems to be NULL
.