The document discusses the compilation process of a C program called "hello" from source code to executable program. It explains that the compilation system consists of four phases - preprocessing, compilation, assembly, and linking. Each phase converts the program into a different form, starting from human-readable C code and ultimately generating a machine-readable executable binary. It also discusses some factors for understanding how compilation systems work, such as optimizing performance, avoiding linking errors, and preventing security holes.
The document discusses the compilation process of a C program called "hello" from source code to executable program. It explains that the compilation system consists of four phases - preprocessing, compilation, assembly, and linking. Each phase converts the program into a different form, starting from human-readable C code and ultimately generating a machine-readable executable binary. It also discusses some factors for understanding how compilation systems work, such as optimizing performance, avoiding linking errors, and preventing security holes.
The document discusses the compilation process of a C program called "hello" from source code to executable program. It explains that the compilation system consists of four phases - preprocessing, compilation, assembly, and linking. Each phase converts the program into a different form, starting from human-readable C code and ultimately generating a machine-readable executable binary. It also discusses some factors for understanding how compilation systems work, such as optimizing performance, avoiding linking errors, and preventing security holes.
The document discusses the compilation process of a C program called "hello" from source code to executable program. It explains that the compilation system consists of four phases - preprocessing, compilation, assembly, and linking. Each phase converts the program into a different form, starting from human-readable C code and ultimately generating a machine-readable executable binary. It also discusses some factors for understanding how compilation systems work, such as optimizing performance, avoiding linking errors, and preventing security holes.
Download as PPTX, PDF, TXT or read online from Scribd
Download as pptx, pdf, or txt
You are on page 1of 19
Chapter-1
Tour of Computer System Computer System
A computer system consists of hardware and
systems software that work together to run application programs. Information is Bits and Context
“hello” program begins life as a source
program (or source file) that the programmer creates with an editor and saves in a text file called hello.c. The source program is a sequence of bits, each with a value of 0 or 1, organized in 8-bit chunks called bytes. Each byte represents some text character in the program. Cont…
Most modern systems represent text characters
using the ASCII standard that represents each character with a unique byte-sized integer value. The hello.c program is stored in a file as a sequence of bytes. Each byte has an integer value that corresponds to some character. For example, the first byte has the integer value 35, which corresponds to the character ‘#’. ASCII code for Text Representation Cont…
All information in a system—including disk
files, programs stored in memory, user data stored in memory and data transferred across a network—is represented as a bunch of bits.
As programmers, need to understand machine
representations of numbers because they are not the same as integers and real numbers. Programs are translated by other Programs into Different Forms The hello program begins life as a high-level C program It can be read and understood by human beings in that form. In order to run hello.c on the system Individual C statements are translated by other programs into a sequence of low-level machine- language instructions. Instructions are packaged in a form called an executable object program and stored as a binary disk file. Compilation Process Compilation System
The program that performs four phases
(preprocessor, compiler, assembler and linker) are known collectively as the compilation system. Preprocessor Phase:
The preprocessor (cpp) modifies the original C
program according to directives begins with # character. For example, #include <stdio.h> command in line 1 of hello.c tells the preprocessor To read the contents of the system header file stdio.h Insert it directly into the program text. The result is another C program with .i suffix. Compilation Phase:
The compiler (cc1) translates the text file
hello.i into text file hello.s, Contains an assembly-language program. Each statement in an assembly-language program exactly describes one low-level machine-language instruction to a standard text form. Assembly language provides a common output language for different compilers for different high-level languages. C compilers and Fortran compilers both generate output files in the same assembly language. Assembly Phase:
Assembler (as) translates hello.s into
Machine language instructions & packages them into a relocatable object program Stores the result in the object file hello.o. The hello.o file is a binary file whose bytes encode machine language instructions rather than characters. File hello.o with a text editor appears as gibberish (unrecognizable) form text. Linking Phase:
The hello program calls the printf function,
Part of the standard C library provided by every C compiler. The printf function is a separate pre-compiled object file called printf.o That merges with hello.o program. The linker (ld) handles this merging. The result is the hello file, which is an executable object file (executable) that is ready to be loaded into memory and executed by the system. How Compilation System Works
Several factors to understand compilation
system work are: Optimizing Program Performance Understanding Link-time errors Avoiding Security Holes Optimizing Program Performance:
Modern compilers are sophisticated tools that
usually produce good code. Understand inner workings of the compiler in order to write efficient code. Performance of C programs by making simple transformations to the C code that helps the compiler do its job better. C compilers store data arrays in memory and how C programs can exploit this knowledge to run more efficiently. Understanding Link-time errors
Most perplexing programming errors are
related to the operation of the linker, In order to build large software systems. e.g Linker cannot resolve a reference Difference b/w static and global variable Difference b/w static Library and Global Library Two global variables in different C files with same name. Linker related errors not appear until run time. Avoiding Security Holes:
Only few programmers understand careful
restriction of quantity and forms of data they accept from untrusted sources. Secure programming is to understand the consequences of the way data and control information are stored on the program stack. Stack Discipline and Buffer overflow can lead to serious program errors. e.g array is allocated on the stack to hold a string, but the size of the string exceeds the space allocated for the array.