K
StationaryIt is difficult to deal with other people ' s functions by name. It is for her decision that an intermediate level between the reference code and the code being executed is established, namely objective code♪ The programme undergoes two stages of compilation - the establishment of objective modules and Location (laughs) Link)The module contains a machine code, but also names along with objects ' addresses: procedures and data structures.The formats of the objective modules may be different. For the DOS, the format was developed by Intel firm in time-free, for architecture x86. It was more or less adhered to by different language producers and media, so in theory, libraries created by different compilers and even different languages could be collated.The characteristic exception was Turbo Pascal and Borland Delphi, using its own objective format. *.dcu♪UNIX and Windows used the COFF standard not attached to the architecture. ELF is now in UNIX mira. For small microprocessary systems IEEE695.In addition to formats, there is a set of conditions under which modules can be compatible. These include, for example, agreements on the transfer of parameters, architecture, memory model, etc.Now how it works. Each function in each reference module shall be performed in this module. If not, the compiler expects that the function will be described: what parameters it accepts and what it returns. This information enables the compiler to generate a code to challenge the function with these parameters of " unknown origin " .When the code is generated, the compiler keeps all the areas of external function in the module. When her address is known, it will need to be updated in all these places.All internal functions (executed in the module), the compiler calls to a known address, but this address is relative, i.e., from the start of the module.All functions and data not flagged static See other modules, i.e., the module contains a table of conformity of names and relative addresses. You may not only serve from other modules, but contact the masses and variables from these modules.Next, if you create a library of functions, for example, Standard Library♪ it's convenient for all these hundreds of objective modules to be leaked into one file ♪ Library♪ It is important that only the necessary objective modules, not all, will be delivered from the library file when the software is assembled.Now, focus, focus, when compiling the program, you clearly indicate what it should be. You list everything. *.c files, all *.o or *.obj files as well as all *.lib or *.a files. The compiler creates objective modules from the reference code, and then transmits them all, including those that you clearly indicated to the consignor.Component collects an ongoing module. He adds all objective modules to each other, and counts the addresses so that they can count from the beginning of the image. The objective module is the smallest unit of the unit: one function, or one set, is not to be taken from it, but all together. But only the necessary objective modules are chosen from the libraries.Computer also Authorizes referencesI mean, compares names and writes addresses. There are no types at this stage, so the consignor can't verify the parameters or anything. He's just making names.As a result, you have an ongoing file that will be loaded by the downloader at the start of the program. In turn, the loader can change some relative addresses to absolutes, depending on the operating system, architecture, and so on, that's not always necessary. I write this later that this part becomes important when the code dynamics.Brief retreat. If objective modules produced by different compilers are compatible with each other, even modules written in different languages may be combined. It's quite common for C and C++, but it's simple. However, you can combine Fortran and C, or Pascal and C. Usually, in this case, you have to clearly follow the call agreements and use strange key words like this. _cdecl♪ _stdcall etc.If you cause one C function from another C function, which is located in different source files,, they'll have a similar default, and you don't have to take care of it.Dynamic configurationThe procedure described above has one major flaw: all the necessary objective modules will be stitched into the current module. The standard library is used in all programmes, so it's on a disk in dozens and hundreds of copies.Ideally, it should be in one copy copy, and the programmes should download objective modules from one standard location.These dynamically connected libraries are widely distributed in all modern operating systems. Windows is it. *.dllAnd in Linux... *.so♪In fact, it's the same library files that are actually loaded entirely. The final contact of the addresses is no longer a consignor, but a loader. The algorithm is approximately the same: in the simplest case, when the application starts, all the dynamic libraries he needs are immediately downloaded, and the loader describes the real addresses of the functions to all the calls.Naturally, the name of all export methods and data is clearly stated in such a library file.When and when usedIt may be a thought that a static and dynamic structure is strictly contradictory, but it is not. You can connect some of the libraries staticly, and some dynamically. Dynamic libraries, you can even download clearly in your program, but in this case you will not be able to summon the functions themselves directly, but only through a performance indicator.There's a lot of options, but you have a simple case.When you're calling. mallocthe compiler of arguments understands that it's a dynamic layout. *.so files). It means that your rolling module will require certain dynamic libraries that are listed within it with the names of functions.The downloader will find these libraries, upload them to the programme ' s address space, and write corrective addresses at all locations. On call. malloc The function will be created at a direct address, without any indicator for the function, in the fastest possible manner.DisclaimerAll this information is summarized. Additional agreements may exist for individual formats, operational systems, compilers.For example:The objective modules contain information, including information.The objective modules contain a partial compilation result. Like this. necessary C+++ to " hide " the reference code of the class(s). Naturally, it's not instant. When I dealt with it, there were separate, almost experimental compilators who supported it. I don't know how things are on the front now.In the Top Speed Compilers System, the format system was harder than described because the developers wanted to maximize the same tools for different languages, for example, a common low-level optimist was used. This means that common files were used to the level of objective modules.In DOS/Windows, there is a format for performing files *.com♪ It does not require a correction of addresses, in fact, that it should be downloaded to operational memory, and that the control should be transferred to the first instruction, and it will be operational. It's possible because of a segmental memory organization in architecture x86, and because *.com The file should be placed in one segment.Therefore, in some cases, things may be more complicated or easier than described here. Better on specific issues to check with documentation.