I. Assemblers A. Overview ------------------------------------------ ASSEMBLY LANGUAGE AND ASSEMBLERS def: *Assembly language* is a language def: An *assembler* translates from to ------------------------------------------ ------------------------------------------ ASSEMBLERS VS. COMPILERS Statements correspond to In assembly language: In a higher-level programming language: Expressions correspond to: In assembly language: In a higher-level programming language: Names are abstractions of In assembly language: In a higher-level programming language: ------------------------------------------ B. goals of Assemblers and Assembly Language Having written machine code using numbers, why is that hard? ------------------------------------------ GOALS OF ASSEMBLERS - Relieve tedium of machine code by: - Help communication between people with: ------------------------------------------ Does an assembly language programmer need to know how the machine's instructions work? Does a programmer in a higher level programming language need to know that? C. How assemblers work ------------------------------------------ BASIC PROBLEM FOR ASSEMBLERS ... JMP ahead ; forward reference ... ahead: ; label How can assembler know the address of the label "ahead"? ------------------------------------------ 1. Two pass design ------------------------------------------ TWO PASS DESIGN OF ASSEMBLER Pass 1: count instructions determine address of each label Pass 2: check that all labels are defined generate machine code ------------------------------------------ 2. Relative Jumps ------------------------------------------ RELATIVE JUMPS Additional task for assembler: If computer architecture has jumps to (absolute) addresses Then translate jumps relative to PC into ------------------------------------------ II. Executable Files A. Sections of Executable Files ------------------------------------------ SECTIONS OF EXECUTABLE FILES (header: info about each section) Text Section: Data Section: Relocation Section: (debugging sections: symbol table section: global labels debugging section: file + line info ------------------------------------------ ------------------------------------------ EXECUTABLE ELF FILE LAYOUT |------------------------| [ General info ] (header [ Program name ] section) [ Start address of text ] [ Length of text section ] [ Start address of data ] [ Length of data section ] [ Start address of reloc.] [ Length of reloc. sect. ] |------------------------| | | | | | Text Section | | | | | |------------------------| | | | | | Data Section | | | | | |------------------------| | | | | | Relocation Section | | | | | |------------------------| ------------------------------------------ B. Relocation ------------------------------------------ RELOCATION OF EXECUTABLE FILES Assemblers generate code assuming starting address is 0 Relocation data identifies parts of instructions that need offset added if the starting address is changed to 0 + offset ------------------------------------------ III. Linkers A. 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] ------------------------------------------ Why not refer to addresses in the library's code? Does linking support separate compilation? Is linking necessary for execution? 1. 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: ------------------------------------------ Which is better for computer security? IV. Loaders A. Job of a Loader ------------------------------------------ WHAT A LOADER DOES A loader places Types of loaders: - Absolute loader: - Bootstrap loader: - Relocating loader: ------------------------------------------ Where does a program loaded by an absolute loader start execution? How does a relocating loader work? If we have a computer with virtual memory, do we still need relocating loaders?