Difference between revisions of "Mach-O"
m (typos and language tweaks.) |
|||
Line 15: | Line 15: | ||
== Objective-C segment == | == Objective-C segment == | ||
− | There | + | There is no documentation about __OBJC segment and its sections. The following information has been gathered from cctools [http://opensource.apple.com/source/cctools/cctools-667.3/ sources] |
=== Structures strings === | === Structures strings === | ||
− | Some structures in sections | + | Some structures in sections contain name pointers. |
− | + | These names are stored in the c-strings section (segment: __TEXT; section: __cstring). | |
− | + | The file offset for the string name can be evaluated in the following way: | |
string_file_offset := cstr_section.offset + (name_addr - cstr_section.addr); | string_file_offset := cstr_section.offset + (name_addr - cstr_section.addr); | ||
Line 31: | Line 31: | ||
(objc_module record is declared at objc headers). | (objc_module record is declared at objc headers). | ||
− | + | The number of objc_module structures depends on the number of .m files with objects declarations compiled. _symtab contains the number of classes and categories declared in the module. | |
objc_module = packed record | objc_module = packed record | ||
Line 43: | Line 43: | ||
=== __class, __meta_class === | === __class, __meta_class === | ||
− | Sections uses identical structure objc_class. (objc_class record is declared at objc header, but has different meaning in the file) | + | Sections uses identical structure objc_class. (objc_class record is declared at objc header, but has a different meaning in the file) |
objc_class = record | objc_class = record | ||
Line 81: | Line 81: | ||
== Mach-O additional 30Kb size == | == Mach-O additional 30Kb size == | ||
− | FPC built mach-o executables are somehow larger, | + | FPC built mach-o executables are somehow larger, compared to the win32 target, for example |
begin | begin | ||
writeln('hello world'); | writeln('hello world'); |
Revision as of 15:34, 28 August 2009
from Wikipedia:
Mach-O, short for Mach object file format, is a file format for executables, object code, shared libraries, dynamically-loaded code, and core dumps. A derivation of the a.out format, Mach-O offered more extensibility and faster access to information in the symbol table.
File Format Reference can be found here
Following tools are used in Mac OS X to view Mach-O files:
otool - object file displaying tool
nm - display name list (symbol table)
Objective-C segment
There is no documentation about __OBJC segment and its sections. The following information has been gathered from cctools sources
Structures strings
Some structures in sections contain name pointers. These names are stored in the c-strings section (segment: __TEXT; section: __cstring). The file offset for the string name can be evaluated in the following way:
string_file_offset := cstr_section.offset + (name_addr - cstr_section.addr);
Sections
__module_info
(objc_module record is declared at objc headers).
The number of objc_module structures depends on the number of .m files with objects declarations compiled. _symtab contains the number of classes and categories declared in the module.
objc_module = packed record version : culong; // version number = 7 size : culong; // sizeof(objc_module)? name : PChar; // virtual memory address of the module name // Usually mapped to NULL string _symtab : Symtab; // virtual memory address to a proper Symtab structure. end;
__class, __meta_class
Sections uses identical structure objc_class. (objc_class record is declared at objc header, but has a different meaning in the file)
objc_class = record isa : PChar; // for classes ... // for meta-classes ... super_class : PChar; // contains the pointer to super_class name name : PChar; // pointer to class name version : PChat; // = 0 (for obj-c version 1?) info : culong; // CLS_CLASS for classes // CLS_META for meta-classes instance_size : culong; // size of the instance ivars : Pobjc_ivar_list; // pointer to virtual mapped ivars methodLists : PPobjc_method_list; // pointer to virtual mapped method list // description for methods are stored in "__inst_meth" section cache : Pobjc_cache; // zero protocols : Pobjc_protocol_list; // todo: end;
__image_info
The section contains only the image info information:
imageInfo = packed record version : uint32_t; flags : uint32_t; end;
Flags values:
ImageInfo_F_and_C = $01; ImageInfo_GC = $02; ImageInfo_GC_only = $04;
Mach-O additional 30Kb size
FPC built mach-o executables are somehow larger, compared to the win32 target, for example
begin writeln('hello world'); end.
gives a 30k (stripped) executable for Win, and 60k for Mac OS X.
Jonas Maebe: It's because there was a bug in older versions of the Darwin linker that required adding ".reference" assembler directives for routines that have more than one assembler name (most of the compiler helpers in the rtl have that). This fixed the problem, but as a result they are never smart linked out. It's only a fixed overhead of that 30kb (most programs don't contain any extra routines with multiple assembler names)