MacOS Dynamic Executables
When you use MacOS and refer to:
ld foo.o -lc -macosx_version_min 10.12.0 -e _start -o foo
. _start
, . C/++/ Objective-C, , -e
. Apple Forking and Executing the Process :
Mach-O , . , , , . Xcode, /usr/lib/dyld, OS X.
execve, mach_header . , Mach-O , . , , .
, , ( ) . . /usr/lib/crt1.o. ++, Objective-C ,
_start
. , , ret
, _start
, . . gobjdump -Dx foo
, :
start address 0x0000000000000000
Sections:
Idx Name Size VMA LMA File off Algn
0 .text 00000001 0000000000001fff 0000000000001fff 00000fff 2**0
CONTENTS, ALLOC, LOAD, CODE
SYMBOL TABLE:
0000000000001000 g 03 ABS 01 0010 __mh_execute_header
0000000000001fff g 0f SECT 01 0000 [.text] _start
0000000000000000 g 01 UND 00 0100 dyld_stub_binder
Disassembly of section .text:
0000000000001fff <_start>:
1fff: c3 retq
, start address
0. 0 dyld_stub_binder
. , C, _start
. , main
.
MacOS
static, , ret
, . :
, , , .
dyld
crt1.o
. CRT= C , ++/ Objective-C, MacOS. , C/++/Objective-C , .
, -lc
( -lSystem
) -static
:
ld foo.o -macosx_version_min 10.12.0 -e _start -o foo -static
, . gobjdump -Dx foo
start address 0x0000000000001fff
Sections:
Idx Name Size VMA LMA File off Algn
0 .text 00000001 0000000000001fff 0000000000001fff 00000fff 2**0
CONTENTS, ALLOC, LOAD, CODE
1 LC_THREAD.x86_THREAD_STATE64.0 000000a8 0000000000000000 0000000000000000 00000198 2**0
CONTENTS
SYMBOL TABLE:
0000000000001000 g 03 ABS 01 0010 __mh_execute_header
0000000000001fff g 0f SECT 01 0000 [.text] _start
Disassembly of section .text:
0000000000001fff <_start>:
1fff: c3 retq
, start_address
0x1fff. 0x1fff - (_start
). .
Linux
Linux, , , . , ELF Linux article . , , , Linux C/++/ Objective-C MacOS.
Linux (ld.so) MacOS one (dynld) , MacOS C/++/ Objective-C crt1.o
. crt1.o
, -e
( - main
). Linux , . .
FreeBSD ( MacOS), Linux - . 64- . 32- , 4 , 8.

, , , , . , main
C/++. C, C main
(argc
, argv
, envp
).
fooobar.com/questions/1690738/..., , MacOS .