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: Paul Haddad <email@hidden>
- Date: Wed, 15 Sep 2004 17:58:53 -0500
Bob,
First thanks for the reply.
On Wed, 15 Sep 2004 13:58:39 -0700, Bob Campbell <email@hidden> wrote:
> 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).
In my test hello world type program the last section went all the way
to the last byte of the segment. From that I assumed that the __TEXT
segment was for some reason layed out from end to start. The thing
that made it somewhat confusing is that there is space between the end
of the loader commands and the start of the __text section. I looked
at a different executable and the last section didn't end at the last
byte of the segment, so obviously my original assumption was wrong and
the space between the loader commands and the __TEXT segment is as you
say padding.
Can you (or someone else) explain some more about what that space is
used for? In the few executables I've looked at they were always zero
filled.
> 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.
By ptrs I meant the offsets to the __DATA segment, sorry for the bad
terminology.
My intent for all this is to pop in some code into executables and
frameworks/bundles that runs on load (or very soon afterwards). It
seems to me like the way to do this would be either write my own dyld
(which seems very hard) or add/modify the __mod_init_func section and
pop in the code (after setting any offsets based on the symbol tables)
in some blank space in a segment (which seems less hard and I figured
__TEXT would be ideal).
I'm guessing someone else out there has tried to do this and maybe can
provide some hints?
_______________________________________________
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