SlideServe
Menu
Préférences
© SlideServe · v2026

Compilation Process

yelena avatar
10 diapositives · 309 Views · Sep 14, 2014

Compilation Process. COP 3402 (Summer 2013). Compilation process. Break the command "gcc -o test.c ..." into preprocessing, compilation, assembly, and linking. Input  Program  Output Source code      Preprocessor  Expanded source

Compilation Process - slide 1
01 / 10Compilation Process
1 / 17

Télécharger la présentation

Compilation Process
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. Compilation Process COP 3402 (Summer 2013)

  2. Compilation process Break the command "gcc -o test.c ..." into preprocessing, compilation, assembly, and linking. InputProgramOutput Source code     Preprocessor  Expanded source Expanded code    Compiler        Assembly source Assembly source  Assembler     Object code Object code     Linker        Executable code Executable code  Loader    Execution

  3. A simple program that adds two numbers (not including any library). Example1: Source program (call it test.c) int test_fun(int x) {return x + 17;} int main(void) { int x = 1; int y; y = test_fun(x); return 0; } Example

  4. Step 1: cpp test.c test.i Output: # 1 "test.c" # 1 "<built-in>" # 1 "<command-line>" # 1 "test.c" int test_fun(int x) {return x + 17;} int main(void) { int x = 1; int y; y = test_fun(x); return 0; } Example: Step 1

  5. Step 2: gcc -S test.i -o test.s Output: .file "test.c" .text .globl _test_fun .def _test_fun; .scl 2; .type 32; .endef _test_fun: pushl %ebp movl %esp, %ebp movl 8(%ebp), %eax addl $17, %eax popl %ebp ret .def ___main; .scl 2; .type 32; .endef .globl _main .def _main; .scl 2; .type 32; .endef Example: Step 2

  6. Step 2: gcc -S test.i -o test.s Output continued: _main: pushl %ebp movl %esp, %ebp andl $-16, %esp subl $32, %esp call ___main movl $1, 28(%esp) movl 28(%esp), %eax movl %eax, (%esp) call _test_fun movl %eax, 24(%esp) movl $0, %eax leave ret Example: Step 2 Continued

  7. Step 3: as test.s -o test.o The file contains the machine code for program test Output (Big Endian; viewed with Notepad++ hex editor plugin): Example: Step 3

  8. Step 4: gcc test.o (for linking) and produces a.out a.out is a long file, so it will not be shown here, but you may view it with a hex editor if you follow these steps on your own. Step 5: ./a.out (to load and execute) There will not be any output, but the program should run without error. Example: Steps 4 & 5

  9. Step 1: cpp test.c test.i test.i contains the preprocessed c file Step 2: gcc -S test.i -o test.s test.s contains the assembly code Step 3: as test.s -o test.o test.o contains the machine code Step 4: gcc test.o (for linking) and produces a.out a.out is the ELF file Step 5: ./a.out (to load and execute) Compilation Process Summary

  10. 1. Follow the steps of the example on your own. Results may vary. 2. Follow the steps of the example with a simple hello world program that includes I/O, and therefore the standard I/O library, stdio.h: #include <stdio.h> Int main (void) {  printf (“Hello, world!\n");  return 0; } Exercises