Computer System Organization and Compilation Process

 
 
C
o
m
p
u
t
e
r
 
S
y
s
t
e
m
 
O
r
g
a
n
i
z
a
t
i
o
n
O
O
v
v
e
e
r
r
v
v
i
i
e
e
w
w
 
 
o
o
f
f
 
 
h
h
o
o
w
w
 
 
t
t
h
h
i
i
n
n
g
g
s
s
 
 
w
w
o
o
r
r
k
k
C
o
m
p
i
l
a
t
i
o
n
 
a
n
d
 
l
i
n
k
i
n
g
 
s
y
s
t
e
m
O
p
e
r
a
t
i
n
g
 
s
y
s
t
e
m
C
o
m
p
u
t
e
r
 
o
r
g
a
n
i
z
a
t
i
o
n
T
o
d
a
y
s
 
a
g
e
n
d
a
User
Interface
A
 
s
o
f
t
w
a
r
e
 
v
i
e
w
H
o
w
 
i
t
 
w
o
r
k
s
h
h
e
e
l
l
l
l
o
o
.
.
c
c
 
 
p
p
r
r
o
o
g
g
r
r
a
a
m
m
  
  
#include <stdio.h>
#include <stdio.h>
  #define FOO 4
  #define FOO 4
  int main()
  int main()
 
 
{
{
     printf(“hello, world %d\n”, FOO);
     printf(“hello, world %d\n”, FOO);
  }
  }
Program
Source
Modified
Source
Assembly
Code
Object
Code
Executable
Code
hello.c
hello.i
hello.s
hello.o
hello
T
h
e
 
C
o
m
p
i
l
a
t
i
o
n
 
s
y
s
t
e
m
g
g
c
c
c
c
 
 
i
i
s
s
 
 
t
t
h
h
e
e
 
 
c
c
o
o
m
m
p
p
i
i
l
l
e
e
r
r
 
 
d
d
r
r
i
i
v
v
e
e
r
r
g
g
c
c
c
c
 
 
i
i
n
n
v
v
o
o
k
k
e
e
s
s
 
 
s
s
e
e
v
v
e
e
r
r
a
a
l
l
 
 
o
o
t
t
h
h
e
e
r
r
 
 
c
c
o
o
m
m
p
p
i
i
l
l
a
a
t
t
i
i
o
o
n
n
 
 
p
p
h
h
a
a
s
s
e
e
s
s
P
r
e
p
r
o
c
e
s
s
o
r
C
o
m
p
i
l
e
r
A
s
s
e
m
b
l
e
r
L
i
n
k
e
r
W
W
h
h
a
a
t
t
 
 
d
d
o
o
e
e
s
s
 
 
e
e
a
a
c
c
h
h
 
 
o
o
n
n
e
e
 
 
d
d
o
o
?
?
 
 
 
 
W
W
h
h
a
a
t
t
 
 
a
a
r
r
e
e
 
 
t
t
h
h
e
e
i
i
r
r
 
 
o
o
u
u
t
t
p
p
u
u
t
t
s
s
?
?
P
r
e
p
r
o
c
e
s
s
o
r
F
F
i
i
r
r
s
s
t
t
,
,
 
 
g
g
c
c
c
c
 
 
c
c
o
o
m
m
p
p
i
i
l
l
e
e
r
r
 
 
d
d
r
r
i
i
v
v
e
e
r
r
 
 
i
i
n
n
v
v
o
o
k
k
e
e
s
s
 
 
c
c
p
p
p
p
 
 
t
t
o
o
 
 
g
g
e
e
n
n
e
e
r
r
a
a
t
t
e
e
e
e
x
x
p
p
a
a
n
n
d
d
e
e
d
d
 
 
C
C
 
 
s
s
o
o
u
u
r
r
c
c
e
e
c
p
p
 
j
u
s
t
 
d
o
e
s
 
t
e
x
t
 
s
u
b
s
t
i
t
u
t
i
o
n
C
o
n
v
e
r
t
s
 
t
h
e
 
C
 
s
o
u
r
c
e
 
f
i
l
e
 
t
o
 
a
n
o
t
h
e
r
 
C
 
s
o
u
r
c
e
 
f
i
l
e
E
x
p
a
n
d
s
 
#
 
d
i
r
e
c
t
i
v
e
s
O
u
t
p
u
t
 
i
s
 
a
n
o
t
h
e
r
 
 
C
 
s
o
u
r
c
e
 
f
i
l
e
#include <stdio.h>
#include <stdio.h>
#define FOO 4
#define FOO 4
int main()
int main()
{
{
     printf("hello, world %d\n", FOO);
     printf("hello, world %d\n", FOO);
}
}
extern int printf (const char *__restrict __format, ...);
extern int printf (const char *__restrict __format, ...);
int main() {
int main() {
 printf("hello, world %d\n", 4);
 printf("hello, world %d\n", 4);
}
}
P
r
e
p
r
o
c
e
s
s
o
r
I
I
n
n
c
c
l
l
u
u
d
d
e
e
d
d
 
 
f
f
i
i
l
l
e
e
s
s
:
:
#include <foo.h>
    
/* /usr/include/…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
o
m
m
e
n
t
i
n
g
 
c
o
d
e
 
o
u
t
P
r
e
p
r
o
c
e
s
s
e
r
h
t
t
p
:
/
/
t
h
e
f
e
n
g
s
.
c
o
m
/
w
u
c
h
a
n
g
/
c
o
u
r
s
e
s
/
c
s
2
0
1
/
c
l
a
s
s
/
0
3
/
d
e
f
#include
 
<stdio.h>
int
 
main
()
 
{
#ifdef DEBUG
  
printf
(
"Debug flag on
\n
"
);
#endif
  
printf
(
"Hello world
\n
"
);
 
return
 
0
;
 
}
 
% gcc -o def def.c
% ./def
Hello world
% gcc -D DEBUG -o def def.c
% ./def
Debug flag on
Hello world
P
r
e
p
r
o
c
e
s
s
e
r
C
C
o
o
n
n
d
d
i
i
t
t
i
i
o
o
n
n
a
a
l
l
 
 
c
c
o
o
m
m
p
p
i
i
l
l
a
a
t
t
i
i
o
o
n
n
 
 
t
t
o
o
 
 
s
s
u
u
p
p
p
p
o
o
r
r
t
t
 
 
p
p
o
o
r
r
t
t
a
a
b
b
i
i
l
l
i
i
t
t
y
y
C
o
m
p
i
l
e
r
s
 
w
i
t
h
 
b
u
i
l
t
 
i
n
 
c
o
n
s
t
a
n
t
s
 
d
e
f
i
n
e
d
U
s
e
 
t
o
 
c
o
n
d
i
t
i
o
n
a
l
l
y
 
i
n
c
l
u
d
e
 
c
o
d
e
O
p
e
r
a
t
i
n
g
 
s
y
s
t
e
m
 
s
p
e
c
i
f
i
c
 
c
o
d
e
#if defined(__i386__) || defined(WIN32) || …
C
o
m
p
i
l
e
r
-
s
p
e
c
i
f
i
c
 
c
o
d
e
#if defined(__INTEL_COMPILER)
P
r
o
c
e
s
s
o
r
-
s
p
e
c
i
f
i
c
 
c
o
d
e
#if defined(__SSE__)
N
N
e
e
x
x
t
t
,
,
 
 
g
g
c
c
c
c
 
 
i
i
n
n
v
v
o
o
k
k
e
e
s
s
 
 
c
c
c
c
1
1
 
 
t
t
o
o
 
 
g
g
e
e
n
n
e
e
r
r
a
a
t
t
e
e
 
 
a
a
s
s
s
s
e
e
m
m
b
b
l
l
y
y
 
 
c
c
o
o
d
d
e
e
T
r
a
n
s
l
a
t
e
s
 
h
i
g
h
-
l
e
v
e
l
 
C
 
c
o
d
e
 
i
n
t
o
 
a
s
s
e
m
b
l
y
V
a
r
i
a
b
l
e
 
a
b
s
t
r
a
c
t
i
o
n
 
m
a
p
p
e
d
 
t
o
 
m
e
m
o
r
y
 
l
o
c
a
t
i
o
n
s
 
a
n
d
 
r
e
g
i
s
t
e
r
s
L
o
g
i
c
a
l
 
a
n
d
 
a
r
i
t
h
m
e
t
i
c
 
o
p
e
r
a
t
i
o
n
s
 
m
a
p
p
e
d
 
t
o
 
u
n
d
e
r
l
y
i
n
g
m
a
c
h
i
n
e
 
o
p
c
o
d
e
s
F
u
n
c
t
i
o
n
 
c
a
l
l
 
a
b
s
t
r
a
c
t
i
o
n
 
i
m
p
l
e
m
e
n
t
e
d
C
o
m
p
i
l
e
r
C
o
m
p
i
l
e
r
extern int printf (const char *__restrict __format, ...);
extern int printf (const char *__restrict __format, ...);
int main() {
int main() {
 
 
printf("hello, world %d\n", 4);
printf("hello, world %d\n", 4);
}
}
  
  
.section        .rodata
.section        .rodata
.LC0:
.LC0:
 
 
.string "hello, world %d\n"
.string "hello, world %d\n"
 
 
.text
.text
main:
main:
 
 
pushq   %rbp
pushq   %rbp
 
 
movq    %rsp, %rbp
movq    %rsp, %rbp
 
 
movl    $4, %esi
movl    $4, %esi
 
 
movl    $.LC0, %edi
movl    $.LC0, %edi
 
 
movl    $0, %eax
movl    $0, %eax
 
 
call    printf
call    printf
 
 
popq    %rbp
popq    %rbp
 
 
ret
ret
A
s
s
e
m
b
l
e
r
N
N
e
e
x
x
t
t
,
,
 
 
g
g
c
c
c
c
 
 
i
i
n
n
v
v
o
o
k
k
e
e
s
s
 
 
a
a
s
s
 
 
t
t
o
o
 
 
g
g
e
e
n
n
e
e
r
r
a
a
t
t
e
e
 
 
o
o
b
b
j
j
e
e
c
c
t
t
 
 
c
c
o
o
d
d
e
e
T
r
a
n
s
l
a
t
e
s
 
a
s
s
e
m
b
l
y
 
c
o
d
e
 
i
n
t
o
 
b
i
n
a
r
y
 
o
b
j
e
c
t
 
c
o
d
e
 
t
h
a
t
 
c
a
n
b
e
 
d
i
r
e
c
t
l
y
 
e
x
e
c
u
t
e
d
 
b
y
 
C
P
U
A
s
s
e
m
b
l
e
r
%  readelf -a hello | egrep rodata
%  readelf -a hello | egrep rodata
[16] .rodata           PROGBITS         00000000004005d0  000005d0
[16] .rodata           PROGBITS         00000000004005d0  000005d0
%  readelf –x 16 hello
%  readelf –x 16 hello
Hex dump of section '.rodata':
Hex dump of section '.rodata':
0x004005d0 
0x004005d0 
01000200
01000200
 
 
68656c6c
68656c6c
 
 
6f2c2077
6f2c2077
 
 
6f726c64
6f726c64
 ....hello, world
 ....hello, world
0x004005e0 
0x004005e0 
2025640a
2025640a
 
 
00
00
                          %d..
                          %d..
%  objdump –d hello
%  objdump –d hello
Disassembly of section .text:
Disassembly of section .text:
000000000040052d <main>:
000000000040052d <main>:
40052d:
40052d:
 
 
55
55
                   
                   
 
 
push   %rbp
push   %rbp
40052e:
40052e:
 
 
48 89 e5             
48 89 e5             
 
 
mov    %rsp,%rbp
mov    %rsp,%rbp
400531:
400531:
 
 
be 04 00 00 00       
be 04 00 00 00       
 
 
mov    $0x4,%esi
mov    $0x4,%esi
400536:
400536:
 
 
bf d4 05 40 00       
bf d4 05 40 00       
 
 
mov    $0x4005d4,%edi
mov    $0x4005d4,%edi
40053b:
40053b:
 
 
b8 00 00 00 00       
b8 00 00 00 00       
 
 
mov    $0x0,%eax
mov    $0x0,%eax
400540:
400540:
 
 
e8 cb fe ff ff       
e8 cb fe ff ff       
 
 
callq  400410 <printf@plt>
callq  400410 <printf@plt>
400545:
400545:
 
 
5d
5d
                   
                   
 
 
pop    %rbp
pop    %rbp
400546:
400546:
 
 
c3
c3
                   
                   
 
 
retq
retq
  
  
.section        .rodata
.section        .rodata
.LC0:
.LC0:
 
 
.string "hello, world %d\n“
.string "hello, world %d\n“
  
  
.text
.text
main:
main:
 
 
pushq   %rbp
pushq   %rbp
 
 
movq    %rsp, %rbp
movq    %rsp, %rbp
 
 
movl    $4, %esi
movl    $4, %esi
 
 
movl    $.LC0, %edi
movl    $.LC0, %edi
 
 
movl    $0, %eax
movl    $0, %eax
 
 
call    printf
call    printf
 
 
popq    %rbp
popq    %rbp
 
 
ret
ret
L
i
n
k
e
r
F
F
i
i
n
n
a
a
l
l
l
l
y
y
,
,
 
 
g
g
c
c
c
c
 
 
c
c
o
o
m
m
p
p
i
i
l
l
e
e
r
r
 
 
d
d
r
r
i
i
v
v
e
e
r
r
 
 
c
c
a
a
l
l
l
l
s
s
 
 
l
l
i
i
n
n
k
k
e
e
r
r
 
 
(
(
l
l
d
d
)
)
 
 
t
t
o
o
 
 
g
g
e
e
n
n
e
e
r
r
a
a
t
t
e
e
e
e
x
x
e
e
c
c
u
u
t
t
a
a
b
b
l
l
e
e
M
e
r
g
e
s
 
m
u
l
t
i
p
l
e
 
(
.
o
)
 
o
b
j
e
c
t
 
f
i
l
e
s
 
i
n
t
o
 
a
 
s
i
n
g
l
e
 
e
x
e
c
u
t
a
b
l
e
p
r
o
g
r
a
m
C
o
p
i
e
s
 
l
i
b
r
a
r
y
 
o
b
j
e
c
t
 
c
o
d
e
 
a
n
d
 
d
a
t
a
 
i
n
t
o
 
e
x
e
c
u
t
a
b
l
e
 
(
e
.
g
.
p
r
i
n
t
f
)
R
e
l
o
c
a
t
e
s
 
r
e
l
a
t
i
v
e
 
p
o
s
i
t
i
o
n
s
 
i
n
 
l
i
b
r
a
r
y
 
a
n
d
 
o
b
j
e
c
t
 
f
i
l
e
s
 
t
o
a
b
s
o
l
u
t
e
 
o
n
e
s
 
i
n
 
f
i
n
a
l
 
e
x
e
c
u
t
a
b
l
e
L
i
n
k
e
r
 
(
l
d
)
a.o
p
 
m.o
Libraries
libc.a
This is the executable program
L
i
n
k
e
r
 
(
s
t
a
t
i
c
)
R
R
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it.c
% gcc -c -o cubeit.o cubeit.c
% ar rv libmyutil.a squareit.o cubeit.o
ar: creating libmyutil.a
a - squareit.o
a - cubeit.o
% ranlib libmyutil.a
squareit.c
cubeit.c
#include
 
<stdio.h>
#include
 
<stdlib.h>
extern
 
int
 
squareit
(
int
);
extern
 
int
 
cubeit
(
int
);
int
 
main
()
 
{
  
int
 
i
=
3
;
  
printf
(
"square: %d cube: %d
\n
"
,
 
squareit
(
i
),
 
cubeit
(
i
));
  
exit
(
0
);
}
 
% gcc -m32 -o mathtest mathtest.c -L. –lmyutil
% ./mathtest
square: 9   cube: 27
 
L
i
s
t
 
f
u
n
c
t
i
o
n
s
 
i
n
 
o
b
j
e
c
t
 
f
i
l
e
mathtest.c
% nm libmyutil.a
squareit.o:
00000000 T squareit
cubeit.o:
00000000 T cubeit
% objdump –d libmyutil.a
squareit.o:     file format elf32-i386
00000000 <squareit>:
   0:   push   %ebp
   1:   mov    %esp,%ebp
...
cubeit.o:     file format elf32-i386
00000000 <cubeit>:
   0:   push   %ebp
   1:   mov    %esp,%ebp
...
P
r
o
b
l
e
m
s
 
w
i
t
h
 
s
t
a
t
i
c
 
l
i
b
r
a
r
i
e
s
M
M
u
u
l
l
t
t
i
i
p
p
l
l
e
e
 
 
c
c
o
o
p
p
i
i
e
e
s
s
 
 
o
o
f
f
 
 
c
c
o
o
m
m
m
m
o
o
n
n
 
 
c
c
o
o
d
d
e
e
 
 
o
o
n
n
 
 
d
d
i
i
s
s
k
k
S
t
a
t
i
c
 
c
o
m
p
i
l
a
t
i
o
n
 
c
r
e
a
t
e
s
 
a
 
b
i
n
a
r
y
 
w
i
t
h
 
l
i
b
c
 
o
b
j
e
c
t
 
c
o
d
e
c
o
p
i
e
d
 
i
n
t
o
 
i
t
 
(
l
i
b
c
.
a
)
A
l
m
o
s
t
 
a
l
l
 
p
r
o
g
r
a
m
s
 
u
s
e
 
l
i
b
c
!
L
a
r
g
e
 
n
u
m
b
e
r
 
o
f
 
b
i
n
a
r
i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
e
e
r
r
e
e
n
n
c
c
e
e
 
 
t
t
o
o
 
 
a
a
 
 
l
l
i
i
b
b
r
r
a
a
r
r
y
y
 
 
o
o
f
f
s
s
h
h
a
a
r
r
e
e
d
d
 
 
o
o
b
b
j
j
e
e
c
c
t
t
s
s
 
 
o
o
n
n
 
 
d
d
i
i
s
s
k
k
L
i
b
r
a
r
i
e
s
 
l
o
a
d
e
d
 
a
t
 
r
u
n
-
t
i
m
e
 
f
r
o
m
 
f
i
l
e
 
s
y
s
t
e
m
 
r
a
t
h
e
r
 
t
h
a
n
c
o
p
i
e
d
 
i
n
 
a
t
 
c
o
m
p
i
l
e
-
t
i
m
e
N
o
w
 
t
h
e
 
d
e
f
a
u
l
t
 
o
p
t
i
o
n
 
f
o
r
 
l
i
b
c
 
w
h
e
n
 
c
o
m
p
i
l
i
n
g
 
v
i
a
 
g
c
c
% gcc hello.o -static -o hello.static
% gcc hello.o -o hello.dynamic
% size hello.dynamic hello.static
   text
 
   data
 
    bss
 
    dec
 
    hex
  
filename
   1521
 
    600
 
      8
 
   2129
 
    851
  
hello.dynamic
 742889
 
  20876
 
   5984
 
 769749
 
  bbed5
  
hello.static
% nm hello.dynamic | wc –l
33
% nm hello.static | wc –l
1659
h
t
t
p
:
/
/
t
h
e
f
e
n
g
s
.
c
o
m
/
w
u
c
h
a
n
g
/
c
o
u
r
s
e
s
/
c
s
2
0
1
/
c
l
a
s
s
/
0
3
/
h
e
l
l
o
.
d
y
n
a
m
i
c
D
y
n
a
m
i
c
 
l
i
b
r
a
r
i
e
s
l
d
d
 
<
b
i
n
a
r
y
>
 
 
t
o
 
s
e
e
 
d
e
p
e
n
d
e
n
c
i
e
s
% ldd hello.dynamic
linux-vdso.so.1 (0x00007fff405dd000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f556a468000)
/lib64/ld-linux-x86-64.so.2 (0x00007f556aa5b000)
C
r
e
a
t
i
n
g
 
d
y
n
a
m
i
c
 
l
i
b
r
a
r
i
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
 
 
s
s
e
e
c
c
t
t
i
i
o
o
n
n
I
n
f
o
 
f
o
r
 
s
y
m
b
o
l
i
c
 
d
e
b
u
g
g
i
n
g
 
(
g
c
c
 
-
g
)
int e=7;
extern int a(); 
 
 
int main() {
  int r = a();
  exit(0); 
} 
m.c
a.c
extern int e; 
 
int *ep=&e;
int x=15; 
int y; 
 
int a() { 
  return *ep+x+y; 
} 
E
L
F
 
e
x
a
m
p
l
e
P
P
r
r
o
o
g
g
r
r
a
a
m
m
 
 
w
w
i
i
t
t
h
h
 
 
s
s
y
y
m
m
b
b
o
o
l
l
s
s
 
 
f
f
o
o
r
r
 
 
c
c
o
o
d
d
e
e
 
 
a
a
n
n
d
d
 
 
d
d
a
a
t
t
a
a
C
o
n
t
a
i
n
s
 
d
e
f
i
n
i
t
i
o
n
s
 
a
n
d
 
r
e
f
e
r
e
n
c
e
s
 
t
h
a
t
 
a
r
e
 
e
i
t
h
e
r
 
l
o
c
a
l
 
o
r
 
e
x
t
e
r
n
a
l
.
A
d
d
r
e
s
s
e
s
 
o
f
 
r
e
f
e
r
e
n
c
e
s
 
m
u
s
t
 
b
e
 
r
e
s
o
l
v
e
d
 
w
h
e
n
 
l
o
a
d
e
d
main()
&a(),&exit()
m.o
int *ep = 
&e
a()
a.o
int e = 7
headers
main()
&a(),&exit()
a()
0
s
y
s
t
e
m
 
c
o
d
e
int *ep = 
&e
int e = 7
s
y
s
t
e
m
 
d
a
t
a
more system code
int x = 15
int y
system data
int x = 15
O
b
j
e
c
t
 
F
i
l
e
s
E
x
e
c
u
t
a
b
l
e
 
O
b
j
e
c
t
 
F
i
l
e
.text
.text
.data
.text
.data
.text
.data
.bss  
.symtab
.debug
.data
uninitialized data
.bss
system code
M
e
r
g
i
n
g
 
O
b
j
e
c
t
 
F
i
l
e
s
 
i
n
t
o
 
a
n
E
x
e
c
u
t
a
b
l
e
 
O
b
j
e
c
t
 
F
i
l
e
int e=7;
extern int a(); 
 
 
int main() {
  int r = a();
  exit(0); 
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d
r
e
s
s
e
s
 
o
f
 
p
o
i
n
t
e
r
 
d
a
t
a
 
t
h
a
t
 
w
i
l
l
 
n
e
e
d
t
o
 
b
e
 
m
o
d
i
f
i
e
d
 
i
n
 
t
h
e
 
m
e
r
g
e
d
 
e
x
e
c
u
t
a
b
l
e
(
e
.
g
.
 
e
p
 
r
e
f
e
r
e
n
c
e
 
t
o
 
&
e
 
i
n
 
a
(
)
)
int e = 7
headers
main()
&a(),&exit()
a()
0
int *ep = 
&e
more system code
system data
int x = 15
E
x
e
c
u
t
a
b
l
e
 
O
b
j
e
c
t
 
F
i
l
e
.text
.symtab
.debug
.data
uninitialized data
.bss
system code
R
e
l
o
c
a
t
i
o
n
 
e
x
a
m
p
l
e
int e=7;
extern int a(); 
 
 
int main() {
  int r = a();
  exit(0); 
} 
m.c
a.c
extern int e; 
 
int *ep=&
e
;
int x=15; 
int y; 
 
int a() { 
  return *
ep
+
x
+
y
; 
} 
 
readelf -r a.o
 
; .rela.text contains ep, x, and y from a()
     
; .rela.data contains e to initialize ep
 
Relocation section '.rela.text' at offset 0x480 contains 3 entries:
  Offset          Info           Type           Sym. Value    Sym. Name + Addend
000000000007  000d00000002 R_X86_64_PC32     0000000000000000 
ep
 - 4
00000000000f  000f00000002 R_X86_64_PC32     0000000000000008 
x
 - 4
000000000017  001000000002 R_X86_64_PC32     0000000000000004 
y
 - 4
Relocation section '.rela.data' at offset 0x4c8 contains 1 entry:
  Offset          Info           Type           Sym. Value    Sym. Name + Addend
000000000000  000e00000001 R_X86_64_64       0000000000000000 
e
 + 0
h
t
t
p
:
/
/
t
h
e
f
e
n
g
s
.
c
o
m
/
w
u
c
h
a
n
g
/
c
o
u
r
s
e
s
/
c
s
2
0
1
/
c
l
a
s
s
/
0
3
/
e
l
f
_
e
x
a
m
p
l
e
W
W
h
h
a
a
t
t
 
 
i
i
s
s
 
 
i
i
n
n
 
 
.
.
t
t
e
e
x
x
t
t
,
,
 
 
.
.
d
d
a
a
t
t
a
a
,
,
 
 
.
.
r
r
e
e
l
l
a
a
.
.
t
t
e
e
x
x
t
t
,
,
 
 
a
a
n
n
d
d
 
 
.
.
r
r
e
e
l
l
a
a
.
.
d
d
a
a
t
t
a
a
?
?
R
e
l
o
c
a
t
i
o
n
 
e
x
a
m
p
l
e
int e=7;
extern int a(); 
 
 
int main() {
  int r = 
a()
;
  
exit(0)
; 
} 
m.c
a.c
extern int e; 
 
int *ep=&e;
int x=15; 
int y; 
 
int a() { 
  return *ep+x+y; 
} 
readelf -r m.o
 
; .rela.text contains a and exit from main()
Relocation section '.rela.text' at offset 0x528 contains 2 entries:
  Offset          Info           Type           Sym. Value    Sym. Name + Addend
00000000000e  000f00000002 R_X86_64_PC32     0000000000000000 
a
 - 4
00000000001b  001000000002 R_X86_64_PC32     0000000000000000 
exit
 - 4
h
t
t
p
:
/
/
t
h
e
f
e
n
g
s
.
c
o
m
/
w
u
c
h
a
n
g
/
c
o
u
r
s
e
s
/
c
s
2
0
1
/
c
l
a
s
s
/
0
3
/
e
l
f
_
e
x
a
m
p
l
e
W
W
h
h
a
a
t
t
 
 
i
i
s
s
 
 
i
i
n
n
 
 
.
.
t
t
e
e
x
x
t
t
,
,
 
 
.
.
d
d
a
a
t
t
a
a
,
,
 
 
.
.
r
r
e
e
l
l
a
a
.
.
t
t
e
e
x
x
t
t
,
,
 
 
a
a
n
n
d
d
 
 
.
.
r
r
e
e
l
l
a
a
.
.
d
d
a
a
t
t
a
a
?
?
R
e
l
o
c
a
t
i
o
n
 
e
x
a
m
p
l
e
int e=7;
extern int a(); 
 
 
int main() {
  int r = a();
  exit(0); 
} 
m.c
a.c
extern int e; 
 
int *ep=&e;
int x=15; 
int y; 
 
int a() { 
  return 
*ep+x+y
; 
} 
objdump -d a.o
 
0000000000000000 <a>:
   0:
 
push   %rbp
   1:
 
mov    %rsp,%rbp
   4:
 
mov    0x0(%rip),%rax   # b <a+0xb>
   b:
 
mov    (%rax),%edx
   d:
 
mov    0x0(%rip),%eax   # 13 <a+0x13>
  13:
 
add    %eax,%edx
  15:
 
mov    0x0(%rip),%eax   # 1b <a+0x1b>
  1b:
 
add    %edx,%eax
  1d:
 
pop    %rbp
  1e:
 
retq 
h
t
t
p
:
/
/
t
h
e
f
e
n
g
s
.
c
o
m
/
w
u
c
h
a
n
g
/
c
o
u
r
s
e
s
/
c
s
2
0
1
/
c
l
a
s
s
/
0
3
/
e
l
f
_
e
x
a
m
p
l
e
W
W
h
h
a
a
t
t
 
 
i
i
s
s
 
 
i
i
n
n
 
 
.
.
t
t
e
e
x
x
t
t
,
,
 
 
.
.
d
d
a
a
t
t
a
a
,
,
 
 
.
.
r
r
e
e
l
l
a
a
.
.
t
t
e
e
x
x
t
t
,
,
 
 
a
a
n
n
d
d
 
 
.
.
r
r
e
e
l
l
a
a
.
.
d
d
a
a
t
t
a
a
?
?
objdump –d m.o
 
0000000000000000 <main>:
   0:
 
push   %rbp
   1:
 
mov    %rsp,%rbp
   4:
 
sub    $0x10,%rsp
   8:
 
mov    $0x0,%eax
   d:
 
callq  12 <main+0x12>
  12:
 
mov    %eax,-0x4(%rbp)
  15:
 
mov    $0x0,%edi
  1a:
 
callq  1f <main+0x1f>
R
R
e
e
s
s
o
o
l
l
v
v
e
e
d
d
 
 
w
w
h
h
e
e
n
n
 
 
s
s
t
t
a
a
t
t
i
i
c
c
a
a
l
l
l
l
y
y
 
 
l
l
i
i
n
n
k
k
e
e
d
d
R
e
l
o
c
a
t
i
o
n
 
e
x
a
m
p
l
e
int e=7;
extern int a(); 
 
 
int main() {
  int r = a();
  exit(0); 
} 
m.c
a.c
extern int e; 
 
int *ep=&e;
int x=15; 
int y; 
 
int a() { 
  return *ep+x+y; 
} 
 
 
objdump –d m
  
; Symbols resolved in <main>.
     
; References in <a> resolved at fixed offsets to RIP
 
00000000004009ae <main>:
  4009ae:  push   %rbp
  4009af:  mov    %rsp,%rbp
  4009b2:  sub    $0x10,%rsp
  4009b6:  mov    $0x0,%eax
  4009bb:  callq  4009cd <a>
  4009c0:  mov    %eax,-0x4(%rbp)
  4009c3:  mov    $0x0,%edi
  4009c8:  callq  40ea10 <exit>
 
h
t
t
p
:
/
/
t
h
e
f
e
n
g
s
.
c
o
m
/
w
u
c
h
a
n
g
/
c
o
u
r
s
e
s
/
c
s
2
0
1
/
c
l
a
s
s
/
0
3
/
e
l
f
_
e
x
a
m
p
l
e
 
 
00000000004009cd <a>:
  4009cd:  push   %rbp
  4009ce:  mov    %rsp,%rbp
  4009d1:  mov    0x2c96c0(%rip),%rax  # 6ca098 <ep>
  4009d8:  mov    (%rax),%edx
  4009da:  mov    0x2c96c0(%rip),%eax  # 6ca0a0 <x>
  4009e0:  add    %eax,%edx
  4009e2:  mov    0x2cc370(%rip),%eax  # 6ccd58 <y>
  4009e8:  add    %edx,%eax
  4009ea:  pop    %rbp
  4009eb:  retq
P
r
o
g
r
a
m
 
e
x
e
c
u
t
i
o
n
:
 
o
p
e
r
a
t
i
n
g
 
s
y
s
t
e
m
 
P
P
r
r
o
o
g
g
r
r
a
a
m
m
 
 
r
r
u
u
n
n
s
s
 
 
o
o
n
n
 
 
t
t
o
o
p
p
 
 
o
o
f
f
 
 
o
o
p
p
e
e
r
r
a
a
t
t
i
i
n
n
g
g
 
 
s
s
y
y
s
s
t
t
e
e
m
m
 
 
t
t
h
h
a
a
t
t
 
 
i
i
m
m
p
p
l
l
e
e
m
m
e
e
n
n
t
t
s
s
 
 
a
a
b
b
s
s
t
t
r
r
a
a
c
c
t
t
v
v
i
i
e
e
w
w
 
 
o
o
f
f
 
 
r
r
e
e
s
s
o
o
u
u
r
r
c
c
e
e
s
s
F
i
l
e
s
 
a
s
 
a
n
 
a
b
s
t
r
a
c
t
i
o
n
 
o
f
 
s
t
o
r
a
g
e
 
a
n
d
 
n
e
t
w
o
r
k
 
d
e
v
i
c
e
s
S
y
s
t
e
m
 
c
a
l
l
s
 
a
n
 
a
b
s
t
r
a
c
t
i
o
n
 
f
o
r
 
O
S
 
s
e
r
v
i
c
e
s
V
i
r
t
u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b
a
l
 
v
a
r
i
a
b
l
e
s
,
 
f
u
n
c
t
i
o
n
s
u
s
e
d
 
t
o
 
a
l
l
o
w
 
o
v
e
r
r
i
d
e
s
 
o
f
 
f
u
n
c
t
i
o
n
 
i
m
p
l
e
m
e
n
t
a
t
i
o
n
s
S
i
m
u
l
a
t
e
s
 
i
n
h
e
r
i
t
a
n
c
e
 
a
n
d
 
f
u
n
c
t
i
o
n
 
o
v
e
r
i
d
i
n
g
 
(
a
s
 
i
n
 
C
+
+
)
R
u
l
e
s
M
u
l
t
i
p
l
e
 
s
t
r
o
n
g
 
s
y
m
b
o
l
s
 
n
o
t
 
a
l
l
o
w
e
d
C
h
o
o
s
e
 
s
t
r
o
n
g
 
s
y
m
b
o
l
s
 
o
v
e
r
 
w
e
a
k
 
s
y
m
b
o
l
s
C
h
o
o
s
e
 
a
n
y
 
w
e
a
k
 
s
y
m
b
o
l
 
i
f
 
m
u
l
t
i
p
l
e
 
o
n
e
s
 
e
x
i
s
t
Slide Note
Embed
Share

Explore the intricate details of computer system organization, the compilation process, and the role of components like the preprocessor, compiler, assembler, and linker. Learn how programs are processed and executed, from source code to executable code.

  • Computer Systems
  • Compilation Process
  • Programming Basics
  • Software Development
  • Operating Systems

Uploaded on Sep 14, 2024 | 1 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. Download presentation by click this link. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

E N D

Presentation Transcript


  1. Computer System Organization

  2. Todays agenda Overview of how things work Compilation and linking system Operating system Computer organization

  3. A software view User Interface

  4. How it works hello.c program #include <stdio.h> #define FOO 4 int main() { printf( hello, world %d\n , FOO); }

  5. The Compilation system gcc is the compiler driver gcc invokes several other compilation phases Preprocessor Compiler Assembler Linker What does each one do? What are their outputs? Pre- hello.c hello.i hello.s hello.o hello Compiler Assembler Linker processor Program Source Modified Source Assembly Code Object Code Executable Code

  6. Preprocessor First, gcc compiler driver invokes cpp to generate expanded C source cpp just does text substitution Converts the C source file to another C source file Expands # directives Output is another C source file #include <stdio.h> #define FOO 4 int main(){ printf("hello, world %d\n", FOO); } extern int printf (const char *__restrict __format, ...); int main() { printf("hello, world %d\n", 4); }

  7. Preprocessor Included files: #include <foo.h> #include "bar.h" /* within cwd */ Defined constants: #define MAXVAL 40000000 By convention, all capitals tells us it s a constant, not a variable. Defined macros: #define MIN(x,y) ((x)<(y) ? (x):(y)) /* /usr/include/ */

  8. Preprocesser Conditional compilation: Code you think you may need again Example: Debug print statements Include or exclude code using DEBUG condition and #ifdef, #if preprocessor directive in source code #ifdef DEBUG or #if defined( DEBUG ) #endif Set DEBUG condition via gcc D DEBUG in compilation or within source code via #define DEBUG More readable than commenting code out

  9. Preprocesser #include <stdio.h> int main() { #ifdef DEBUG printf("Debug flag on\n"); #endif printf("Hello world\n"); return 0; } % gcc -o def def.c % ./def Hello world % gcc -D DEBUG -o def def.c % ./def Debug flag on Hello world http://thefengs.com/wuchang/courses/cs201/class/03/def

  10. Preprocesser Conditional compilation to support portability Compilers with built in constants defined Use to conditionally include code Operating system specific code #if defined(__i386__) || defined(WIN32) || Compiler-specific code #if defined(__INTEL_COMPILER) Processor-specific code #if defined(__SSE__)

  11. Compiler Next, gcc invokes cc1 to generate assembly code Translates high-level C code into assembly Variable abstraction mapped to memory locations and registers Logical and arithmetic operations mapped to underlying machine opcodes Function call abstraction implemented

  12. Compiler extern int printf (const char *__restrict __format, ...); int main() { printf("hello, world %d\n", 4); } .LC0: .section .rodata .string "hello, world %d\n" main: .text pushq %rbp movq %rsp, %rbp movl $4, %esi movl $.LC0, %edi movl $0, %eax call printf popq %rbp ret

  13. Assembler Next, gcc invokes as to generate object code Translates assembly code into binary object code that can be directly executed by CPU

  14. .LC0: main: .section .rodata Assembler .string "hello, world %d\n .text pushq %rbp movq %rsp, %rbp movl $4, %esi movl $.LC0, %edi movl $0, %eax call printf popq %rbp ret % readelf -a hello | egrep rodata [16] .rodata PROGBITS 00000000004005d0 000005d0 % readelf x 16 hello Hex dump of section '.rodata': 0x004005d0 01000200 68656c6c 6f2c2077 6f726c64 ....hello, world 0x004005e0 2025640a 00 %d.. % objdump d hello Disassembly of section .text: 000000000040052d <main>: 40052d: 55 push %rbp 40052e: 48 89 e5 mov %rsp,%rbp 400531: be 04 00 00 00 mov $0x4,%esi 400536: bf d4 05 40 00 mov $0x4005d4,%edi 40053b: b8 00 00 00 00 mov $0x0,%eax 400540: e8 cb fe ff ff callq 400410 <printf@plt> 400545: 5d pop %rbp 400546: c3 retq

  15. Linker Finally, gcc compiler driver calls linker (ld) to generate executable Merges multiple (.o) object files into a single executable program Copies library object code and data into executable (e.g. printf) Relocates relative positions in library and object files to absolute ones in final executable

  16. Linker (static) Resolves external references External reference: reference to a symbol defined in another object file (e.g. printf) Updates all references to these symbols to reflect their new positions. References in both code and data printf(); /* reference to symbol printf */ int *xp=&x; /* reference to symbol x */ a.o Libraries libc.a m.o Linker (ld) p This is the executable program

  17. Benefits of linking Modularity and space Program can be written as a collection of smaller source files, rather than one monolithic mass. Compilation efficiency Change one source file, compile, and then relink. No need to recompile other source files. Can build libraries of common functions (more on this later) e.g., Math library, standard C library

  18. Summary of compilation process Compiler driver (cc or gcc) coordinates all steps Invokes preprocessor (cpp), compiler (cc1), assembler (as), and linker (ld). Passes command line arguments to appropriate phases Pre- hello.c hello.i hello.s hello.o hello.static Compiler Assembler Linker processor Program Source Modified Source Assembly Code Object Code Executable Code http://thefengs.com/wuchang/courses/cs201/class/03/hello.static

  19. Creating and using static libraries atoi.c printf.c random.c ... Compile Compile Compile atoi.o printf.o random.o Archiver (ar) p1.c p2.c ar rs libc.a atoi.o printf.o random.o ranlib libc.a Compile Compile C standard library archive of relocatable object files concatenated into one file p1.o p2.o libc.a Linker (ld) executable object file (with code and data for libc functions needed by p1.c and p2.c copied in) p

  20. libc static libraries libc.a (the C standard library) 5 MB archive of more than 1000 object files. I/O, memory allocation, signals, strings, time, random numbers libm.a (the C math library) 2 MB archive of more than 400 object files. floating point math (sin, cos, tan, log, exp, sqrt, ) % ar -t /usr/lib/x86_64-linux-gnu/libc.a | sort fork.o fprintf.o fpu_control.o fputc.o freopen.o fscanf.o fseek.o fstab.o % ar -t /usr/lib/x86_64-linux-gnu/libm.a | sort e_acos.o e_acosf.o e_acosh.o e_acoshf.o e_acoshl.o e_acosl.o e_asin.o e_asinf.o e_asinl.o

  21. Creating your own static libraries squareit.c cubeit.c Code in squareit.c and cubeit.c that all programs use Create library libmyutil.a to link in functions Compile Compile squareit.o cubeit.o Archive & index (ar, ranlib) mathtest.c Compile Library of object files concatenated into single file mathtest.o libmyutil.a Linker (ld) executable object file (with code and data for libmyutil functions needed by mathtest.c copied in) p

  22. Creating your own static libraries Compilation steps for building static libraries int squareit(int x) { return (x*x); } squareit.c int cubeit(int x) { return (x*x*x); } cubeit.c % gcc -c -o squareit.o squareit.c % gcc -c -o cubeit.o cubeit.c % ar rv libmyutil.a squareit.o cubeit.o ar: creating libmyutil.a a - squareit.o a - cubeit.o % ranlib libmyutil.a http://thefengs.com/wuchang/courses/cs201/class/03/libexample

  23. #include <stdio.h> #include <stdlib.h> extern int squareit(int); extern int cubeit(int); int main() { int i=3; printf("square: %d cube: %d\n", squareit(i), cubeit(i)); exit(0); } mathtest.c % gcc -m32 -o mathtest mathtest.c -L. lmyutil % ./mathtest square: 9 cube: 27 List functions in object file % objdump d libmyutil.a % nm libmyutil.a squareit.o: file format elf32-i386 00000000 <squareit>: 0: push %ebp 1: mov %esp,%ebp squareit.o: 00000000 T squareit cubeit.o: 00000000 T cubeit ... cubeit.o: file format elf32-i386 00000000 <cubeit>: 0: push %ebp 1: mov %esp,%ebp ...

  24. Problems with static libraries Multiple copies of common code on disk Static compilation creates a binary with libc object code copied into it (libc.a) Almost all programs use libc! Large number of binaries on disk with the same code in it Security issue Hard to update Security bug in libpng (11/2015) requires all statically-linked applications to be recompiled!

  25. Dynamic libraries Two types of libraries (Previously) Static libraries Library of code that linker copies into the executable at compile time Dynamic shared object libraries Code loaded at run-time from the file system by system loader upon program execution

  26. Dynamic libraries Have binaries compiled with a reference to a library of shared objects on disk Libraries loaded at run-time from file system rather than copied in at compile-time Now the default option for libc when compiling via gcc % gcc hello.o -static -o hello.static % gcc hello.o -o hello.dynamic % size hello.dynamic hello.static text data bss dec hex 1521 600 8 2129 851 742889 20876 5984 769749 bbed5 % nm hello.dynamic | wc l 33 % nm hello.static | wc l 1659 filename hello.dynamic hello.static http://thefengs.com/wuchang/courses/cs201/class/03/hello.dynamic

  27. Dynamic libraries ldd <binary> to see dependencies % ldd hello.dynamic linux-vdso.so.1 (0x00007fff405dd000) libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f556a468000) /lib64/ld-linux-x86-64.so.2 (0x00007f556aa5b000) Creating dynamic libraries gcc flag shared to create dynamic shared object files (.so) http://thefengs.com/wuchang/courses/cs201/class/03/hello.dynamic

  28. Caveat How does one ensure dynamic libraries are present across all run-time environments? Must fall back to static linking (via gcc s static flag) to create self-contained binaries and avoid problems with DLL versions

  29. The Complete Picture m.c a.c Compile (cpp,cc1, as) Compile (cpp, cc1, as) m.o a.o libwhatever.a Static Linker (ld) Shared library of dynamically relocatable object files Partially linked executable p (on disk) p libc.so libm.so libc.so functions called by m.c and a.c are loaded, linked, and (potentially) shared among processes. Loader/Dynamic Linker (ld-linux.so) Fully linked executable p (in memory) p

  30. The (Actual) Complete Picture Dozens of processes use libc.so If each process reads libc.so from disk and loads private copy into address space Multiple copies of the *exact* code resident in memory for each! Modern operating systems keep one copy of library in read- only memory Single shared copy Use shared virtual memory (page-sharing) to reduce memory use

  31. Program execution gcc/cc output an executable in the ELF format (Linux) Executable and Linkable Format Standard unified binary format for Relocatable object files (.o), Shared object files (.so) Executable object files Equivalent to Windows Portable Executable (PE) format

  32. ELF Object File Format ELF header Magic number, type (.o, exec, .so), machine, byte ordering, etc. 0 ELF header Program header table (required for executables) .text section Program header table Page size, addresses of memory segments (sections), segment sizes. .text section Code (machine instructions) .data section Initialized (static) global data .bss section Uninitialized (static) global data Block Started by Symbol .data section .bss section .symtab .rela.text .rela.data .debug Section header table (required for relocatables)

  33. ELF Object File Format (cont) .rela.text section Relocation info for .text section For dynamic linker 0 ELF header Program header table (required for executables) .text section .rela.data section Relocation info for .data section For dynamic linker .data section .bss section .symtab .symtab section Symbol table Procedure and static variable names Section names and locations .rela.text .rela.data .debug Section header table (required for relocatables) .debug section Info for symbolic debugging (gcc -g)

  34. ELF example Program with symbols for code and data Contains definitions and references that are either local or external. Addresses of references must be resolved when loaded m.c a.c extern int e; int *ep=&e; int x=15; int y; int a() { return *ep+x+y; } int e=7; Ref to external symbol e Def of local symbol e extern int a(); int main() { int r = a(); exit(0); } Def of local symbol ep Defs of local symbols x and y Ref to external symbol exit (defined in libc.so) Def of local symbol a Refs of local symbols ep,x,y Ref to external symbol a

  35. Merging Object Files into an Executable Object File Executable Object File Object Files .text .data 0 system code system data int e=7; headers system code extern int a(); int main() { int r = a(); exit(0); } m.c main() &a(),&exit() main() &a(),&exit() int e = 7 .text .text a() .data m.o more system code system data extern int e; int *ep=&e; int x=15; int y; int a() { return *ep+x+y; } a.c .text a() int e = 7 int *ep = &e int x = 15 uninitialized data .data int *ep = &e int x = 15 int y .data .bss .bss a.o .symtab .debug

  36. Relocation Compiler does not know where code will be loaded into memory upon execution Instructions and data that depend on location must be fixed to actual addresses i.e. variables, pointers, jump instructions Executable Object File 0 headers system code .rela.text section Addresses of instructions that will need to be modified in the executable Instructions for modifying (e.g. &a() &exit()in main()) main() &a(),&exit() .text a() more system code system data .rela.data section Addresses of pointer data that will need to be modified in the merged executable (e.g. ep reference to &e in a()) int e = 7 int *ep = &e int x = 15 uninitialized data .data .bss .symtab .debug

  37. Relocation example m.c a.c extern int e; int *ep=&e; int x=15; int y; int a() { return *ep+x+y; } int e=7; extern int a(); int main() { int r = a(); exit(0); } What is in .text, .data, .rela.text, and .rela.data? objdump d m.o objdump -d a.o 0000000000000000 <main>: 0: push %rbp 1: mov %rsp,%rbp 4: sub $0x10,%rsp 8: mov $0x0,%eax d: callq 12 <main+0x12> 12: mov %eax,-0x4(%rbp) 15: mov $0x0,%edi 1a: callq 1f <main+0x1f> 0000000000000000 <a>: 0: push %rbp 1: mov %rsp,%rbp 4: mov 0x0(%rip),%rax # b <a+0xb> b: mov (%rax),%edx d: mov 0x0(%rip),%eax # 13 <a+0x13> 13: add %eax,%edx 15: mov 0x0(%rip),%eax # 1b <a+0x1b> 1b: add %edx,%eax 1d: pop %rbp 1e: retq http://thefengs.com/wuchang/courses/cs201/class/03/elf_example

  38. Relocation example m.c a.c extern int e; int *ep=&e; int x=15; int y; int a() { return *ep+x+y; } int e=7; extern int a(); int main() { int r = a(); exit(0); } Resolved when statically linked objdump d m ; Symbols resolved in <main>. ; References in <a> resolved at fixed offsets to RIP 00000000004009ae <main>: 4009ae: push %rbp 4009af: mov %rsp,%rbp 4009b2: sub $0x10,%rsp 4009b6: mov $0x0,%eax 4009bb: callq 4009cd <a> 4009c0: mov %eax,-0x4(%rbp) 4009c3: mov $0x0,%edi 4009c8: callq 40ea10 <exit> 00000000004009cd <a>: 4009cd: push %rbp 4009ce: mov %rsp,%rbp 4009d1: mov 0x2c96c0(%rip),%rax # 6ca098 <ep> 4009d8: mov (%rax),%edx 4009da: mov 0x2c96c0(%rip),%eax # 6ca0a0 <x> 4009e0: add %eax,%edx 4009e2: mov 0x2cc370(%rip),%eax # 6ccd58 <y> 4009e8: add %edx,%eax 4009ea: pop %rbp 4009eb: retq http://thefengs.com/wuchang/courses/cs201/class/03/elf_example

  39. Program execution: operating system Program runs on top of operating system that implements abstract view of resources Files as an abstraction of storage and network devices System calls an abstraction for OS services Virtual memory a uniform memory space abstraction for each process Gives the illusion that each process has entire memory space A process (in conjunction with the OS) provides an abstraction for a virtual computer Slices of CPU time to run in CPU state Open files Thread of execution Code and data in memory Operating system also provides protection Protects the hardware/itself from user programs Protects user programs from each other Protects files from unauthorized access

  40. Program execution The operating system creates a process. Including among other things, a virtual memory space System loader reads program from file system and loads its code into memory Program includes any statically linked libraries Done via DMA (direct memory access) System loader loads dynamic shared objects/libraries into memory Links everything together and then starts a thread of execution running Note: the program binary in file system remains and can be executed again Program is a cookie recipe, processes are the cookies

  41. Where are programs loaded in memory? An evolution . Primitive operating systems Single tasking. Physical memory addresses go from zero to N. The problem of loading is simple Load the program starting at address zero Use as much memory as it takes. Linker binds the program to absolute addresses at compile- time Code starts at zero Data concatenated after that etc.

  42. Where are programs loaded, contd Next imagine a multi-tasking operating system on a primitive computer. Physical memory space, from zero to N. Applications share space Memory allocated at load time in unused space Linker does not know where the program will be loaded Binds together all the modules, but keeps them relocatable How does the operating system load this program? Not a pretty solution, must find contiguous unused blocks How does the operating system provide protection? Not pretty either

  43. Where are programs loaded, contd Next, imagine a multi-tasking operating system on a modern computer, with hardware-assisted virtual memory (Intel 80286/80386) OS creates a virtual memory space for each program. As if program has all of memory to itself. Back to the simple model The linker statically binds the program to virtual addresses At load time, OS allocates memory, creates a virtual address space, and loads the code and data. Binaries are simply virtual memory snapshots of programs (Windows .com format)

  44. But, modern linking and loading Want to reduce storage Dynamic linking and loading versus static Single, uniform VM address space still But, library code must vie for addresses at load-time Many dynamic libraries, no fixed/reserved addresses to map them into Code must be relocatable again Useful also as a security feature to prevent predictability in exploits (Address-Space Layout Randomization)

  45. Modern loading of executables Executable object file for example program p 0 ELF header Virtual addr Process image Program header table (required for executables) 0x04083e0 init and shared lib segments .text section .data section 0x0408494 .text segment (r/o) .bss section .symtab .rel.text 0x040a010 .data segment (initialized r/w) .rel.data .debug 0x040a3b0 Section header table (required for relocatables) .bss segment (uninitialized r/w)

  46. Extra

  47. More on the linking process (ld) Resolves multiply defined symbols with some restrictions Strong symbols = initialized global variables, functions Weak symbols = uninitialized global variables, functions used to allow overrides of function implementations Simulates inheritance and function overiding (as in C++) Rules Multiple strong symbols not allowed Choose strong symbols over weak symbols Choose any weak symbol if multiple ones exist

More Related Content

giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#