• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: mach-o __TEXT segment layed out backwards?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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 16:32:24 -0700

At 5:58 PM -0500 9/15/04, Paul Haddad wrote:
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.

The only references to the padding is in the linker man page (man ld) and in the linker sources. It is partly for the case where the system libraries change, it allows a process to fix up paths in existing binaries (even those which are non-pick and can't be moved in memory). See -headerpad <value> and -headerpad_max_install_names.



 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 have never really thought about how to do that, and I am not sure it is a good idea.
--
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
References: 
 >Re: mach-o __TEXT segment layed out backwards? (From: Paul Haddad <email@hidden>)

  • Prev by Date: Re: RAID-1 possible for multi-filesystem disk?
  • Next by Date: Re: RAID-1 possible for multi-filesystem disk?
  • Previous by thread: Re: mach-o __TEXT segment layed out backwards?
  • Next by thread: Mach RPC and SecToken
  • Index(es):
    • Date
    • Thread