What is Link Map File
Link Map File is a text generated by Xcode when it generates an executable File. It is used to record Link information.
- Path of the executable file
CPU
architecture.o
Target text path- Method of symbol
What’s the use of Link Map File
- View the code load order
- Understand partitioned memory
Crash
throughSymbols
Mechanism for locating source code- Analyze the class or library volume in the executable file and optimize the package volume
The Link Map File is generated
Xcode does not generate executable files by default when generating them.
Target -> Build Setting -> Linking set Write Link Map File to YES to generate Link Map File
You can also see the path of the generated file under Linking
It’s accessible through this path
~ / Developer/Xcode/DerivedData/project/Build/Intermediates noindex/project. The Build/Debug - iphonesimulator/project. The Build/project - LinkMap - normal - x 86_64.txtCopy the code
Another easy way is to find the. App file under Products, and then go back to the upper layer and follow the path to find the Link Map
View the Link Map File
The Link Map File is divided into three parts
- The path section shows the path of the generated related files
Section
Section to display related address segmentsSymbols
Section, method symbol segment
Path to the part
Path
is.app
The file pathObject files
is.o
The file path
Section
Part of the
The virtual address in the Mach-o file eventually maps to the physical address. These addresses are divided into separate sework-related: __TEXT, __DATA, and __LINKEDIT segments.
__TEXT
containsMach header
, the code being executed and read-only constants (e.gC
String), read-only executable (r-x
).__DATA
Contain global variables, static variables, etc., read and write (rw-
).__LINKEDIT
Contains metadata for the loader, such as the name and address of the function. It is read-only (R -
).
The sefile is divided into different sections, which store different information. The following is the introduction of some commonly used sections.
__TEXT
In the period ofSection
field | instructions |
---|---|
__text |
Code section to store machine compiled code |
__stubs |
Used to assist in dynamic linking code (dyld ) |
__stub_helper |
Used to assist dynamic linking |
__objc_methname |
Objc method name |
__stub_helper |
Used to assist dynamic linking |
__cstring |
String constants included in the code run, Ex. : #define kKey @"123" .123 It’s going to be in this area |
__objc_classname |
The name of the class |
__objc_methtype |
Method type |
__ustring |
|
__gcc_except_tab |
|
__const |
storageconst Modified constant |
__dof_RACSignal |
|
__dof_RACCompou |
|
__unwind_info |
__DATA
In the period ofSection
field | instructions |
---|---|
__got |
The physical address where the referenced symbol is stored, similar to a dynamic symbol table |
__la_symbol_ptr |
Lazy symbol Pointers. Lazily loaded function pointer address. Cooperate with __stubs andstub_helper Use. |
__mod_init_func |
Method of module initialization |
__const |
storageconstant Constant data.Such as the use extern The exportedconst Modifier constant. |
__cfstring |
Core Foundation string |
__objc_classlist |
OC Class list and class informationMapping the __objc_data The address of the |
__objc_nlclslist |
OC 的 +load The list of functions,than __mod_init_func Perform earlier |
__objc_catlist |
categories |
__objc_nlcatlist |
categoriesthe +load ‘function list |
__objc_protolist |
Agreement list |
__objc_imageinfo |
Image information |
__objc_const |
OC Constants. saveobjc_classdata Structure data.Address used to map data related to a class, such as class name, method name, etc |
__objc_selrefs |
Refer to theOC methods |
__objc_protorefs |
Refer to theOC agreement |
__objc_classrefs |
Refer to theOC 类 |
__objc_superrefs |
Refer to theOC The super class |
__objc_ivar |
ivar Pointer to the |
__objc_data |
Used to hold the data required by the class. The main thing is to map the __objc_const address, Find the relevant data for the class. |
__data |
Holds the protocol and the static quantity that has been initialized |
__bss |
Stores uninitialized static quantities |
__common |
Stores exported global data |
Symbols
Part of the
Address
: The address of the method codeSize
: The space occupied by the methodFile
: Indicates the file numberName
:.o
The method symbol in the file
Symbols
Part of theFile
The order is andTarget -> Build Phase -> Compile Sources
The file order is consistent.
Binary rearrangement
The binary rearrangement is to rearrange the order of the symbols of these methods. The main idea is to move the code used for startup to the front of the load!