COP 3402 meeting -*- Outline -*- * Linkers ** Job of a Linker ------------------------------------------ WHAT A LINKER DOES Combines object files resolving symbolic names For example, a program and Object Code P Executable [ header ] [ header ] [ text P ] [ text P ] [ data P ] \ [ text L ] [ sym tab P] \ [ data P ] > Linker ->[ data L ] Object Code L > [ sym tab P ] [ header ] / [ sym tab L ] [ text L ] / [ data L ] [ sym tab L] ------------------------------------------ ... a library (e.g., of mathematical functions, like sine...) (This is figure 7.11 in Montagne's book) Q: Why not refer to addresses in the library's code? That might change, it's not convenient, helpful, or modular Q: Does linking support separate compilation? Yes! The files linked can be different modules of a program Q: Is linking necessary for execution? No, but it saves coding time! *** kinds of linking ------------------------------------------ KINDS OF LINKING def: *static linking* is linking that happens def: *dynamic linking* is linking that happens Advantages: + static linking: + dynamic linking: ------------------------------------------ ... before running a program, once and for all ... when a program is running or starting to run ... avoids runtime overhead for linking avoids missing library code problems allows checking of library code before running it ... can share library code among running processes (saving execution space) can propagate updates to library code quickly Q: Which is better for computer security? Dynamic linking allows for faster updates (but it also allows for faster attacks!) Modern OSs use dynamic linking for libraries, but compilers often use static linking for programs * Loaders ** Job of a Loader ------------------------------------------ WHAT A LOADER DOES A loader places Types of loaders: - Absolute loader: - Bootstrap loader: - Relocating loader: ------------------------------------------ ... a program (it's instructions and data) into a computer's memory so it can be run ... puts program's text and data into specific memory locations ... loads (a loader to load) the operating system (OS) ... put's a program in memory anywhere there is space Q: Where does a program loaded by an absolute loader start execution? At the address specified Q: How does a relocating loader work? By adding an offset to each place identified in the relocation section Q: If we have a computer with virtual memory, do we still need relocating loaders? Yes, if we want to use address space layout randomization (ASLR) to start the program at a random offset, for security purposes