<s>
Relocation	B-Library
is	O
the	O
process	O
of	O
assigning	O
load	O
addresses	O
for	O
position-dependent	B-Operating_System
code	I-Operating_System
and	O
data	O
of	O
a	O
program	B-Application
and	O
adjusting	O
the	O
code	O
and	O
data	O
to	O
reflect	O
the	O
assigned	O
addresses	O
.	O
</s>
<s>
Since	O
multiprocessing	O
systems	O
dynamically	O
link	O
and	O
switch	O
between	O
programs	O
it	O
became	O
necessary	O
to	O
be	O
able	O
to	O
relocate	O
objects	O
using	O
position-independent	B-Operating_System
code	I-Operating_System
.	O
</s>
<s>
A	O
linker	B-Application
usually	O
performs	O
relocation	B-Library
in	O
conjunction	O
with	O
symbol	O
resolution	O
,	O
the	O
process	O
of	O
searching	O
files	O
and	O
libraries	B-Library
to	O
replace	O
symbolic	O
references	O
or	O
names	O
of	O
libraries	B-Library
with	O
actual	O
usable	O
addresses	O
in	O
memory	B-General_Concept
before	O
running	O
a	O
program	B-Application
.	O
</s>
<s>
Relocation	B-Library
is	O
typically	O
done	O
by	O
the	O
linker	B-Application
at	O
link	B-Application
time	I-Application
,	O
but	O
it	O
can	O
also	O
be	O
done	O
at	O
load	B-Operating_System
time	I-Operating_System
by	O
a	O
relocating	B-Library
loader	I-Library
,	O
or	O
at	O
run	B-Library
time	I-Library
by	O
the	O
running	O
program	B-Application
itself	O
.	O
</s>
<s>
Some	O
architectures	O
avoid	O
relocation	B-Library
entirely	O
by	O
deferring	O
address	B-General_Concept
assignment	O
to	O
run	B-Library
time	I-Library
;	O
as	O
,	O
for	O
example	O
,	O
in	O
stack	B-Application
machines	I-Application
with	O
zero	B-Application
address	I-Application
arithmetic	I-Application
or	O
in	O
some	O
segmented	O
architectures	O
where	O
every	O
compilation	B-Language
unit	O
is	O
loaded	O
into	O
a	O
separate	O
segment	B-Device
.	O
</s>
<s>
Object	B-Application
files	I-Application
are	O
segmented	O
into	O
various	O
memory	B-General_Concept
segment	I-General_Concept
types	O
.	O
</s>
<s>
Example	O
segments	O
include	O
code	B-General_Concept
segment	I-General_Concept
(	O
.text	B-General_Concept
)	O
,	O
initialized	O
data	B-General_Concept
segment	I-General_Concept
(	O
.data	B-General_Concept
)	O
,	O
uninitialized	O
data	B-General_Concept
segment	I-General_Concept
(	O
.bss	B-General_Concept
)	O
,	O
or	O
others	O
.	O
</s>
<s>
The	O
relocation	B-Library
table	I-Library
is	O
a	O
list	O
of	O
pointers	O
created	O
by	O
the	O
translator	O
(	O
a	O
compiler	B-Language
or	O
assembler	O
)	O
and	O
stored	O
in	O
the	O
object	O
or	O
executable	O
file	O
.	O
</s>
<s>
Each	O
entry	O
in	O
the	O
table	O
,	O
or	O
"	O
fixup	O
"	O
,	O
is	O
a	O
pointer	O
to	O
an	O
absolute	O
address	B-General_Concept
in	O
the	O
object	O
code	O
that	O
must	O
be	O
changed	O
when	O
the	O
loader	B-Operating_System
relocates	O
the	O
program	B-Application
so	O
that	O
it	O
will	O
refer	O
to	O
the	O
correct	O
location	O
.	O
</s>
<s>
Fixups	O
are	O
designed	O
to	O
support	O
relocation	B-Library
of	O
the	O
program	B-Application
as	O
a	O
complete	O
unit	O
.	O
</s>
<s>
In	O
some	O
cases	O
,	O
each	O
fixup	O
in	O
the	O
table	O
is	O
itself	O
relative	O
to	O
a	O
base	O
address	B-General_Concept
of	O
zero	O
,	O
so	O
the	O
fixups	O
themselves	O
must	O
be	O
changed	O
as	O
the	O
loader	B-Operating_System
moves	O
through	O
the	O
table	O
.	O
</s>
<s>
In	O
some	O
architectures	O
a	O
fixup	O
that	O
crosses	O
certain	O
boundaries	O
(	O
such	O
as	O
a	O
segment	B-Device
boundary	O
)	O
or	O
that	O
is	O
not	O
aligned	O
on	O
a	O
word	O
boundary	O
is	O
illegal	O
and	O
flagged	O
as	O
an	O
error	O
by	O
the	O
linker	B-Application
.	O
</s>
<s>
Far	O
pointers	O
(	O
32-bit	O
pointers	O
with	O
segment:offset	B-Device
,	O
used	O
to	O
address	B-General_Concept
20-bit	O
640	O
KB	O
memory	B-General_Concept
space	O
available	O
to	O
DOS	B-Device
programs	O
)	O
,	O
which	O
point	O
to	O
code	O
or	O
data	O
within	O
a	O
DOS	B-Device
executable	O
(	O
EXE	O
)	O
,	O
do	O
not	O
have	O
absolute	O
segments	O
,	O
because	O
the	O
actual	O
address	B-General_Concept
of	O
code/data	O
depends	O
on	O
where	O
the	O
program	B-Application
is	O
loaded	O
in	O
memory	B-General_Concept
and	O
this	O
is	O
not	O
known	O
until	O
the	O
program	B-Application
is	O
loaded	O
.	O
</s>
<s>
Instead	O
,	O
segments	O
are	O
relative	O
values	O
in	O
the	O
DOS	B-Device
EXE	O
file	O
.	O
</s>
<s>
These	O
segments	O
need	O
to	O
be	O
corrected	O
,	O
when	O
the	O
executable	O
has	O
been	O
loaded	O
into	O
memory	B-General_Concept
.	O
</s>
<s>
The	O
EXE	O
loader	B-Operating_System
uses	O
a	O
relocation	B-Library
table	I-Library
to	O
find	O
the	O
segments	O
which	O
need	O
to	O
be	O
adjusted	O
.	O
</s>
<s>
With	O
32-bit	O
Windows	O
operating	O
systems	O
,	O
it	O
is	O
not	O
mandatory	O
to	O
provide	O
relocation	B-Library
tables	I-Library
for	O
EXE	O
files	O
,	O
since	O
they	O
are	O
the	O
first	O
image	O
loaded	O
into	O
the	O
virtual	O
address	B-General_Concept
space	O
and	O
thus	O
will	O
be	O
loaded	O
at	O
their	O
preferred	O
base	O
address	B-General_Concept
.	O
</s>
<s>
For	O
both	O
DLLs	O
and	O
for	O
EXEs	O
which	O
opt	O
into	O
address	B-General_Concept
space	O
layout	O
randomization	O
(	O
ASLR	O
)	O
,	O
an	O
exploit	O
mitigation	O
technique	O
introduced	O
with	O
Windows	B-Application
Vista	I-Application
,	O
relocation	B-Library
tables	I-Library
once	O
again	O
become	O
mandatory	O
because	O
of	O
the	O
possibility	O
that	O
the	O
binary	O
may	O
be	O
dynamically	O
moved	O
before	O
being	O
executed	O
,	O
even	O
though	O
they	O
are	O
still	O
the	O
first	O
thing	O
loaded	O
in	O
the	O
virtual	O
address	B-General_Concept
space	O
.	O
</s>
<s>
When	O
running	O
native	O
64-bit	O
binaries	O
on	O
Windows	B-Application
Vista	I-Application
and	O
above	O
,	O
ASLR	O
is	O
mandatory	O
,	O
and	O
thus	O
relocation	B-Library
sections	O
cannot	O
be	O
omitted	O
by	O
the	O
compiler	B-Language
.	O
</s>
<s>
The	O
Executable	O
and	O
Linkable	O
Format	O
(	O
ELF	O
)	O
executable	B-Application
format	I-Application
and	O
shared	O
library	O
format	O
used	O
by	O
most	O
Unix-like	O
systems	O
allows	O
several	O
types	O
of	O
relocation	B-Library
to	O
be	O
defined	O
.	O
</s>
<s>
The	O
linker	B-Application
reads	O
segment	B-Device
information	O
and	O
relocation	B-Library
tables	I-Library
in	O
the	O
object	B-Application
files	I-Application
and	O
performs	O
relocation	B-Library
by	O
:	O
</s>
<s>
referring	O
to	O
the	O
relocation	B-Library
table	I-Library
to	O
modify	O
symbols	O
so	O
that	O
they	O
point	O
to	O
the	O
correct	O
run	B-Library
time	I-Library
addresses	O
.	O
</s>
<s>
(	O
A	O
)	O
Program	B-Application
SUBR	O
is	O
compiled	B-Language
to	O
produce	O
object	B-Application
file	I-Application
(	O
B	O
)	O
,	O
shown	O
as	O
both	O
machine	O
code	O
and	O
assembler	O
.	O
</s>
<s>
The	O
compiler	B-Language
may	O
start	O
the	O
compiled	B-Language
code	O
at	O
an	O
arbitrary	O
location	O
,	O
often	O
location	O
1	O
as	O
shown	O
.	O
</s>
<s>
In	O
this	O
example	O
the	O
linker	B-Application
places	O
it	O
at	O
location	O
120	O
.	O
</s>
<s>
The	O
address	B-General_Concept
in	O
the	O
jump	O
instruction	O
,	O
which	O
is	O
now	O
at	O
location	O
133	O
,	O
must	O
be	O
relocated	O
to	O
point	O
to	O
the	O
new	O
location	O
of	O
the	O
code	O
for	O
statement	O
ST	O
,	O
now	O
125	O
.	O
</s>
<s>
(	O
D	O
)	O
When	O
the	O
program	B-Application
is	O
loaded	O
into	O
memory	B-General_Concept
to	O
run	O
it	O
may	O
be	O
loaded	O
at	O
some	O
location	O
other	O
than	O
the	O
one	O
assigned	O
by	O
the	O
linker	B-Application
.	O
</s>
<s>
The	O
address	B-General_Concept
in	O
the	O
jump	O
instruction	O
,	O
now	O
at	O
313	O
,	O
needs	O
to	O
be	O
relocated	O
again	O
so	O
that	O
it	O
points	O
to	O
the	O
updated	O
location	O
of	O
ST	O
,	O
305	O
.	O
</s>
