COP 3402 meeting -*- Outline -*- * Overview of Systems Software Q: What consitutes systems software? Programs that enable running programs on a computer Q: What are examples? Compilers, interpreters, assemblers, linkers, loaders, OS Q: What does a compiler do? It translates a (high-level) language into a form that can be (more easily) executed by a computer. Q: How is a compiler different than an interpreter? A compiler produces programs that (usually) run faster, as they are directly executed by a machine. It translates programs (in a programming language) into object code (or something that is easily translated into object code, such as assembly language). An interpreter executes a programming language directly, without translating it into some other language first However, an interpreter may do some translation into an internal format (e.g., a virtual machine language). Modern compiler systems are often blends of compilers and interpreters, e.g., Java (and C#) translate programs into a virtual machine language (the JVM for Java), and then use a "just-in-time compiler" (which is part of the JVM) that only compiles programs into machine code as needed, and interprets seldom used code. Q: What is an assembler? An assembler translates a low-level language that is close to machine code into object code. It provides several conveniences: human readable mnemonics for op codes, symbolic names for locations and subroutines, macros to abstract from common instruction sequences. ** Compilation overview ------------------------------------------ INFO. FLOW FOR COMPILED LANGUAGES Source ---> [ Compiler ] ---> Object Code Code Other | Module(s) | \ | \ v Library v(Static) Code --> [Linker] | | v Executable (ELF) | | v [Loader] Dynamic | Library - | Code | | v v (Dynamic)<-Running [Linker]-->Program [Operating System (OS)] ------------------------------------------ Q: What's an example of a programming language that source code might be written in? C, C++, C#, Java Point out what is happening statically (compiler and static linker, loader) and dynamically (dynamic linker, execution of program) For C++ note that the static linker also does type checking ** Interpreter overview ------------------------------------------ FLOW FOR INTERPRETED LANGUAGES Source--> [ Interpreter ]--> (Bytecode) Other | Module(s) | \ | \ | Library v v Code --> [Virtual Dynamic > Machine] Library / Code [Operating System (OS)] ------------------------------------------ Q: What are some examples of interpreted programming languages? Python, Lisp, Scheme, Java (to some extent) In this flow the VM *is* a running program (which is probably compiled by a compiler and might include one) The interpreter might just directly execute the program without a VM, but using a VM is the modern way Q: What are the advantages of using a VM (vs. direct execution)? Faster: as can do just-in-time compilation, some simple optimization... More portable: only the VM needs to be rewritten for portability Flexibility: the VM can support better linking and debugging ** OS support for running programs Q: What is a computer's memory like (as a data structure)? A (big) one-dimensional array *** Object Files ------------------------------------------ OBJECT FILES def: an *object file* holds What data is needed? ------------------------------------------ ... the compiled code of a program module. It can be linked into a complete program. Q: What information must be stored in an object file? Think about what is available in C: ... - code (compiled, sometimes called the "text" of the program) - data space (and initial values for some, static, data and just space reservations for uninitialized data) - metadata about the file (sizes of text and data, header) - symbols (exported, imported) for linkage to other modules Q: If you were designing a format for object files, which would you put first? The metadata, to facilitate reading the file ------------------------------------------ OBJECT FILE FORMAT ------------------------------------------ ... header - magic number (to identify the type of file) - other metadata (type of machine, data, version, OS, etc.) - text (code) starting address and size (etc.) - initialized data starting address and size - uninitialized data size - symbol table size - entry point(s) and their sizes text section - machine code data section - sizes and initial values symbol table - names of imported subroutines or data - names and addresses of exported subroutines and data