today ’ s topic
DESCRIPTION
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 - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: Today ’ s Topic](https://reader033.vdocument.in/reader033/viewer/2022052603/5681487b550346895db5845b/html5/thumbnails/1.jpg)
TodayToday’’s Topics Topic
Breakdown of CC scriptBreakdown of CC script
![Page 2: Today ’ s Topic](https://reader033.vdocument.in/reader033/viewer/2022052603/5681487b550346895db5845b/html5/thumbnails/2.jpg)
TodayToday’’s Objectivess Objectives
Within context of Within context of ““compilingcompiling”” C program C program Define actions of linker, compiler, assembler, Define actions of linker, compiler, assembler, OS, macro preprocessor, loaderOS, macro preprocessor, loader
Draw block diagram showing order of linker, Draw block diagram showing order of linker, compiler, assembler, OS, macro preprocessor, compiler, assembler, OS, macro preprocessor, loaderloader
Explain why runtime stack needed for CExplain why runtime stack needed for C Draw logical division of memory into Draw logical division of memory into stack, heapstack, heap
Compare and contrast stack and heapCompare and contrast stack and heap For C program, indicate which variables For C program, indicate which variables are stored in heap; in stack; in neitherare stored in heap; in stack; in neither
![Page 3: Today ’ s Topic](https://reader033.vdocument.in/reader033/viewer/2022052603/5681487b550346895db5845b/html5/thumbnails/3.jpg)
Breaking Down CCBreaking Down CC
source
Preprocessed
SourceASM
O
B
J
E
C
T
.s
.o
Preprocessor
Compiler
Assembler
LinkerLoader
Executablea.out
Executable
Program
In Memory
![Page 4: Today ’ s Topic](https://reader033.vdocument.in/reader033/viewer/2022052603/5681487b550346895db5845b/html5/thumbnails/4.jpg)
Breaking Down CCBreaking Down CC
source
Preprocessed
SourceASM
O
B
J
E
C
T
.s
.o
Preprocessor
Compiler
Assembler
LinkerLoader
Executablea.out
Executable
Program
In Memory
![Page 5: Today ’ s Topic](https://reader033.vdocument.in/reader033/viewer/2022052603/5681487b550346895db5845b/html5/thumbnails/5.jpg)
C Preprocessor (cpp)C Preprocessor (cpp)
Pass over sourcePass over source Insert included filesInsert included files Perform macro substitutionsPerform macro substitutions
Define macrosDefine macros #define NUM 100#define NUM 100 #define xx(v,name,op,metrics) \ #define xx(v,name,op,metrics) \ v=xxinit(op,name,IR->metrics)v=xxinit(op,name,IR->metrics)
gcc –E example.c sends preprocessor gcc –E example.c sends preprocessor output to stdoutoutput to stdout
![Page 6: Today ’ s Topic](https://reader033.vdocument.in/reader033/viewer/2022052603/5681487b550346895db5845b/html5/thumbnails/6.jpg)
Breaking Down CCBreaking Down CC
source
Preprocessed
SourceASM
O
B
J
E
C
T
.s
.o
Preprocessor
Compiler
Assembler
LinkerLoader
Executablea.out
Executable
Program
In Memory
![Page 7: Today ’ s Topic](https://reader033.vdocument.in/reader033/viewer/2022052603/5681487b550346895db5845b/html5/thumbnails/7.jpg)
CompilerCompiler
gcc actually name of a scriptgcc actually name of a script Compiler translates one language to Compiler translates one language to another (or the same???)another (or the same???)
gcc compiler translates C to gcc compiler translates C to assemblerassembler
gcc –S example.c gcc –S example.c ““savessaves”” example.s example.s Compiler consists ofCompiler consists of
ParserParser Code generationCode generation MysticismMysticism
![Page 8: Today ’ s Topic](https://reader033.vdocument.in/reader033/viewer/2022052603/5681487b550346895db5845b/html5/thumbnails/8.jpg)
Breaking Down CCBreaking Down CC
source
Preprocessed
SourceASM
O
B
J
E
C
T
.s
.o
Preprocessor
Compiler
Assembler
LinkerLoader
Executablea.out
Executable
Program
In Memory
![Page 9: Today ’ s Topic](https://reader033.vdocument.in/reader033/viewer/2022052603/5681487b550346895db5845b/html5/thumbnails/9.jpg)
AssemblerAssembler
Another translator ??? (Another translator ??? (asas example.s)example.s)
Assembler to (binary) objectAssembler to (binary) object Why not compile straight to Why not compile straight to binary?binary?
gcc –c example.c to gcc –c example.c to ““savesave”” object object NM to look at object (nm NM to look at object (nm example.o)example.o)
![Page 10: Today ’ s Topic](https://reader033.vdocument.in/reader033/viewer/2022052603/5681487b550346895db5845b/html5/thumbnails/10.jpg)
Breaking Down CCBreaking Down CC
source
Preprocessed
SourceASM
O
B
J
E
C
T
.s
.o
Preprocessor
Compiler
Assembler
LinkerLoader
Executablea.out
Executable
Program
In Memory
![Page 11: Today ’ s Topic](https://reader033.vdocument.in/reader033/viewer/2022052603/5681487b550346895db5845b/html5/thumbnails/11.jpg)
LinkerLinker
Combine objects, both user .o Combine objects, both user .o files and libraries, make an files and libraries, make an executableexecutable
gcc *.o –lm yields a.outgcc *.o –lm yields a.out gcc –o myExec *.o –lm gcc –o myExec *.o –lm Use nm to look at objectUse nm to look at object
![Page 12: Today ’ s Topic](https://reader033.vdocument.in/reader033/viewer/2022052603/5681487b550346895db5845b/html5/thumbnails/12.jpg)
Breaking Down CCBreaking Down CC
source
Preprocessed
SourceASM
O
B
J
E
C
T
.s
.o
Preprocessor
Compiler
Assembler
LinkerLoader
Executablea.out
Executable
Program
In Memory
![Page 13: Today ’ s Topic](https://reader033.vdocument.in/reader033/viewer/2022052603/5681487b550346895db5845b/html5/thumbnails/13.jpg)
LoaderLoader
Gets an address to place Gets an address to place programprogram
Changes necessary addresses (if Changes necessary addresses (if any)any)
Places code into memory Places code into memory
![Page 14: Today ’ s Topic](https://reader033.vdocument.in/reader033/viewer/2022052603/5681487b550346895db5845b/html5/thumbnails/14.jpg)
Operating SystemOperating System
Oversees whole processOversees whole process ““RecognizesRecognizes”” gcc example.c command gcc example.c command Parses flags and argumentsParses flags and arguments Invokes gcc scriptInvokes gcc script Performs memory mangagement Performs memory mangagement (malloc)(malloc)
Chooses Chooses ““addressaddress”” to place program to place program