notebook/notes/linkers/index.md

197 lines
7.7 KiB
Markdown
Raw Normal View History

2024-12-12 13:28:56 +00:00
---
title: Linkers
TARGET DECK: Obsidian::STEM
2024-12-16 15:06:26 +00:00
FILE TAGS: linker
2024-12-12 13:28:56 +00:00
tags:
2024-12-16 15:06:26 +00:00
- linker
2024-12-12 13:28:56 +00:00
---
2024-12-16 15:06:26 +00:00
## 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.
<!--ID: 1733671136073-->
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.
<!--ID: 1733671136078-->
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.
<!--ID: 1733671136081-->
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.
<!--ID: 1733671136084-->
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.
<!--ID: 1733671136088-->
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.
<!--ID: 1733671136092-->
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.
<!--ID: 1733671136097-->
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.
<!--ID: 1733671136102-->
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.
<!--ID: 1733671136107-->
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.
<!--ID: 1733671136112-->
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.
<!--ID: 1733671136117-->
END%%
2024-12-16 17:48:51 +00:00
## 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.
<!--ID: 1734356868367-->
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
<!--ID: 1734356868394-->
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
<!--ID: 1734356868399-->
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
<!--ID: 1734356868403-->
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
<!--ID: 1734356868406-->
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.
<!--ID: 1734356868428-->
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.
<!--ID: 1734356868413-->
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.
<!--ID: 1734356868418-->
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.
<!--ID: 1734356868423-->
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.
<!--ID: 1734356868433-->
END%%
2024-12-16 15:06:26 +00:00
## Bibliography
* Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.