Linkers, Loaders & Executables

In a C program, which statement is correct about the address where the OS first starts execution (the entry point)?

  1. AIt is always the start of main
  2. BIt is always the first byte of the executable
  3. CIt is usually not main but start-up code such as _start, which initializes things and then calls main
Show answer and explanation

Answer: C. It is usually not main but start-up code such as _start, which initializes things and then calls main

The linker adds start-up objects supplied by the C runtime (such as crt1.o) to the program and makes the _start inside them the entry point. _start takes the command-line arguments from the stack, initializes the standard library and global objects, and then calls main. When main returns, its return value is passed to exit, which performs the shutdown steps.

  • A. Preparation code runs before main.
  • B. The entry address is recorded in the ELF header.
  • C. Correct. It is start-up code supplied by the C runtime.
Practice this topic Back to topic

More Linkers, Loaders & Executables questions

  1. When a C main function ends with "return 3;", what generally happens to the value 3?
  2. What happens when the strip command is applied to an executable?
  3. How does a linker treat a weak symbol?
  4. What is the main purpose of name mangling, in which a C++ compiler encodes argument types and other information into symbol names?
  5. What is the most suitable use of Linux's dlopen function (the counterpart of Windows LoadLibrary)?