@@ -25,6 +25,7 @@ linker_script: ?[]const u8,
2525version_script : ? []const u8 ,
2626print_icf_sections : bool ,
2727print_map : bool ,
28+ entry_name : ? []const u8 ,
2829
2930ptr_width : PtrWidth ,
3031
@@ -290,6 +291,13 @@ pub fn createEmpty(
290291 .page_size = page_size ,
291292 .default_sym_version = default_sym_version ,
292293
294+ .entry_name = switch (options .entry ) {
295+ .disabled = > null ,
296+ .default = > if (output_mode != .Exe ) null else defaultEntrySymbolName (target .cpu .arch ),
297+ .enabled = > defaultEntrySymbolName (target .cpu .arch ),
298+ .named = > | name | name ,
299+ },
300+
293301 .image_base = b : {
294302 if (is_dyn_lib ) break :b 0 ;
295303 if (output_mode == .Exe and comp .config .pie ) break :b 0 ;
@@ -1305,7 +1313,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node
13051313
13061314 // Look for entry address in objects if not set by the incremental compiler.
13071315 if (self .entry_index == null ) {
1308- if (comp . config . entry ) | name | {
1316+ if (self . entry_name ) | name | {
13091317 self .entry_index = self .globalByName (name );
13101318 }
13111319 }
@@ -1679,9 +1687,8 @@ fn dumpArgv(self: *Elf, comp: *Compilation) !void {
16791687 }
16801688 }
16811689
1682- if (comp .config .entry ) | entry | {
1683- try argv .append ("--entry" );
1684- try argv .append (entry );
1690+ if (self .entry_name ) | name | {
1691+ try argv .appendSlice (&.{ "--entry" , name });
16851692 }
16861693
16871694 for (self .base .rpath_list ) | rpath | {
@@ -2427,7 +2434,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node) !v
24272434
24282435 // We can skip hashing libc and libc++ components that we are in charge of building from Zig
24292436 // installation sources because they are always a product of the compiler version + target information.
2430- man .hash .addOptionalBytes (comp . config . entry );
2437+ man .hash .addOptionalBytes (self . entry_name );
24312438 man .hash .add (self .image_base );
24322439 man .hash .add (self .base .gc_sections );
24332440 man .hash .addOptional (self .sort_section );
@@ -2563,9 +2570,8 @@ fn linkWithLLD(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node) !v
25632570 .ReleaseFast , .ReleaseSafe = > try argv .append ("-O3" ),
25642571 }
25652572
2566- if (comp .config .entry ) | entry | {
2567- try argv .append ("--entry" );
2568- try argv .append (entry );
2573+ if (self .entry_name ) | name | {
2574+ try argv .appendSlice (&.{ "--entry" , name });
25692575 }
25702576
25712577 for (self .base .force_undefined_symbols .keys ()) | sym | {
@@ -6512,6 +6518,13 @@ const RelaSectionTable = std.AutoArrayHashMapUnmanaged(u32, RelaSection);
65126518pub const R_X86_64_ZIG_GOT32 = elf .R_X86_64_NUM + 1 ;
65136519pub const R_X86_64_ZIG_GOTPCREL = elf .R_X86_64_NUM + 2 ;
65146520
6521+ fn defaultEntrySymbolName (cpu_arch : std.Target.Cpu.Arch ) []const u8 {
6522+ return switch (cpu_arch ) {
6523+ .mips , .mipsel , .mips64 , .mips64el = > "__start" ,
6524+ else = > "_start" ,
6525+ };
6526+ }
6527+
65156528const std = @import ("std" );
65166529const build_options = @import ("build_options" );
65176530const builtin = @import ("builtin" );
0 commit comments