Download presentation
Presentation is loading. Please wait.
Published byCamron Salvage Modified over 9 years ago
1
Today ’ s Topic Breakdown of GCC script Breakdown of GCC script Description of how different system programs work together to build (and run) a C program. Description of how different system programs work together to build (and run) a C program.
2
System Software ( for today ) Assembler Assembler Compiler Compiler Linker Linker Loader Loader Operating system Operating system Preprocessor Preprocessor
3
Today ’ s Objectives Within context of “ compiling ” a C program Within context of “ compiling ” a C program Define actions of linker, compiler, assembler, OS, macro preprocessor, loader Define actions of linker, compiler, assembler, OS, macro preprocessor, loader Draw block diagram showing order of linker, compiler, assembler, macro preprocessor, loader Draw block diagram showing order of linker, compiler, assembler, macro preprocessor, loader
4
Breaking Down CC source Preprocessed Source ASM OBJECTOBJECT.s.o Preprocessor CompilerAssembler LinkerLoader Executable a.out Executable Program In Memory
5
Breaking Down CC source Preprocessed Source ASM OBJECTOBJECT.s.o Preprocessor CompilerAssembler LinkerLoader Executable a.out Executable Program In Memory
6
C Preprocessor (cpp) Pass over source Pass over source Insert included files Insert included files Perform macro substitutions Perform macro substitutions Define macros Define macros #define NUM 100 #define NUM 100 #define xx(v,name,op,metrics) \ v=xxinit(op,name,IR->metrics) #define xx(v,name,op,metrics) \ v=xxinit(op,name,IR->metrics) gcc –E example.c sends preprocessor output to stdout gcc –E example.c sends preprocessor output to stdout
7
Breaking Down CC source Preprocessed Source ASM OBJECTOBJECT.s.o Preprocessor CompilerAssembler LinkerLoader Executable a.out Executable Program In Memory
8
Compiler gcc actually name of a script gcc actually name of a script Compiler translates one language to another (or the same???) Compiler translates one language to another (or the same???) gcc compiler translates C to assembler gcc compiler translates C to assembler gcc –S example.c “ saves ” example.s gcc –S example.c “ saves ” example.s Compiler consists of Compiler consists of Parser Parser Code generation Code generation Mysticism Mysticism
9
Breaking Down CC source Preprocessed Source ASM OBJECTOBJECT.s.o Preprocessor CompilerAssembler LinkerLoader Executable a.out Executable Program In Memory
10
Assembler Another translator ??? (as example.s) Another translator ??? (as example.s) Assembler to (binary) object Assembler to (binary) object Why not compile straight to binary? Why not compile straight to binary? gcc –c example.c to “ save ” object gcc –c example.c to “ save ” object NM to look at object (nm example.o) NM to look at object (nm example.o)
11
Breaking Down CC source Preprocessed Source ASM OBJECTOBJECT.s.o Preprocessor CompilerAssembler LinkerLoader Executable a.out Executable Program In Memory
12
Linker Combines objects, both user.o files and libraries; makes an executable file Combines objects, both user.o files and libraries; makes an executable file gcc *.o –lm yields a.out gcc *.o –lm yields a.out gcc –o myExec *.o –lm gcc –o myExec *.o –lm Use nm to look at executable Use nm to look at executable
13
Breaking Down CC source Preprocessed Source ASM OBJECTOBJECT.s.o Preprocessor CompilerAssembler LinkerLoader Executable a.out Executable Program In Memory
14
Loader Runs when you type./a.out Runs when you type./a.out Gets an address to place program (from the operating system) Gets an address to place program (from the operating system) Changes necessary addresses (if any) Changes necessary addresses (if any) Places code into memory Places code into memory
15
Operating System OS is ALWAYS running OS is ALWAYS running Oversees whole compilation process Oversees whole compilation process “ Recognizes ” gcc example.c command “ Recognizes ” gcc example.c command Parses flags and arguments Parses flags and arguments Invokes gcc script Invokes gcc script Performs memory management (malloc) Performs memory management (malloc) Chooses “ address ” to place program Chooses “ address ” to place program
16
Compiler Optimization What does optimization mean? What does optimization mean? What does compiler optimization mean? What does compiler optimization mean? “Optimization” takes more time to compile in hopes of generating faster executable “Optimization” takes more time to compile in hopes of generating faster executable -O# is the flag to ask for optimization -O# is the flag to ask for optimization gcc –O3 tsp.c gives “highest” level gcc –O3 tsp.c gives “highest” level
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.