keropaloha.blogg.se

Mac executable file format
Mac executable file format









mac executable file format

#MAC EXECUTABLE FILE FORMAT CODE#

It only needs to free up the memory and, when the code is later referenced, read it back in from disk. Thus, if the kernel needs to reclaim the physical memory occupied by some _text pages, it does not have to save the pages to backing store and page them in later. As noted in The _TEXT Segment: Read Only, the _TEXT segment is read-only and is mapped directly to the executable file. Most of a typical Mach-O file consists of executable code, which occupies the _TEXT, _text section. However, they have as a common goal: greater efficiency in the use of memory. The techniques and goals for optimizing these segments are different. The composition of the _TEXT and _DATA segments of a Mach-O executable file has a direct bearing on performance. Symbol pointers for each undefined data symbol referenced by the executable. Symbol pointers for each undefined function called by the executable. Uninitialized external globals (for example, intĪ placeholder section, used by the dynamic linker. Uninitialized static variables (for example, static Initialized global variables (for example intĬonstant data needing relocation (for example, char * const p = "foo" ). Table 2 Major sections of the _DATA segment For a complete list of segments, see Mach-O Runtime Architecture. Table 2 lists some of the more important sections that can appear in the _DATA segment. The _DATA segment has a number of sections, some of which are used only by the dynamic linker. When that happens, the kernel creates a private copy of the page for that process. This technique defers copying the page until one of the processes sharing that page attempts to write to it. When memory pages are readable and writable, the kernel marks them copy-on-write. Because it is writable, the _DATA segment of a framework or other shared library is logically copied for each process linking with the library. This segment is both readable and writable. The _DATA segment contains the non-constant data for an executable. Position-independent code stub routines used by the dynamic linker ( dyld). Literal string constants (quoted strings in source code) The general constant data for the executable

mac executable file format

The compiled machine code for the executable Table 1 Major sections in the _TEXT segment

mac executable file format

Table 1 lists some of the more important sections that can appear in the _TEXT segment. If the kernel needs to free up physical memory, it can discard one or more _TEXT pages and re-read them from disk when they are needed. (This is primarily the case with frameworks and other shared libraries.) The read-only attribute also means that the pages that make up the _TEXT segment never have to be saved to backing store. When the segment is mapped into memory, it can be shared among all processes interested in its contents. Because the segment is read-only, the kernel can map the _TEXT segment directly from the executable into memory just once. By convention, the compiler tools create every executable file with at least one read-only _TEXT segment. The _TEXT segment is a read-only area containing executable code and constant data. There are several possible segments within a Mach-O executable, but only two of them are of interest in relation to performance: the _TEXT segment and the _DATA segment. The convention for segment names is to use all-uppercase letters preceded by double underscores (for example, _TEXT) the convention for section names is to use all-lowercase letters preceded by double underscores (for example, _text). The segments and sections of a Mach-O executable are named according to their intended use. Thus, a segment is always a multiple of 4096 bytes, or 4 kilobytes, with 4096 bytes being the minimum size. The size of a segment is measured by the number of bytes in all the sections it contains and rounded up to the next virtual memory page boundary. Segments always start on a page boundary, but sections are not necessarily page-aligned. Code or data of different types goes into each section. Each segment contains one or more sections. The ordering of code and data has implications for memory usage and paging activity and thus directly affects the performance of your program.Ī Mach-O binary is organized into segments. An executable format determines the order in which the code and data in a binary file are read into memory. Mach-O is the native executable format of binaries in OS X and is the preferred format for shipping code. Links to downloads and other resources may no longer be valid. This document may not represent best practices for current development.











Mac executable file format