Re: mach-o: why is code placed towards the end of a page?
Re: mach-o: why is code placed towards the end of a page?
- Subject: Re: mach-o: why is code placed towards the end of a page?
- From: Joel Reymont <email@hidden>
- Date: Thu, 8 Jan 2009 22:45:16 +0000
Ed,
On Jan 8, 2009, at 10:31 PM, Ed Wynne wrote:
It should not be intentionally towards the end of the page. If you
look closer, you'll see that the mach-o header, as well as any
additional space reserved for library names, comes before the code
in the TEXT segment.
My understanding is that the Mach-O header always goes at the
beginning of the file. According to the docs, the load commands go
into page #1.
The page is 4096 bytes but the size of all commands is just 772.
Mach header
magic cputype cpusubtype caps filetype ncmds
sizeofcmds flags
0xfeedface 7 3 0x00 2 11 772
0x00000085
According to the text section,
sectname __text
segname __TEXT
addr 0x00001fc8
size 0x00000035
offset 4040
0x1fc8 = 8136, 0x35 = 53.
8136 - 4096 (pagezero) = 4040, exactly our offset above. This is fine,
we are on the 2nd page in memory, right after PAGEZERO.
4096 - 4040 = 56, our code size (0x35, 53) rounded to a multiple of 4.
Load commands 2, 3, etc. go after the text section, e.g. 4096 below.
Load command 2
cmd LC_SEGMENT
cmdsize 124
segname __DATA
vmaddr 0x00002000
vmsize 0x00001000
fileoff 4096
This proves that the linker places the first page of code towards the
end of the page. Would you agree?
I ran the test on a few more executables with similar results.
---
http://twitter.com/wagerlabs
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden