[MLton] Darwin/PPC changes
Stephen Weeks
MLton@mlton.org
Tue, 28 Sep 2004 09:51:23 -0700
> The key point is to see if the difference between get_etext() and
> the lowest use code address (how you get that varies with the OS) is
> close to the code size as printed out by the size command. If it
> is, then using that should be fine.
The man page that Filip sent earlier on get_{edata,end,etext}
http://developer.apple.com/documentation/Darwin/Reference/ManPages/man3/get_end.3.html
where they very strongly discourage use of these functions points at
another library, dyld.
http://developer.apple.com/documentation/Darwin/Reference/ManPages/man3/dyld.3.html
I can see how to use that to obtain the code start address. And
testing it shows that the size matches Henry's criterion. So, it
looks like using a combination of dyld and get_etext will do the
trick. I'd be happy if someone could show me how to use dyld to get
the end of the text segment, but until then, I'll use get_etext.
Here's the code snippet that I used to test.
----------------------------------------------------------------------
#include <mach-o/dyld.h>
#include <mach-o/getsect.h>
#include <stdio.h>
int main () {
unsigned long address;
void *module;
struct mach_header *mh;
_dyld_lookup_and_bind ("_main", &address, &module);
mh = _dyld_get_image_header_containing_address (address);
fprintf (stderr, "start = 0x%08x\nget_etext = 0x%08lx\n",
(unsigned int)mh,
get_etext ());
return 0;
}