Export compiled binaries and headers
Header files - include preprocesor keyword is used export compiled binaries and headers include a header file in a C program. Header files does not include any function definitions except static or inline type. Library - We often write our program with the help of API or with function calls which are imported from other modules like C Library. Compiler contains several library files are to resolve external symbols during linking process. These library files are nothing but pre-compiled object binaries given by compiler tool chain or by external third party vendors.
Library file are in compiled binary format and thus source are protected. In this way Compiler toolchain providers or third party vendors expose thier software components to public and same time protects thier source code copyright. There are two types of libraries: Static libraries are like complied object code archived inside a single tar file. Linker takes only the object code during linking time.
This is same like using another object code of a source file except the source C file is not given. Source code for libraries are not given in the compiler. The reason can export compiled binaries and headers the copy-right. Static link export compiled binaries and headers one disadvantage as it increases the code size and code sharing between two modules is not possible. Dynamic link libraries have these advantages. DLL executable comes in a separate binary file and it will be loaded in a common area of the OS and can be shared across many applications.
Compilation - Compiler generates object code from source file. Object codes are intermediate code needed by the linker. After preprocessing a single file gets expanded with headers and macros. Now it passes to compiler. Compiler does syntax checking, validation and generates object code.
Compiler also works in conjunction with optimizer. The job of optimizer is to arrange the code or steps in such a way to reduce size or execution time. For example to optimize export compiled binaries and headers time optimizer often takes a frequently used local variable in one of CPU register. This ensures speed optimization.
Again optimizer sometimes changes logic flow of the code to make the output size smaller. Here it is clear that optimizer alters program a bit thus line by like stepping info may not be generated when optimization has been applied. Linker takes all object files and combined into one output binary. Linker links external symbols between these object files and also arranges code, rodata, data and BSS segments and generates a binary in the form of formats often known as a.
Now it is clear that linker checks the definition all symbols which is there in all object files but what will happen to the symbols which are imported from external libraries.
For these external symbols linker needs library files. There are mainly two types of library files - Static and dynamic. Export compiled binaries and headers libraries are same as object files archived in a container. Thus linking to static library is same as linking to an object file.
Dynamic libraries are compiled and linked binary file. There is concept of exporting table for symbols. Dynamic link library exports a set of function symbols through an export table. An application or C program imports these external symbols by means of import table.
During linking linker checks the symbol if it is imported from a DLL it creates an import table and there it writes the DLL name and function entry point. This way linker links these symbols.
It is the job of the loader of load the imported DLL first into the memory and checks the linkage then load the source application and links the import table with the exported function from DLL. This is called dynamic linking. Program loader does this process. Running - We execute a program in shell and we get the output in the console.
This seems very simple but a huge process is involved in this. There is a loader for a. It reads header of the binary and checks and validates code, rodata, data, BSS, import, export table etc. After this it export compiled binaries and headers corresponding segments in memory. If there are external symbols in import table it also loads all related dynamic link libraries if not loaded earlier. One thing to point here is loader also populates all the export entries of the DLL with proper loaded address.
Then it links all the symbols of the external libraries to the loaded application. It links via import table. It fills all the export compiled binaries and headers address of the external symbols from the export table of the DLL to import table of the application.
C runtime library glibc is one of such dynamic link library which takes these steps of loading. Now all the linking and loading process are done. So it creates task and copies these loaded address to code, rodata, data and BSS segments. It also creates a stack and heap space. There is a small startup code to do all the initialization. Then after all segment initialization it opens three files with descriptors stdin, stdout and stderr. These file descriptors are used for taking inputs and printing outputs and errors.
Next thing is argument parsing and creating argument count argc and argument vector argv. Now execution is inside our source code. You have viewed 1 page out of Your Export compiled binaries and headers learning is 0.
Login to check your learning progress.