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)
- Which statement is correct about the object file (.o) a compiler produces from one source file?
- What is the main role of a linker?
- Which describes the symbol resolution a linker performs?
- Which describes the relocation a linker performs?
- Linking a C program gives "undefined reference to `foo'". What is the most likely cause?
- 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?
- In C, what is the effect of defining a function with static (e.g. static int helper(void))?
- In C, what does writing "extern int count;" mean?
- Which statement is correct about files in the ELF format commonly used on Linux and similar systems?
- What is in the .text section of an executable?
- In C, a global variable written outside any function as "int limit = 100;" is generally placed in which section?
- What is a characteristic of the .bss section?
- Running C code "char *p = "hello"; p[0] = 'H';" crashes in many environments. Why?
- Of the global variables above, which are generally placed in the .bss section?
- Where is a non-static local (automatic) variable declared inside a C function placed at run time?
- Memory allocated with C's malloc generally comes from which area of a process?
- Which lists the typical memory layout of a process on Linux and similar systems from low to high addresses?
- What is the advantage of laying out the heap and stack so they grow in opposite directions with a large gap between them?
- Which describes static linking?
- What is an advantage of dynamic linking (shared libraries)?
- A dynamically linked program copied to another computer fails to start. What is the most likely cause?
- When linking with a static library (.a file), what does the linker put into the executable?
- 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?
- Which describes position-independent code (PIC)?
- What is the role of the GOT (global offset table) used in shared libraries?
- When dynamic linking uses lazy binding through the PLT (procedure linkage table), which statement is correct?
- What is the role of the dynamic linker (such as ld.so) when a dynamically linked program starts on Linux?
- What is the purpose of ASLR (address space layout randomization)?
- What is the main reason to build an executable as a PIE (position-independent executable)?
- What does the OS loader do when a program is started (for example by execve on Linux)?
- In a C program, which statement is correct about the address where the OS first starts execution (the entry point)?
- When a C main function ends with "return 3;", what generally happens to the value 3?
- What happens when the strip command is applied to an executable?
- How does a linker treat a weak symbol?
- What is the main purpose of name mangling, in which a C++ compiler encodes argument types and other information into symbol names?
- What is the most suitable use of Linux's dlopen function (the counterpart of Windows LoadLibrary)?
- When 100 processes use the same shared library, how is physical memory used?
- 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?
- What is the role of a linker script used in embedded development?
- On a microcontroller without an OS, what does the start-up code do right after power-on before calling main?
- What is the difference between "sections" and "segments" in an ELF file?
- Which attack does W^X (never allowing a page to be both writable and executable) make harder?
- On Linux, when is the version number in a shared library's soname, such as the ".1" in libfoo.so.1, generally increased?
- What does running the ldd command on an executable on Linux show?
- Which pairs major operating systems with the executable formats they use correctly?
- When recursion goes so deep that it exceeds the stack limit, what generally happens on Linux and similar systems?
- In C, what is true of the starting values of a local variable and a global variable declared without initializers?
- 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?
- When building a shared library, what is the advantage of exporting only the public functions and giving internal functions "hidden" symbol visibility?
- How does C++ run the constructors of global objects before main?