Linkers, Loaders & Executables

Learn about object files and the ELF format, symbol resolution and relocation, static and dynamic linking, and process memory layout with multiple-choice questions.

—Your accuracy
0 / 50Questions answered
Practice this topicAll questions in this topic, in random order Weak questionsRetry only the questions you last got wrong

Linkers, Loaders & Executables: key points

What a compiler produces is an object file, which cannot run on its own. A linker gathers object files and libraries, binds names of functions and variables (symbols) to actual addresses (symbol resolution), patches those addresses into instructions (relocation), and produces an executable.

A loader reads the executable into memory, sets up the text, data, BSS, heap and stack regions, and starts the program. Dynamic linking, which binds libraries at run time, and position-independent code (PIC), which runs at any address, help both to save memory and to improve security.

All Linkers, Loaders & Executables questions (50)

  1. Which statement is correct about the object file (.o) a compiler produces from one source file?
  2. What is the main role of a linker?
  3. Which describes the symbol resolution a linker performs?
  4. Which describes the relocation a linker performs?
  5. Linking a C program gives "undefined reference to `foo'". What is the most likely cause?
  6. Both a.c and b.c define a non-static global function void init(void) with the same name, and they are linked. What happens?
  7. In C, what is the effect of defining a function with static (e.g. static int helper(void))?
  8. In C, what does writing "extern int count;" mean?
  9. Which statement is correct about files in the ELF format commonly used on Linux and similar systems?
  10. What is in the .text section of an executable?
  11. In C, a global variable written outside any function as "int limit = 100;" is generally placed in which section?
  12. What is a characteristic of the .bss section?
  13. Running C code "char *p = "hello"; p[0] = 'H';" crashes in many environments. Why?
  14. Of the global variables above, which are generally placed in the .bss section?
  15. Where is a non-static local (automatic) variable declared inside a C function placed at run time?
  16. Memory allocated with C's malloc generally comes from which area of a process?
  17. Which lists the typical memory layout of a process on Linux and similar systems from low to high addresses?
  18. What is the advantage of laying out the heap and stack so they grow in opposite directions with a large gap between them?
  19. Which describes static linking?
  20. What is an advantage of dynamic linking (shared libraries)?
  21. A dynamically linked program copied to another computer fails to start. What is the most likely cause?
  22. When linking with a static library (.a file), what does the linker put into the executable?
  23. With the GNU linker, writing a static library before the object file that uses it, as in "gcc -lmylib main.o", can cause undefined-reference errors. Why?
  24. Which describes position-independent code (PIC)?
  25. What is the role of the GOT (global offset table) used in shared libraries?
  26. When dynamic linking uses lazy binding through the PLT (procedure linkage table), which statement is correct?
  27. What is the role of the dynamic linker (such as ld.so) when a dynamically linked program starts on Linux?
  28. What is the purpose of ASLR (address space layout randomization)?
  29. What is the main reason to build an executable as a PIE (position-independent executable)?
  30. What does the OS loader do when a program is started (for example by execve on Linux)?
  31. In a C program, which statement is correct about the address where the OS first starts execution (the entry point)?
  32. When a C main function ends with "return 3;", what generally happens to the value 3?
  33. What happens when the strip command is applied to an executable?
  34. How does a linker treat a weak symbol?
  35. What is the main purpose of name mangling, in which a C++ compiler encodes argument types and other information into symbol names?
  36. What is the most suitable use of Linux's dlopen function (the counterpart of Windows LoadLibrary)?
  37. When 100 processes use the same shared library, how is physical memory used?
  38. Disassembling an object file shows that an instruction calling the external function printf has a placeholder target such as 0. When is the correct value filled in?
  39. What is the role of a linker script used in embedded development?
  40. On a microcontroller without an OS, what does the start-up code do right after power-on before calling main?
  41. What is the difference between "sections" and "segments" in an ELF file?
  42. Which attack does W^X (never allowing a page to be both writable and executable) make harder?
  43. On Linux, when is the version number in a shared library's soname, such as the ".1" in libfoo.so.1, generally increased?
  44. What does running the ldd command on an executable on Linux show?
  45. Which pairs major operating systems with the executable formats they use correctly?
  46. When recursion goes so deep that it exceeds the stack limit, what generally happens on Linux and similar systems?
  47. In C, what is true of the starting values of a local variable and a global variable declared without initializers?
  48. After repeated malloc and free, a large block may become impossible to allocate even though total free memory is sufficient. What is this phenomenon called?
  49. When building a shared library, what is the advantage of exporting only the public functions and giving internal functions "hidden" symbol visibility?
  50. How does C++ run the constructors of global objects before main?

Other topics in Computer systems