Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Steps that GCC goes through to compile a Linux C Program #11

Open
mmcky opened this issue Feb 12, 2016 · 0 comments
Open

Steps that GCC goes through to compile a Linux C Program #11

mmcky opened this issue Feb 12, 2016 · 0 comments

Comments

@mmcky
Copy link

mmcky commented Feb 12, 2016

Information for Interested Students

There are generally considered 4 phases to GCC compilation for C programs in Linux

  1. Pre-Processing
  2. Compilation
  3. Assembly [Shown in Class]
  4. Linking

The pre-processing stage the text file that you have written is pre-processed to strip unnecessary information such as comments. It also processes any include statements etc.

The compilation stage converts the output of pre-processing and is responsible for converting it to an assembly layer. In this process the compiler is responsible for doing a lot of work and perform various optimizations in generating the assembly code

The assembly stage converts the assembly into object level code.

The linking stage manages the linking requirements to external calls such as printf.

You can actually see these steps using -save-temps option during compilation.

gcc -Wall -save-temps print.c -o print

There is a lot more to it under the surface - but this gives you a sense of the compilation process.

If you are really keen then here is some interesting reading:

  1. http://www.thegeekstuff.com/2011/10/c-program-to-an-executable/
  2. https://www.redhat.com/magazine/002dec04/features/gcc/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant