Linker joins code from all used units, determines addresses of variables, functions and procedures, resolves references and generates executable file.

This is the last phase of program compilation – linking all modules and creating the executable file for program. Turbo Pascal first marks all symbol table blocks for variables, typed constants, procedures and code blocks as unused, then it iterates through all modules and marks used blocks starting from the main program, after that it …

Turbo Pascal uses “smart” linker which eleminates code and variables that are never referenced. This reduces code size and memory usage. First all symbol table blocks in all modules that reference variables, typed constants and code blocks are marked as unused. Finally, the main program block is marked as referenced since it will be executed …

This procedure calculates offset of each program code block and total code size.

This procedure calculates offset in data segment for each block of typed constants and variables and checks total data size.

Once the offsets of code blocks, variables and typed constants are known, the compiler can resolve references. This procedure calculates all references (displacements, offsets, near and far pointers) to code or data.

This procedure creates space in heap for exe header and typed constants, creates exe file and positions it to the start of the code.