@@ -1001,7 +1001,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node
10011001 // --verbose-link
10021002 if (self .base .comp .verbose_link ) try self .dumpArgv (comp );
10031003
1004- const csu = try CsuObjects .init (arena , self . base . options , comp );
1004+ const csu = try CsuObjects .init (arena , comp );
10051005 const compiler_rt_path : ? []const u8 = blk : {
10061006 if (comp .compiler_rt_lib ) | x | break :blk x .full_object_path ;
10071007 if (comp .compiler_rt_obj ) | x | break :blk x .full_object_path ;
@@ -1021,8 +1021,8 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node
10211021 if (csu .crti ) | v | try positionals .append (.{ .path = v });
10221022 if (csu .crtbegin ) | v | try positionals .append (.{ .path = v });
10231023
1024- try positionals .ensureUnusedCapacity (self .base .options .objects .len );
1025- positionals .appendSliceAssumeCapacity (self .base .options .objects );
1024+ try positionals .ensureUnusedCapacity (self .base .comp .objects .len );
1025+ positionals .appendSliceAssumeCapacity (self .base .comp .objects );
10261026
10271027 // This is a set of object files emitted by clang in a single `build-exe` invocation.
10281028 // For instance, the implicit `a.o` as compiled by `zig build-exe a.c` will end up
@@ -1051,7 +1051,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node
10511051 _ = try rpath_table .put (lib_dir_path , {});
10521052 }
10531053 }
1054- for (self .base .options .objects ) | obj | {
1054+ for (self .base .comp .objects ) | obj | {
10551055 if (Compilation .classifyFileExt (obj .path ) == .shared_library ) {
10561056 const lib_dir_path = std .fs .path .dirname (obj .path ) orelse continue ;
10571057 if (obj .loption ) continue ;
@@ -1061,7 +1061,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node
10611061 }
10621062
10631063 // TSAN
1064- if (self .base .options . tsan ) {
1064+ if (self .base .comp . config . any_sanitize_thread ) {
10651065 try positionals .append (.{ .path = comp .tsan_static_lib .? .full_object_path });
10661066 }
10671067
@@ -1093,21 +1093,21 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node
10931093 }
10941094
10951095 // libc++ dep
1096- if (self .base .options .link_libcpp ) {
1096+ if (self .base .comp . config .link_libcpp ) {
10971097 try system_libs .ensureUnusedCapacity (2 );
10981098 system_libs .appendAssumeCapacity (.{ .path = comp .libcxxabi_static_lib .? .full_object_path });
10991099 system_libs .appendAssumeCapacity (.{ .path = comp .libcxx_static_lib .? .full_object_path });
11001100 }
11011101
11021102 // libunwind dep
1103- if (self .base .options .link_libunwind ) {
1103+ if (self .base .comp . config .link_libunwind ) {
11041104 try system_libs .append (.{ .path = comp .libunwind_static_lib .? .full_object_path });
11051105 }
11061106
11071107 // libc dep
11081108 self .error_flags .missing_libc = false ;
1109- if (self .base .options .link_libc ) {
1110- if (self .base .options .libc_installation ) | lc | {
1109+ if (self .base .comp . config .link_libc ) {
1110+ if (self .base .comp .libc_installation ) | lc | {
11111111 const flags = target_util .libcFullLinkFlags (target );
11121112 try system_libs .ensureUnusedCapacity (flags .len );
11131113
@@ -1246,7 +1246,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node
12461246 // Look for entry address in objects if not set by the incremental compiler.
12471247 if (self .entry_index == null ) {
12481248 const entry : ? []const u8 = entry : {
1249- if (self .base .options .entry ) | entry | break :entry entry ;
1249+ if (self .base .comp . config .entry ) | entry | break :entry entry ;
12501250 if (! self .base .isDynLib ()) break :entry "_start" ;
12511251 break :entry null ;
12521252 };
@@ -1571,7 +1571,7 @@ fn dumpArgv(self: *Elf, comp: *Compilation) !void {
15711571 }
15721572 } else null ;
15731573
1574- const csu = try CsuObjects .init (arena , self . base . options , comp );
1574+ const csu = try CsuObjects .init (arena , comp );
15751575 const compiler_rt_path : ? []const u8 = blk : {
15761576 if (comp .compiler_rt_lib ) | x | break :blk x .full_object_path ;
15771577 if (comp .compiler_rt_obj ) | x | break :blk x .full_object_path ;
@@ -1713,7 +1713,7 @@ fn dumpArgv(self: *Elf, comp: *Compilation) !void {
17131713 }
17141714
17151715 if (self .base .options .link_libc ) {
1716- if (self .base .options .libc_installation ) | libc_installation | {
1716+ if (self .base .comp .libc_installation ) | libc_installation | {
17171717 try argv .append ("-L" );
17181718 try argv .append (libc_installation .crt_dir .? );
17191719 }
@@ -1803,7 +1803,7 @@ fn dumpArgv(self: *Elf, comp: *Compilation) !void {
18031803
18041804 // libc dep
18051805 if (self .base .options .link_libc ) {
1806- if (self .base .options .libc_installation != null ) {
1806+ if (self .base .comp .libc_installation != null ) {
18071807 const needs_grouping = link_mode == .Static ;
18081808 if (needs_grouping ) try argv .append ("--start-group" );
18091809 try argv .appendSlice (target_util .libcFullLinkFlags (target ));
@@ -2405,8 +2405,8 @@ fn linkWithLLD(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node) !v
24052405 man .hash .add (self .base .options .hash_style );
24062406 // strip does not need to go into the linker hash because it is part of the hash namespace
24072407 if (self .base .options .link_libc ) {
2408- man .hash .add (self .base .options .libc_installation != null );
2409- if (self .base .options .libc_installation ) | libc_installation | {
2408+ man .hash .add (self .base .comp .libc_installation != null );
2409+ if (self .base .comp .libc_installation ) | libc_installation | {
24102410 man .hash .addBytes (libc_installation .crt_dir .? );
24112411 }
24122412 if (have_dynamic_linker ) {
@@ -2669,7 +2669,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node) !v
26692669 try argv .append (full_out_path );
26702670
26712671 // csu prelude
2672- const csu = try CsuObjects .init (arena , self . base . options , comp );
2672+ const csu = try CsuObjects .init (arena , comp );
26732673 if (csu .crt0 ) | v | try argv .append (v );
26742674 if (csu .crti ) | v | try argv .append (v );
26752675 if (csu .crtbegin ) | v | try argv .append (v );
@@ -2719,7 +2719,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node) !v
27192719 }
27202720
27212721 if (self .base .options .link_libc ) {
2722- if (self .base .options .libc_installation ) | libc_installation | {
2722+ if (self .base .comp .libc_installation ) | libc_installation | {
27232723 try argv .append ("-L" );
27242724 try argv .append (libc_installation .crt_dir .? );
27252725 }
@@ -2839,7 +2839,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node) !v
28392839 // libc dep
28402840 self .error_flags .missing_libc = false ;
28412841 if (self .base .options .link_libc ) {
2842- if (self .base .options .libc_installation != null ) {
2842+ if (self .base .comp .libc_installation != null ) {
28432843 const needs_grouping = link_mode == .Static ;
28442844 if (needs_grouping ) try argv .append ("--start-group" );
28452845 try argv .appendSlice (target_util .libcFullLinkFlags (target ));
@@ -5444,9 +5444,11 @@ const CsuObjects = struct {
54445444 crtend : ? []const u8 = null ,
54455445 crtn : ? []const u8 = null ,
54465446
5447- fn init (arena : mem.Allocator , link_options : link.Options , comp : * const Compilation ) ! CsuObjects {
5447+ const InitArgs = struct {};
5448+
5449+ fn init (arena : Allocator , comp : * const Compilation ) ! CsuObjects {
54485450 // crt objects are only required for libc.
5449- if (! link_options . link_libc ) return CsuObjects {};
5451+ if (! comp . config . link_libc ) return . {};
54505452
54515453 var result : CsuObjects = .{};
54525454
@@ -5457,19 +5459,21 @@ const CsuObjects = struct {
54575459 dynamic_pie ,
54585460 static_exe ,
54595461 static_pie ,
5460- } = switch (link_options .output_mode ) {
5462+ } = switch (comp . config .output_mode ) {
54615463 .Obj = > return CsuObjects {},
5462- .Lib = > switch (link_options .link_mode ) {
5464+ .Lib = > switch (comp . config .link_mode ) {
54635465 .Dynamic = > .dynamic_lib ,
54645466 .Static = > return CsuObjects {},
54655467 },
5466- .Exe = > switch (link_options .link_mode ) {
5467- .Dynamic = > if (link_options .pie ) .dynamic_pie else .dynamic_exe ,
5468- .Static = > if (link_options .pie ) .static_pie else .static_exe ,
5468+ .Exe = > switch (comp . config .link_mode ) {
5469+ .Dynamic = > if (comp . config .pie ) .dynamic_pie else .dynamic_exe ,
5470+ .Static = > if (comp . config .pie ) .static_pie else .static_exe ,
54695471 },
54705472 };
54715473
5472- if (link_options .target .isAndroid ()) {
5474+ const target = comp .root_mod .resolved_target .result ;
5475+
5476+ if (target .isAndroid ()) {
54735477 switch (mode ) {
54745478 // zig fmt: off
54755479 .dynamic_lib = > result .set ( null , null , "crtbegin_so.o" , "crtend_so.o" , null ),
@@ -5480,7 +5484,7 @@ const CsuObjects = struct {
54805484 // zig fmt: on
54815485 }
54825486 } else {
5483- switch (link_options . target .os .tag ) {
5487+ switch (target .os .tag ) {
54845488 .linux = > {
54855489 switch (mode ) {
54865490 // zig fmt: off
@@ -5491,15 +5495,15 @@ const CsuObjects = struct {
54915495 .static_pie = > result .set ( "rcrt1.o" , "crti.o" , "crtbeginS.o" , "crtendS.o" , "crtn.o" ),
54925496 // zig fmt: on
54935497 }
5494- if (link_options .libc_installation ) | _ | {
5498+ if (comp .libc_installation ) | _ | {
54955499 // hosted-glibc provides crtbegin/end objects in platform/compiler-specific dirs
54965500 // and they are not known at comptime. For now null-out crtbegin/end objects;
54975501 // there is no feature loss, zig has never linked those objects in before.
54985502 result .crtbegin = null ;
54995503 result .crtend = null ;
55005504 } else {
55015505 // Bundled glibc only has Scrt1.o .
5502- if (result .crt0 != null and link_options . target .isGnuLibC ()) result .crt0 = "Scrt1.o" ;
5506+ if (result .crt0 != null and target .isGnuLibC ()) result .crt0 = "Scrt1.o" ;
55035507 }
55045508 },
55055509 .dragonfly = > switch (mode ) {
@@ -5561,16 +5565,16 @@ const CsuObjects = struct {
55615565 }
55625566
55635567 // Convert each object to a full pathname.
5564- if (link_options .libc_installation ) | lci | {
5568+ if (comp .libc_installation ) | lci | {
55655569 const crt_dir_path = lci .crt_dir orelse return error .LibCInstallationMissingCRTDir ;
5566- switch (link_options . target .os .tag ) {
5570+ switch (target .os .tag ) {
55675571 .dragonfly = > {
55685572 if (result .crt0 ) | * obj | obj .* = try fs .path .join (arena , &[_ ][]const u8 { crt_dir_path , obj .* });
55695573 if (result .crti ) | * obj | obj .* = try fs .path .join (arena , &[_ ][]const u8 { crt_dir_path , obj .* });
55705574 if (result .crtn ) | * obj | obj .* = try fs .path .join (arena , &[_ ][]const u8 { crt_dir_path , obj .* });
55715575
55725576 var gccv : []const u8 = undefined ;
5573- if (link_options . target .os .version_range .semver .isAtLeast (.{ .major = 5 , .minor = 4 , .patch = 0 }) orelse true ) {
5577+ if (target .os .version_range .semver .isAtLeast (.{ .major = 5 , .minor = 4 , .patch = 0 }) orelse true ) {
55745578 gccv = "gcc80" ;
55755579 } else {
55765580 gccv = "gcc54" ;
0 commit comments