--- title: Linkers TARGET DECK: Obsidian::STEM FILE TAGS: linker tags: - linker --- ## Overview To build an executable, a linker must perform two main tasks: 1. **Symbol resolution**. The linker must associate each symbol reference with exactly one symbol definition. 2. **Relocation**. The linker must relocate code and data sections by associating a memory location with each symbol definition, and then modifying all of the references to those symbols so that they point to this memory location. The linker blindly performs relocations using detailed instructions generated by the assembler called **relocation entries**. %%ANKI Basic According to Bryant et al., a static linker must perform what two tasks? Back: Symbol resolution and relocation. Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. END%% %%ANKI Basic Which of symbol resolution or relocation happens first? Back: Symbol resolution. Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. END%% %%ANKI Basic What is the goal of symbol resolution? Back: To associate each symbol reference with exactly one symbol definition. Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. END%% %%ANKI Basic What is the goal of relocation? Back: To assign a memory location to each symbol and update references accordingly. Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. END%% %%ANKI Basic *Why* must relocation happen after symbol resolution? Back: We should not assign multiple addresses to the same symbol. Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. END%% %%ANKI Cloze {Symbol resolution} associates each {symbol reference} with exactly one {symbol definition}. Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. END%% %%ANKI Cloze {Relocation} assigns a {memory location} to each symbol and {updates references} accordingly. Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. END%% %%ANKI Basic What does it mean for a linker to relocate a code and/or data section? Back: It associates a memory location with each symbol definition and updates references accordingly. Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. END%% %%ANKI Basic What is emitted by the assembler to help the linker relocate sections? Back: Relocation entries. Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. END%% %%ANKI Cloze The assembler outputs {relocation entries} to guide the linker during {relocation}. Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. END%% %%ANKI Cloze The {1:assembler} outputs relocation entries to guide the {1:linker} during relocation. Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. END%% ## Object Files Object files come in three forms: 1. **Relocatable object files**. Contains binary code and data in a form that can be combined with other relocatable object files at compile time. 2. **Executable object files**. Contains binary code and data in a form that can be copied directly into memory and executed. 3. **Shared object files**. A special type of relocatable object file that can be loaded into memory and linked dynamically, at either load time or run time. An **object module** is a sequence of bytes whereas an **object file** is an object module stored on disk. %%ANKI Basic What are the three types of object files? Back: Relocatable, executable, and shared. Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. END%% %%ANKI Basic Relocatable object files are outputs of which compiler driver component? Back: The assembler. Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. Tags: c17 END%% %%ANKI Basic Executable object files are outputs of which compiler driver component? Back: The linker. Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. Tags: c17 END%% %%ANKI Basic Relocatable object files are inputs into which compiler driver component? Back: The linker. Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. Tags: c17 END%% %%ANKI Basic Executable object files are inputs into which compiler driver component? Back: N/A. Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. Tags: c17 END%% %%ANKI Cloze A {shared} object file is a special case of a {relocatable} object file. Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. END%% %%ANKI Basic What is an object module? Back: A sequence of bytes. Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. END%% %%ANKI Basic In terms of object modules, what is an object file? Back: An object module stored on disk. Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. END%% %%ANKI Basic What distinguishes an object module from an object file? Back: An object file is an object module stored on disk. Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. END%% %%ANKI Basic In what way is the term "object file" misused by Bryant et al.? Back: Technically this term only refers to object modules on disk. Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. END%% ## Bibliography * Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.