The linking process in detail
The relocatable modules in object files and libraries, produced by the IAR compiler and assembler, cannot be executed as is. To become an executable application, they must be linked.
Note
Modules produced by a toolset from another vendor can be included in the build as well, as long as the module is AEABI (Arm Embedded Application Binary Interface) compliant. Be aware that this might also require a compiler utility library from the same vendor.
The linker is used for the link process. It normally performs the following procedure (note that some of the steps can be turned off by command line options or by directives in the linker configuration file):
Determine which modules to include in the application. Modules provided in object files are always included. A module in a library file is only included if it provides a definition for a global symbol that is referenced from an included module.
Select which standard library files to use. The selection is based on attributes of the included modules. These libraries are then used for satisfying any still outstanding undefined symbols.
Handle symbols with more than one definition. If there is more than one non-weak definition, an error is emitted. Otherwise, one of the definitions is picked (the non-weak one, if there is one) and the others are suppressed. Weak definitions are typically used for inline and template functions. If you need to override some of the non-weak definitions from a library module, you must ensure that the library module is not included (typically by providing alternate definitions for all the symbols your application uses in that library module).
Determine which sections/section fragments from the included modules to include in the application. Only those sections/section fragments that are actually needed by the application are included. There are several ways to determine which sections/section fragments that are needed, for example, the
__rootobject attribute, the#pragma requireddirective, and thekeeplinker directive. In case of duplicate sections, only one is included.Where appropriate, arrange for the initialization of initialized variables and code in RAM. The
initializedirective causes the linker to create extra sections to enable copying from ROM to RAM. Each section that will be initialized by copying is divided into two sections—one for the ROM part, and one for the RAM part. If manual initialization is not used, the linker also arranges for the startup code to perform the initialization.Determine where to place each section according to the section placement directives in the linker configuration file. Sections that are to be initialized by copying appear twice in the matching against placement directives, once for the ROM part and once for the RAM part, with different attributes. During the placement, the linker also adds any required veneers to make a code reference reach its destination or to switch CPU modes.
Produce an absolute file that contains the executable image and any debug information provided. The contents of each needed section in the relocatable input files is calculated using the relocation information supplied in its file and the addresses determined when placing sections. This process can result in one or more relocation failures if some of the requirements for a particular section are not met, for instance if placement resulted in the destination address for a
PC-relative jump instruction being out of range for that instruction.Optionally, produce a map file that lists the result of the section placement, the address of each global symbol, and finally, a summary of memory usage for each module and library.
This illustration shows the linking process:

During the linking, ILINK might produce error and logging messages on stdout and stderr. The log messages are useful for understanding why an application was linked as it was. For example, why a module or section (or section fragment) was included.
Note
To see the actual content of an ELF object file, use ielfdumparm. See The IAR ELF Dumper—ielfdumparm.