<s>
Mach-O	B-Operating_System
,	O
short	O
for	O
Mach	B-Operating_System
object	B-Language
file	O
format	O
,	O
is	O
a	O
file	O
format	O
for	O
executables	B-Application
,	O
object	B-Language
code	I-Language
,	O
shared	O
libraries	O
,	O
dynamically	O
loaded	O
code	O
,	O
and	O
core	B-Error_Name
dumps	I-Error_Name
.	O
</s>
<s>
Mach-O	B-Operating_System
is	O
used	O
by	O
some	O
systems	O
based	O
on	O
the	O
Mach	B-Operating_System
kernel	I-Operating_System
.	O
</s>
<s>
NeXTSTEP	B-Application
,	O
macOS	B-Application
,	O
and	O
iOS	B-Application
are	O
examples	O
of	O
systems	O
that	O
use	O
this	O
format	O
for	O
native	O
executables	B-Application
,	O
libraries	O
and	O
object	B-Language
code	I-Language
.	O
</s>
<s>
Each	O
Mach-O	B-Operating_System
file	O
is	O
made	O
up	O
of	O
one	O
Mach-O	B-Operating_System
header	O
,	O
followed	O
by	O
a	O
series	O
of	O
load	O
commands	O
,	O
followed	O
by	O
one	O
or	O
more	O
segments	O
,	O
each	O
of	O
which	O
contains	O
between	O
0	O
and	O
255	O
sections	O
.	O
</s>
<s>
Mach-O	B-Operating_System
uses	O
the	O
REL	O
relocation	B-Library
format	O
to	O
handle	O
references	O
to	O
symbols	O
.	O
</s>
<s>
When	O
looking	O
up	O
symbols	O
Mach-O	B-Operating_System
uses	O
a	O
two-level	O
namespace	O
that	O
encodes	O
each	O
symbol	O
into	O
an	O
'	O
object/symbol	O
name	O
 '	O
pair	O
that	O
is	O
then	O
linearly	O
searched	O
for	O
,	O
first	O
by	O
the	O
object	B-Language
and	O
then	O
the	O
symbol	O
name	O
.	O
</s>
<s>
The	O
basic	O
structure	O
—	O
a	O
list	O
of	O
variable-length	O
"	O
load	O
commands	O
"	O
that	O
reference	O
pages	O
of	O
data	O
elsewhere	O
in	O
the	O
file	O
—	O
was	O
also	O
used	O
in	O
the	O
executable	B-Application
file	I-Application
format	I-Application
for	O
Accent	B-Operating_System
.	O
</s>
<s>
The	O
Accent	B-Operating_System
file	O
format	O
was	O
in	O
turn	O
,	O
based	O
on	O
an	O
idea	O
from	O
Spice	B-Language
Lisp	I-Language
.	O
</s>
<s>
The	O
magic	O
number	O
for	O
32-bit	O
code	O
is	O
,	O
so	O
the	O
first	O
4	O
bytes	O
of	O
the	O
header	O
will	O
be	O
,	O
in	O
that	O
order	O
,	O
if	O
the	O
code	O
is	O
for	O
a	O
big-endian	O
instruction	B-General_Concept
set	I-General_Concept
architecture	I-General_Concept
such	O
as	O
PowerPC	B-Architecture
on	O
a	O
Mac	O
,	O
and	O
will	O
be	O
,	O
in	O
that	O
order	O
,	O
if	O
the	O
code	O
is	O
for	O
a	O
little-endian	O
instruction	B-General_Concept
set	I-General_Concept
architecture	I-General_Concept
such	O
as	O
x86	B-Operating_System
or	O
ARM	B-Architecture
.	O
</s>
<s>
The	O
reserved	O
value	O
is	O
only	O
present	O
in	O
64-bit	O
Mach-O	B-Operating_System
files	O
.	O
</s>
<s>
The	O
CPU	O
type	O
indicates	O
the	O
instruction	B-General_Concept
set	I-General_Concept
architecture	I-General_Concept
for	O
the	O
code	O
.	O
</s>
<s>
If	O
the	O
file	O
is	O
for	O
the	O
64-bit	O
version	O
of	O
the	O
instruction	B-General_Concept
set	I-General_Concept
architecture	I-General_Concept
,	O
the	O
CPU	O
type	O
value	O
has	O
the	O
bit	O
set	O
.	O
</s>
<s>
Newer	O
models	O
of	O
a	O
CPU	O
type	O
may	O
support	O
instructions	O
,	O
or	O
other	O
features	O
,	O
not	O
supported	O
by	O
older	O
CPU	O
models	O
,	O
so	O
that	O
code	O
compiled	O
or	O
written	O
for	O
a	O
newer	O
model	O
might	O
contain	O
instructions	O
that	O
are	O
illegal	B-Language
instructions	I-Language
on	O
an	O
older	O
model	O
,	O
causing	O
that	O
code	O
to	O
trap	B-Application
or	O
otherwise	O
fail	O
to	O
operate	O
correctly	O
when	O
run	O
on	O
an	O
older	O
model	O
.	O
</s>
<s>
If	O
the	O
CPU	O
type	O
is	O
ARM	B-Architecture
then	O
the	O
subtypes	O
are	O
as	O
follows	O
:	O
</s>
<s>
+	O
CPU	O
subtype	O
ARM	B-Architecture
Value	O
CPU	O
version	O
0x00000000	O
All	O
ARM	B-Architecture
processors	I-Architecture
.	O
</s>
<s>
0x00000001	O
Optimized	O
for	O
ARM-A500	O
ARCH	O
or	O
newer	O
.	O
</s>
<s>
0x00000002	O
Optimized	O
for	O
ARM-A500	O
or	O
newer	O
.	O
</s>
<s>
0x00000003	O
Optimized	O
for	O
ARM-A440	O
or	O
newer	O
.	O
</s>
<s>
0x00000004	O
Optimized	O
for	O
ARM-M4	O
or	O
newer	O
.	O
</s>
<s>
0x00000005	O
Optimized	O
for	O
ARM-V4T	O
or	O
newer	O
.	O
</s>
<s>
0x00000006	O
Optimized	O
for	O
ARM-V6	O
or	O
newer	O
.	O
</s>
<s>
0x00000007	O
Optimized	O
for	O
ARM-V5TEJ	O
or	O
newer	O
.	O
</s>
<s>
0x00000008	O
Optimized	O
for	O
ARM-XSCALE	O
or	O
newer	O
.	O
</s>
<s>
0x00000009	O
Optimized	O
for	O
ARM-V7	O
or	O
newer	O
.	O
</s>
<s>
0x0000000A	O
Optimized	O
for	O
ARM-V7F	O
(	O
Cortex	O
A9	O
)	O
or	O
newer	O
.	O
</s>
<s>
0x0000000B	O
Optimized	O
for	O
ARM-V7S	O
(	O
Swift	O
)	O
or	O
newer	O
.	O
</s>
<s>
0x0000000C	O
Optimized	O
for	O
ARM-V7K	O
(	O
Kirkwood40	O
)	O
or	O
newer	O
.	O
</s>
<s>
0x0000000D	O
Optimized	O
for	O
ARM-V8	O
or	O
newer	O
.	O
</s>
<s>
0x0000000E	O
Optimized	O
for	O
ARM-V6M	O
or	O
newer	O
.	O
</s>
<s>
0x0000000F	O
Optimized	O
for	O
ARM-V7M	O
or	O
newer	O
.	O
</s>
<s>
0x00000010	O
Optimized	O
for	O
ARM-V7EM	O
or	O
newer	O
.	O
</s>
<s>
If	O
the	O
CPU	O
type	O
is	O
x86	B-Operating_System
then	O
the	O
subtypes	O
are	O
as	O
follows	O
:	O
</s>
<s>
+	O
CPU	O
subtype	O
x86	B-Operating_System
Value	O
CPU	O
version	O
0x00000003	O
All	O
x86	B-Operating_System
processors	O
.	O
</s>
<s>
+	O
File	O
type	O
Value	O
Description	O
0x00000001	O
Relocatable	B-Library
object	I-Library
file	I-Library
.	O
</s>
<s>
0x00000002	O
Demand	O
paged	O
executable	B-Application
file	I-Application
.	O
</s>
<s>
0x00000004	O
Core	B-Error_Name
file	I-Error_Name
.	O
</s>
<s>
0x00000005	O
Preloaded	O
executable	B-Application
file	I-Application
.	O
</s>
<s>
0x0000000C	O
a	O
file	O
composed	O
of	O
other	O
Mach-Os	O
to	O
be	O
run	O
in	O
the	O
same	O
userspace	O
sharing	O
a	O
single	O
linkedit	O
.	O
</s>
<s>
After	O
the	O
file	O
type	O
value	O
is	O
the	O
number	O
of	O
load	O
commands	O
and	O
the	O
total	O
number	O
of	O
bytes	O
the	O
load	O
commands	O
are	O
after	O
the	O
Mach-O	B-Operating_System
header	O
,	O
then	O
a	O
32-bit	O
flag	O
with	O
the	O
following	O
possible	O
settings	O
.	O
</s>
<s>
+	O
Flag	O
Settings	O
Flag	O
in	O
Binary	O
Description0000_0000_0000_0000_0000_0000_0000_0001	O
The	O
object	B-Language
file	O
has	O
no	O
undefined	O
references.0000_0000_0000_0000_0000_0000_0000_0010	O
The	O
object	B-Language
file	O
is	O
the	O
output	O
of	O
an	O
incremental	O
link	O
against	O
a	O
base	O
file	O
and	O
ca	O
n't	O
be	O
link	O
edited	O
again.0000_0000_0000_0000_0000_0000_0000_0100	O
The	O
object	B-Language
file	O
is	O
input	O
for	O
the	O
dynamic	B-Application
linker	I-Application
and	O
ca	O
n't	O
be	O
statically	O
link	O
edited	O
again.0000_0000_0000_0000_0000_0000_0000_1000	O
The	O
object	B-Language
file	O
's	O
undefined	O
references	O
are	O
bound	O
by	O
the	O
dynamic	B-Application
linker	I-Application
when	O
loaded.0000_0000_0000_0000_0000_0000_0001_0000	O
The	O
file	O
has	O
its	O
dynamic	O
undefined	O
references	O
prebound.0000_0000_0000_0000_0000_0000_0010_0000	O
The	O
file	O
has	O
its	O
read-only	O
and	O
read-write	O
segments	O
split.0000_0000_0000_0000_0000_0000_0100_0000	O
The	O
shared	O
library	O
init	O
routine	O
is	O
to	O
be	O
run	O
lazily	O
via	O
catching	O
memory	O
faults	O
to	O
its	O
writeable	O
segments	O
(	O
obsolete	O
)	O
.0000_0000_0000_0000_0000_0000_1000_0000	O
The	O
image	O
is	O
using	O
two-level	O
name	O
space	O
bindings.0000_0000_0000_0000_0000_0001_0000_0000	O
The	O
executable	B-Application
is	O
forcing	O
all	O
images	O
to	O
use	O
flat	O
name	O
space	O
bindings.0000_0000_0000_0000_0000_0010_0000_0000	O
This	O
umbrella	O
guarantees	O
no	O
multiple	O
definitions	O
of	O
symbols	O
in	O
its	O
sub-images	O
so	O
the	O
two-level	O
namespace	O
hints	O
can	O
always	O
be	O
used.0000_0000_0000_0000_0000_0100_0000_0000	O
Do	O
not	O
have	O
dyld	B-Application
notify	O
the	O
prebinding	O
agent	O
about	O
this	O
executable.0000_0000_0000_0000_0000_1000_0000_0000	O
The	O
binary	O
is	O
not	O
prebound	O
but	O
can	O
have	O
its	O
prebinding	O
redone	O
.	O
</s>
<s>
only	O
used	O
when	O
MH_PREBOUND	O
is	O
not	O
set.0000_0000_0000_0000_0001_0000_0000_0000	O
Indicates	O
that	O
this	O
binary	O
binds	O
to	O
all	O
two-level	O
namespace	O
modules	O
of	O
its	O
dependent	O
libraries.0000_0000_0000_0000_0010_0000_0000_0000	O
Safe	O
to	O
divide	O
up	O
the	O
sections	O
into	O
sub-sections	O
via	O
symbols	O
for	O
dead	O
code	O
stripping.0000_0000_0000_0000_0100_0000_0000_0000	O
The	O
binary	O
has	O
been	O
canonicalized	O
via	O
the	O
un-prebind	O
operation.0000_0000_0000_0000_1000_0000_0000_0000	O
The	O
final	O
linked	O
image	O
contains	O
external	O
weak	O
symbols.0000_0000_0000_0001_0000_0000_0000_0000	O
The	O
final	O
linked	O
image	O
uses	O
weak	O
symbols.0000_0000_0000_0010_0000_0000_0000_0000	O
When	O
this	O
bit	O
is	O
set	O
,	O
all	O
stacks	O
in	O
the	O
task	O
will	O
be	O
given	O
stack	O
execution	O
privilege.0000_0000_0000_0100_0000_0000_0000_0000	O
When	O
this	O
bit	O
is	O
set	O
,	O
the	O
binary	O
declares	O
it	O
is	O
safe	O
for	O
use	O
in	O
processes	O
with	O
uid	O
zero.0000_0000_0000_1000_0000_0000_0000_0000	O
When	O
this	O
bit	O
is	O
set	O
,	O
the	O
binary	O
declares	O
it	O
is	O
safe	O
for	O
use	O
in	O
processes	O
when	O
UGID	O
is	O
true.0000_0000_0001_0000_0000_0000_0000_0000	O
When	O
this	O
bit	O
is	O
set	O
on	O
a	O
dylib	O
,	O
the	O
static	O
linker	O
does	O
not	O
need	O
to	O
examine	O
dependent	O
dylibs	O
to	O
see	O
if	O
any	O
are	O
re-exported.0000_0000_0010_0000_0000_0000_0000_0000	O
When	O
this	O
bit	O
is	O
set	O
,	O
the	O
OS	O
will	O
load	O
the	O
main	O
executable	B-Application
at	O
a	O
random	O
address.0000_0000_0100_0000_0000_0000_0000_0000	O
Only	O
for	O
use	O
on	O
dylibs	O
.	O
</s>
<s>
When	O
linking	O
against	O
a	O
dylib	O
that	O
has	O
this	O
bit	O
set	O
,	O
the	O
static	O
linker	O
will	O
automatically	O
not	O
create	O
a	O
load	O
command	O
to	O
the	O
dylib	O
if	O
no	O
symbols	O
are	O
being	O
referenced	O
from	O
the	O
dylib.0000_0000_1000_0000_0000_0000_0000_0000	O
Contains	O
a	O
section	O
of	O
type	O
S_THREAD_LOCAL_VARIABLES.0000_0001_0000_0000_0000_0000_0000_0000	O
When	O
this	O
bit	O
is	O
set	O
,	O
the	O
OS	O
will	O
run	O
the	O
main	O
executable	B-Application
with	O
a	O
non-executable	O
heap	O
even	O
on	O
platforms	O
(	O
e.g.	O
</s>
<s>
i386	O
)	O
that	O
do	O
n't	O
require	O
it.0000_0010_0000_0000_0000_0000_0000_0000	O
The	O
code	O
was	O
linked	O
for	O
use	O
in	O
an	O
application.0000_0100_0000_0000_0000_0000_0000_0000	O
The	O
external	O
symbols	O
listed	O
in	O
the	O
nlist	O
symbol	O
table	O
do	O
not	O
include	O
all	O
the	O
symbols	O
listed	O
in	O
the	O
dyld	B-Application
info.0000_1000_0000_0000_0000_0000_0000_0000	O
Allow	O
LC_MIN_VERSION_MACOS	O
and	O
LC_BUILD_VERSION	O
load	O
commands	O
with	O
the	O
platforms	O
macOS	B-Application
,	O
macCatalyst	O
,	O
iOSSimulator	O
,	O
tvOSSimulator	O
and	O
watchOSSimulator.1000_0000_0000_0000_0000_0000_0000_0000	O
Only	O
for	O
use	O
on	O
dylibs	O
.	O
</s>
<s>
When	O
this	O
bit	O
is	O
set	O
,	O
the	O
dylib	O
is	O
part	O
of	O
the	O
dyld	B-Application
shared	O
cache	O
,	O
rather	O
than	O
loose	O
in	O
the	O
filesystem.0xxx_0000_0000_0000_0000_0000_0000_0000	O
The	O
digits	O
marked	O
with	O
"	O
x	O
"	O
have	O
no	O
use	O
,	O
and	O
are	O
reserved	O
for	O
future	O
use	O
.	O
</s>
<s>
Now	O
the	O
load	O
commands	O
are	O
read	O
as	O
we	O
have	O
reached	O
the	O
end	O
of	O
the	O
Mach-O	B-Operating_System
header	O
.	O
</s>
<s>
Multiple	O
Mach-O	B-Operating_System
files	O
can	O
be	O
combined	O
in	O
a	O
multi-architecture	O
binary	O
.	O
</s>
<s>
This	O
allows	O
a	O
single	O
binary	O
file	O
to	O
contain	O
code	O
to	O
support	O
multiple	O
instruction	B-General_Concept
set	I-General_Concept
architectures	I-General_Concept
,	O
for	O
example	O
for	O
different	O
generations	O
and	O
types	O
of	O
Apple	O
devices	O
,	O
including	O
different	O
processor	O
architectures	O
such	O
as	O
ARM64	B-Architecture
and	O
x86-64	B-Device
.	O
</s>
<s>
The	O
sequence	O
of	O
entries	O
is	O
followed	O
by	O
a	O
sequence	O
of	O
Mach-O	B-Operating_System
images	O
.	O
</s>
<s>
Each	O
entry	O
refers	O
to	O
a	O
Mach-O	B-Operating_System
image	O
.	O
</s>
<s>
The	O
CPU	O
type	O
and	O
subtype	O
for	O
an	O
entry	O
must	O
be	O
the	O
same	O
as	O
the	O
CPU	O
type	O
and	O
subtype	O
for	O
the	O
Mach-O	B-Operating_System
image	O
to	O
which	O
the	O
entry	O
refers	O
.	O
</s>
<s>
The	O
file	O
offset	O
and	O
size	O
are	O
the	O
offset	O
in	O
the	O
file	O
of	O
the	O
beginning	O
of	O
the	O
Mach-O	B-Operating_System
image	O
,	O
and	O
the	O
size	O
of	O
the	O
Mach-O	B-Operating_System
image	O
,	O
to	O
which	O
the	O
entry	O
refers	O
.	O
</s>
<s>
The	O
section	O
alignment	O
is	O
the	O
logarithm	O
,	O
base	O
2	O
,	O
of	O
the	O
byte	O
alignment	O
in	O
the	O
file	O
required	O
for	O
the	O
Mach-O	B-Operating_System
image	O
to	O
which	O
the	O
entry	O
refers	O
;	O
for	O
example	O
,	O
a	O
value	O
of	O
14	O
means	O
that	O
the	O
image	O
must	O
be	O
aligned	O
on	O
a	O
214-byte	O
boundary	O
,	O
i.e.	O
</s>
<s>
The	O
load	O
commands	O
are	O
read	O
immediately	O
after	O
the	O
Mach-O	B-Operating_System
header	O
.	O
</s>
<s>
The	O
Mach-O	B-Operating_System
header	O
tells	O
us	O
how	O
many	O
load	O
commands	O
exist	O
after	O
the	O
Mach-O	B-Operating_System
header	O
and	O
the	O
size	O
in	O
bytes	O
to	O
where	O
the	O
load	O
commands	O
end	O
.	O
</s>
<s>
This	O
allows	O
older	O
Mach-O	B-Operating_System
loaders	O
to	O
skip	O
commands	O
not	O
understood	O
by	O
the	O
loader	O
that	O
are	O
not	O
mandatory	O
for	O
loading	O
the	O
application	O
.	O
</s>
<s>
Mach-O	B-Operating_System
binaries	O
that	O
use	O
load	O
command	O
type	O
use	O
the	O
32-bit	O
version	O
of	O
the	O
segment	O
load	O
command	O
,	O
while	O
is	O
used	O
to	O
specify	O
the	O
64-bit	O
version	O
of	O
the	O
segment	O
load	O
command.	O
,	O
</s>
<s>
The	O
segment	O
load	O
command	O
varies	O
if	O
the	O
Mach-O	B-Operating_System
header	O
is	O
32-bit	O
,	O
or	O
64-bit	O
.	O
</s>
<s>
Each	O
section	O
in	O
a	O
segment	O
load	O
command	O
has	O
a	O
relocation	B-Library
list	I-Library
offset	O
that	O
specifies	O
the	O
offsets	O
in	O
the	O
section	O
that	O
must	O
be	O
adjusted	O
based	O
on	O
the	O
application	O
's	O
base	O
address	O
.	O
</s>
<s>
The	O
relocations	B-Library
are	O
unnecessary	O
if	O
the	O
application	O
can	O
be	O
placed	O
at	O
its	O
defined	O
RAM	O
address	O
locations	O
such	O
as	O
a	O
base	O
address	O
of	O
zero	O
.	O
</s>
<s>
After	O
the	O
address	O
information	O
is	O
the	O
file	O
offset	O
the	O
segment	O
data	O
is	O
located	O
in	O
the	O
Mach-O	B-Operating_System
binary	O
,	O
and	O
the	O
number	O
of	O
bytes	O
to	O
read	O
from	O
the	O
file	O
.	O
</s>
<s>
Flag32	O
in	O
Binary	O
Description	O
00000000000000000000000000000001	O
The	O
file	O
contents	O
for	O
this	O
segment	O
is	O
for	O
the	O
high	O
part	O
of	O
the	O
VM	O
space	O
,	O
the	O
low	O
part	O
is	O
zero	O
filled	O
(	O
for	O
stacks	O
in	O
core	B-Error_Name
files	I-Error_Name
)	O
.	O
</s>
<s>
00000000000000000000000000000100	O
This	O
segment	O
has	O
nothing	O
that	O
was	O
relocated	O
in	O
it	O
and	O
nothing	O
relocated	O
to	O
it	O
,	O
that	O
is	O
it	O
maybe	O
safely	O
replaced	O
without	O
relocation	B-Library
.	O
</s>
<s>
00000000000000000000000000010000	O
This	O
segment	O
is	O
made	O
read-only	O
after	O
relocations	B-Library
are	O
applied	O
if	O
needed	O
.	O
</s>
<s>
Each	O
section	O
locates	O
to	O
the	O
relocation	B-Library
entries	O
for	O
adjusting	O
addresses	O
in	O
the	O
section	O
if	O
the	O
application	O
base	O
address	O
is	O
added	O
to	O
anything	O
other	O
than	O
zero	O
.	O
</s>
<s>
The	O
Mach-O	B-Operating_System
loader	O
records	O
the	O
symbol	O
pointer	O
sections	O
and	O
symbol	O
stub	O
sections	O
.	O
</s>
<s>
Each	O
pointer	O
is	O
32-bit	O
address	O
locations	O
in	O
32-bit	O
Mach-O	B-Operating_System
and	O
64-bit	O
address	O
locations	O
in	O
64-bit	O
Mach-O	B-Operating_System
.	O
</s>
<s>
A	O
segment	O
value	O
of	O
3	O
would	O
mean	O
the	O
offset	O
to	O
the	O
data	O
of	O
the	O
fourth	O
segment	O
load	O
command	O
in	O
the	O
Mach-O	B-Operating_System
file	O
starting	O
from	O
zero	O
up	O
(	O
0	O
,	O
1	O
,	O
2	O
,	O
3	O
=	O
4th	O
segment	O
)	O
.	O
</s>
<s>
You	O
can	O
easily	O
use	O
file	O
offset	O
without	O
using	O
the	O
RAM	O
addresses	O
and	O
relocations	B-Library
to	O
build	O
a	O
symbol	O
reader	O
and	O
to	O
read	O
the	O
link	O
edit	O
sections	O
and	O
even	O
map	O
method	O
calls	O
or	O
design	O
a	O
disassembler	O
.	O
</s>
<s>
If	O
building	O
a	O
Mach-O	B-Operating_System
loader	O
,	O
then	O
you	O
want	O
to	O
dump	O
the	O
sections	O
to	O
the	O
defined	O
RAM	O
addresses	O
plus	O
a	O
base	O
address	O
to	O
keep	O
applications	O
spaced	O
apart	O
so	O
they	O
do	O
not	O
write	O
over	O
one	O
another	O
.	O
</s>
<s>
Link	O
libraries	O
are	O
the	O
same	O
as	O
any	O
other	O
Mach-O	B-Operating_System
binary	O
,	O
just	O
that	O
there	O
is	O
no	O
command	O
that	O
specifies	O
the	O
main	O
entry	O
point	O
at	O
which	O
the	O
program	O
begins	O
.	O
</s>
<s>
The	O
ordinal	O
value	O
zero	O
is	O
used	O
in	O
the	O
symbol	O
table	O
to	O
specify	O
the	O
symbol	O
does	O
not	O
exist	O
as	O
an	O
external	O
symbol	O
in	O
another	O
Mach-O	B-Operating_System
binary	O
.	O
</s>
<s>
Mach-O	B-Operating_System
application	O
files	O
and	O
link	O
libraries	O
both	O
have	O
a	O
symbol	O
table	O
command	O
.	O
</s>
<s>
The	O
symbol	O
address	O
uses	O
a	O
32-bit	O
address	O
for	O
32-bit	O
Mach-O	B-Operating_System
files	O
and	O
a	O
64-bit	O
address	O
for	O
64-bit	O
Mach-O	B-Operating_System
files	O
.	O
</s>
<s>
External	O
symbols	O
are	O
symbols	O
that	O
have	O
a	O
defined	O
address	O
in	O
the	O
link	O
library	O
and	O
can	O
be	O
copied	O
to	O
an	O
undefined	O
symbol	O
in	O
a	O
Mach-O	B-Operating_System
application	O
.	O
</s>
<s>
xxxxxxxx0010xxxx	O
Used	O
by	O
the	O
dynamic	B-Application
linker	I-Application
at	O
runtime	O
.	O
</s>
<s>
xxxxxxxx0100xxxx	O
If	O
the	O
dynamic	B-Application
linker	I-Application
cannot	O
find	O
a	O
definition	O
for	O
this	O
symbol	O
,	O
it	O
sets	O
the	O
address	O
of	O
this	O
symbol	O
to	O
0	O
.	O
xxxxxxxx1000xxxx	O
If	O
the	O
static	O
linker	O
or	O
the	O
dynamic	B-Application
linker	I-Application
finds	O
another	O
definition	O
for	O
this	O
symbol	O
,	O
the	O
definition	O
is	O
ignored	O
.	O
</s>
<s>
The	O
first	O
symbols	O
that	O
are	O
read	O
are	O
local	O
debug	O
symbols	O
if	O
any	O
,	O
then	O
private	O
symbols	O
,	O
then	O
external	O
symbols	O
,	O
and	O
finally	O
the	O
undefined	O
symbols	O
that	O
link	O
to	O
another	O
binary	O
symbol	O
table	O
containing	O
the	O
external	O
symbol	O
address	O
in	O
another	O
Mach-O	B-Operating_System
binary	O
.	O
</s>
<s>
The	O
symbol	O
table	O
information	O
load	O
command	O
always	O
exists	O
if	O
there	O
is	O
a	O
symbol	O
table	O
section	O
in	O
the	O
Mach-O	B-Operating_System
binary	O
.	O
</s>
<s>
The	O
symbol	O
table	O
information	O
is	O
used	O
before	O
reading	O
the	O
symbol	O
entries	O
by	O
the	O
dynamic	B-Application
linker	I-Application
as	O
it	O
tells	O
the	O
dynamic	B-Application
linker	I-Application
where	O
to	O
start	O
reading	O
the	O
symbols	O
to	O
load	O
in	O
undefined	O
symbols	O
and	O
where	O
to	O
start	O
reading	O
to	O
look	O
for	O
matching	O
external	O
symbols	O
without	O
having	O
to	O
read	O
all	O
the	O
symbol	O
entries	O
.	O
</s>
<s>
The	O
symbol	O
table	O
information	O
command	O
is	O
used	O
by	O
the	O
dynamic	B-Application
linker	I-Application
to	O
know	O
where	O
to	O
read	O
the	O
symbol	O
table	O
entries	O
under	O
symbol	O
table	O
command	O
,	O
for	O
fast	O
lookup	O
of	O
undefined	O
symbols	O
and	O
external	O
symbols	O
while	O
linking	O
.	O
</s>
<s>
The	O
symbol	O
index	O
is	O
multiplied	O
by	O
12	O
for	O
Mach-O	B-Operating_System
32-bit	O
,	O
or	O
16	O
for	O
Mach-O	B-Operating_System
64-bit	O
plus	O
the	O
symbol	O
table	O
entries	O
offset	O
to	O
find	O
the	O
offset	O
to	O
read	O
the	O
symbol	O
entries	O
by	O
symbol	O
number	O
index	O
.	O
</s>
<s>
The	O
Mach-O	B-Operating_System
loader	O
records	O
the	O
symbol	O
pointer	O
sections	O
and	O
symbol	O
stub	O
sections	O
during	O
the	O
segment	O
load	O
commands	O
.	O
</s>
<s>
The	O
symbol	O
stub	O
section	O
contains	O
machine	O
code	O
instructions	O
with	O
JUMP	O
instructions	O
to	O
the	O
indirect	O
symbol	O
address	O
to	O
call	O
a	O
method/function	O
from	O
another	O
Mach-O	B-Operating_System
binary	O
.	O
</s>
<s>
The	O
pointer	O
sections	O
are	O
32-bit	O
(	O
4-byte	O
)	O
address	O
values	O
for	O
32-bit	O
Mach-O	B-Operating_System
binaries	O
and	O
64-bit	O
(	O
8-byte	O
)	O
address	O
values	O
for	O
64-bit	O
Mach-O	B-Operating_System
binaries	O
.	O
</s>
<s>
If	O
you	O
are	O
designing	O
a	O
disassembler	O
you	O
can	O
easily	O
map	O
just	O
the	O
symbol	O
name	O
to	O
the	O
offset	O
address	O
of	O
each	O
stub	O
and	O
pointer	O
to	O
show	O
the	O
method	O
or	O
function	O
call	O
taking	O
place	O
without	O
looking	O
for	O
the	O
undefined	O
symbol	O
address	O
location	O
in	O
other	O
Mach-O	B-Operating_System
files	O
.	O
</s>
<s>
The	O
indirect	O
symbol	O
table	O
still	O
exists	O
in	O
the	O
case	O
of	O
building	O
backwards	O
compatible	O
Mach-O	B-Operating_System
files	O
that	O
load	O
on	O
newer	O
and	O
older	O
OS	O
versions	O
.	O
</s>
<s>
Weak	O
binding	O
means	O
that	O
if	O
the	O
set	O
library	O
to	O
look	O
in	O
by	O
library	O
ordinal	O
number	O
,	O
and	O
the	O
set	O
symbol	O
name	O
does	O
not	O
exist	O
but	O
exists	O
under	O
a	O
different	O
previously	O
loaded	O
Mach-O	B-Operating_System
file	O
then	O
the	O
symbol	O
location	O
is	O
used	O
from	O
the	O
other	O
Mach-O	B-Operating_System
file	O
.	O
</s>
<s>
The	O
number	O
value	O
after	O
the	O
operation	O
code	O
is	O
encoded	O
as	O
a	O
LEB128	B-Algorithm
number	O
.	O
</s>
<s>
After	O
the	O
operation	O
code	O
is	O
the	O
added	O
offset	O
as	O
a	O
LEB128	B-Algorithm
number	O
to	O
the	O
segment	O
offset	O
.	O
</s>
<s>
Increments	O
the	O
current	O
set	O
location	O
by	O
the	O
size	O
4	O
bytes	O
for	O
a	O
32-bit	O
Mach-O	B-Operating_System
binary	O
or	O
increments	O
the	O
set	O
address	O
by	O
8	O
for	O
a	O
64-bit	O
Mach-O	B-Operating_System
binary	O
.	O
</s>
<s>
This	O
is	O
only	O
if	O
the	O
application	O
segment	O
addresses	O
are	O
added	O
to	O
an	O
application	O
base	O
address	O
of	O
zero	O
and	O
the	O
sections	O
did	O
not	O
need	O
any	O
relocations	B-Library
.	O
</s>
<s>
The	O
main	O
entry	O
point	O
in	O
a	O
Mach-O	B-Operating_System
loader	O
is	O
the	O
program	O
's	O
base	O
address	O
plus	O
the	O
Address	O
location	O
.	O
</s>
<s>
With	O
the	O
introduction	O
of	O
Mac	B-Device
OS	I-Device
X	I-Device
10.6	I-Device
platform	O
the	O
Mach-O	B-Operating_System
file	O
underwent	O
a	O
significant	O
modification	O
that	O
causes	O
binaries	O
compiled	O
on	O
a	O
computer	O
running	O
10.6	B-Device
or	O
later	O
to	O
be	O
(	O
by	O
default	O
)	O
executable	B-Application
only	O
on	O
computers	O
running	O
Mac	B-Device
OS	I-Device
X	I-Device
10.6	I-Device
or	O
later	O
.	O
</s>
<s>
The	O
difference	O
stems	O
from	O
load	O
commands	O
that	O
the	O
dynamic	B-Application
linker	I-Application
,	O
in	O
previous	O
Mac	B-Device
OS	I-Device
X	I-Device
versions	O
,	O
does	O
not	O
understand	O
.	O
</s>
<s>
Another	O
significant	O
change	O
to	O
the	O
Mach-O	B-Operating_System
format	O
is	O
the	O
change	O
in	O
how	O
the	O
Link	O
Edit	O
tables	O
(	O
found	O
in	O
the	O
__LINKEDIT	O
section	O
)	O
function	O
.	O
</s>
<s>
In	O
10.6	B-Device
these	O
new	O
Link	O
Edit	O
tables	O
are	O
compressed	O
by	O
removing	O
unused	O
and	O
unneeded	O
bits	O
of	O
information	O
,	O
however	O
Mac	B-Device
OS	I-Device
X	I-Device
10.5	O
and	O
earlier	O
cannot	O
read	O
this	O
new	O
Link	O
Edit	O
table	O
format	O
.	O
</s>
<s>
To	O
make	O
backwards-compatible	O
executables	B-Application
,	O
the	O
linker	O
flag	O
"	O
-mmacosx-version-min	O
=	O
"	O
can	O
be	O
used	O
.	O
</s>
<s>
A	O
Mach-O	B-Operating_System
application	O
can	O
be	O
run	O
on	O
different	O
operating	O
systems	O
or	O
OS	O
as	O
long	O
as	O
a	O
Mach-O	B-Operating_System
binary	O
image	O
exists	O
that	O
matches	O
the	O
core	O
type	O
in	O
your	O
computer	O
.	O
</s>
<s>
Most	O
desktops	O
are	O
x86	B-Operating_System
,	O
meaning	O
that	O
a	O
Mach-O	B-Operating_System
with	O
an	O
x86	B-Operating_System
binary	O
will	O
run	O
without	O
problems	O
if	O
you	O
load	O
the	O
sections	O
into	O
memory	O
.	O
</s>
<s>
If	O
the	O
Mach-O	B-Operating_System
is	O
designed	O
for	O
iPhone	O
,	O
which	O
has	O
an	O
ARM	B-Architecture
core	O
,	O
then	O
you	O
would	O
need	O
a	O
PC	O
with	O
an	O
ARM	B-Architecture
core	O
(	O
does	O
not	O
have	O
to	O
be	O
apple	O
silicon	O
ARM	B-Architecture
)	O
to	O
run	O
it	O
;	O
otherwise	O
,	O
you	O
would	O
have	O
to	O
change	O
ARM	B-Architecture
encoded	O
instructions	O
to	O
equivalent	O
x86	B-Operating_System
encoded	O
instructions	O
.	O
</s>
<s>
The	O
problem	O
of	O
loading	O
and	O
directly	O
executing	O
a	O
Mach-O	B-Operating_System
is	O
undefined	O
symbols	O
that	O
call	O
functions/methods	O
from	O
other	O
Mach-O	B-Operating_System
binaries	O
that	O
do	O
not	O
exist	O
on	O
another	O
operating	O
system	O
.	O
</s>
<s>
Some	O
symbols	O
can	O
call	O
other	O
equivalent	O
functions	O
in	O
the	O
different	O
operating	O
systems	O
or	O
even	O
call	O
adaptor	O
functions	O
to	O
make	O
other	O
binary	O
function	O
calls	O
behave	O
like	O
the	O
macOS	B-Application
equivalents	O
.	O
</s>
<s>
The	O
Mach-O	B-Operating_System
files	O
stored	O
on	O
the	O
device	O
can	O
vary	O
between	O
iPhone	O
(	O
iOS	B-Application
)	O
,	O
macOS	B-Application
,	O
watchOS	O
,	O
and	O
tvOS	O
.	O
</s>
<s>
Some	O
versions	O
of	O
NetBSD	B-Device
have	O
had	O
Mach-O	B-Operating_System
support	O
added	O
as	O
part	O
of	O
an	O
implementation	O
of	O
binary	O
compatibility	O
,	O
which	O
allowed	O
some	O
Mac	B-Application
OS	I-Application
10.3	O
binaries	O
to	O
be	O
executed	O
.	O
</s>
<s>
For	O
Linux	O
,	O
a	O
Mach-O	B-Operating_System
loader	O
was	O
written	O
by	O
Shinichiro	O
Hamaji	O
that	O
can	O
load	O
10.6	B-Device
binaries	O
.	O
</s>
<s>
As	O
a	O
more	O
extensive	O
solution	O
based	O
on	O
this	O
loader	O
,	O
the	O
Darling	B-Language
Project	I-Language
aims	O
at	O
providing	O
a	O
complete	O
environment	O
allowing	O
macOS	B-Application
applications	O
to	O
run	O
on	O
Linux	O
.	O
</s>
<s>
For	O
the	O
Ruby	B-Language
programming	I-Language
language	I-Language
,	O
the	O
ruby-macho	O
library	O
provides	O
an	O
implementation	O
of	O
a	O
Mach-O	B-Operating_System
binary	O
parser	O
and	O
editor	O
.	O
</s>
