06 Compilation Linking Loading
06 Compilation Linking Loading
Abhijit A M
Review of last few lectures
Boot sequence: BIOS, boot-loader, kernel
● Boot sequence: Process world
–kernel->init -> many forks+execs() -> ....
● Hardware interrupts, system calls, exceptions
● Event driven kernel
● System calls
2
What are compiler, assembler, linker
and loader, and C library
System Programs/Utilities
Most essential to make a kernel really usable
3
Standard C Library
A collection of some of the most frequently
●
language
● E.g. GCC /usr/bin/gcc
–Usage: e.g. 5
Assembler
application program, converts assembly code into
●
machine code
● What is assembly language? main.s as main
gcc
●From the
textbook
Example
try.c f.c g.c
#include <stdio.h> int g(int); int g(int x) {
#define MAX 30 #define ADD(a, b) (a + b) return x + 10;
int f(int, int); int f(int m, int n) { }
int main() { return ADD(m,n) + g(10);
int i, j, k; }
scanf("%d%d", &i, &j);
k = f(i, j) + MAX; Try these commands, observe the output/errors/warnings, and try to unde
printf("%d\n", k); $ gcc try.c
return 0; $ gcc -c try.c
} $ gcc -c f.c
$ gcc -c g.c
$ gcc try.o f.o g.o -o try
$ gcc -E try.c
$ gcc -E f.c
More about the steps
● Pre-processor
–#define ABC XYZ
cut ABC and paste XYZ
●
–# include <stdio.h>
copy-paste the file stdio.h
●
● Linking
–Normally links with the standard C-library by default
–To link with other libraries, use the -l option of gcc
Using gcc itself to understand the
process
Run only the preprocessor
●
–cc -E test.c
–cc -c test.c
–gcc -S main.c
hexdump
–$ gcc hello.o -shared -o
●
on target system
–see gcc -m option