Presentation on theme: "Mr. D. J. Patel, AITS, Rajkot 1 Operating Systems, by Dhananjay Dhamdhere1 Static and Dynamic Memory Allocation Memory allocation is an aspect of a more."— Presentation transcript:
Mr. D. J. Patel, AITS, Rajkot 1 Operating Systems, by Dhananjay Dhamdhere1 Static and Dynamic Memory Allocation Memory allocation is an aspect of a more general action in software operation known as binding Static allocation performed by compiler, linker, or loader Sizes of data structures must be known a priori Dynamic allocation provides flexibility Memory allocation actions constitute an overhead during operation
Mr. D. J. Patel, AITS, Rajkot LINKERS
3 Operating Systems, by Dhananjay Dhamdhere3 Execution of Programs A has to be transformed before it can be executed Many of these transformations perform memory bindings Accordingly, an address is called compiled address, linked address, etc
Mr. D. J. Patel, AITS, Rajkot Why Linkers ?? Modularity Modularity Program can be written as a collection of smaller source files, rather than one monolithic mass. Can build libraries of common functions e.g., Math library, standard C library Efficiency Efficiency Time: Change one source file, compile, and then relink. No need to recompile other source files. Space: Libraries of common functions can be aggregated into a single file... Yet executable files and running memory images contain only code for the functions they actually use.
Mr. D. J. Patel, AITS, Rajkot Introduction to Linkers Linking Linking The process of collecting and combining various pieces of code and data into a single file that can be loaded (copied) into memory and executed. Linking time Can be done at compile time, i.e. when the source code is translated Or, at load time, i.e. when the program is loaded into memory Or, even at run time. Static Linker Static Linker Performs the linking at compile time. Takes a collection of relocatable object files and command line arguments and generate a fully linked executable object file that can be loaded and run. Performs two main tasks Symbol resolution: associate each symbol reference with exactly one symbol definition Relocation: relocate code and data sections and modify symbol references to the relocated memory locations Dynamic Linker Dynamic Linker Performs the linking at load time or at run time.
Mr. D. J. Patel, AITS, Rajkot relocation_factor P = l_origin P – t_origin P l symb = t symb + relocation_factor P Performing Relocation re Ref : 224 – D M Dhamdhere
Mr. D. J. Patel, AITS, Rajkot 7 Operating Systems, by Dhananjay Dhamdhere7 Relocation Instructions using memory addresses are address- sensitive Relocation is needed if program is to execute correctly in some other memory area: involves changing addresses Ref : 223 –Figure : 7.2 D M Dhamdhere
Mr. D. J. Patel, AITS, Rajkot Example - I Ref : Pg: 226 Example 7.5 – D M Dhamdhere
Mr. D. J. Patel, AITS, Rajkot Solution - I Size A = 51 B = 69 C = 54 Load time Origin A = 300 B = 351 C = 420 Relocation Factor RF A = 300 – 200 = 100 RF B = 351 – 302 = 49 RF C = 420 – 480 = -60
Mr. D. J. Patel, AITS, Rajkot Design of Linker Relocation Requirement Linking Requirement Name Table (NTAB) – with the field of Synbols name and Linked_address eg. : Pg: 231 – Example : 7.9
Mr. D. J. Patel, AITS, Rajkot Self Relocating Programs Which program can be modified, or can modfied it self, to execute from a given Load Origin. Classifications : 1) Non Relocatable Program 2) Relocatable Programs 3) Self Relocating Programs Ref : pg: Dhamdhere
Mr. D. J. Patel, AITS, Rajkot Non Relocatable Program 1) Can't Execute in Any Memory Area, Only on Traslated Origin 2) Lack of Address Sensitive Instructions 3) e.g. Hand Coded Machine Language Program
Mr. D. J. Patel, AITS, Rajkot Relocatable Programs 1) Can Execute in Any Desired Memory Area 2) Availability of Address Sensitve Instruction 3) e.g. Object Module
Mr. D. J. Patel, AITS, Rajkot Self Relocating Programs 1) Can Execute in Any Memory Area 2) Availability of Own Address Sensitve Instruction 3) Relocating Logic Specified on the start of the Program 4) Useful for Time sharing Operating System
Mr. D. J. Patel, AITS, Rajkot Linking for Overlays Overlay : It is a part of a program that use same load origin as some part of the program. Advantages : ► Keep in memory only those instructions and data that are needed at any given time. ► Needed when process is larger than amount of memory allocated to it. ► Implemented by user, no special support needed from operating system, programming design of overlay structure is complex. ►Used to reduce the Main Memory Requirements.
Mr. D. J. Patel, AITS, Rajkot An Overlay Tree
Mr. D. J. Patel, AITS, Rajkot Loader An operating system utility that copies programs from a storage device to main memory, where they can be executed. In addition to copying a program into main memory, the loader can also replace virtual addresses with physical addresses. Most loaders are transparent, i.e., you cannot directly execute them, but the operating system uses them when necessary. Absolute loader can only load origin = linked Origin.