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
  • CPUarchitecture
  • .oTarget text path
  • Method of symbol

What’s the use of Link Map File

  • View the code load order
  • Understand partitioned memory
  • CrashthroughSymbolsMechanism 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
  • SectionSection to display related address segments
  • SymbolsSection, method symbol segment

Path to the part

  • Pathis.appThe file path
  • Object filesis.oThe file path

SectionPart 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.

  • __TEXTcontainsMach header, the code being executed and read-only constants (e.gCString), read-only executable (r-x).
  • __DATAContain global variables, static variables, etc., read and write (rw-).
  • __LINKEDITContains 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.

__TEXTIn 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".

123It’s going to be in this area
__objc_classname The name of the class
__objc_methtype Method type
__ustring
__gcc_except_tab
__const storageconstModified constant
__dof_RACSignal
__dof_RACCompou
__unwind_info

__DATAIn 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__stubsandstub_helperUse.
__mod_init_func Method of module initialization
__const storageconstantConstant data.

Such as the useexternThe exportedconstModifier constant.
__cfstring Core Foundationstring
__objc_classlist OCClass list and class information

Mapping the__objc_dataThe address of the
__objc_nlclslist OC+loadThe list of functions,

than__mod_init_funcPerform earlier
__objc_catlist categories
__objc_nlcatlist categoriesthe+load ‘function list
__objc_protolist Agreement list
__objc_imageinfo Image information
__objc_const OCConstants. saveobjc_classdataStructure data.

Address used to map data related to a class, such as class name, method name, etc
__objc_selrefs Refer to theOCmethods
__objc_protorefs Refer to theOCagreement
__objc_classrefs Refer to theOC
__objc_superrefs Refer to theOCThe super class
__objc_ivar ivarPointer 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

SymbolsPart of the

  • Address: The address of the method code
  • Size: The space occupied by the method
  • File: Indicates the file number
  • Name:.oThe method symbol in the file

SymbolsPart of theFileThe order is andTarget -> Build Phase -> Compile SourcesThe 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!