CrazyEngineers
  • What is Relocating Loader in System Programming?

    Updated: Oct 26, 2024
    Views: 13.1K

    Sure. To fully understand the concept of a relocating loader, you need to have some familiarity with operating systems, program loading, and memory management. Let's break it down:

    What is a Loader?

    In computer systems, a loader is the part of an operating system that is responsible for loading programs and libraries. It is one of the essential stages in the process of starting a program, as it places programs into memory and prepares them for execution.

    Loading involves reading the contents of the executable file containing the program instructions into memory, and then carrying out other necessary preparatory tasks to prepare the executable for running.

    What is a Relocating Loader?

    A relocating loader is a type of loader that can load the program into different regions of memory at different times during execution. This process allows better utilization of the system's memory.

    The term "relocating" refers to the ability of the loader to adjust, or "relocate", the absolute addresses in a program so that it can be loaded at an address different from the one originally specified for it.

    It achieves this by modifying the object code of a program based on the offset address, which is the starting address where the program is loaded in main memory.

    For instance, if a program has an instruction that refers to a memory location, the address of that memory location is determined when the program is assembled or compiled.

    If the program is later loaded into a different part of memory, the addresses referred to by those instructions will be incorrect. The relocating loader adjusts these addresses based on the new location of the program in memory.

    Absolute Loader Vs Dynamic Loader

    1. Absolute Loader: An absolute loader assumes that a program can be loaded at a specific memory address. Once loaded, the program must remain at that address throughout its execution. If that specific address is not available, or if the program has to be moved during its execution, the absolute loader cannot handle this. In contrast, a relocating loader adjusts the program so it can be loaded at different addresses.

    2. Dynamic Loader: A dynamic loader, as used in modern operating systems, is even more flexible. It not only allows programs to be loaded at different memory addresses, but it also allows parts of the program to be loaded and unloaded as needed during the program's execution, which can save memory.

    However, this requires the programs to be written in a way that supports dynamic loading, and it requires support from the operating system. A relocating loader does not provide this level of flexibility.

    Overall, the concept of a relocating loader is an important part of the history of memory management in computer systems, and forms the basis for more advanced techniques used in modern systems.

    Example of a Relocating Loader:

    The best examples of relocating loaders are found in early operating systems. Here's a simple hypothetical scenario to illustrate how a relocating loader would work:

    Imagine an operating system that starts each program at memory address 0. A programmer writes a program that uses memory addresses 0 through 999, and compiles it. The compiled program includes instructions that refer to these memory addresses.

    However, when the program is loaded into memory, another program is already using memory addresses 0 through 999. So, the operating system decides to load the new program starting at memory address 1000.

    An absolute loader would not be able to handle this situation, because the new program's instructions refer to addresses 0 through 999, not 1000 through 1999.

    But a relocating loader can adjust these addresses as it loads the program. The loader would add 1000 to each memory address in the program's instructions, so they refer to the correct memory locations.

    Relocating Loader vs Direct Linking Loader:

    A Direct Linking Loader (DLL) is a type of loader that combines several program modules (each compiled separately) into a single program that can be executed in memory.

    In other words, a direct linking loader resolves all the symbolic references among different object programs while loading them into memory.

    The main difference between a relocating loader and a direct linking loader involves the ability to handle multiple program modules:

    1. Relocating Loader: A relocating loader primarily concerns itself with adjusting memory addresses to allow a single program module to be loaded at a different location in memory than it was originally designed for.

    2. Direct Linking Loader: A direct linking loader goes a step further, allowing multiple program modules to be combined and loaded into memory, with the appropriate adjustments made for memory addresses. It is capable of resolving references between these modules, allowing for more complex programs that are composed of multiple modules that have been separately compiled.

    It's important to note that these capabilities aren't mutually exclusive. Many modern loaders, like those in Unix-based or Windows operating systems, combine these capabilities: they can load programs at different memory locations (like a relocating loader) and combine multiple program modules into a single program (like a direct linking loader).

    These modern loaders also support dynamic loading and linking, providing even greater flexibility.

    0
    Replies
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Replies
  • sushant005

    MemberJun 12, 2010

    It is a type of loader which load the program anywhere in the program.
    Initially the programmers write their main program is so that it would transfer to the location assigned to the square root subroutine(SQRT).
    the problem associated with this was that if the length of the program increased that may overlay the SQRT subroutine so to avoid this problem programmer used the subroutine that referred to each other symbolically rather then with the address part of the program.So the Relocating loader placed the subroutine in arbitrary core location.
    Are you sure? This action cannot be undone.
    Cancel
  • vishnu priya

    MemberJun 12, 2010

    The relocating loader will load the program anywhere in memory, altering the various addresses as required to ensure correct referencing. The decision as to where in memory the program is placed is done by the Operating System, not the programs header file. This is obviously more efficient, but introduces a slight overhead in terms of a small delay whilst all the relative offsets are calculated. The relocating loader can only relocate code that has been produced by a linker capable of producing relative code.
    Are you sure? This action cannot be undone.
    Cancel
  • sushant005

    MemberJun 15, 2010

    @ Kangyuataii,
    What you have written is totally making no sense to what is being asked in this thread.
    please don't copy paste and read the question again it is about what is relocating loader?
    Are you sure? This action cannot be undone.
    Cancel
  • Ankita Katdare

    AdministratorMar 18, 2014

    #-Link-Snipped-# That's a really informative reply! Thank you.
    Are you sure? This action cannot be undone.
    Cancel
  • pratik bembalkar

    MemberApr 30, 2019

    what is direct linking loader?

    Are you sure? This action cannot be undone.
    Cancel
Home Channels Search Login Register