<s>
In	O
computing	O
,	O
position-independent	B-Operating_System
code	I-Operating_System
(	O
PIC	O
)	O
or	O
position-independent	B-Operating_System
executable	O
(	O
PIE	O
)	O
is	O
a	O
body	O
of	O
machine	B-Language
code	I-Language
that	O
,	O
being	O
placed	O
somewhere	O
in	O
the	O
primary	O
memory	O
,	O
executes	O
properly	O
regardless	O
of	O
its	O
absolute	O
address	O
.	O
</s>
<s>
PIC	O
is	O
commonly	O
used	O
for	O
shared	O
libraries	O
,	O
so	O
that	O
the	O
same	O
library	O
code	O
can	O
be	O
loaded	O
at	O
a	O
location	O
in	O
each	O
program	O
's	O
address	B-General_Concept
space	I-General_Concept
where	O
it	O
does	O
not	O
overlap	O
with	O
other	O
memory	O
in	O
use	O
by	O
,	O
for	O
example	O
,	O
other	O
shared	O
libraries	O
.	O
</s>
<s>
PIC	O
was	O
also	O
used	O
on	O
older	O
computer	O
systems	O
that	O
lacked	O
an	O
MMU	B-General_Concept
,	O
so	O
that	O
the	O
operating	B-General_Concept
system	I-General_Concept
could	O
keep	O
applications	O
away	O
from	O
each	O
other	O
even	O
within	O
the	O
single	O
address	B-General_Concept
space	I-General_Concept
of	O
an	O
MMU-less	O
system	O
.	O
</s>
<s>
Position-independent	B-Operating_System
code	I-Operating_System
can	O
be	O
executed	O
at	O
any	O
memory	O
address	O
without	O
modification	O
.	O
</s>
<s>
This	O
differs	O
from	O
absolute	O
code	O
,	O
which	O
must	O
be	O
loaded	O
at	O
a	O
specific	O
location	O
to	O
function	O
correctly	O
,	O
and	O
load-time	B-Operating_System
locatable	O
(	O
LTL	O
)	O
code	O
,	O
in	O
which	O
a	O
linker	B-Application
or	O
program	B-Operating_System
loader	I-Operating_System
modifies	O
a	O
program	O
before	O
execution	O
,	O
so	O
it	O
can	O
be	O
run	O
only	O
from	O
a	O
particular	O
memory	O
location	O
.	O
</s>
<s>
Generating	O
position-independent	B-Operating_System
code	I-Operating_System
is	O
often	O
the	O
default	O
behavior	O
for	O
compilers	B-Language
,	O
but	O
they	O
may	O
place	O
restrictions	O
on	O
the	O
use	O
of	O
some	O
language	O
features	O
,	O
such	O
as	O
disallowing	O
use	O
of	O
absolute	O
addresses	O
(	O
position-independent	B-Operating_System
code	I-Operating_System
has	O
to	O
use	O
relative	B-General_Concept
addressing	I-General_Concept
)	O
.	O
</s>
<s>
In	O
early	O
computers	O
such	O
as	O
the	O
IBM	B-Device
701	I-Device
(	O
29	O
April	O
1952	O
)	O
or	O
the	B-Operating_System
UNIVAC	I-Operating_System
I	O
(	O
31	O
March	O
1951	O
)	O
code	O
was	O
not	O
position-independent	B-Operating_System
:	O
each	O
program	O
was	O
built	O
to	O
load	O
into	O
and	O
run	O
from	O
a	O
particular	O
address	O
.	O
</s>
<s>
Those	O
early	O
computers	O
did	O
not	O
have	O
an	O
operating	B-General_Concept
system	I-General_Concept
and	O
were	O
not	O
multitasking-capable	O
.	O
</s>
<s>
In	O
such	O
an	O
operational	O
context	O
,	O
position-independent	B-Operating_System
code	I-Operating_System
was	O
not	O
necessary	O
.	O
</s>
<s>
The	O
IBM	B-Device
System/360	I-Device
(	O
7	O
April	O
1964	O
)	O
was	O
designed	O
with	O
truncated	O
addressing	O
similar	O
to	O
that	O
of	O
the	B-Operating_System
UNIVAC	I-Operating_System
III	O
,	O
with	O
code	O
position	O
independence	O
in	O
mind	O
.	O
</s>
<s>
In	O
truncated	O
addressing	O
,	O
memory	O
addresses	O
are	O
calculated	O
from	O
a	O
base	O
register	O
and	O
an	O
offset	B-General_Concept
.	O
</s>
<s>
Such	O
instructions	O
require	O
less	O
memory	O
because	O
they	O
do	O
not	O
have	O
to	O
hold	O
a	O
full	O
24	O
,	O
31	O
,	O
32	O
,	O
or	O
64	O
bit	O
address	O
(	O
4	O
or	O
8	O
bytes	O
)	O
,	O
but	O
instead	O
a	O
base	O
register	O
number	O
(	O
encoded	O
in	O
4	O
bits	O
)	O
and	O
a	O
12	O
–	O
bit	O
address	O
offset	B-General_Concept
(	O
encoded	O
in	O
12	O
bits	O
)	O
,	O
requiring	O
only	O
two	O
bytes	O
.	O
</s>
<s>
Compilers	B-Language
automatically	O
take	O
care	O
of	O
this	O
kind	O
of	O
addressing	O
.	O
</s>
<s>
IBM	O
's	O
early	O
operating	B-General_Concept
system	I-General_Concept
DOS/360	O
(	O
1966	O
)	O
was	O
not	O
using	O
virtual	O
storage	O
(	O
since	O
the	O
early	O
models	O
of	O
System	O
S/360	O
did	O
not	O
support	O
it	O
)	O
,	O
but	O
it	O
did	O
have	O
the	O
ability	O
to	O
place	O
programs	O
to	O
an	O
arbitrary	O
(	O
or	O
automatically	O
chosen	O
)	O
storage	O
location	O
during	O
loading	O
via	O
the	O
PHASE	O
name	O
,	O
*	O
JCL	O
(	O
Job	O
Control	O
Language	O
)	O
statement	O
.	O
</s>
<s>
Sometimes	O
memory	B-Architecture
fragmentation	I-Architecture
would	O
occur	O
from	O
loading	O
and	O
unloading	O
differently	O
sized	O
modules	O
.	O
</s>
<s>
While	O
DOS/360	O
and	O
OS/360	B-Application
did	O
not	O
support	O
PIC	O
,	O
transient	O
SVC	O
routines	O
in	O
OS/360	B-Application
could	O
not	O
contain	O
relocatable	O
address	O
constants	O
and	O
could	O
run	O
in	O
any	O
of	O
the	O
transient	O
areas	O
without	O
relocation	B-Library
.	O
</s>
<s>
Virtual	O
storage	O
was	O
first	O
introduced	O
on	O
IBM	B-Device
System/360	I-Device
model	I-Device
67	I-Device
in	O
(	O
1965	O
)	O
to	O
support	O
IBM	O
's	O
first	O
multi-tasking	O
operating	O
and	O
time-sharing	O
operating	B-General_Concept
system	I-General_Concept
TSS/360	B-Application
.	O
</s>
<s>
and	O
later	O
IBM	O
operating	B-General_Concept
systems	I-General_Concept
all	O
utilized	O
virtual	O
storage	O
.	O
</s>
<s>
Truncated	O
addressing	O
remained	O
as	O
part	O
of	O
the	O
base	O
architecture	O
,	O
and	O
still	O
advantageous	O
when	O
multiple	O
modules	O
must	O
be	O
loaded	O
into	O
the	O
same	O
virtual	O
address	B-General_Concept
space	I-General_Concept
.	O
</s>
<s>
By	O
way	O
of	O
comparison	O
,	O
on	O
early	O
segmented	B-General_Concept
systems	O
such	O
as	O
Burroughs	B-Application
MCP	I-Application
on	O
the	O
Burroughs	B-Device
B5000	I-Device
(	O
1961	O
)	O
and	O
Multics	B-Application
(	O
1964	O
)	O
,	O
paging	O
systems	O
such	O
as	O
IBM	B-Application
TSS/360	I-Application
(	O
1967	O
)	O
or	O
base	B-General_Concept
and	I-General_Concept
bounds	I-General_Concept
systems	O
such	O
as	O
GECOS	B-Application
on	O
the	O
GE	B-Device
625	I-Device
and	O
EXEC	B-Application
on	O
the	B-Operating_System
UNIVAC	I-Operating_System
1107	O
,	O
code	O
was	O
also	O
inherently	O
position-independent	B-Operating_System
,	O
since	O
addresses	O
in	O
a	O
program	O
were	O
relative	O
to	O
the	O
current	O
segment	O
rather	O
than	O
absolute	O
.	O
</s>
<s>
The	O
invention	O
of	O
dynamic	O
address	O
translation	O
(	O
the	O
function	O
provided	O
by	O
an	O
MMU	B-General_Concept
)	O
originally	O
reduced	O
the	O
need	O
for	O
position-independent	B-Operating_System
code	I-Operating_System
because	O
every	O
process	O
could	O
have	O
its	O
own	O
independent	O
address	B-General_Concept
space	I-General_Concept
(	O
range	O
of	O
addresses	O
)	O
.	O
</s>
<s>
A	O
shared	O
module	O
(	O
a	O
shared	O
library	O
is	O
a	O
form	O
of	O
shared	O
module	O
)	O
gets	O
loaded	O
once	O
and	O
mapped	O
into	O
the	O
two	O
address	B-General_Concept
spaces	I-General_Concept
.	O
</s>
<s>
Data	O
references	O
from	O
position-independent	B-Operating_System
code	I-Operating_System
are	O
usually	O
made	O
indirectly	O
,	O
through	O
Global	B-General_Concept
Offset	I-General_Concept
Tables	I-General_Concept
(	O
GOTs	O
)	O
,	O
which	O
store	O
the	O
addresses	O
of	O
all	O
accessed	O
global	O
variables	O
.	O
</s>
<s>
There	O
is	O
one	O
GOT	O
per	O
compilation	B-Language
unit	O
or	O
object	B-Application
module	I-Application
,	O
and	O
it	O
is	O
located	O
at	O
a	O
fixed	O
offset	B-General_Concept
from	O
the	O
code	O
(	O
although	O
this	O
offset	B-General_Concept
is	O
not	O
known	O
until	O
the	O
library	O
is	O
linked	B-Library
)	O
.	O
</s>
<s>
When	O
a	O
linker	B-Application
links	O
modules	O
to	O
create	O
a	O
shared	O
library	O
,	O
it	O
merges	O
the	O
GOTs	O
and	O
sets	O
the	O
final	O
offsets	B-General_Concept
in	O
code	O
.	O
</s>
<s>
It	O
is	O
not	O
necessary	O
to	O
adjust	O
the	O
offsets	B-General_Concept
when	O
loading	O
the	O
shared	O
library	O
later	O
.	O
</s>
<s>
Position	B-Operating_System
independent	I-Operating_System
functions	O
accessing	O
global	O
data	O
start	O
by	O
determining	O
the	O
absolute	O
address	O
of	O
the	O
GOT	O
given	O
their	O
own	O
current	O
program	B-General_Concept
counter	I-General_Concept
value	O
.	O
</s>
<s>
This	O
often	O
takes	O
the	O
form	O
of	O
a	O
fake	O
function	O
call	O
in	O
order	O
to	O
obtain	O
the	O
return	O
value	O
on	O
stack	O
(	O
x86	B-Operating_System
)	O
,	O
in	O
a	O
specific	O
standard	O
register	O
(	O
SPARC	B-Architecture
,	O
MIPS	B-Device
)	O
,	O
or	O
a	O
special	O
register	O
(	O
POWER/PowerPC/Power	O
ISA	O
)	O
,	O
which	O
can	O
then	O
be	O
moved	O
to	O
a	O
predefined	O
standard	O
register	O
,	O
or	O
to	O
obtain	O
it	O
into	O
that	O
standard	O
register	O
(	O
PA-RISC	B-Device
,	O
Alpha	B-Device
,	O
ESA/390	O
and	O
z/Architecture	B-Device
)	O
.	O
</s>
<s>
Some	O
processor	O
architectures	O
,	O
such	O
as	O
the	O
Motorola	B-Device
68000	I-Device
,	O
Motorola	B-Device
6809	I-Device
,	O
WDC	B-General_Concept
65C816	I-General_Concept
,	O
Knuth	B-General_Concept
's	I-General_Concept
MMIX	O
,	O
ARM	B-Architecture
and	O
x86-64	B-Device
allow	O
referencing	O
data	O
by	O
offset	B-General_Concept
from	O
the	O
program	B-General_Concept
counter	I-General_Concept
.	O
</s>
<s>
This	O
is	O
specifically	O
targeted	O
at	O
making	O
position-independent	B-Operating_System
code	I-Operating_System
smaller	O
,	O
less	O
register	O
demanding	O
and	O
hence	O
more	O
efficient	O
.	O
</s>
<s>
Dynamic-link	O
libraries	O
(	O
DLLs	O
)	O
in	O
Microsoft	B-Application
Windows	I-Application
use	O
variant	O
E8	O
of	O
the	O
CALL	O
instruction	O
(	O
Call	O
near	O
,	O
relative	O
,	O
displacement	O
relative	O
to	O
next	B-General_Concept
instruction	I-General_Concept
)	O
.	O
</s>
<s>
arrays	O
of	O
string	O
literals	O
,	O
virtual	O
function	O
tables	O
)	O
are	O
expected	O
to	O
contain	O
an	O
address	O
of	O
an	O
object	O
in	O
data	O
section	O
respectively	O
in	O
code	O
section	O
of	O
the	O
dynamic	B-Application
library	I-Application
;	O
therefore	O
,	O
the	O
stored	O
address	O
in	O
the	O
global	O
variable	O
must	O
be	O
updated	O
to	O
reflect	O
the	O
address	O
where	O
the	O
DLL	O
was	O
loaded	O
to	O
.	O
</s>
<s>
The	O
dynamic	O
loader	B-Operating_System
calculates	O
the	O
address	O
referred	O
to	O
by	O
a	O
global	O
variable	O
and	O
stores	O
the	O
value	O
in	O
such	O
global	O
variable	O
;	O
this	O
triggers	O
copy-on-write	O
of	O
a	O
memory	O
page	O
containing	O
such	O
global	O
variable	O
.	O
</s>
<s>
This	O
operation	O
must	O
be	O
done	O
in	O
any	O
OS	O
that	O
can	O
load	O
a	O
dynamic	B-Application
library	I-Application
at	O
arbitrary	O
address	O
.	O
</s>
<s>
In	O
Windows	O
Vista	O
and	O
later	O
versions	O
of	O
Windows	O
,	O
the	O
relocation	B-Library
of	O
DLLs	O
and	O
executables	O
is	O
done	O
by	O
the	O
kernel	O
memory	O
manager	O
,	O
which	O
shares	O
the	O
relocated	O
binaries	O
across	O
multiple	O
processes	O
.	O
</s>
<s>
Images	O
are	O
always	O
relocated	O
from	O
their	O
preferred	O
base	O
addresses	O
,	O
achieving	O
address	B-General_Concept
space	I-General_Concept
layout	O
randomization	O
(	O
ASLR	O
)	O
.	O
</s>
<s>
Versions	O
of	O
Windows	O
prior	O
to	O
Vista	O
require	O
that	O
system	O
DLLs	O
be	O
prelinked	B-Library
at	O
non-conflicting	O
fixed	O
addresses	O
at	O
the	O
link	O
time	O
in	O
order	O
to	O
avoid	O
runtime	O
relocation	B-Library
of	O
images	O
.	O
</s>
<s>
Runtime	O
relocation	B-Library
in	O
these	O
older	O
versions	O
of	O
Windows	O
is	O
performed	O
by	O
the	O
DLL	O
loader	B-Operating_System
within	O
the	O
context	O
of	O
each	O
process	O
,	O
and	O
the	O
resulting	O
relocated	O
portions	O
of	O
each	O
image	O
can	O
no	O
longer	O
be	O
shared	O
between	O
processes	O
.	O
</s>
<s>
The	O
handling	O
of	O
DLLs	O
in	O
Windows	O
differs	O
from	O
the	O
earlier	O
OS/2	B-Application
procedure	O
it	O
derives	O
from	O
.	O
</s>
<s>
OS/2	B-Application
presents	O
a	O
third	O
alternative	O
and	O
attempts	O
to	O
load	O
DLLs	O
that	O
are	O
not	O
position-independent	B-Operating_System
into	O
a	O
dedicated	O
"	O
shared	O
arena	O
"	O
in	O
memory	O
,	O
and	O
maps	O
them	O
once	O
they	O
are	O
loaded	O
.	O
</s>
<s>
In	O
Multics	B-Application
each	O
procedure	O
conceptually	O
has	O
a	O
code	B-General_Concept
segment	I-General_Concept
and	O
a	O
linkage	O
segment	O
.	O
</s>
<s>
The	O
code	B-General_Concept
segment	I-General_Concept
contains	O
only	O
code	O
and	O
the	O
linkage	O
section	O
serves	O
as	O
a	O
template	O
for	O
a	O
new	O
linkage	O
segment	O
.	O
</s>
<s>
In	O
IBM	O
S/360	O
Time	O
Sharing	O
System	O
(	O
TSS/360	B-Application
and	O
TSS/370	B-Application
)	O
each	O
procedure	O
may	O
have	O
a	O
read-only	O
public	O
CSECT	O
and	O
a	O
writable	O
private	O
Prototype	O
Section	O
(	O
PSECT	O
)	O
.	O
</s>
<s>
The	O
Dynamic	O
Loader	B-Operating_System
does	O
not	O
load	O
program	O
pages	O
or	O
resolve	O
address	O
constants	O
until	O
the	O
first	O
page	O
fault	O
.	O
</s>
<s>
Position-independent	B-Operating_System
executables	O
(	O
PIE	O
)	O
are	O
executable	O
binaries	O
made	O
entirely	O
from	O
position-independent	B-Operating_System
code	I-Operating_System
.	O
</s>
<s>
PIE	O
binaries	O
are	O
used	O
in	O
some	O
security-focused	O
Linux	B-Application
distributions	O
to	O
allow	O
PaX	B-Device
or	O
Exec	B-Application
Shield	O
to	O
use	O
address	B-General_Concept
space	I-General_Concept
layout	O
randomization	O
(	O
ASLR	O
)	O
to	O
prevent	O
attackers	O
from	O
knowing	O
where	O
existing	O
executable	O
code	O
is	O
during	O
a	O
security	O
attack	O
using	O
exploits	O
that	O
rely	O
on	O
knowing	O
the	O
offset	B-General_Concept
of	O
the	O
executable	O
code	O
in	O
the	O
binary	O
,	O
such	O
as	O
return-to-libc	B-Language
attacks	O
.	O
</s>
<s>
(	O
The	O
official	O
Linux	B-Application
kernel	O
since	O
2.6.12	O
of	O
2005	O
has	O
a	O
weaker	O
ASLR	O
that	O
also	O
works	O
with	O
PIE	O
.	O
</s>
<s>
Apple	O
's	O
macOS	B-Application
and	O
iOS	B-Application
fully	O
support	O
PIE	O
executables	O
as	O
of	O
versions	O
10.7	O
and	O
4.3	O
,	O
respectively	O
;	O
a	O
warning	O
is	O
issued	O
when	O
non-PIE	O
iOS	B-Application
executables	O
are	O
submitted	O
for	O
approval	O
to	O
Apple	O
's	O
App	O
Store	O
but	O
there	O
's	O
no	O
hard	O
requirement	O
yet	O
and	O
non-PIE	O
applications	O
are	O
not	O
rejected	O
.	O
</s>
<s>
OpenBSD	B-Operating_System
has	O
PIE	O
enabled	O
by	O
default	O
on	O
most	O
architectures	O
since	O
OpenBSD	B-Operating_System
5.3	O
,	O
released	O
on	O
1	O
May	O
2013	O
.	O
</s>
<s>
Support	O
for	O
PIE	O
in	O
statically	B-General_Concept
linked	I-General_Concept
binaries	O
,	O
such	O
as	O
the	O
executables	O
in	O
/bin	O
and	O
/sbin	O
directories	O
,	O
was	O
added	O
near	O
the	O
end	O
of	O
2014	O
.	O
openSUSE	O
added	O
PIE	O
as	O
a	O
default	O
in	O
2015-02	O
.	O
</s>
<s>
Ubuntu	B-Operating_System
17.10	O
has	O
PIE	O
enabled	O
by	O
default	O
across	O
all	O
architectures	O
.	O
</s>
<s>
Gentoo	B-Application
's	O
new	O
profiles	O
now	O
support	O
PIE	O
by	O
default	O
.	O
</s>
<s>
Android	B-Application
enabled	O
support	O
for	O
PIEs	O
in	O
Jelly	B-Application
Bean	I-Application
and	O
removed	O
non-PIE	O
linker	B-Application
support	O
in	O
Lollipop	B-Application
.	O
</s>
