<s>
Dynamic	B-Operating_System
loading	I-Operating_System
is	O
a	O
mechanism	O
by	O
which	O
a	O
computer	B-Application
program	I-Application
can	O
,	O
at	O
run	B-Library
time	I-Library
,	O
load	O
a	O
library	B-Library
(	O
or	O
other	O
binary	B-Application
)	O
into	O
memory	O
,	O
retrieve	O
the	O
addresses	O
of	O
functions	B-Library
and	O
variables	O
contained	O
in	O
the	O
library	B-Library
,	O
execute	O
those	O
functions	B-Library
or	O
access	O
those	O
variables	O
,	O
and	O
unload	O
the	O
library	B-Library
from	O
memory	O
.	O
</s>
<s>
It	O
is	O
one	O
of	O
the	O
3	O
mechanisms	O
by	O
which	O
a	O
computer	B-Application
program	I-Application
can	O
use	O
some	O
other	O
software	O
;	O
the	O
other	O
two	O
are	O
static	B-Library
linking	I-Library
and	O
dynamic	B-Application
linking	I-Application
.	O
</s>
<s>
Unlike	O
static	B-Library
linking	I-Library
and	O
dynamic	B-Application
linking	I-Application
,	O
dynamic	B-Operating_System
loading	I-Operating_System
allows	O
a	O
computer	B-Application
program	I-Application
to	O
start	O
up	O
in	O
the	O
absence	O
of	O
these	O
libraries	B-Library
,	O
to	O
discover	O
available	O
libraries	B-Library
,	O
and	O
to	O
potentially	O
gain	O
additional	O
functionality	O
.	O
</s>
<s>
Dynamic	B-Operating_System
loading	I-Operating_System
was	O
a	O
common	O
technique	O
for	O
IBM	O
's	O
operating	B-General_Concept
systems	I-General_Concept
for	O
System/360	B-Application
such	O
as	O
OS/360	B-Application
,	O
particularly	O
for	O
I/O	B-General_Concept
subroutines	O
,	O
and	O
for	O
COBOL	B-Application
and	O
PL/I	B-Language
runtime	B-Library
libraries	I-Library
,	O
and	O
continues	O
to	O
be	O
used	O
in	O
IBM	O
's	O
operating	B-General_Concept
systems	I-General_Concept
for	O
z/Architecture	B-Device
,	O
such	O
as	O
z/OS	B-Application
.	O
</s>
<s>
As	O
far	O
as	O
the	O
application	O
programmer	O
is	O
concerned	O
,	O
the	O
loading	O
is	O
largely	O
transparent	O
,	O
since	O
it	O
is	O
mostly	O
handled	O
by	O
the	O
operating	B-General_Concept
system	I-General_Concept
(	O
or	O
its	O
I/O	B-General_Concept
subsystem	O
)	O
.	O
</s>
<s>
IBM	O
's	O
strategic	O
transaction	B-General_Concept
processing	I-General_Concept
system	O
,	O
CICS	B-Application
(	O
1970s	O
onwards	O
)	O
uses	O
dynamic	B-Operating_System
loading	I-Operating_System
extensively	O
both	O
for	O
its	O
kernel	B-Operating_System
and	O
for	O
normal	O
application	B-Application
program	I-Application
loading	O
.	O
</s>
<s>
Corrections	O
to	O
application	B-Application
programs	I-Application
could	O
be	O
made	O
offline	O
and	O
new	O
copies	O
of	O
changed	O
programs	O
loaded	O
dynamically	O
without	O
needing	O
to	O
restart	O
CICS	B-Application
(	O
which	O
can	O
,	O
and	O
frequently	O
does	O
,	O
run	O
24/7	O
)	O
.	O
</s>
<s>
Shared	O
libraries	B-Library
were	O
added	O
to	O
Unix	B-Application
in	O
the	O
1980s	O
,	O
but	O
initially	O
without	O
the	O
ability	O
to	O
let	O
a	O
program	O
load	O
additional	O
libraries	B-Library
after	O
startup	O
.	O
</s>
<s>
Dynamic	B-Operating_System
loading	I-Operating_System
is	O
most	O
frequently	O
used	O
in	O
implementing	O
software	B-Application
plugins	I-Application
.	O
</s>
<s>
For	O
example	O
,	O
the	O
Apache	B-Application
Web	I-Application
Server	I-Application
's	I-Application
*	O
.dso	O
"	O
dynamic	B-Application
shared	I-Application
object	I-Application
"	O
plugin	B-Application
files	O
are	O
libraries	B-Library
which	O
are	O
loaded	O
at	B-Library
runtime	I-Library
with	O
dynamic	B-Operating_System
loading	I-Operating_System
.	O
</s>
<s>
Dynamic	B-Operating_System
loading	I-Operating_System
is	O
also	O
used	O
in	O
implementing	O
computer	B-Application
programs	I-Application
where	O
multiple	O
different	O
libraries	B-Library
may	O
supply	O
the	O
requisite	O
functionality	O
and	O
where	O
the	O
user	O
has	O
the	O
option	O
to	O
select	O
which	O
library	B-Library
or	O
libraries	B-Library
to	O
provide	O
.	O
</s>
<s>
Not	O
all	O
systems	O
support	O
dynamic	B-Operating_System
loading	I-Operating_System
.	O
</s>
<s>
UNIX-like	B-Operating_System
operating	I-Operating_System
systems	I-Operating_System
such	O
as	O
macOS	B-Application
,	O
Linux	B-Application
,	O
and	O
Solaris	B-Application
provide	O
dynamic	B-Operating_System
loading	I-Operating_System
with	O
the	O
C	B-Language
programming	I-Language
language	I-Language
"	O
dl	O
"	O
library	B-Library
.	O
</s>
<s>
The	O
Windows	B-Application
operating	I-Application
system	I-Application
provides	O
dynamic	B-Operating_System
loading	I-Operating_System
through	O
the	O
Windows	B-Library
API	I-Library
.	O
</s>
<s>
Loading	O
the	O
library	B-Library
is	O
accomplished	O
with	O
LoadLibrary	O
or	O
LoadLibraryEx	O
on	O
Windows	B-Application
and	O
with	O
dlopen	B-Operating_System
on	O
UNIX-like	B-Operating_System
operating	I-Operating_System
systems	I-Operating_System
.	O
</s>
<s>
As	O
a	O
UNIX	B-Application
library	B-Library
:	O
</s>
<s>
As	O
a	O
macOS	B-Application
Framework	I-Application
:	O
</s>
<s>
Or	O
if	O
the	O
framework	O
or	O
bundle	O
contains	O
Objective-C	O
code	O
:	O
</s>
<s>
Extracting	O
the	O
contents	O
of	O
a	O
dynamically	B-Operating_System
loaded	I-Operating_System
library	I-Operating_System
is	O
achieved	O
with	O
GetProcAddress	O
on	O
Windows	B-Application
and	O
with	O
dlsym	O
on	O
UNIX-like	B-Operating_System
operating	I-Operating_System
systems	I-Operating_System
.	O
</s>
<s>
On	O
macOS	B-Application
,	O
when	O
using	O
Objective-C	O
bundles	O
,	O
one	O
can	O
also	O
:	O
</s>
<s>
In	O
Windows	B-Application
,	O
the	O
conversion	O
is	O
straightforward	O
,	O
since	O
FARPROC	O
is	O
essentially	O
already	O
a	O
function	B-Language
pointer	I-Language
:	O
</s>
<s>
However	O
,	O
usually	O
one	O
wants	O
to	O
extract	O
functions	B-Library
anyway	O
,	O
so	O
this	O
is	O
normally	O
not	O
a	O
problem	O
.	O
</s>
<s>
However	O
,	O
a	O
function	B-Language
pointer	I-Language
is	O
not	O
required	O
to	O
even	O
have	O
the	O
same	O
size	O
as	O
a	O
data	O
object	O
pointer	O
,	O
and	O
therefore	O
a	O
valid	O
conversion	O
between	O
type	O
void*	O
and	O
a	O
pointer	O
to	O
a	O
function	O
may	O
not	O
be	O
easy	O
to	O
implement	O
on	O
all	O
platforms	O
.	O
</s>
<s>
This	O
makes	O
use	O
of	O
the	O
fact	O
that	O
reading	O
from	O
a	O
different	O
union	O
member	O
than	O
the	O
one	O
most	O
recently	O
written	O
to	O
(	O
called	O
"	O
type	B-Language
punning	I-Language
"	O
)	O
is	O
common	O
,	O
and	O
explicitly	O
allowed	O
even	O
if	O
strict	O
aliasing	O
is	O
in	O
force	O
,	O
provided	O
the	O
memory	O
is	O
accessed	O
through	O
the	O
union	O
type	O
directly	O
.	O
</s>
<s>
However	O
,	O
this	O
is	O
not	O
strictly	O
the	O
case	O
here	O
,	O
since	O
the	O
function	B-Language
pointer	I-Language
is	O
copied	O
to	O
be	O
used	O
outside	O
the	O
union	O
.	O
</s>
<s>
Note	O
that	O
this	O
trick	O
may	O
not	O
work	O
on	O
platforms	O
where	O
the	O
size	O
of	O
data	O
pointers	O
and	O
the	O
size	O
of	O
function	B-Language
pointers	I-Language
is	O
not	O
the	O
same	O
.	O
</s>
<s>
Because	O
of	O
this	O
problem	O
,	O
the	O
POSIX	O
documentation	O
on	O
dlsym( )	O
for	O
the	O
outdated	O
issue	O
6	O
stated	O
that	O
"	O
a	O
future	O
version	O
may	O
either	O
add	O
a	O
new	O
function	O
to	O
return	O
function	B-Language
pointers	I-Language
,	O
or	O
the	O
current	O
interface	O
may	O
be	O
deprecated	O
in	O
favor	O
of	O
two	O
new	O
functions	B-Library
:	O
one	O
that	O
returns	O
data	O
pointers	O
and	O
the	O
other	O
that	O
returns	O
function	B-Language
pointers	I-Language
"	O
.	O
</s>
<s>
For	O
the	O
subsequent	O
version	O
of	O
the	O
standard	O
(	O
issue	O
7	O
,	O
2008	O
)	O
,	O
the	O
problem	O
has	O
been	O
discussed	O
and	O
the	O
conclusion	O
was	O
that	O
function	B-Language
pointers	I-Language
have	O
to	O
be	O
convertible	O
to	O
void*	O
for	O
POSIX	O
compliance	O
.	O
</s>
<s>
If	O
the	O
contents	O
of	O
the	O
library	B-Library
can	O
be	O
changed	O
(	O
i.e.	O
</s>
<s>
in	O
the	O
case	O
of	O
a	O
custom	O
library	B-Library
)	O
,	O
in	O
addition	O
to	O
the	O
function	O
itself	O
a	O
pointer	O
to	O
it	O
can	O
be	O
exported	O
.	O
</s>
<s>
Since	O
a	O
pointer	O
to	O
a	O
function	B-Language
pointer	I-Language
is	O
itself	O
an	O
object	O
pointer	O
,	O
this	O
pointer	O
can	O
always	O
be	O
legally	O
retrieved	O
by	O
call	O
to	O
dlsym( )	O
and	O
subsequent	O
conversion	O
.	O
</s>
<s>
However	O
,	O
this	O
approach	O
requires	O
maintaining	O
separate	O
pointers	O
to	O
all	O
functions	B-Library
that	O
are	O
to	O
be	O
used	O
externally	O
,	O
and	O
the	O
benefits	O
are	O
usually	O
small	O
.	O
</s>
<s>
Loading	O
a	O
library	B-Library
causes	O
memory	O
to	O
be	O
allocated	O
;	O
the	O
library	B-Library
must	O
be	O
deallocated	O
in	O
order	O
to	O
avoid	O
a	O
memory	B-Error_Name
leak	I-Error_Name
.	O
</s>
<s>
Additionally	O
,	O
failure	O
to	O
unload	O
a	O
library	B-Library
can	O
prevent	O
filesystem	B-Application
operations	O
on	O
the	O
file	B-Operating_System
which	O
contains	O
the	O
library	B-Library
.	O
</s>
<s>
Unloading	O
the	O
library	B-Library
is	O
accomplished	O
with	O
FreeLibrary	O
on	O
Windows	B-Application
and	O
with	O
dlclose	O
on	O
UNIX-like	B-Operating_System
operating	I-Operating_System
systems	I-Operating_System
.	O
</s>
<s>
Likewise	O
,	O
if	O
the	O
DLL	O
introduces	O
a	O
factory	O
function	O
for	O
instantiating	O
dynamically	O
loaded	O
classes	B-Language
,	O
calling	O
or	O
dereferencing	O
that	O
function	O
after	O
the	O
DLL	O
is	O
closed	O
leads	O
to	O
undefined	O
behaviour	O
.	O
</s>
<s>
The	O
implementations	O
of	O
dynamic	B-Operating_System
loading	I-Operating_System
on	O
UNIX-like	B-Operating_System
operating	I-Operating_System
systems	I-Operating_System
and	O
Windows	B-Application
allow	O
programmers	O
to	O
extract	O
symbols	O
from	O
the	O
currently	O
executing	O
process	O
.	O
</s>
<s>
UNIX-like	B-Operating_System
operating	I-Operating_System
systems	I-Operating_System
allow	O
programmers	O
to	O
access	O
the	O
global	O
symbol	O
table	O
,	O
which	O
includes	O
both	O
the	O
main	O
executable	B-Application
and	O
subsequently	O
loaded	O
dynamic	B-Application
libraries	I-Application
.	O
</s>
<s>
Windows	B-Application
allows	O
programmers	O
to	O
access	O
symbols	O
exported	O
by	O
the	O
main	O
executable	B-Application
.	O
</s>
<s>
Windows	B-Application
does	O
not	O
use	O
a	O
global	O
symbol	O
table	O
and	O
has	O
no	O
API	O
to	O
search	O
across	O
multiple	O
modules	O
to	O
find	O
a	O
symbol	O
by	O
name	O
.	O
</s>
<s>
In	O
the	O
Java	B-Language
programming	I-Language
language	I-Language
,	O
classes	B-Language
can	O
be	O
dynamically	O
loaded	O
using	O
the	O
object	O
.	O
</s>
<s>
Loaded	O
classes	B-Language
can	O
only	O
be	O
unloaded	O
in	O
a	O
controlled	O
way	O
,	O
i.e.	O
</s>
<s>
when	O
the	O
programmer	O
wants	O
this	O
to	O
happen	O
,	O
if	O
the	O
classloader	O
used	O
to	O
load	O
the	O
class	O
is	O
not	O
the	O
system	O
class	O
loader	B-Operating_System
,	O
and	O
is	O
itself	O
unloaded	O
.	O
</s>
<s>
This	O
makes	O
unloading	O
of	O
classes	B-Language
tedious	O
.	O
</s>
<s>
Implicit	O
unloading	O
of	O
classes	B-Language
,	O
i.e.	O
</s>
<s>
in	O
an	O
uncontrolled	O
way	O
by	O
the	O
garbage	O
collector	O
,	O
has	O
changed	O
a	O
few	O
times	O
in	O
Java	B-Language
.	O
</s>
<s>
Until	O
Java	B-Language
1.2	O
.	O
the	O
garbage	O
collector	O
could	O
unload	O
a	O
class	O
whenever	O
it	O
felt	O
it	O
needed	O
the	O
space	O
,	O
independent	O
of	O
which	O
class	O
loader	B-Operating_System
was	O
used	O
to	O
load	O
the	O
class	O
.	O
</s>
<s>
Starting	O
with	O
Java	B-Language
1.2	O
classes	B-Language
loaded	O
via	O
the	O
system	O
classloader	O
were	O
never	O
unloaded	O
and	O
classes	B-Language
loaded	O
via	O
other	O
classloaders	O
only	O
when	O
this	O
other	O
classloader	O
was	O
unloaded	O
.	O
</s>
<s>
Starting	O
with	O
Java	B-Language
6	O
classes	B-Language
can	O
contain	O
an	O
internal	O
marker	O
indicating	O
to	O
the	O
garbage	O
collector	O
they	O
can	O
be	O
unloaded	O
if	O
the	O
garbage	O
collector	O
desires	O
to	O
do	O
so	O
,	O
independent	O
of	O
the	O
classloader	O
used	O
to	O
load	O
the	O
class	O
.	O
</s>
<s>
Similarly	O
,	O
libraries	B-Library
implementing	O
native	O
methods	O
are	O
dynamically	O
loaded	O
using	O
the	O
System.loadLibrary	O
method	O
.	O
</s>
<s>
Despite	O
its	O
promulgation	O
in	O
the	O
1980s	O
through	O
UNIX	B-Application
and	O
Windows	B-Application
,	O
some	O
systems	O
still	O
chose	O
not	O
to	O
add	O
—	O
or	O
even	O
to	O
remove	O
—	O
dynamic	B-Operating_System
loading	I-Operating_System
.	O
</s>
<s>
For	O
example	O
,	O
Plan	B-Operating_System
9	I-Operating_System
from	I-Operating_System
Bell	I-Operating_System
Labs	I-Operating_System
and	O
its	O
successor	O
9front	B-Operating_System
intentionally	O
avoid	O
dynamic	B-Application
linking	I-Application
,	O
as	O
they	O
consider	O
it	O
to	O
be	O
"	O
harmful	O
"	O
.	O
</s>
<s>
The	O
Go	B-Application
programming	I-Application
language	I-Application
,	O
by	O
some	O
of	O
the	O
same	O
developers	O
as	O
Plan	B-Operating_System
9	I-Operating_System
,	O
also	O
did	O
not	O
support	O
dynamic	B-Application
linking	I-Application
,	O
but	O
plugin	B-Application
loading	O
is	O
available	O
since	O
(	O
February	O
2017	O
)	O
.	O
</s>
<s>
The	O
Go	O
runtime	B-Library
and	O
any	O
library	B-Library
functions	I-Library
are	O
statically	O
linked	O
into	O
the	O
compiled	O
binary	B-Application
.	O
</s>
