Loader (computing)

From Wikipedia, the free encyclopedia
  (Redirected from Program loader)
Jump to: navigation, search
For applications that speed up loading from a tape or disk drive, see fast loader.

In computing, 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 a program involves reading the contents of the executable file containing the program instructions into memory, and then carrying out other required preparatory tasks to prepare the executable for running. Once loading is complete, the operating system starts the program by passing control to the loaded program code.

All operating systems that support program loading have loaders, apart highly specialized computer systems that only have a fixed set of specialized programs. Embedded systems typically do not have loaders, and instead the code executes directly from ROM. In order to load the operating system itself, as part of booting, a specialized boot loader is used. In many operating systems the loader is permanently resident in memory, although some operating systems that support virtual memory may allow the loader to be located in a region of memory that is pageable.

In the case of operating systems that support virtual memory, the loader may not actually copy the contents of executable files into memory, but rather may simply declare to the virtual memory subsystem that there is a mapping between a region of memory allocated to contain the running program's code and the contents of the associated executable file. (See memory-mapped file.) The virtual memory subsystem is then made aware that pages with that region of memory need to be filled on demand if and when program execution actually hits those areas of unfilled memory. This may mean parts of a program's code are not actually copied into memory until they are actually used, and unused code may never be loaded into memory at all.

Responsibilities[edit]

In Unix, the loader is the handler for the system call execve().[1] The Unix loader's tasks include:

  1. validation (permissions, memory requirements etc.);
  2. copying the program image from the disk into main memory;
  3. copying the command-line arguments on the stack;
  4. initializing registers (e.g., the stack pointer);
  5. jumping to the program entry point (_start).

Relocating loaders[edit]

Some operating systems need relocating loaders, which adjust addresses (pointers) in the executable to compensate for variations in the address at which loading starts. The operating systems that need relocating loaders are those in which a program is not always loaded into the same location in the address space and in which pointers are absolute addresses rather than offsets from the program's base address. Some well-known examples are IBM's OS/360 for their System/360 mainframes, and its descendants, including z/OS for the z/Architecture mainframes. In OS/360 systems the operating system facility is called "Program Fetch", while the "Loader" is an application program.

A program that is loaded may itself contain components that are not initially loaded into main storage, but can be loaded if and when their logic is needed. In a multitasking operating system, a program that is sometimes called a dispatcher juggles the computer processor's time among different tasks and calls the loader when a program associated with a task is not already in main storage. (By 'program,' here we mean a binary file that is the result of a programming language compilation, linkage editing, or some other program preparation process.) [2]

Dynamic linkers[edit]

Dynamic linking loaders are another type of loader that load and link shared libraries (like .dll files) to already loaded running programs.

See also[edit]

References[edit]

  1. ^ "exec". The Open Group Base Specifications Issue 6, IEEE Std 1003.1, 2004 Edition. The Open Group. Retrieved 2008-06-23. 
  2. ^ http://whatis.techtarget.com/definition/loader