What is Loader? Types, Functions, Pros, Cons & More

3
2
What is Loader

What is Loader?

A loader refers to the specific component that loads the necessary programs and libraries into the main memory of the computer to facilitate their execution, especially during the startup phase.

Technically, the loader is the component that reads the contents of the executable object codes generated by the compiler and assembler and performs the other necessary preparatory tasks to run them.

KEY TAKEAWAYS

  • A loader is designed to load parts of programs into the computer memory.
  • It helps in validating the program for permissions, memory requirements, and others.
  • The loader loads the command-line arguments needed for execution in the stack.
  • This component links the beginning of any program and other necessary libraries.
  • It initializes the registers and helps in jumping to the starting point of the program in the memory.

Understanding Loader

What is Loader

A loader in a computer memory is an important component that helps in starting any application by loading the program into the memory and preparing it for execution.

It is for this reason that the loader is typically located permanently in the memory of most of the operating systems. This helps in the faster loading of the programs.

Typically, every operating system that supports loading programs will use loaders. However, loaders may be absent in:

  • Extremely specialized computer systems are designed for running a particular set of special programs.
  • Embedded systems in which the codes are typically executed directly from the Read Only Memory (ROM).

However, there are quite a few operating systems supporting virtual memory that may have the loader stored in a pageable area in the memory.

In such situations, the loader will not copy the object codes or the content of it to the memory.

Instead, it will simply inform the subsystem of the virtual memory that there is a mapping between the contents of the related executable file and the specific space of the memory assigned for containing the codes of the program running.

Read Also:  What is Driver? Function, Types & More

This will actually help the virtual memory subsystem to know the following:

  • Which specific part of the memory is to be filled when required
  • When exactly the program execution will hit those unfilled areas in the memory

This means that:

  • Portions of the code of a program will not be really copied into the memory till these are not actually used.
  • The unused codes of the program may not be copied into the memory at all.

Functions of Loader

The loader is a specific type of a system program located in the memory that accepts object codes from the language translators as input for a program and helps in preparing them for execution.

It typically coordinates the operating system to get the original loading address of a file and loads it into the memory.

The functions of the loader are typically performed in four steps such as allocation, linking, relocation, and loading, where specific operations are performed in each step, as mentioned below.

In the allocation stage, the loader performs the following functions:

  • Assigning a memory space to load an object program for execution
  • Calculating the size of the program before allocating the space

In the linking stage, the functions performed by the loader include:

  • Linking two or more object codes
  • Providing information necessary for referencing between the codes
  • Resolving symbolic references between the object modules
  • Assigning addresses to user and library subroutines

In the relocation stage, the loader performs these basic functions:

  • Modifying the object program
  • Altering specific instructions to load at different addresses than the originally specified location
  • Adjusting address constants depending on the allocated space

In the final loading stage, the functions performed by the loader are:

  • Bringing the object codes for execution into the memory
  • Placing the data and machine instructions of relevant subroutines and programs into the memory

In addition to the above major functions, here are some other functions performed by the loader, depending on the type of operating system:

  • Validation
  • Memory mapping
  • Copying command-line arguments to virtual memory
  • Initializing registers
  • Initializing structures in the DLL
  • Creating a heap
  • Assigning environment variable blocks
  • Assigning PATH blocks
  • Adding NTDLL and executable to the module list
  • Loading KERNEL32.DLL
  • Loading executable imports
  • Garbage collection
  • Calling ntcontinue on the context parameter
Read Also:  What is Data Scrubbing? (Explained)

Types of Loaders

There are five major types of loaders that perform diverse sets of functions such as, Compile and Go Loader, Absolute Loader, Relocatable Loader Dynamic Run-time Loader, and Bootstrap Loader.

  • Compile and Go Loader – This loader reads every line of the compiled program and produces machine code that is placed directly in the assigned memory location.
  • Absolute Loader – This loader takes a relocated object file and puts it in a particular memory location without needing relocation information as it is in the program itself.
  • Relocatable Loader – This loader can assign space to the executable codes for proper execution at any place within the main memory.
  • Dynamic Run Time Loader – This loader detects and loads all shared libraries and executable codes while a program is being executed.
  • Boot Strap Loader – This loader is executed when the computer system is turned on for the first time or restarted and loads the operating system in the main system memory.

Advantages

  • There is no need to translate a program every time because an object program is created when a source program is executed.
  • There is no wastage of memory since the loader, which is located in the memory, is smaller than an assembly and therefore occupies a smaller space.
  • The source program can be written in multiple languages and with multiple programs.

Disadvantages

  • A modified program must be retranslated.
  • A specific portion of the memory needs to be reserved for it.

Loader Vs Linker

  • The loader is an important component of the operating system that loads programs and libraries. Linker is a utility program that takes other codes and joins them into one executable file.
  • Loader uses the input of executable files generated by the linker. On the other hand, the linker takes object codes from the compiler and assembler.
  • The job of the loader is to load the executable files into the memory, but the linker produces the executable files.
  • The loader allocates the addresses to the executable files. In comparison, the linker joins all different modules.
  • The loader is responsible for setting up references to be used in the program. On the other hand, the linker is responsible for object management in the program space.
  • There are usually four different types of loaders, but in comparison there are only two types of linkers such as Linkage Editor Linker and Dynamic Linker.
  • The loader is located after the linker, but the linker is located after the language translators, such as the assembler and compiler.
Read Also:  What is Virtual Address Extension (VAX)? (Explained)

Conclusion

The loader is a useful component in the memory that accepts object codes generated by the compilers and assemblers and helps in executing them by bringing them to the main memory.

Situated after the linker, it is also responsible for setting up references that will further help the programs in their operation.

About Puja Chatterjee

AvatarPuja Chatterjee, a distinguished technical writer, boasts an extensive and nuanced understanding of computer technology. She is an esteemed graduate of the Bengal Institute of Management Studies (BIMS), where she honed her skills and knowledge in the tech domain. Over the span of more than 12 years, Puja has developed a deep expertise that encompasses not only technology writing, where she articulates complex technical concepts with clarity and precision, but also in the realm of client relationship management. Her experience in this area is characterized by her ability to effectively communicate and engage with clients, ensuring their needs are met with the highest level of professionalism and understanding of their technical requirements. Puja's career is marked by a commitment to excellence in both written communication within the tech industry and fostering strong, productive relationships with clients.

Previous articleWhat is Write Error? Causes, Fixes & More
Next articleLRDIMM (Load Reduced Dual Inline Memory Module) Explained
Puja Chatterjee
Puja Chatterjee, a distinguished technical writer, boasts an extensive and nuanced understanding of computer technology. She is an esteemed graduate of the Bengal Institute of Management Studies (BIMS), where she honed her skills and knowledge in the tech domain. Over the span of more than 12 years, Puja has developed a deep expertise that encompasses not only technology writing, where she articulates complex technical concepts with clarity and precision, but also in the realm of client relationship management. Her experience in this area is characterized by her ability to effectively communicate and engage with clients, ensuring their needs are met with the highest level of professionalism and understanding of their technical requirements. Puja's career is marked by a commitment to excellence in both written communication within the tech industry and fostering strong, productive relationships with clients.
3 Comments
Oldest
Newest
Inline Feedbacks
View all comments