Re: mach-o __TEXT segment layed out backwards?
site_archiver@lists.apple.com Delivered-To: darwin-dev@lists.apple.com Date: Wed, 15 Sep 2004 10:36:56 -0500 From: Paul Haddad <paul.haddad@gmail.com> Subject: mach-o __TEXT segment layed out backwards? To: darwin-dev@lists.apple.com Message-ID: <944074f304091508363060a449@mail.gmail.com> 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. 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? At 12:11 PM -0700 9/15/04, <darwin-dev-request@lists.apple.com> wrote: 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). 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 bobc@metrowerks.com 408.991.7490 _______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-dev mailing list (Darwin-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-dev/site_archiver%40lists.appl... This email sent to site_archiver@lists.apple.com
participants (1)
-
Bob Campbell