Keyboard shortcuts

/ or ⌘/Ctrl K
Find a note
j / k
Next / previous section or linked note
h / l
Collapse or go to parent / expand or enter
e or Alt-click
Read a linked note here
o
Open focused note on its own
g g / G
First / last section or linked note
g h / g a
Home / all notes
g b / g t
Backlinks / table of contents
t
Cycle System, Light, Dark
? / Esc
Show / close this reference

Search: ↑/↓ or Ctrl N/P, Enter to open. Shortcuts pause while typing.

linker essay [56453d11]

Tags: linkers

1. Intro

1.1. What does a linker do?

  • Converts object files into executables and shared libraries

    • C/C++/Fortran (java uses a loader)

2. What's a linker: Dynamic linking, linker data types, linker operation

2.1. Shared libs

  • shared libs were invented as an op for virtual memory systems running many processes simultaneously

    • virtual memory system would map the same routine for each process
    • first implementation in SVR3, based on COFF

      • assigned each shared library a fixed portion of virtual address space
    • SunOS4 introduced a more fleixbile version

      • programs would link shared librarys during runtime (dynamic linker)
      • program linker are the linkers during compilation

2.2. Basic Linker Data Types

  • Linkers use symbols, relocations, and contents

2.2.1. Symbols

  • Name and a value
  • usually represent static objects in the original source code

    • For C, a single symbol for each function and each global and static variable
  • used to indicate a reference to a name defined in another file

2.2.2. Relocation

  • Computation to perform on the contents
  • Usually refers to a symbol and a offset
  • Also provides an additional operand called addend
  • Simple relocation is "set this location in the contents to the value of this symbol + addend"

2.2.3. Contents

  • What memory should look like during the execution of the program
  • Have a size, array of bytes, and a type
  • Contain machine code generated by the compiler and assembler (text)
  • Also contain values of initialized variables (data)
  • Also contain static unnamed data like string constants or switch varialbes (rdata)
  • Empty uninitalized variables as well

2.2.4. Basic Linker Operation

Linkers:

  1. Read input object files, determine the length and types of contents, reads the symbols.
  2. Build a symbol table containing all the symbols, linking undefined symbols to their definitions.
  3. Decide where the contents should go in the output executable file, which means deciding where they should go in memory when the program runs
  4. Reads the contents data and the relocations, apply the relocations to the contents, write the result to the output file
  5. Optionally write out the complete symbol table with the final value of the symbols