@@ -509,7 +509,9 @@ const usage_build_generic =
509
509
\\ --dynamic-linker [path] Set the dynamic interpreter path (usually ld.so)
510
510
\\ --sysroot [path] Set the system root directory (usually /)
511
511
\\ --version [ver] Dynamic library semver
512
- \\ --entry [name] Set the entrypoint symbol name
512
+ \\ -fentry Enable entry point with default symbol name
513
+ \\ -fentry=[name] Override the entry point symbol name
514
+ \\ -fno-entry Do not output any entry point
513
515
\\ --force_undefined [name] Specify the symbol must be defined for the link to succeed
514
516
\\ -fsoname[=name] Override the default SONAME value
515
517
\\ -fno-soname Disable emitting a SONAME
@@ -577,8 +579,6 @@ const usage_build_generic =
577
579
\\ --shared-memory (WebAssembly) use shared linear memory
578
580
\\ --global-base=[addr] (WebAssembly) where to start to place global data
579
581
\\ --export=[value] (WebAssembly) Force a symbol to be exported
580
- \\ -fentry (WebAssembly) Force output an entry point
581
- \\ -fno-entry (WebAssembly) Do not output any entry point
582
582
\\
583
583
\\Test Options:
584
584
\\ --test-filter [text] Skip tests that do not match filter
@@ -837,7 +837,7 @@ fn buildOutputType(
837
837
var linker_import_symbols : bool = false ;
838
838
var linker_import_table : bool = false ;
839
839
var linker_export_table : bool = false ;
840
- var linker_no_entry : ? bool = null ;
840
+ var linker_force_entry : ? bool = null ;
841
841
var linker_initial_memory : ? u64 = null ;
842
842
var linker_max_memory : ? u64 = null ;
843
843
var linker_shared_memory : bool = false ;
@@ -1074,8 +1074,8 @@ fn buildOutputType(
1074
1074
subsystem = try parseSubSystem (args_iter .nextOrFatal ());
1075
1075
} else if (mem .eql (u8 , arg , "-O" )) {
1076
1076
optimize_mode_string = args_iter .nextOrFatal ();
1077
- } else if (mem .eql (u8 , arg , "--entry " )) {
1078
- entry = args_iter . nextOrFatal () ;
1077
+ } else if (mem .startsWith (u8 , arg , "-fentry= " )) {
1078
+ entry = arg [ "-fentry=" .len .. ] ;
1079
1079
} else if (mem .eql (u8 , arg , "--force_undefined" )) {
1080
1080
try force_undefined_symbols .put (gpa , args_iter .nextOrFatal (), {});
1081
1081
} else if (mem .eql (u8 , arg , "--stack" )) {
@@ -1507,9 +1507,9 @@ fn buildOutputType(
1507
1507
} else if (mem .eql (u8 , arg , "--import-memory" )) {
1508
1508
linker_import_memory = true ;
1509
1509
} else if (mem .eql (u8 , arg , "-fentry" )) {
1510
- linker_no_entry = false ;
1510
+ linker_force_entry = true ;
1511
1511
} else if (mem .eql (u8 , arg , "-fno-entry" )) {
1512
- linker_no_entry = true ;
1512
+ linker_force_entry = false ;
1513
1513
} else if (mem .eql (u8 , arg , "--export-memory" )) {
1514
1514
linker_export_memory = true ;
1515
1515
} else if (mem .eql (u8 , arg , "--import-symbols" )) {
@@ -2142,7 +2142,7 @@ fn buildOutputType(
2142
2142
} else if (mem .eql (u8 , arg , "--export-table" )) {
2143
2143
linker_export_table = true ;
2144
2144
} else if (mem .eql (u8 , arg , "--no-entry" )) {
2145
- linker_no_entry = true ;
2145
+ linker_force_entry = false ;
2146
2146
} else if (mem .eql (u8 , arg , "--initial-memory" )) {
2147
2147
const next_arg = linker_args_it .nextOrFatal ();
2148
2148
linker_initial_memory = std .fmt .parseUnsigned (u32 , eatIntPrefix (next_arg , 16 ), 16 ) catch | err | {
@@ -2605,6 +2605,23 @@ fn buildOutputType(
2605
2605
link_libcpp = true ;
2606
2606
}
2607
2607
2608
+ const linker_default_entry = linker_force_entry orelse true ;
2609
+ if (! linker_default_entry and entry != null ) {
2610
+ fatal ("combination of '-fentry=[name]' and `-fno-entry` are incompatible" , .{});
2611
+ }
2612
+ if (linker_default_entry and entry == null and output_mode == .Exe ) {
2613
+ entry = switch (target_info .target .ofmt ) {
2614
+ .coff = > "wWinMainCRTStartup" ,
2615
+ .macho = > "_main" ,
2616
+ .elf , .plan9 = > "_start" ,
2617
+ .wasm = > if (wasi_exec_model != null and wasi_exec_model .? == .reactor )
2618
+ "_initialize"
2619
+ else
2620
+ "_start" ,
2621
+ else = > | tag | fatal ("No default entry point available for output format {s}" , .{@tagName (tag )}),
2622
+ };
2623
+ }
2624
+
2608
2625
if (target_info .target .ofmt == .coff ) {
2609
2626
// Now that we know the target supports resources,
2610
2627
// we can add the res files as link objects.
@@ -2637,23 +2654,11 @@ fn buildOutputType(
2637
2654
linker_export_memory = false ;
2638
2655
}
2639
2656
}
2640
- if (wasi_exec_model ) | model | {
2641
- if (model == .reactor ) {
2642
- if (linker_no_entry != null and ! linker_no_entry .? ) {
2643
- fatal ("WASI exucution model ' reactor' incompatible with flag '-fentry'. Reactor execution model has no entry point " , .{});
2657
+ if (wasi_exec_model != null and wasi_exec_model .? == .reactor ) {
2658
+ if (entry ) | entry_name | {
2659
+ if (! mem . eql ( u8 , "_initialize" , entry_name ) ) {
2660
+ fatal ("the entry symbol of the reactor model must be '_initialize', but found '{s}' " , .{entry_name });
2644
2661
}
2645
- if (entry ) | entry_name | {
2646
- if (! mem .eql (u8 , "_initialize" , entry_name )) {
2647
- fatal ("the entry symbol of the reactor model must be '_initialize', but found '{s}'" , .{entry_name });
2648
- }
2649
- } else {
2650
- entry = "_initialize" ;
2651
- }
2652
- }
2653
- }
2654
- if (linker_no_entry ) | no_entry | {
2655
- if (no_entry and entry != null ) {
2656
- fatal ("combination of '--entry' and `-fno-entry` are incompatible" , .{});
2657
2662
}
2658
2663
}
2659
2664
if (linker_shared_memory ) {
@@ -3503,7 +3508,6 @@ fn buildOutputType(
3503
3508
.linker_import_symbols = linker_import_symbols ,
3504
3509
.linker_import_table = linker_import_table ,
3505
3510
.linker_export_table = linker_export_table ,
3506
- .linker_no_entry = linker_no_entry orelse false ,
3507
3511
.linker_initial_memory = linker_initial_memory ,
3508
3512
.linker_max_memory = linker_max_memory ,
3509
3513
.linker_shared_memory = linker_shared_memory ,
0 commit comments