Re: mach-o __TEXT segment layed out backwards?
Re: mach-o __TEXT segment layed out backwards?
- Subject: Re: mach-o __TEXT segment layed out backwards?
- From: Bob Campbell <email@hidden>
- Date: Wed, 15 Sep 2004 13:58:39 -0700
At 12:11 PM -0700 9/15/04, <email@hidden> wrote:
Date: Wed, 15 Sep 2004 10:36:56 -0500
From: Paul Haddad <email@hidden>
Subject: mach-o __TEXT segment layed out backwards?
To: email@hidden
Message-ID: <email@hidden>
Content-Type: text/plain; charset=US-ASCII
Hi All,
I've been looking around mach-o executables and I noticed that the
__TEXT segment seems to be layed out backwards, i.e. the last section
ends at the end of the segment and the other sections go backwards
from that.
Can someone explain to me why this is?
I am not really sure that "backwards" is the correct term. In an
application (or dylib) the loader commands are included in the __TEXT
segment, and then padded to have some space for some post link
operations to update various tables (like two-level namespaces etc).
When you look at the "sections" with in the __TEXT segment, it looks
like there is a hole at the beginning of the __TEXT segment, but that
space is really used for the loader commands.
(It is possible I am not understanding why you think there are
backwards so if my assumptions are incorrect, please clearify and I
will try to explain).
Also on a related note is it possible to relocate the __text section
post link? Well obviously it can be moved, but all the data/function
pointers will be screwed up so I guess the better question is after
link and after relocation can the __text ptrs be fixed?
After linking most all of the relocations are removed so that you
can't move things around (unless you effectively disassemble
everything and figure out what all of the relocations would have
been). In the PIC case you can move everything, but you must maintain
the relative offsets between all sections. (I.e. it moves as one
whole piece and references from __TEXT to __DATA are relative to the
__TEXT segment).
I am not completely sure what you mean by "__text ptrs", my
understanding is that the loader can run relocations on the __TEXT
segment, but really causes problems in that it forces the __TEXT
segment to become write able and prevents swapping from the original
image (I made that mistake 6 or so years ago and Kevin Enderby
correctly slapped my hand). It is for this reason that the literal
pointers end up in the __DATA segment.
--
Message Classification
[x] General Business Information
___________________________________________________________________
Bob Campbell email@hidden 408.991.7490
_______________________________________________
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