





















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!






















object files
linkers
class11.ppt
Introduction to Computer Systems
class11.ppt
Problems:
Translators
p.c p
Loader
p
(memory image)executing program(memory image on disk)executable object file source file
class11.ppt
Translator
p1.o^ p1.c
Translator
p2.o p2.c
libc.a
object filesof relocatable static library
from p1.c and p2.c)libc functions that are called(only contains code and data forexecutable object file
common functions in different processesFurther improves modularity and efficiency, but duplicates
Static Linker
p
Loader
class11.ppt
processes.time and shared amongand p2.c are loaded at run- libc functions called by p1.c
relocatable object filesshared library of dynamically
Translator
p1.o p1.c
Translator
p2.o p2.c
libc.so
Static Linker
p
Loader/Dynamic Linker
CS 213 F’
class11.ppt
main() {int n=20;double d; char c[100];
c[i] = ‘z’;i=5; int i;
}
Headers
Relocation info Symbol table^ text
sections:
read-only code and data
data
sections
initialized static variables
0
bss
sections
uninitialized static variables Block Started by Symbol
Better Save Space
runtime on the stack.object files. They are created atNote: local variables don’t go in
addressesIncreasing
class11.ppt
main() {
zip();
code(int *p) {int x=0xfe;
srand(*p);
int *pextern int x;
&x;
zip()
code(p);
main.c:
zip.c:
code.c:
CS 213 F’
class11.ppt
main()
Resolving external references
Relocating symbol definitions and references
*p
zip()
x
code()
x
crt
main() zip()
crt
code()
*p
Data Text
class11.ppt
Lexical entities that correspond to functions and global variables
Each symbol has a
value (address)
Code consists of symbol
definitions and
references
References can be either
local or
external
main() {
zip();
code(int *p) {int x=0xfe;
srand(*p);
int *pextern int x;
&x;
zip()
code(p);
main.c:
zip.c:
code.c:
symbol zipexternal Ref to
symbol zipDef of local
symbol plocalDef of
symbol xexternalRef to
symbol xlocalDef of
(defined in libc.so)symbol srandRef to external
Ref to local symbol p
class11.ppt
.bss
.sbss
.sdata
.lita.lit8.lit
.data
.init/.fini
.text
.pdata/.xdata
.rdata
.rconst
bss segment
(better save space!)(block started by symbol) uninitialized variables
data segment
initialized variables
text segment
machine code
machine instructionsprocess init/deinit codelarge datasmall dataread only dataread only constants8-byte literal address pool8-byte literal pool4-byte literal poolsupport for exceptionssmall (4-byte) bssuninitialized data
(Runtime memory image)
(File format)
class11.ppt
main:
0x0:
lda
sp,
-16(sp)
0x4:
ldah
gp,
1(t12)
0x8:
lda
gp,
-32704(gp)
0xc:
stq
ra,
0(sp)
0x10: ldq
t12,
-32752(gp)
0x14: jsr
ra,
(t12),
zip
0x18: ldah
gp,
1(ra)
0x1c: ldq
ra,
0(sp)
0x20: bis
zero,
zero,
v
0x24: lda
gp,
-32728(gp)
0x28: lda
sp,
16(sp)
0x2c: ret
zero,
(ra),
main() {
zip();
.text .lita
0x00 (0)
0x50 (80) start
0x10 (16)0x30 (48) size
(Note: ra = pc)resets gp to 32,832t12 = address stored at .lita+0(Note that t12 = pc-4)that gp=32,832=(64K+128)/2Assembler assumes
referencing of data and functions?Question: Why use gp-relative
CS 213 F’
class11.ppt
Vaddr Symndx
Type
Extern Name
0x04 .text:
local
0x
local
.lita
0x
local
0x
extern zip
0x
local
0x50.lita:
REFQUAD extern zip
main() {
zip();
.text .lita
0x00 (0)
0x50 (80) start
0x10 (16)0x30 (48) size
instruction pair that
LITERAL: sets gp value
gp-relative
LITUSE: reference to literal in .lita
identifies instance of
HINT: loaded into a registera literal address previously
14 bit jsr hint reference
64-bit reference to
the symbol’s virtual address
CS 213 F’
class11.ppt
main:
0x0:
lda
sp, -16(sp)
0x4:
ldah
gp, 1(t12)
0x8:
lda
gp, -32704(gp)
0xc:
stq
ra, 0(sp)
0x10:
ldq
t12, -32752(gp)
0x14:
jsr
ra, (t12), zip
0x18:
ldah
gp, 1(ra)
0x1c:
ldq
ra, 0(sp)
0x20:
bis
zero, zero, v
0x24:
lda
gp, -32728(gp)
0x28:
lda
sp, 16(sp)
0x2c: ret
zero, (ra), 1
main() {
zip();
.lita^ .text
0x00 (0)
0x50 (80) start
0x10 (16)0x30 (48) Vaddr Symndx Type size
Extern Name
0x04 .text:
4
GPDISP
local
0x
13
LITERAL
local
.lita
0x
3
LITUSE
local
R_LU_JSR
0x
1
HINT
extern zip
0x
12
GPDISP
local
0x50.lita:
1
REFQUAD extern zip
class11.ppt
[Index]
Name
Value
Sclass
Symtype
p
0x
SData
Global
x
0x
SUndefined Global
zip
0x
Text
Proc
code
0x
Undefined
Proc
zip() {int *p = &x; extern int x;
code(p);
.text .lita
0x00 (0)
0x60 (96) start
0x10 (16)0x40 (64) size
.sdata
0x70 (112)
0x10 (16)
CS 213 F’
class11.ppt
zip() {int *p = &x; extern int x;
code(p);
.text .lita
0x00 (0)
0x60 (96) start
0x10 (16)0x40 (64) size
.sdata
0x70 (112)
0x10 (16)
Vaddr Symndx
Type
Extern
Name
.text:
0x
4
GPDISP
local
0x
13
LITERAL
local
.lita
0x
1
LITUSE
local
R_LU_BASE
0x
13
LITERAL
local
.lita
0x1c
3
LITUSE
local
R_LU_JSR
0x1c
3
HINT
extern code
0x
8
GPDISP
local
.lita:
0x
0
REFQUAD
extern p
0x
3
REFQUAD
extern code
.sdata:
0x
1
REFQUAD
extern x
0x0:
lda
sp, -16(sp)
0x4:
ldah
gp, 1(t12)
0x8:
lda
gp, -32688(gp)
0xc:
stq
ra, 0(sp)
0x10: ldq
t12, -32744(gp)
0x14: ldq
a0, -32752(gp)
0x18: ldq
a0, 0(a0)
0x1c: jsr
ra, (t12), code
0x20: ldah
gp, 1(ra)
0x24: ldq
ra, 0(sp)
0x28: lda
gp, -32720(gp)
0x2c: lda
sp, 16(sp)
0x30: ret
zero, (ra), 1