Breaking Down CC command
Download
Report
Transcript Breaking Down CC command
Today’s Topic
Breakdown of CC script
Today’s Objectives
Within context of “compiling” C program
Define actions of linker, compiler, assembler, OS,
macro preprocessor, loader
Draw block diagram showing order of linker,
compiler, assembler, OS, macro preprocessor, loader
Explain why runtime stack needed for C
Draw logical division of memory into stack, heap
Compare and contrast stack and heap
For C program, indicate which variables are
stored in heap; in stack; in neither
Breaking Down CC
Preprocessed
source
Preprocessor
Source
Executable
Program
In Memory
Compiler
ASM
.s
Assembler
O
B
Executable
Loader
a.out
J
Linker
.o
E
C
T
Breaking Down CC
Preprocessed
source
Preprocessor
Source
Executable
Program
In Memory
Compiler
ASM
.s
Assembler
O
B
Executable
Loader
a.out
J
Linker
.o
E
C
T
C Preprocessor (cpp)
Pass over source
Define macros
Insert included files
Perform macro substitutions
#define NUM 100
#define xx(v,name,op,metrics) \
v=xxinit(op,name,IR->metrics)
gcc –E example.c sends preprocessor output to
stdout
Breaking Down CC
Preprocessed
source
Preprocessor
Source
Executable
Program
In Memory
Compiler
ASM
.s
Assembler
O
B
Executable
Loader
a.out
J
Linker
.o
E
C
T
Compiler
gcc actually name of a script
Compiler translates one language to another (or
the same???)
gcc compiler translates C to assembler
gcc –S example.c “saves” example.s
Compiler consists of
Parser
Code generation
Mysticism
Breaking Down CC
Preprocessed
source
Preprocessor
Source
Executable
Program
In Memory
Compiler
ASM
.s
Assembler
O
B
Executable
Loader
a.out
J
Linker
.o
E
C
T
Assembler
Another translator ??? (as example.s)
Assembler to (binary) object
Why not compile straight to binary?
gcc –c example.c to “save” object
NM to look at object (nm example.o)
Breaking Down CC
Preprocessed
source
Preprocessor
Source
Executable
Program
In Memory
Compiler
ASM
.s
Assembler
O
B
Executable
Loader
a.out
J
Linker
.o
E
C
T
Linker
Combine objects, both user .o files and
libraries, make an executable
gcc *.o –lm yields a.out
gcc –o myExec *.o –lm
Use nm to look at object
Breaking Down CC
Preprocessed
source
Preprocessor
Source
Executable
Program
In Memory
Compiler
ASM
.s
Assembler
O
B
Executable
Loader
a.out
J
Linker
.o
E
C
T
Loader
Gets an address to place program
Changes necessary addresses (if any)
Places code into memory
Operating System
Oversees whole process
“Recognizes” gcc example.c command
Parses flags and arguments
Invokes gcc script
Performs memory mangagement (malloc)
Chooses “address” to place program