authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-12-16 15:22:31-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-01-01 17:51:20-07:00
logf2564318385ea90b08af044ae32ddef26e6346bd
treeacb36d3268bace51f780a872f40b04da092591de
parent57afdfc8fae667e69850650ebb8606805d0d2272

fix compilation errors when enabling llvm


15 files changed, 363 insertions(+), 255 deletions(-)

src/Compilation.zig+39-18
......@@ -1410,7 +1410,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
14101410 .inherited = .{},
14111411 .global = options.config,
14121412 .parent = options.root_mod,
1413 .builtin_mod = options.root_mod.deps.get("builtin").?,
1413 .builtin_mod = options.root_mod.getBuiltinDependency(),
14141414 });
14151415
14161416 const zcu = try arena.create(Module);
......@@ -3830,6 +3830,7 @@ pub fn obtainCObjectCacheManifest(
38303830 // that apply both to @cImport and compiling C objects. No linking stuff here!
38313831 // Also nothing that applies only to compiling .zig code.
38323832 man.hash.add(owner_mod.sanitize_c);
3833 man.hash.add(owner_mod.sanitize_thread);
38333834 man.hash.addListOfBytes(owner_mod.cc_argv);
38343835 man.hash.add(comp.config.link_libcpp);
38353836
......@@ -3970,10 +3971,13 @@ pub fn cImport(comp: *Compilation, c_src: []const u8, owner_mod: *Package.Module
39703971
39713972 const dep_basename = std.fs.path.basename(out_dep_path);
39723973 try man.addDepFilePost(zig_cache_tmp_dir, dep_basename);
3973 if (comp.whole_cache_manifest) |whole_cache_manifest| {
3974 comp.whole_cache_manifest_mutex.lock();
3975 defer comp.whole_cache_manifest_mutex.unlock();
3976 try whole_cache_manifest.addDepFilePost(zig_cache_tmp_dir, dep_basename);
3974 switch (comp.cache_use) {
3975 .whole => |whole| if (whole.cache_manifest) |whole_cache_manifest| {
3976 whole.cache_manifest_mutex.lock();
3977 defer whole.cache_manifest_mutex.unlock();
3978 try whole_cache_manifest.addDepFilePost(zig_cache_tmp_dir, dep_basename);
3979 },
3980 .incremental => {},
39773981 }
39783982
39793983 const digest = man.final();
......@@ -4425,10 +4429,15 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: *std.P
44254429 const dep_basename = std.fs.path.basename(dep_file_path);
44264430 // Add the files depended on to the cache system.
44274431 try man.addDepFilePost(zig_cache_tmp_dir, dep_basename);
4428 if (comp.whole_cache_manifest) |whole_cache_manifest| {
4429 comp.whole_cache_manifest_mutex.lock();
4430 defer comp.whole_cache_manifest_mutex.unlock();
4431 try whole_cache_manifest.addDepFilePost(zig_cache_tmp_dir, dep_basename);
4432 switch (comp.cache_use) {
4433 .whole => |whole| {
4434 if (whole.cache_manifest) |whole_cache_manifest| {
4435 whole.cache_manifest_mutex.lock();
4436 defer whole.cache_manifest_mutex.unlock();
4437 try whole_cache_manifest.addDepFilePost(zig_cache_tmp_dir, dep_basename);
4438 }
4439 },
4440 .incremental => {},
44324441 }
44334442 // Just to save disk space, we delete the file because it is never needed again.
44344443 zig_cache_tmp_dir.deleteFile(dep_basename) catch |err| {
......@@ -4724,10 +4733,13 @@ fn updateWin32Resource(comp: *Compilation, win32_resource: *Win32Resource, win32
47244733 const dep_basename = std.fs.path.basename(out_dep_path);
47254734 // Add the files depended on to the cache system.
47264735 try man.addDepFilePost(zig_cache_tmp_dir, dep_basename);
4727 if (comp.whole_cache_manifest) |whole_cache_manifest| {
4728 comp.whole_cache_manifest_mutex.lock();
4729 defer comp.whole_cache_manifest_mutex.unlock();
4730 try whole_cache_manifest.addDepFilePost(zig_cache_tmp_dir, dep_basename);
4736 switch (comp.cache_use) {
4737 .whole => |whole| if (whole.cache_manifest) |whole_cache_manifest| {
4738 whole.cache_manifest_mutex.lock();
4739 defer whole.cache_manifest_mutex.unlock();
4740 try whole_cache_manifest.addDepFilePost(zig_cache_tmp_dir, dep_basename);
4741 },
4742 .incremental => {},
47314743 }
47324744 // Just to save disk space, we delete the file because it is never needed again.
47334745 zig_cache_tmp_dir.deleteFile(dep_basename) catch |err| {
......@@ -4799,10 +4811,13 @@ fn updateWin32Resource(comp: *Compilation, win32_resource: *Win32Resource, win32
47994811
48004812 for (dependencies_list.items) |dep_file_path| {
48014813 try man.addFilePost(dep_file_path);
4802 if (comp.whole_cache_manifest) |whole_cache_manifest| {
4803 comp.whole_cache_manifest_mutex.lock();
4804 defer comp.whole_cache_manifest_mutex.unlock();
4805 try whole_cache_manifest.addFilePost(dep_file_path);
4814 switch (comp.cache_use) {
4815 .whole => |whole| if (whole.cache_manifest) |whole_cache_manifest| {
4816 whole.cache_manifest_mutex.lock();
4817 defer whole.cache_manifest_mutex.unlock();
4818 try whole_cache_manifest.addFilePost(dep_file_path);
4819 },
4820 .incremental => {},
48064821 }
48074822 }
48084823
......@@ -6247,7 +6262,9 @@ pub fn build_crt_file(
62476262 output_mode: std.builtin.OutputMode,
62486263 misc_task_tag: MiscTask,
62496264 prog_node: *std.Progress.Node,
6250 c_source_files: []const CSourceFile,
6265 /// These elements have to get mutated to add the owner module after it is
6266 /// created within this function.
6267 c_source_files: []CSourceFile,
62516268) !void {
62526269 const tracy_trace = trace(@src());
62536270 defer tracy_trace.end();
......@@ -6305,6 +6322,10 @@ pub fn build_crt_file(
63056322 .builtin_mod = null,
63066323 });
63076324
6325 for (c_source_files) |*item| {
6326 item.owner = root_mod;
6327 }
6328
63086329 const sub_compilation = try Compilation.create(gpa, .{
63096330 .local_cache_directory = comp.global_cache_directory,
63106331 .global_cache_directory = comp.global_cache_directory,
src/Module.zig+1-1
......@@ -5275,7 +5275,7 @@ pub fn populateTestFunctions(
52755275) !void {
52765276 const gpa = mod.gpa;
52775277 const ip = &mod.intern_pool;
5278 const builtin_mod = mod.main_mod.deps.get("builtin").?;
5278 const builtin_mod = mod.main_mod.getBuiltinDependency();
52795279 const builtin_file = (mod.importPkg(builtin_mod) catch unreachable).file;
52805280 const root_decl = mod.declPtr(builtin_file.root_decl.unwrap().?);
52815281 const builtin_namespace = mod.namespacePtr(root_decl.src_namespace);
src/Package/Module.zig+41-35
......@@ -310,7 +310,39 @@ pub fn create(arena: Allocator, options: CreateOptions) !*Package.Module {
310310 break :b buf.items[0 .. buf.items.len - 1 :0].ptr;
311311 };
312312
313 const builtin_mod = options.builtin_mod orelse b: {
313 const mod = try arena.create(Module);
314 mod.* = .{
315 .root = options.paths.root,
316 .root_src_path = options.paths.root_src_path,
317 .fully_qualified_name = options.fully_qualified_name,
318 .resolved_target = .{
319 .result = target,
320 .is_native_os = resolved_target.is_native_os,
321 .is_native_abi = resolved_target.is_native_abi,
322 .llvm_cpu_features = llvm_cpu_features,
323 },
324 .optimize_mode = optimize_mode,
325 .single_threaded = single_threaded,
326 .error_tracing = error_tracing,
327 .valgrind = valgrind,
328 .pic = pic,
329 .strip = strip,
330 .omit_frame_pointer = omit_frame_pointer,
331 .stack_check = stack_check,
332 .stack_protector = stack_protector,
333 .code_model = code_model,
334 .red_zone = red_zone,
335 .sanitize_c = sanitize_c,
336 .sanitize_thread = sanitize_thread,
337 .unwind_tables = unwind_tables,
338 .cc_argv = options.cc_argv,
339 .structured_cfg = structured_cfg,
340 .builtin_file = null,
341 };
342
343 const opt_builtin_mod = options.builtin_mod orelse b: {
344 if (!options.global.have_zcu) break :b null;
345
314346 const generated_builtin_source = try Builtin.generate(.{
315347 .target = target,
316348 .zig_backend = zig_backend,
......@@ -388,38 +420,10 @@ pub fn create(arena: Allocator, options: CreateOptions) !*Package.Module {
388420 break :b new;
389421 };
390422
391 const mod = try arena.create(Module);
392 mod.* = .{
393 .root = options.paths.root,
394 .root_src_path = options.paths.root_src_path,
395 .fully_qualified_name = options.fully_qualified_name,
396 .resolved_target = .{
397 .result = target,
398 .is_native_os = resolved_target.is_native_os,
399 .is_native_abi = resolved_target.is_native_abi,
400 .llvm_cpu_features = llvm_cpu_features,
401 },
402 .optimize_mode = optimize_mode,
403 .single_threaded = single_threaded,
404 .error_tracing = error_tracing,
405 .valgrind = valgrind,
406 .pic = pic,
407 .strip = strip,
408 .omit_frame_pointer = omit_frame_pointer,
409 .stack_check = stack_check,
410 .stack_protector = stack_protector,
411 .code_model = code_model,
412 .red_zone = red_zone,
413 .sanitize_c = sanitize_c,
414 .sanitize_thread = sanitize_thread,
415 .unwind_tables = unwind_tables,
416 .cc_argv = options.cc_argv,
417 .structured_cfg = structured_cfg,
418 .builtin_file = null,
419 };
420
421 try mod.deps.ensureUnusedCapacity(arena, 1);
422 mod.deps.putAssumeCapacityNoClobber("builtin", builtin_mod);
423 if (opt_builtin_mod) |builtin_mod| {
424 try mod.deps.ensureUnusedCapacity(arena, 1);
425 mod.deps.putAssumeCapacityNoClobber("builtin", builtin_mod);
426 }
423427
424428 return mod;
425429}
......@@ -462,8 +466,10 @@ pub fn createLimited(gpa: Allocator, options: LimitedOptions) Allocator.Error!*P
462466 return mod;
463467}
464468
465pub fn getBuiltinDependency(m: *Module) *Module {
466 return m.deps.values()[0];
469pub fn getBuiltinDependency(m: Module) *Module {
470 const result = m.deps.values()[0];
471 assert(result.isBuiltin());
472 return result;
467473}
468474
469475const Module = @This();
src/Sema.zig+31-6
......@@ -5759,14 +5759,39 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr
57595759 };
57605760 return sema.failWithOwnedErrorMsg(&child_block, msg);
57615761 }
5762 const c_import_mod = try Package.Module.create(comp.arena.allocator(), .{
5763 .root = .{
5764 .root_dir = Compilation.Directory.cwd(),
5765 .sub_path = std.fs.path.dirname(c_import_res.out_zig_path) orelse "",
5762 const parent_mod = parent_block.ownerModule();
5763 const c_import_mod = Package.Module.create(comp.arena.allocator(), .{
5764 .global_cache_directory = comp.global_cache_directory,
5765 .paths = .{
5766 .root = .{
5767 .root_dir = Compilation.Directory.cwd(),
5768 .sub_path = std.fs.path.dirname(c_import_res.out_zig_path) orelse "",
5769 },
5770 .root_src_path = std.fs.path.basename(c_import_res.out_zig_path),
57665771 },
5767 .root_src_path = std.fs.path.basename(c_import_res.out_zig_path),
57685772 .fully_qualified_name = c_import_res.out_zig_path,
5769 });
5773 .cc_argv = parent_mod.cc_argv,
5774 .inherited = .{},
5775 .global = comp.config,
5776 .parent = parent_mod,
5777 .builtin_mod = parent_mod.getBuiltinDependency(),
5778 }) catch |err| switch (err) {
5779 // None of these are possible because we are creating a package with
5780 // the exact same configuration as the parent package, which already
5781 // passed these checks.
5782 error.ValgrindUnsupportedOnTarget => unreachable,
5783 error.TargetRequiresSingleThreaded => unreachable,
5784 error.BackendRequiresSingleThreaded => unreachable,
5785 error.TargetRequiresPic => unreachable,
5786 error.PieRequiresPic => unreachable,
5787 error.DynamicLinkingRequiresPic => unreachable,
5788 error.TargetHasNoRedZone => unreachable,
5789 error.StackCheckUnsupportedByTarget => unreachable,
5790 error.StackProtectorUnsupportedByTarget => unreachable,
5791 error.StackProtectorUnavailableWithoutLibC => unreachable,
5792
5793 else => |e| return e,
5794 };
57705795
57715796 const result = mod.importPkg(c_import_mod) catch |err|
57725797 return sema.fail(&child_block, src, "C import failed: {s}", .{@errorName(err)});
src/glibc.zig+15-8
......@@ -170,7 +170,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr
170170 defer arena_allocator.deinit();
171171 const arena = arena_allocator.allocator();
172172
173 const target = comp.getTarget();
173 const target = comp.root_mod.resolved_target.result;
174174 const target_ver = target.os.version_range.linux.glibc;
175175 const start_old_init_fini = target_ver.order(.{ .major = 2, .minor = 33, .patch = 0 }) != .gt;
176176
......@@ -196,12 +196,14 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr
196196 "-DASSEMBLER",
197197 "-Wa,--noexecstack",
198198 });
199 return comp.build_crt_file("crti", .Obj, .@"glibc crti.o", prog_node, &.{
199 var files = [_]Compilation.CSourceFile{
200200 .{
201201 .src_path = try start_asm_path(comp, arena, "crti.S"),
202202 .cache_exempt_flags = args.items,
203 .owner = comp.root_mod,
203204 },
204 });
205 };
206 return comp.build_crt_file("crti", .Obj, .@"glibc crti.o", prog_node, &files);
205207 },
206208 .crtn_o => {
207209 var args = std.ArrayList([]const u8).init(arena);
......@@ -215,12 +217,14 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr
215217 "-DASSEMBLER",
216218 "-Wa,--noexecstack",
217219 });
218 return comp.build_crt_file("crtn", .Obj, .@"glibc crtn.o", prog_node, &.{
220 var files = [_]Compilation.CSourceFile{
219221 .{
220222 .src_path = try start_asm_path(comp, arena, "crtn.S"),
221223 .cache_exempt_flags = args.items,
224 .owner = undefined,
222225 },
223 });
226 };
227 return comp.build_crt_file("crtn", .Obj, .@"glibc crtn.o", prog_node, &files);
224228 },
225229 .scrt1_o => {
226230 const start_o: Compilation.CSourceFile = blk: {
......@@ -244,6 +248,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr
244248 break :blk .{
245249 .src_path = try start_asm_path(comp, arena, src_path),
246250 .cache_exempt_flags = args.items,
251 .owner = undefined,
247252 };
248253 };
249254 const abi_note_o: Compilation.CSourceFile = blk: {
......@@ -263,11 +268,11 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr
263268 break :blk .{
264269 .src_path = try lib_path(comp, arena, lib_libc_glibc ++ "csu" ++ path.sep_str ++ "abi-note.S"),
265270 .cache_exempt_flags = args.items,
271 .owner = undefined,
266272 };
267273 };
268 return comp.build_crt_file("Scrt1", .Obj, .@"glibc Scrt1.o", prog_node, &.{
269 start_o, abi_note_o,
270 });
274 var files = [_]Compilation.CSourceFile{ start_o, abi_note_o };
275 return comp.build_crt_file("Scrt1", .Obj, .@"glibc Scrt1.o", prog_node, &files);
271276 },
272277 .libc_nonshared_a => {
273278 const s = path.sep_str;
......@@ -364,6 +369,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr
364369 files_buf[files_index] = .{
365370 .src_path = try lib_path(comp, arena, dep.path),
366371 .cache_exempt_flags = args.items,
372 .owner = undefined,
367373 };
368374 files_index += 1;
369375 }
......@@ -1065,6 +1071,7 @@ fn buildSharedLib(
10651071 const c_source_files = [1]Compilation.CSourceFile{
10661072 .{
10671073 .src_path = try path.join(arena, &[_][]const u8{ bin_directory.path.?, asm_file_basename }),
1074 .owner = undefined,
10681075 },
10691076 };
10701077
src/libcxx.zig+93-89
......@@ -138,6 +138,50 @@ pub fn buildLibCXX(comp: *Compilation, prog_node: *std.Progress.Node) !void {
138138 const abi_namespace_arg = try std.fmt.allocPrint(arena, "-D_LIBCPP_ABI_NAMESPACE=__{d}", .{
139139 @intFromEnum(comp.libcxx_abi_version),
140140 });
141
142 const optimize_mode = comp.compilerRtOptMode();
143 const strip = comp.compilerRtStrip();
144
145 const config = try Compilation.Config.resolve(.{
146 .output_mode = output_mode,
147 .link_mode = link_mode,
148 .resolved_target = comp.root_mod.resolved_target,
149 .is_test = false,
150 .have_zcu = false,
151 .emit_bin = true,
152 .root_optimize_mode = optimize_mode,
153 .root_strip = strip,
154 .link_libc = true,
155 .lto = comp.config.lto,
156 });
157
158 const root_mod = try Module.create(arena, .{
159 .global_cache_directory = comp.global_cache_directory,
160 .paths = .{
161 .root = .{ .root_dir = comp.zig_lib_directory },
162 .root_src_path = "",
163 },
164 .fully_qualified_name = "root",
165 .inherited = .{
166 .resolved_target = comp.root_mod.resolved_target,
167 .strip = strip,
168 .stack_check = false,
169 .stack_protector = 0,
170 .sanitize_c = false,
171 .sanitize_thread = comp.config.any_sanitize_thread,
172 .red_zone = comp.root_mod.red_zone,
173 .omit_frame_pointer = comp.root_mod.omit_frame_pointer,
174 .valgrind = false,
175 .optimize_mode = optimize_mode,
176 .structured_cfg = comp.root_mod.structured_cfg,
177 .pic = comp.root_mod.pic,
178 },
179 .global = config,
180 .cc_argv = &.{},
181 .parent = null,
182 .builtin_mod = null,
183 });
184
141185 var c_source_files = try std.ArrayList(Compilation.CSourceFile).initCapacity(arena, libcxx_files.len);
142186
143187 for (libcxx_files) |cxx_src| {
......@@ -224,52 +268,10 @@ pub fn buildLibCXX(comp: *Compilation, prog_node: *std.Progress.Node) !void {
224268 .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libcxx", cxx_src }),
225269 .extra_flags = cflags.items,
226270 .cache_exempt_flags = cache_exempt_flags.items,
271 .owner = root_mod,
227272 });
228273 }
229274
230 const optimize_mode = comp.compilerRtOptMode();
231 const strip = comp.compilerRtStrip();
232
233 const config = try Compilation.Config.resolve(.{
234 .output_mode = output_mode,
235 .link_mode = link_mode,
236 .resolved_target = comp.root_mod.resolved_target,
237 .is_test = false,
238 .have_zcu = false,
239 .emit_bin = true,
240 .root_optimize_mode = optimize_mode,
241 .root_strip = strip,
242 .link_libc = true,
243 .lto = comp.config.lto,
244 });
245
246 const root_mod = try Module.create(arena, .{
247 .global_cache_directory = comp.global_cache_directory,
248 .paths = .{
249 .root = .{ .root_dir = comp.zig_lib_directory },
250 .root_src_path = "",
251 },
252 .fully_qualified_name = "root",
253 .inherited = .{
254 .resolved_target = comp.root_mod.resolved_target,
255 .strip = strip,
256 .stack_check = false,
257 .stack_protector = 0,
258 .sanitize_c = false,
259 .sanitize_thread = comp.config.any_sanitize_thread,
260 .red_zone = comp.root_mod.red_zone,
261 .omit_frame_pointer = comp.root_mod.omit_frame_pointer,
262 .valgrind = false,
263 .optimize_mode = optimize_mode,
264 .structured_cfg = comp.root_mod.structured_cfg,
265 .pic = comp.root_mod.pic,
266 },
267 .global = config,
268 .cc_argv = &.{},
269 .parent = null,
270 .builtin_mod = null,
271 });
272
273275 const sub_compilation = try Compilation.create(comp.gpa, .{
274276 .local_cache_directory = comp.global_cache_directory,
275277 .global_cache_directory = comp.global_cache_directory,
......@@ -339,6 +341,53 @@ pub fn buildLibCXXABI(comp: *Compilation, prog_node: *std.Progress.Node) !void {
339341 const abi_namespace_arg = try std.fmt.allocPrint(arena, "-D_LIBCPP_ABI_NAMESPACE=__{d}", .{
340342 @intFromEnum(comp.libcxx_abi_version),
341343 });
344
345 const optimize_mode = comp.compilerRtOptMode();
346 const strip = comp.compilerRtStrip();
347 const unwind_tables = true;
348
349 const config = try Compilation.Config.resolve(.{
350 .output_mode = output_mode,
351 .link_mode = link_mode,
352 .resolved_target = comp.root_mod.resolved_target,
353 .is_test = false,
354 .have_zcu = false,
355 .emit_bin = true,
356 .root_optimize_mode = optimize_mode,
357 .root_strip = strip,
358 .link_libc = true,
359 .any_unwind_tables = unwind_tables,
360 .lto = comp.config.lto,
361 });
362
363 const root_mod = try Module.create(arena, .{
364 .global_cache_directory = comp.global_cache_directory,
365 .paths = .{
366 .root = .{ .root_dir = comp.zig_lib_directory },
367 .root_src_path = "",
368 },
369 .fully_qualified_name = "root",
370 .inherited = .{
371 .resolved_target = comp.root_mod.resolved_target,
372 .strip = strip,
373 .stack_check = false,
374 .stack_protector = 0,
375 .sanitize_c = false,
376 .sanitize_thread = comp.config.any_sanitize_thread,
377 .red_zone = comp.root_mod.red_zone,
378 .omit_frame_pointer = comp.root_mod.omit_frame_pointer,
379 .valgrind = false,
380 .optimize_mode = optimize_mode,
381 .structured_cfg = comp.root_mod.structured_cfg,
382 .unwind_tables = unwind_tables,
383 .pic = comp.root_mod.pic,
384 },
385 .global = config,
386 .cc_argv = &.{},
387 .parent = null,
388 .builtin_mod = null,
389 });
390
342391 var c_source_files = try std.ArrayList(Compilation.CSourceFile).initCapacity(arena, libcxxabi_files.len);
343392
344393 for (libcxxabi_files) |cxxabi_src| {
......@@ -406,55 +455,10 @@ pub fn buildLibCXXABI(comp: *Compilation, prog_node: *std.Progress.Node) !void {
406455 .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libcxxabi", cxxabi_src }),
407456 .extra_flags = cflags.items,
408457 .cache_exempt_flags = cache_exempt_flags.items,
458 .owner = root_mod,
409459 });
410460 }
411461
412 const optimize_mode = comp.compilerRtOptMode();
413 const strip = comp.compilerRtStrip();
414 const unwind_tables = true;
415
416 const config = try Compilation.Config.resolve(.{
417 .output_mode = output_mode,
418 .link_mode = link_mode,
419 .resolved_target = comp.root_mod.resolved_target,
420 .is_test = false,
421 .have_zcu = false,
422 .emit_bin = true,
423 .root_optimize_mode = optimize_mode,
424 .root_strip = strip,
425 .link_libc = true,
426 .any_unwind_tables = unwind_tables,
427 .lto = comp.config.lto,
428 });
429
430 const root_mod = try Module.create(arena, .{
431 .global_cache_directory = comp.global_cache_directory,
432 .paths = .{
433 .root = .{ .root_dir = comp.zig_lib_directory },
434 .root_src_path = "",
435 },
436 .fully_qualified_name = "root",
437 .inherited = .{
438 .resolved_target = comp.root_mod.resolved_target,
439 .strip = strip,
440 .stack_check = false,
441 .stack_protector = 0,
442 .sanitize_c = false,
443 .sanitize_thread = comp.config.any_sanitize_thread,
444 .red_zone = comp.root_mod.red_zone,
445 .omit_frame_pointer = comp.root_mod.omit_frame_pointer,
446 .valgrind = false,
447 .optimize_mode = optimize_mode,
448 .structured_cfg = comp.root_mod.structured_cfg,
449 .unwind_tables = unwind_tables,
450 .pic = comp.root_mod.pic,
451 },
452 .global = config,
453 .cc_argv = &.{},
454 .parent = null,
455 .builtin_mod = null,
456 });
457
458462 const sub_compilation = try Compilation.create(comp.gpa, .{
459463 .local_cache_directory = comp.global_cache_directory,
460464 .global_cache_directory = comp.global_cache_directory,
src/libtsan.zig+54-48
......@@ -34,6 +34,52 @@ pub fn buildTsan(comp: *Compilation, prog_node: *std.Progress.Node) !void {
3434 .basename = basename,
3535 };
3636
37 const optimize_mode = comp.compilerRtOptMode();
38 const strip = comp.compilerRtStrip();
39
40 const config = try Compilation.Config.resolve(.{
41 .output_mode = output_mode,
42 .link_mode = link_mode,
43 .resolved_target = comp.root_mod.resolved_target,
44 .is_test = false,
45 .have_zcu = false,
46 .emit_bin = true,
47 .root_optimize_mode = optimize_mode,
48 .root_strip = strip,
49 .link_libc = true,
50 });
51
52 const common_flags = [_][]const u8{
53 "-DTSAN_CONTAINS_UBSAN=0",
54 };
55
56 const root_mod = try Module.create(arena, .{
57 .global_cache_directory = comp.global_cache_directory,
58 .paths = .{
59 .root = .{ .root_dir = comp.zig_lib_directory },
60 .root_src_path = "",
61 },
62 .fully_qualified_name = "root",
63 .inherited = .{
64 .resolved_target = comp.root_mod.resolved_target,
65 .strip = strip,
66 .stack_check = false,
67 .stack_protector = 0,
68 .sanitize_c = false,
69 .sanitize_thread = false,
70 .red_zone = comp.root_mod.red_zone,
71 .omit_frame_pointer = comp.root_mod.omit_frame_pointer,
72 .valgrind = false,
73 .optimize_mode = optimize_mode,
74 .structured_cfg = comp.root_mod.structured_cfg,
75 .pic = true,
76 },
77 .global = config,
78 .cc_argv = &common_flags,
79 .parent = null,
80 .builtin_mod = null,
81 });
82
3783 var c_source_files = std.ArrayList(Compilation.CSourceFile).init(arena);
3884 try c_source_files.ensureUnusedCapacity(tsan_sources.len);
3985
......@@ -50,8 +96,9 @@ pub fn buildTsan(comp: *Compilation, prog_node: *std.Progress.Node) !void {
5096 try cflags.append("-fno-rtti");
5197
5298 c_source_files.appendAssumeCapacity(.{
53 .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "tsan", tsan_src }),
99 .src_path = try comp.zig_lib_directory.join(arena, &.{ "tsan", tsan_src }),
54100 .extra_flags = cflags.items,
101 .owner = root_mod,
55102 });
56103 }
57104
......@@ -74,6 +121,7 @@ pub fn buildTsan(comp: *Compilation, prog_node: *std.Progress.Node) !void {
74121 c_source_files.appendAssumeCapacity(.{
75122 .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "tsan", tsan_src }),
76123 .extra_flags = cflags.items,
124 .owner = root_mod,
77125 });
78126 }
79127 {
......@@ -94,6 +142,7 @@ pub fn buildTsan(comp: *Compilation, prog_node: *std.Progress.Node) !void {
94142 c_source_files.appendAssumeCapacity(.{
95143 .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "tsan", asm_source }),
96144 .extra_flags = cflags.items,
145 .owner = root_mod,
97146 });
98147 }
99148
......@@ -117,6 +166,7 @@ pub fn buildTsan(comp: *Compilation, prog_node: *std.Progress.Node) !void {
117166 "tsan", "sanitizer_common", common_src,
118167 }),
119168 .extra_flags = cflags.items,
169 .owner = root_mod,
120170 });
121171 }
122172
......@@ -141,6 +191,7 @@ pub fn buildTsan(comp: *Compilation, prog_node: *std.Progress.Node) !void {
141191 "tsan", "sanitizer_common", c_src,
142192 }),
143193 .extra_flags = cflags.items,
194 .owner = root_mod,
144195 });
145196 }
146197
......@@ -161,6 +212,7 @@ pub fn buildTsan(comp: *Compilation, prog_node: *std.Progress.Node) !void {
161212 "tsan", "sanitizer_common", c_src,
162213 }),
163214 .extra_flags = cflags.items,
215 .owner = root_mod,
164216 });
165217 }
166218
......@@ -189,56 +241,10 @@ pub fn buildTsan(comp: *Compilation, prog_node: *std.Progress.Node) !void {
189241 "tsan", "interception", c_src,
190242 }),
191243 .extra_flags = cflags.items,
244 .owner = root_mod,
192245 });
193246 }
194247
195 const common_flags = [_][]const u8{
196 "-DTSAN_CONTAINS_UBSAN=0",
197 };
198
199 const optimize_mode = comp.compilerRtOptMode();
200 const strip = comp.compilerRtStrip();
201
202 const config = try Compilation.Config.resolve(.{
203 .output_mode = output_mode,
204 .link_mode = link_mode,
205 .resolved_target = comp.root_mod.resolved_target,
206 .is_test = false,
207 .have_zcu = false,
208 .emit_bin = true,
209 .root_optimize_mode = optimize_mode,
210 .root_strip = strip,
211 .link_libc = true,
212 });
213
214 const root_mod = try Module.create(arena, .{
215 .global_cache_directory = comp.global_cache_directory,
216 .paths = .{
217 .root = .{ .root_dir = comp.zig_lib_directory },
218 .root_src_path = "",
219 },
220 .fully_qualified_name = "root",
221 .inherited = .{
222 .resolved_target = comp.root_mod.resolved_target,
223 .strip = strip,
224 .stack_check = false,
225 .stack_protector = 0,
226 .sanitize_c = false,
227 .sanitize_thread = false,
228 .red_zone = comp.root_mod.red_zone,
229 .omit_frame_pointer = comp.root_mod.omit_frame_pointer,
230 .valgrind = false,
231 .optimize_mode = optimize_mode,
232 .structured_cfg = comp.root_mod.structured_cfg,
233 .pic = true,
234 .cc_argv = &common_flags,
235 },
236 .global = config,
237 .cc_argv = &.{},
238 .parent = null,
239 .builtin_mod = null,
240 });
241
242248 const sub_compilation = try Compilation.create(comp.gpa, .{
243249 .local_cache_directory = comp.global_cache_directory,
244250 .global_cache_directory = comp.global_cache_directory,
src/libunwind.zig+6-4
......@@ -33,7 +33,8 @@ pub fn buildStaticLib(comp: *Compilation, prog_node: *std.Progress.Node) !void {
3333 // Disable LTO to avoid https://github.com/llvm/llvm-project/issues/56825
3434 .lto = false,
3535 });
36 const root_mod = Module.create(.{
36 const root_mod = try Module.create(arena, .{
37 .global_cache_directory = comp.global_cache_directory,
3738 .paths = .{
3839 .root = .{ .root_dir = comp.zig_lib_directory },
3940 .root_src_path = "",
......@@ -55,6 +56,8 @@ pub fn buildStaticLib(comp: *Compilation, prog_node: *std.Progress.Node) !void {
5556 },
5657 .global = config,
5758 .cc_argv = &.{},
59 .parent = null,
60 .builtin_mod = null,
5861 });
5962
6063 const root_name = "unwind";
......@@ -117,6 +120,7 @@ pub fn buildStaticLib(comp: *Compilation, prog_node: *std.Progress.Node) !void {
117120 c_source_files[i] = .{
118121 .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{unwind_src}),
119122 .extra_flags = cflags.items,
123 .owner = root_mod,
120124 };
121125 }
122126 const sub_compilation = try Compilation.create(comp.gpa, .{
......@@ -132,7 +136,6 @@ pub fn buildStaticLib(comp: *Compilation, prog_node: *std.Progress.Node) !void {
132136 .thread_pool = comp.thread_pool,
133137 .libc_installation = comp.libc_installation,
134138 .emit_bin = emit_bin,
135 .link_mode = link_mode,
136139 .function_sections = comp.function_sections,
137140 .c_source_files = &c_source_files,
138141 .verbose_cc = comp.verbose_cc,
......@@ -150,8 +153,7 @@ pub fn buildStaticLib(comp: *Compilation, prog_node: *std.Progress.Node) !void {
150153 try comp.updateSubCompilation(sub_compilation, .libunwind, prog_node);
151154
152155 assert(comp.libunwind_static_lib == null);
153
154 comp.libunwind_static_lib = try sub_compilation.toOwnedLock();
156 comp.libunwind_static_lib = try sub_compilation.toCrtFile();
155157}
156158
157159const unwind_src_list = [_][]const u8{
src/link/Coff.zig+4
......@@ -18,6 +18,8 @@ major_subsystem_version: u16,
1818minor_subsystem_version: u16,
1919lib_dirs: []const []const u8,
2020entry_addr: ?u32,
21module_definition_file: ?[]const u8,
22pdb_out_path: ?[]const u8,
2123
2224ptr_width: PtrWidth,
2325page_size: u32,
......@@ -425,6 +427,8 @@ pub fn createEmpty(
425427 .lib_dirs = options.lib_dirs,
426428 .entry_addr = math.cast(u32, options.entry_addr orelse 0) orelse
427429 return error.EntryAddressTooBig,
430 .module_definition_file = options.module_definition_file,
431 .pdb_out_path = options.pdb_out_path,
428432 };
429433
430434 const use_llvm = comp.config.use_llvm;
src/link/Coff/lld.zig+8-15
......@@ -82,7 +82,7 @@ pub fn linkWithLLD(self: *Coff, comp: *Compilation, prog_node: *std.Progress.Nod
8282 try man.addOptionalFile(module_obj_path);
8383 man.hash.addOptionalBytes(comp.config.entry);
8484 man.hash.add(self.base.stack_size);
85 man.hash.addOptional(self.image_base);
85 man.hash.add(self.image_base);
8686 man.hash.addListOfBytes(self.lib_dirs);
8787 man.hash.add(comp.skip_linker_dependencies);
8888 if (comp.config.link_libc) {
......@@ -102,10 +102,10 @@ pub fn linkWithLLD(self: *Coff, comp: *Compilation, prog_node: *std.Progress.Nod
102102 man.hash.add(self.tsaware);
103103 man.hash.add(self.nxcompat);
104104 man.hash.add(self.dynamicbase);
105 man.hash.addOptional(self.base.allow_shlib_undefined);
105 man.hash.add(self.base.allow_shlib_undefined);
106106 // strip does not need to go into the linker hash because it is part of the hash namespace
107 man.hash.addOptional(self.major_subsystem_version);
108 man.hash.addOptional(self.minor_subsystem_version);
107 man.hash.add(self.major_subsystem_version);
108 man.hash.add(self.minor_subsystem_version);
109109 man.hash.addOptional(comp.version);
110110 try man.addOptionalFile(self.module_definition_file);
111111
......@@ -237,7 +237,7 @@ pub fn linkWithLLD(self: *Coff, comp: *Compilation, prog_node: *std.Progress.Nod
237237
238238 try argv.append(try allocPrint(arena, "-OUT:{s}", .{full_out_path}));
239239
240 if (self.implib_emit) |emit| {
240 if (comp.implib_emit) |emit| {
241241 const implib_out_path = try emit.directory.join(arena, &[_][]const u8{emit.sub_path});
242242 try argv.append(try allocPrint(arena, "-IMPLIB:{s}", .{implib_out_path}));
243243 }
......@@ -310,16 +310,9 @@ pub fn linkWithLLD(self: *Coff, comp: *Compilation, prog_node: *std.Progress.Nod
310310 const Mode = enum { uefi, win32 };
311311 const mode: Mode = mode: {
312312 if (resolved_subsystem) |subsystem| {
313 const subsystem_suffix = ss: {
314 if (self.major_subsystem_version) |major| {
315 if (self.minor_subsystem_version) |minor| {
316 break :ss try allocPrint(arena, ",{d}.{d}", .{ major, minor });
317 } else {
318 break :ss try allocPrint(arena, ",{d}", .{major});
319 }
320 }
321 break :ss "";
322 };
313 const subsystem_suffix = try allocPrint(arena, ",{d}.{d}", .{
314 self.major_subsystem_version, self.minor_subsystem_version,
315 });
323316
324317 switch (subsystem) {
325318 .Console => {
src/link/Elf.zig+11-9
......@@ -23,6 +23,8 @@ soname: ?[]const u8,
2323bind_global_refs_locally: bool,
2424linker_script: ?[]const u8,
2525version_script: ?[]const u8,
26print_icf_sections: bool,
27print_map: bool,
2628
2729ptr_width: PtrWidth,
2830
......@@ -307,6 +309,8 @@ pub fn createEmpty(
307309 .bind_global_refs_locally = options.bind_global_refs_locally,
308310 .linker_script = options.linker_script,
309311 .version_script = options.version_script,
312 .print_icf_sections = options.print_icf_sections,
313 .print_map = options.print_map,
310314 };
311315 if (use_llvm and comp.config.have_zcu) {
312316 self.llvm_object = try LlvmObject.create(arena, comp);
......@@ -1294,12 +1298,9 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node
12941298
12951299 // Look for entry address in objects if not set by the incremental compiler.
12961300 if (self.entry_index == null) {
1297 const entry: ?[]const u8 = entry: {
1298 if (comp.config.entry) |entry| break :entry entry;
1299 if (!self.base.isDynLib()) break :entry "_start";
1300 break :entry null;
1301 };
1302 self.entry_index = if (entry) |name| self.globalByName(name) else null;
1301 if (comp.config.entry) |name| {
1302 self.entry_index = self.globalByName(name);
1303 }
13031304 }
13041305
13051306 if (self.base.gc_sections) {
......@@ -2420,7 +2421,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node) !v
24202421 // We can skip hashing libc and libc++ components that we are in charge of building from Zig
24212422 // installation sources because they are always a product of the compiler version + target information.
24222423 man.hash.addOptionalBytes(comp.config.entry);
2423 man.hash.addOptional(self.image_base);
2424 man.hash.add(self.image_base);
24242425 man.hash.add(self.base.gc_sections);
24252426 man.hash.addOptional(self.sort_section);
24262427 man.hash.add(self.eh_frame_hdr);
......@@ -5896,7 +5897,7 @@ pub fn addSymbol(self: *Elf) !Symbol.Index {
58965897 break :blk index;
58975898 } else {
58985899 log.debug(" (allocating symbol index {d})", .{self.symbols.items.len});
5899 const index = @as(Symbol.Index, @intCast(self.symbols.items.len));
5900 const index: Symbol.Index = @intCast(self.symbols.items.len);
59005901 _ = self.symbols.addOneAssumeCapacity();
59015902 break :blk index;
59025903 }
......@@ -5961,6 +5962,7 @@ pub fn getOrPutGlobal(self: *Elf, name: []const u8) !GetOrPutGlobalResult {
59615962 const gop = try self.resolver.getOrPut(gpa, name_off);
59625963 if (!gop.found_existing) {
59635964 const index = try self.addSymbol();
5965 log.debug("added symbol '{s}' at index {d}", .{ name, index });
59645966 const global = self.symbol(index);
59655967 global.name_offset = name_off;
59665968 global.flags.global = true;
......@@ -5996,7 +5998,7 @@ pub fn getOrCreateComdatGroupOwner(self: *Elf, name: [:0]const u8) !GetOrCreateC
59965998 const off = try self.strings.insert(gpa, name);
59975999 const gop = try self.comdat_groups_table.getOrPut(gpa, off);
59986000 if (!gop.found_existing) {
5999 const index = @as(ComdatGroupOwner.Index, @intCast(self.comdat_groups_owners.items.len));
6001 const index: ComdatGroupOwner.Index = @intCast(self.comdat_groups_owners.items.len);
60006002 const owner = try self.comdat_groups_owners.addOne(gpa);
60016003 owner.* = .{};
60026004 gop.value_ptr.* = index;
src/main.zig+1-1
......@@ -3481,7 +3481,7 @@ fn buildOutputType(
34813481 defer if (!comp_destroyed) comp.destroy();
34823482
34833483 if (show_builtin) {
3484 const builtin_mod = comp.root_mod.deps.get("builtin").?;
3484 const builtin_mod = comp.root_mod.getBuiltinDependency();
34853485 const source = builtin_mod.builtin_file.?.source;
34863486 return std.io.getStdOut().writeAll(source);
34873487 }
src/mingw.zig+17-4
......@@ -41,14 +41,16 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr
4141 //"-D_UNICODE",
4242 //"-DWPRFLAG=1",
4343 });
44 return comp.build_crt_file("crt2", .Obj, .@"mingw-w64 crt2.o", prog_node, &.{
44 var files = [_]Compilation.CSourceFile{
4545 .{
4646 .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{
4747 "libc", "mingw", "crt", "crtexe.c",
4848 }),
4949 .extra_flags = args.items,
50 .owner = undefined,
5051 },
51 });
52 };
53 return comp.build_crt_file("crt2", .Obj, .@"mingw-w64 crt2.o", prog_node, &files);
5254 },
5355
5456 .dllcrt2_o => {
......@@ -60,14 +62,16 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr
6062 "-U__CRTDLL__",
6163 "-D__MSVCRT__",
6264 });
63 return comp.build_crt_file("dllcrt2", .Obj, .@"mingw-w64 dllcrt2.o", prog_node, &.{
65 var files = [_]Compilation.CSourceFile{
6466 .{
6567 .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{
6668 "libc", "mingw", "crt", "crtdll.c",
6769 }),
6870 .extra_flags = args.items,
71 .owner = undefined,
6972 },
70 });
73 };
74 return comp.build_crt_file("dllcrt2", .Obj, .@"mingw-w64 dllcrt2.o", prog_node, &files);
7175 },
7276
7377 .mingw32_lib => {
......@@ -97,6 +101,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr
97101 "libc", "mingw", "crt", dep,
98102 }),
99103 .extra_flags = args.items,
104 .owner = undefined,
100105 };
101106 }
102107 return comp.build_crt_file("mingw32", .Lib, .@"mingw-w64 mingw32.lib", prog_node, &c_source_files);
......@@ -125,6 +130,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr
125130 (try c_source_files.addOne()).* = .{
126131 .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libc", "mingw", dep }),
127132 .extra_flags = extra_flags,
133 .owner = undefined,
128134 };
129135 }
130136 if (comp.getTarget().cpu.arch == .x86) {
......@@ -134,6 +140,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr
134140 "libc", "mingw", dep,
135141 }),
136142 .extra_flags = extra_flags,
143 .owner = undefined,
137144 };
138145 }
139146 } else {
......@@ -143,6 +150,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr
143150 "libc", "mingw", dep,
144151 }),
145152 .extra_flags = extra_flags,
153 .owner = undefined,
146154 };
147155 }
148156 }
......@@ -175,6 +183,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr
175183 "libc", "mingw", dep,
176184 }),
177185 .extra_flags = extra_flags,
186 .owner = undefined,
178187 };
179188 }
180189 const target = comp.getTarget();
......@@ -185,6 +194,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr
185194 "libc", "mingw", dep,
186195 }),
187196 .extra_flags = extra_flags,
197 .owner = undefined,
188198 };
189199 }
190200 } else if (target.cpu.arch.isARM()) {
......@@ -194,6 +204,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr
194204 "libc", "mingw", dep,
195205 }),
196206 .extra_flags = extra_flags,
207 .owner = undefined,
197208 };
198209 }
199210 } else if (target.cpu.arch.isAARCH64()) {
......@@ -203,6 +214,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr
203214 "libc", "mingw", dep,
204215 }),
205216 .extra_flags = extra_flags,
217 .owner = undefined,
206218 };
207219 }
208220 } else {
......@@ -238,6 +250,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr
238250 "libc", "mingw", "libsrc", dep,
239251 }),
240252 .extra_flags = extra_flags,
253 .owner = undefined,
241254 };
242255 }
243256 return comp.build_crt_file("uuid", .Lib, .@"mingw-w64 uuid.lib", prog_node, &c_source_files);
src/musl.zig+26-13
......@@ -34,12 +34,14 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr
3434 try args.appendSlice(&[_][]const u8{
3535 "-Qunused-arguments",
3636 });
37 return comp.build_crt_file("crti", .Obj, .@"musl crti.o", prog_node, &.{
37 var files = [_]Compilation.CSourceFile{
3838 .{
3939 .src_path = try start_asm_path(comp, arena, "crti.s"),
4040 .extra_flags = args.items,
41 .owner = undefined,
4142 },
42 });
43 };
44 return comp.build_crt_file("crti", .Obj, .@"musl crti.o", prog_node, &files);
4345 },
4446 .crtn_o => {
4547 var args = std.ArrayList([]const u8).init(arena);
......@@ -47,12 +49,14 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr
4749 try args.appendSlice(&[_][]const u8{
4850 "-Qunused-arguments",
4951 });
50 return comp.build_crt_file("crtn", .Obj, .@"musl crtn.o", prog_node, &.{
52 var files = [_]Compilation.CSourceFile{
5153 .{
5254 .src_path = try start_asm_path(comp, arena, "crtn.s"),
5355 .extra_flags = args.items,
56 .owner = undefined,
5457 },
55 });
58 };
59 return comp.build_crt_file("crtn", .Obj, .@"musl crtn.o", prog_node, &files);
5660 },
5761 .crt1_o => {
5862 var args = std.ArrayList([]const u8).init(arena);
......@@ -61,14 +65,16 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr
6165 "-fno-stack-protector",
6266 "-DCRT",
6367 });
64 return comp.build_crt_file("crt1", .Obj, .@"musl crt1.o", prog_node, &.{
68 var files = [_]Compilation.CSourceFile{
6569 .{
6670 .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{
6771 "libc", "musl", "crt", "crt1.c",
6872 }),
6973 .extra_flags = args.items,
74 .owner = undefined,
7075 },
71 });
76 };
77 return comp.build_crt_file("crt1", .Obj, .@"musl crt1.o", prog_node, &files);
7278 },
7379 .rcrt1_o => {
7480 var args = std.ArrayList([]const u8).init(arena);
......@@ -78,14 +84,16 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr
7884 "-fno-stack-protector",
7985 "-DCRT",
8086 });
81 return comp.build_crt_file("rcrt1", .Obj, .@"musl rcrt1.o", prog_node, &.{
87 var files = [_]Compilation.CSourceFile{
8288 .{
8389 .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{
8490 "libc", "musl", "crt", "rcrt1.c",
8591 }),
8692 .extra_flags = args.items,
93 .owner = undefined,
8794 },
88 });
95 };
96 return comp.build_crt_file("rcrt1", .Obj, .@"musl rcrt1.o", prog_node, &files);
8997 },
9098 .scrt1_o => {
9199 var args = std.ArrayList([]const u8).init(arena);
......@@ -95,14 +103,16 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr
95103 "-fno-stack-protector",
96104 "-DCRT",
97105 });
98 return comp.build_crt_file("Scrt1", .Obj, .@"musl Scrt1.o", prog_node, &.{
106 var files = [_]Compilation.CSourceFile{
99107 .{
100108 .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{
101109 "libc", "musl", "crt", "Scrt1.c",
102110 }),
103111 .extra_flags = args.items,
112 .owner = undefined,
104113 },
105 });
114 };
115 return comp.build_crt_file("Scrt1", .Obj, .@"musl Scrt1.o", prog_node, &files);
106116 },
107117 .libc_a => {
108118 // When there is a src/<arch>/foo.* then it should substitute for src/foo.*
......@@ -186,6 +196,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr
186196 c_source_file.* = .{
187197 .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libc", src_file }),
188198 .extra_flags = args.items,
199 .owner = undefined,
189200 };
190201 }
191202 return comp.build_crt_file("c", .Lib, .@"musl libc.a", prog_node, c_source_files.items);
......@@ -235,7 +246,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr
235246 .structured_cfg = comp.root_mod.structured_cfg,
236247 },
237248 .global = config,
238 .cc_argv = &.{},
249 .cc_argv = cc_argv,
239250 .parent = null,
240251 .builtin_mod = null,
241252 });
......@@ -261,9 +272,11 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr
261272 .verbose_llvm_cpu_features = comp.verbose_llvm_cpu_features,
262273 .clang_passthrough_mode = comp.clang_passthrough_mode,
263274 .c_source_files = &[_]Compilation.CSourceFile{
264 .{ .src_path = try comp.zig_lib_directory.join(arena, &.{ "libc", "musl", "libc.S" }) },
275 .{
276 .src_path = try comp.zig_lib_directory.join(arena, &.{ "libc", "musl", "libc.S" }),
277 .owner = root_mod,
278 },
265279 },
266 .cc_argv = cc_argv,
267280 .skip_linker_dependencies = true,
268281 .soname = "libc.so",
269282 });
src/wasi_libc.zig+16-4
......@@ -74,27 +74,31 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr
7474 var args = std.ArrayList([]const u8).init(arena);
7575 try addCCArgs(comp, arena, &args, .{});
7676 try addLibcBottomHalfIncludes(comp, arena, &args);
77 return comp.build_crt_file("crt1-reactor", .Obj, .@"wasi crt1-reactor.o", prog_node, &.{
77 var files = [_]Compilation.CSourceFile{
7878 .{
7979 .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{
8080 "libc", try sanitize(arena, crt1_reactor_src_file),
8181 }),
8282 .extra_flags = args.items,
83 .owner = undefined,
8384 },
84 });
85 };
86 return comp.build_crt_file("crt1-reactor", .Obj, .@"wasi crt1-reactor.o", prog_node, &files);
8587 },
8688 .crt1_command_o => {
8789 var args = std.ArrayList([]const u8).init(arena);
8890 try addCCArgs(comp, arena, &args, .{});
8991 try addLibcBottomHalfIncludes(comp, arena, &args);
90 return comp.build_crt_file("crt1-command", .Obj, .@"wasi crt1-command.o", prog_node, &.{
92 var files = [_]Compilation.CSourceFile{
9193 .{
9294 .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{
9395 "libc", try sanitize(arena, crt1_command_src_file),
9496 }),
9597 .extra_flags = args.items,
98 .owner = undefined,
9699 },
97 });
100 };
101 return comp.build_crt_file("crt1-command", .Obj, .@"wasi crt1-command.o", prog_node, &files);
98102 },
99103 .libc_a => {
100104 var libc_sources = std.ArrayList(Compilation.CSourceFile).init(arena);
......@@ -109,6 +113,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr
109113 "libc", try sanitize(arena, file_path),
110114 }),
111115 .extra_flags = args.items,
116 .owner = undefined,
112117 });
113118 }
114119 }
......@@ -125,6 +130,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr
125130 "libc", try sanitize(arena, file_path),
126131 }),
127132 .extra_flags = args.items,
133 .owner = undefined,
128134 });
129135 }
130136 }
......@@ -141,6 +147,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr
141147 "libc", try sanitize(arena, file_path),
142148 }),
143149 .extra_flags = args.items,
150 .owner = undefined,
144151 });
145152 }
146153 }
......@@ -159,6 +166,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr
159166 "libc", try sanitize(arena, file_path),
160167 }),
161168 .extra_flags = args.items,
169 .owner = undefined,
162170 });
163171 }
164172 try comp.build_crt_file("wasi-emulated-process-clocks", .Lib, .@"libwasi-emulated-process-clocks.a", prog_node, emu_clocks_sources.items);
......@@ -175,6 +183,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr
175183 "libc", try sanitize(arena, file_path),
176184 }),
177185 .extra_flags = args.items,
186 .owner = undefined,
178187 });
179188 }
180189 try comp.build_crt_file("wasi-emulated-getpid", .Lib, .@"libwasi-emulated-getpid.a", prog_node, emu_getpid_sources.items);
......@@ -191,6 +200,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr
191200 "libc", try sanitize(arena, file_path),
192201 }),
193202 .extra_flags = args.items,
203 .owner = undefined,
194204 });
195205 }
196206 try comp.build_crt_file("wasi-emulated-mman", .Lib, .@"libwasi-emulated-mman.a", prog_node, emu_mman_sources.items);
......@@ -208,6 +218,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr
208218 "libc", try sanitize(arena, file_path),
209219 }),
210220 .extra_flags = args.items,
221 .owner = undefined,
211222 });
212223 }
213224 }
......@@ -224,6 +235,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr
224235 "libc", try sanitize(arena, file_path),
225236 }),
226237 .extra_flags = args.items,
238 .owner = undefined,
227239 });
228240 }
229241 }