authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-12-12 13:36:33-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-01-01 17:51:19-07:00
log9a48a5ab0784ae9744c72cfcc6d7ad9b2cea6a9c
treee4d9e85b058a1cf23776c8f30bd3fc70e2fdfff5
parent43720be04af8ddb8334b210ff936a834fb8871a7

compiler: update references to single_threaded


8 files changed, 51 insertions(+), 28 deletions(-)

src/Compilation.zig+4-6
......@@ -1871,7 +1871,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
18711871 try comp.work_queue.writeItem(.libtsan);
18721872 }
18731873
1874 if (comp.getTarget().isMinGW() and !comp.bin_file.options.single_threaded) {
1874 if (comp.getTarget().isMinGW() and comp.config.any_non_single_threaded) {
18751875 // LLD might drop some symbols as unused during LTO and GCing, therefore,
18761876 // we force mark them for resolution here.
18771877
......@@ -2418,10 +2418,8 @@ fn addNonIncrementalStuffToCacheManifest(comp: *Compilation, man: *Cache.Manifes
24182418 try addModuleTableToCacheHash(gpa, arena, &man.hash, mod.main_mod, .{ .files = man });
24192419
24202420 // Synchronize with other matching comments: ZigOnlyHashStuff
2421 man.hash.add(comp.bin_file.options.valgrind);
2422 man.hash.add(comp.bin_file.options.single_threaded);
2423 man.hash.add(comp.bin_file.options.use_llvm);
2424 man.hash.add(comp.bin_file.options.use_lib_llvm);
2421 man.hash.add(comp.config.use_llvm);
2422 man.hash.add(comp.config.use_lib_llvm);
24252423 man.hash.add(comp.bin_file.options.dll_export_fns);
24262424 man.hash.add(comp.bin_file.options.is_test);
24272425 man.hash.add(comp.test_evented_io);
......@@ -4922,7 +4920,7 @@ pub fn addCCArgs(
49224920 try argv.append("-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS");
49234921 try argv.append("-D_LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS");
49244922
4925 if (comp.bin_file.options.single_threaded) {
4923 if (!comp.config.any_non_single_threaded) {
49264924 try argv.append("-D_LIBCPP_HAS_NO_THREADS");
49274925 }
49284926
src/Compilation/Config.zig+4-2
......@@ -7,6 +7,8 @@ link_libc: bool,
77link_libcpp: bool,
88link_libunwind: bool,
99any_unwind_tables: bool,
10any_c_source_files: bool,
11any_non_single_threaded: bool,
1012pie: bool,
1113/// If this is true then linker code is responsible for making an LLVM IR
1214/// Module, outputting it to an object file, and then linking that together
......@@ -31,7 +33,6 @@ shared_memory: bool,
3133is_test: bool,
3234test_evented_io: bool,
3335entry: ?[]const u8,
34any_c_source_files: bool,
3536
3637pub const CFrontend = enum { clang, aro };
3738
......@@ -374,6 +375,8 @@ pub fn resolve(options: Options) !Config {
374375 .link_libcpp = link_libcpp,
375376 .link_libunwind = link_libunwind,
376377 .any_unwind_tables = any_unwind_tables,
378 .any_c_source_files = options.any_c_source_files,
379 .any_non_single_threaded = options.any_non_single_threaded,
377380 .pie = pie,
378381 .lto = lto,
379382 .import_memory = import_memory,
......@@ -385,7 +388,6 @@ pub fn resolve(options: Options) !Config {
385388 .use_lld = use_lld,
386389 .entry = entry,
387390 .wasi_exec_model = wasi_exec_model,
388 .any_c_source_files = options.any_c_source_files,
389391 };
390392}
391393
src/arch/wasm/CodeGen.zig+4-1
......@@ -7724,10 +7724,13 @@ fn airAtomicRmw(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
77247724}
77257725
77267726fn airFence(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
7727 const zcu = func.bin_file.base.comp.module.?;
77277728 // Only when the atomic feature is enabled, and we're not building
77287729 // for a single-threaded build, can we emit the `fence` instruction.
77297730 // In all other cases, we emit no instructions for a fence.
7730 if (func.useAtomicFeature() and !func.bin_file.base.options.single_threaded) {
7731 const func_namespace = zcu.namespacePtr(zcu.declPtr(func.decl).namespace);
7732 const single_threaded = func_namespace.file_scope.mod.single_threaded;
7733 if (func.useAtomicFeature() and !single_threaded) {
77317734 try func.addAtomicTag(.atomic_fence);
77327735 }
77337736
src/codegen.zig+3-1
......@@ -942,7 +942,9 @@ fn genDeclRef(
942942
943943 try mod.markDeclAlive(decl);
944944
945 const is_threadlocal = tv.val.isPtrToThreadLocal(mod) and !bin_file.options.single_threaded;
945 const decl_namespace = mod.namespacePtr(decl.namespace_index);
946 const single_threaded = decl_namespace.file_scope.mod.single_threaded;
947 const is_threadlocal = tv.val.isPtrToThreadLocal(mod) and !single_threaded;
946948 const is_extern = decl.isExtern(mod);
947949
948950 if (bin_file.cast(link.File.Elf)) |elf_file| {
src/codegen/llvm.zig+11-4
......@@ -1591,8 +1591,10 @@ pub const Object = struct {
15911591 var di_file: ?if (build_options.have_llvm) *llvm.DIFile else noreturn = null;
15921592 var di_scope: ?if (build_options.have_llvm) *llvm.DIScope else noreturn = null;
15931593
1594 const namespace = mod.namespacePtr(decl.src_namespace);
1595
15941596 if (o.di_builder) |dib| {
1595 di_file = try o.getDIFile(gpa, mod.namespacePtr(decl.src_namespace).file_scope);
1597 di_file = try o.getDIFile(gpa, namespace.file_scope);
15961598
15971599 const line_number = decl.src_line + 1;
15981600 const is_internal_linkage = decl.val.getExternFunc(mod) == null and
......@@ -1623,6 +1625,8 @@ pub const Object = struct {
16231625 di_scope = subprogram.toScope();
16241626 }
16251627
1628 const single_threaded = namespace.file_scope.mod.single_threaded;
1629
16261630 var fg: FuncGen = .{
16271631 .gpa = gpa,
16281632 .air = air,
......@@ -1634,7 +1638,7 @@ pub const Object = struct {
16341638 .arg_index = 0,
16351639 .func_inst_table = .{},
16361640 .blocks = .{},
1637 .sync_scope = if (mod.comp.bin_file.options.single_threaded) .singlethread else .system,
1641 .sync_scope = if (single_threaded) .singlethread else .system,
16381642 .di_scope = di_scope,
16391643 .di_file = di_file,
16401644 .base_line = dg.decl.src_line,
......@@ -1788,8 +1792,10 @@ pub const Object = struct {
17881792 if (mod.wantDllExports()) global_index.setDllStorageClass(.default, &self.builder);
17891793 global_index.setUnnamedAddr(.unnamed_addr, &self.builder);
17901794 if (decl.val.getVariable(mod)) |decl_var| {
1795 const decl_namespace = mod.namespacePtr(decl.namespace_index);
1796 const single_threaded = decl_namespace.file_scope.mod.single_threaded;
17911797 global_index.ptrConst(&self.builder).kind.variable.setThreadLocal(
1792 if (decl_var.is_threadlocal and !mod.comp.bin_file.options.single_threaded)
1798 if (decl_var.is_threadlocal and !single_threaded)
17931799 .generaldynamic
17941800 else
17951801 .default,
......@@ -3176,7 +3182,8 @@ pub const Object = struct {
31763182 variable_index.setLinkage(.external, &o.builder);
31773183 variable_index.setUnnamedAddr(.default, &o.builder);
31783184 if (decl.val.getVariable(mod)) |decl_var| {
3179 const single_threaded = mod.comp.bin_file.options.single_threaded;
3185 const decl_namespace = mod.namespacePtr(decl.namespace_index);
3186 const single_threaded = decl_namespace.file_scope.mod.single_threaded;
31803187 variable_index.setThreadLocal(
31813188 if (decl_var.is_threadlocal and !single_threaded) .generaldynamic else .default,
31823189 &o.builder,
src/libcxx.zig+2-2
......@@ -154,7 +154,7 @@ pub fn buildLibCXX(comp: *Compilation, prog_node: *std.Progress.Node) !void {
154154 continue;
155155 if (std.mem.startsWith(u8, cxx_src, "src/support/ibm/") and target.os.tag != .zos)
156156 continue;
157 if (comp.bin_file.options.single_threaded) {
157 if (!comp.config.any_non_single_threaded) {
158158 if (std.mem.startsWith(u8, cxx_src, "src/support/win32/thread_win32.cpp")) {
159159 continue;
160160 }
......@@ -332,7 +332,7 @@ pub fn buildLibCXXABI(comp: *Compilation, prog_node: *std.Progress.Node) !void {
332332 }
333333
334334 // WASM targets are single threaded.
335 if (comp.bin_file.options.single_threaded) {
335 if (!comp.config.any_non_single_threaded) {
336336 if (std.mem.startsWith(u8, cxxabi_src, "src/cxa_thread_atexit.cpp")) {
337337 continue;
338338 }
src/libunwind.zig+1-1
......@@ -67,7 +67,7 @@ pub fn buildStaticLib(comp: *Compilation, prog_node: *std.Progress.Node) !void {
6767 if (comp.bin_file.options.optimize_mode == .Debug) {
6868 try cflags.append("-D_DEBUG");
6969 }
70 if (comp.bin_file.options.single_threaded) {
70 if (!comp.config.any_non_single_threaded) {
7171 try cflags.append("-D_LIBUNWIND_HAS_NO_THREADS");
7272 }
7373 if (target.cpu.arch.isARM() and target.abi.floatAbi() == .hard) {
src/link/MachO.zig+22-11
......@@ -267,7 +267,10 @@ pub fn open(arena: Allocator, options: link.File.OpenOptions) !*MachO {
267267 });
268268 try self.strtab.buffer.append(gpa, 0);
269269
270 try self.populateMissingMetadata();
270 try self.populateMissingMetadata(.{
271 .symbol_count_hint = options.symbol_count_hint,
272 .program_code_size_hint = options.program_code_size_hint,
273 });
271274
272275 if (self.d_sym) |*d_sym| {
273276 try d_sym.populateMissingMetadata(self);
......@@ -1704,7 +1707,8 @@ pub fn createDsoHandleSymbol(self: *MachO) !void {
17041707}
17051708
17061709pub fn resolveSymbols(self: *MachO) !void {
1707 const output_mode = self.base.comp.config.output_mode;
1710 const comp = self.base.comp;
1711 const output_mode = comp.config.output_mode;
17081712 // We add the specified entrypoint as the first unresolved symbols so that
17091713 // we search for it in libraries should there be no object files specified
17101714 // on the linker line.
......@@ -1729,7 +1733,7 @@ pub fn resolveSymbols(self: *MachO) !void {
17291733 if (self.unresolved.count() > 0 and self.dyld_stub_binder_index == null) {
17301734 self.dyld_stub_binder_index = try self.addUndefined("dyld_stub_binder", .{ .add_got = true });
17311735 }
1732 if (!self.base.options.single_threaded and self.mode == .incremental) {
1736 if (comp.config.any_non_single_threaded and self.mode == .incremental) {
17331737 _ = try self.addUndefined("__tlv_bootstrap", .{});
17341738 }
17351739
......@@ -2436,7 +2440,8 @@ pub fn updateDecl(self: *MachO, mod: *Module, decl_index: InternPool.DeclIndex)
24362440 const tracy = trace(@src());
24372441 defer tracy.end();
24382442
2439 const gpa = self.base.comp.gpa;
2443 const comp = self.base.comp;
2444 const gpa = comp.gpa;
24402445 const decl = mod.declPtr(decl_index);
24412446
24422447 if (decl.val.getExternFunc(mod)) |_| {
......@@ -2453,7 +2458,7 @@ pub fn updateDecl(self: *MachO, mod: *Module, decl_index: InternPool.DeclIndex)
24532458 }
24542459
24552460 const is_threadlocal = if (decl.val.getVariable(mod)) |variable|
2456 variable.is_threadlocal and !self.base.options.single_threaded
2461 variable.is_threadlocal and comp.config.any_non_single_threaded
24572462 else
24582463 false;
24592464 if (is_threadlocal) return self.updateThreadlocalVariable(mod, decl_index);
......@@ -3129,11 +3134,17 @@ pub fn getAnonDeclVAddr(self: *MachO, decl_val: InternPool.Index, reloc_info: li
31293134 return 0;
31303135}
31313136
3132fn populateMissingMetadata(self: *MachO) !void {
3137const PopulateMissingMetadataOptions = struct {
3138 symbol_count_hint: u64,
3139 program_code_size_hint: u64,
3140};
3141
3142fn populateMissingMetadata(self: *MachO, options: PopulateMissingMetadataOptions) !void {
31333143 assert(self.mode == .incremental);
31343144
3135 const gpa = self.base.comp.gpa;
3136 const target = self.base.comp.root_mod.resolved_target.result;
3145 const comp = self.base.comp;
3146 const gpa = comp.gpa;
3147 const target = comp.root_mod.resolved_target.result;
31373148 const cpu_arch = target.cpu.arch;
31383149 const pagezero_vmsize = self.calcPagezeroSize();
31393150
......@@ -3171,7 +3182,7 @@ fn populateMissingMetadata(self: *MachO) !void {
31713182 if (self.text_section_index == null) {
31723183 // Sadly, segments need unique string identfiers for some reason.
31733184 self.text_section_index = try self.allocateSection("__TEXT1", "__text", .{
3174 .size = self.base.options.program_code_size_hint,
3185 .size = options.program_code_size_hint,
31753186 .alignment = switch (cpu_arch) {
31763187 .x86_64 => 1,
31773188 .aarch64 => @sizeOf(u32),
......@@ -3207,7 +3218,7 @@ fn populateMissingMetadata(self: *MachO) !void {
32073218
32083219 if (self.got_section_index == null) {
32093220 self.got_section_index = try self.allocateSection("__DATA_CONST", "__got", .{
3210 .size = @sizeOf(u64) * self.base.options.symbol_count_hint,
3221 .size = @sizeOf(u64) * options.symbol_count_hint,
32113222 .alignment = @alignOf(u64),
32123223 .flags = macho.S_NON_LAZY_SYMBOL_POINTERS,
32133224 .prot = macho.PROT.READ | macho.PROT.WRITE,
......@@ -3245,7 +3256,7 @@ fn populateMissingMetadata(self: *MachO) !void {
32453256 self.segment_table_dirty = true;
32463257 }
32473258
3248 if (!self.base.options.single_threaded) {
3259 if (comp.config.any_non_single_threaded) {
32493260 if (self.thread_vars_section_index == null) {
32503261 self.thread_vars_section_index = try self.allocateSection("__DATA2", "__thread_vars", .{
32513262 .size = @sizeOf(u64) * 3,