L2. Program creation process
Phases of program creation
Compilation
- compiler translates HLL code into assembly program or directly into object file
- every source file is translated into a separate output file
Assembly - asesmbler source file is translated by assembler into an object file
- each assembler source file is translated into a separate object file
Linking - Linker joins object files and library files into executable file which is later loadded into computer's memory
Linker doesn't know the source language of the module
Libraries contain ready-to-use, precompiled object modules stored in a modified (archived) form
Compilation
HLL compiler creates assembler form of each compiler module
may be stored in a file or supplied directly to the assembler via a pipe
later translated by assembler into an object file
some compilers create object files directly, without intermediate assembly
Assembly
Process of translating assembler source into aon object or executable file
Assembly source may be created by compiler or written by a programmer
Object form
Contain binary executable code with some references marked as undefined
Usually executable program consists of many linked modules
module may reference variables and functions defined in other modules
OBject file contains the description of external references - symbols used but not defined in the module and global, symbols defined in the module, made available to other modules
Linking
Process of resolving external references by connecting them to symbols defined as globals in other modules
Linking of the symbol is possible only if the symbol is defined as external - externally-defined
Linking to the symbol (target) is possible only if the target is defined as global - publicly available
The result is an exectable form, with all references resolved
if dynamic libraries are used, final linking occurs during loading the program to computer's memory
Linking fails when:
- external symbol referenced in some module is not defined in any module
- there is more than one (normal) deifnition of a symbol with the same name
External symbols
Sybols referenced in a given module, defined in other modules
Must be declared as external in a way depending on the programming language used
- C -
externkeyword, functions not defined in the module are treated as extrernal by default - ASM - explicit declaration always required -
externorextrn
Public symbols
Defined in a given module which may be used by other modules
Must be declared as public:
- C - every symbol defined on external level is considered public (except if declared with
statickeyword) - ASM - explicit declaration required -
public,global,globl
Libraries
Collection of object modules which may be linked to other modules written by programmer
Library file contains archived object files created from several source modules
Starndard library functions are usually supplied with a compiler
Programmer may create his own libraries which may be used by many programs