16
Today Today s Topic s Topic Breakdown of GCC script Breakdown of GCC script Description of how different Description of how different system programs work together system programs work together to build (and run) a C program. to build (and run) a C program.

Today ’ s Topic

  • Upload
    blaze

  • View
    33

  • Download
    0

Embed Size (px)

DESCRIPTION

Today ’ s Topic. Breakdown of GCC script Description of how different system programs work together to build (and run) a C program. System Software ( for today ). Assembler Compiler Linker Loader Operating system Preprocessor. Today ’ s Objectives. - PowerPoint PPT Presentation

Citation preview

Page 1: Today ’ s Topic

TodayToday’’s Topics Topic Breakdown of GCC scriptBreakdown of GCC script Description of how different system Description of how different system

programs work together to build (and programs work together to build (and run) a C program.run) a C program.

Page 2: Today ’ s Topic

System Software (System Software (for todayfor today)) AssemblerAssembler CompilerCompiler LinkerLinker LoaderLoader Operating systemOperating system PreprocessorPreprocessor

Page 3: Today ’ s Topic

TodayToday’’s Objectivess Objectives

Within context of Within context of ““compilingcompiling”” a C program a 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, macro preprocessor, compiler, assembler, macro preprocessor, loaderloader

Page 4: Today ’ s Topic

Breaking Down CCBreaking Down CC

sourcePreprocessedSource

ASM

OBJECT

.s

.o

Preprocessor Compiler

Assembler

LinkerLoaderExecutable

a.out

ExecutableProgramIn Memory

Page 5: Today ’ s Topic

Breaking Down CCBreaking Down CC

sourcePreprocessedSource

ASM

OBJECT

.s

.o

Preprocessor Compiler

Assembler

LinkerLoaderExecutable

a.out

ExecutableProgramIn Memory

Page 6: Today ’ s Topic

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 7: Today ’ s Topic

Breaking Down CCBreaking Down CC

sourcePreprocessedSource

ASM

OBJECT

.s

.o

Preprocessor Compiler

Assembler

LinkerLoaderExecutable

a.out

ExecutableProgramIn Memory

Page 8: Today ’ s Topic

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 assemblergcc compiler translates C to assembler gcc –S example.c gcc –S example.c ““savessaves”” example.s example.s Compiler consists ofCompiler consists of

ParserParser Code generationCode generation MysticismMysticism

Page 9: Today ’ s Topic

Breaking Down CCBreaking Down CC

sourcePreprocessedSource

ASM

OBJECT

.s

.o

Preprocessor Compiler

Assembler

LinkerLoaderExecutable

a.out

ExecutableProgramIn Memory

Page 10: Today ’ s Topic

AssemblerAssembler Another translator ??? (Another translator ??? (asas

example.s)example.s) Assembler to (binary) objectAssembler to (binary) object Why not compile straight to binary?Why not compile straight to binary? gcc –c example.c to gcc –c example.c to ““savesave”” object object NM to look at object (nm example.o)NM to look at object (nm example.o)

Page 11: Today ’ s Topic

Breaking Down CCBreaking Down CC

sourcePreprocessedSource

ASM

OBJECT

.s

.o

Preprocessor Compiler

Assembler

LinkerLoaderExecutable

a.out

ExecutableProgramIn Memory

Page 12: Today ’ s Topic

LinkerLinker Combines objects, both user .o files Combines objects, both user .o files

and libraries; makes an executable and libraries; makes an executable file file

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 executableUse nm to look at executable

Page 13: Today ’ s Topic

Breaking Down CCBreaking Down CC

sourcePreprocessedSource

ASM

OBJECT

.s

.o

Preprocessor Compiler

Assembler

LinkerLoaderExecutable

a.out

ExecutableProgramIn Memory

Page 14: Today ’ s Topic

LoaderLoader Runs when you type ./a.outRuns when you type ./a.out

Gets an address to place program Gets an address to place program (from the operating system)(from the operating system)

Changes necessary addresses (if Changes necessary addresses (if any)any)

Places code into memory Places code into memory

Page 15: Today ’ s Topic

Operating SystemOperating System OS is ALWAYS runningOS is ALWAYS running Oversees whole compilation processOversees whole compilation process

““RecognizesRecognizes”” gcc example.c command gcc example.c command Parses flags and argumentsParses flags and arguments Invokes gcc scriptInvokes gcc script Performs memory management (malloc)Performs memory management (malloc) Chooses Chooses ““addressaddress”” to place program to place program

Page 16: Today ’ s Topic

Compiler OptimizationCompiler Optimization What does optimization mean?What does optimization mean? What does compiler optimization mean?What does compiler optimization mean? ““Optimization” takes more time to Optimization” takes more time to

compile in hopes of generating faster compile in hopes of generating faster executableexecutable

-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