╭ Module.zig ───────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭ find file ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╮ ╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │ │ │http│ ssh │ │ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╯ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
1 //! Corresponds to something that Zig source code can `@import`. 2 const Module = @This(); 3 4 const std = @import("std"); 5 const Allocator = std.mem.Allocator; 6 const Cache = std.Build.Cache; 7 const assert = std.debug.assert; 8 9 const target_util = @import("target.zig"); 10 const Builtin = @import("Builtin.zig"); 11 const Compilation = @import("Compilation.zig"); 12 const File = @import("Zcu.zig").File; 13 14 /// The root directory of the module. Only files inside this directory can be imported. 15 root: Compilation.Path, 16 /// Path to the root source file of this module. Relative to `root`. May contain path separators. 17 root_src_path: []const u8, 18 /// Name used in compile errors. Looks like "root.foo.bar". 19 fully_qualified_name: []const u8, 20 /// The dependency table of this module. The shared dependencies 'std' and 21 /// 'root' are not specified in every module dependency table, but are stored 22 /// separately in `Zcu`. 'builtin' is also not stored here, although it is 23 /// not necessarily the same between all modules. Handling of `@import` in 24 /// the rest of the compiler must detect these special names and use the 25 /// correct module instead of consulting `deps`. 26 deps: Deps = .{}, 27 28 resolved_target: ResolvedTarget, 29 optimize_mode: std.lang.Optimize, 30 code_model: std.lang.CodeModel, 31 single_threaded: bool, 32 error_tracing: bool, 33 valgrind: bool, 34 pic: bool, 35 strip: bool, 36 omit_frame_pointer: bool, 37 stack_check: bool, 38 stack_protector: u32, 39 red_zone: bool, 40 sanitize_c: std.zig.SanitizeC, 41 sanitize_thread: bool, 42 fuzz: bool, 43 unwind_tables: std.lang.UnwindTables, 44 cc_argv: []const []const u8, 45 no_builtin: bool, 46 patchable_function_entry: u16, 47 48 pub const Deps = std.array_hash_map.String(*Module); 49 50 pub const CreateOptions = struct { 51 paths: Paths, 52 fully_qualified_name: []const u8, 53 54 cc_argv: []const []const u8, 55 inherited: Inherited, 56 global: Compilation.Config, 57 /// If this is null then `resolved_target` must be non-null. 58 parent: ?*Module, 59 60 pub const Paths = struct { 61 root: Compilation.Path, 62 /// Relative to `root`. May contain path separators. 63 root_src_path: []const u8, 64 }; 65 66 pub const Inherited = struct { 67 /// If this is null then `parent` must be non-null. 68 resolved_target: ?ResolvedTarget = null, 69 optimize_mode: ?std.lang.Optimize = null, 70 code_model: ?std.lang.CodeModel = null, 71 single_threaded: ?bool = null, 72 error_tracing: ?bool = null, 73 valgrind: ?bool = null, 74 pic: ?bool = null, 75 strip: ?bool = null, 76 omit_frame_pointer: ?bool = null, 77 stack_check: ?bool = null, 78 /// null means default. 79 /// 0 means no stack protector. 80 /// other number means stack protection with that buffer size. 81 stack_protector: ?u32 = null, 82 red_zone: ?bool = null, 83 unwind_tables: ?std.lang.UnwindTables = null, 84 sanitize_c: ?std.zig.SanitizeC = null, 85 sanitize_thread: ?bool = null, 86 fuzz: ?bool = null, 87 no_builtin: ?bool = null, 88 patchable_function_entry: u16 = 0, 89 }; 90 }; 91 92 pub const ResolvedTarget = struct { 93 result: std.Target, 94 is_native_os: bool, 95 is_native_abi: bool, 96 is_explicit_dynamic_linker: bool, 97 llvm_cpu_features: ?[*:0]const u8 = null, 98 }; 99 100 pub const CreateError = error{ 101 OutOfMemory, 102 ValgrindUnsupportedOnTarget, 103 TargetRequiresSingleThreaded, 104 BackendRequiresSingleThreaded, 105 TargetRequiresPic, 106 PieRequiresPic, 107 DynamicLinkingRequiresPic, 108 TargetHasNoRedZone, 109 StackCheckUnsupportedByTarget, 110 StackProtectorUnsupportedByTarget, 111 StackProtectorUnavailableWithoutLibC, 112 PatchableFunctionEntryUnsupportedByBackend, 113 }; 114 115 /// At least one of `parent` and `resolved_target` must be non-null. 116 pub fn create(arena: Allocator, options: CreateOptions) !*Module { 117 if (options.inherited.sanitize_thread == true) assert(options.global.any_sanitize_thread); 118 if (options.inherited.fuzz == true) assert(options.global.any_fuzz); 119 if (options.inherited.single_threaded == false) assert(options.global.any_non_single_threaded); 120 if (options.inherited.unwind_tables) |uwt| if (uwt != .none) assert(options.global.any_unwind_tables); 121 if (options.inherited.sanitize_c) |sc| if (sc != .off) assert(options.global.any_sanitize_c != .off); 122 if (options.inherited.error_tracing == true) assert(options.global.any_error_tracing); 123 124 const resolved_target = options.inherited.resolved_target orelse options.parent.?.resolved_target; 125 const target = &resolved_target.result; 126 127 const optimize_mode = options.inherited.optimize_mode orelse 128 if (options.parent) |p| p.optimize_mode else options.global.root_optimize_mode; 129 130 const strip = b: { 131 if (options.inherited.strip) |x| break :b x; 132 if (options.parent) |p| break :b p.strip; 133 break :b options.global.root_strip; 134 }; 135 136 const zig_backend = target_util.zigBackend(target, options.global.use_llvm); 137 138 const valgrind = b: { 139 if (!target_util.hasValgrindSupport(target, zig_backend)) { 140 if (options.inherited.valgrind == true) 141 return error.ValgrindUnsupportedOnTarget; 142 break :b false; 143 } 144 if (options.inherited.valgrind) |x| break :b x; 145 if (options.parent) |p| break :b p.valgrind; 146 if (strip) break :b false; 147 break :b optimize_mode == .debug; 148 }; 149 150 const single_threaded = b: { 151 if (target_util.alwaysSingleThreaded(target)) { 152 if (options.inherited.single_threaded == false) 153 return error.TargetRequiresSingleThreaded; 154 break :b true; 155 } 156 157 if (options.global.have_zcu) { 158 if (!target_util.supportsThreads(target, zig_backend)) { 159 if (options.inherited.single_threaded == false) 160 return error.BackendRequiresSingleThreaded; 161 break :b true; 162 } 163 } 164 165 if (options.inherited.single_threaded) |x| break :b x; 166 if (options.parent) |p| break :b p.single_threaded; 167 break :b target_util.defaultSingleThreaded(target); 168 }; 169 170 const error_tracing = b: { 171 if (options.inherited.error_tracing) |x| break :b x; 172 if (options.parent) |p| break :b p.error_tracing; 173 break :b options.global.root_error_tracing; 174 }; 175 176 const pic = b: { 177 if (target_util.requiresPic(target, options.global.link_libc)) { 178 if (options.inherited.pic == false) 179 return error.TargetRequiresPic; 180 break :b true; 181 } 182 if (options.global.pie) { 183 if (options.inherited.pic == false) 184 return error.PieRequiresPic; 185 break :b true; 186 } 187 if (options.global.link_mode == .dynamic and target_util.requiresPicForDynamicLink(target)) { 188 if (options.inherited.pic == false) 189 return error.DynamicLinkingRequiresPic; 190 break :b true; 191 } 192 if (options.inherited.pic) |x| break :b x; 193 if (options.parent) |p| break :b p.pic; 194 195 // Default to PIC on targets where we default to producing PIEs to make 196 // the common case of linking objects and static libraries into an 197 // executable work out of the box. 198 break :b target_util.defaultPie(target); 199 }; 200 201 const red_zone = b: { 202 if (!target_util.hasRedZone(target)) { 203 if (options.inherited.red_zone == true) 204 return error.TargetHasNoRedZone; 205 break :b false; 206 } 207 if (options.inherited.red_zone) |x| break :b x; 208 if (options.parent) |p| break :b p.red_zone; 209 break :b true; 210 }; 211 212 const omit_frame_pointer = b: { 213 if (options.inherited.omit_frame_pointer) |x| break :b x; 214 if (options.parent) |p| break :b p.omit_frame_pointer; 215 if (optimize_mode == .small) { 216 // On x86, in most cases, keeping the frame pointer usually results in smaller binary size. 217 // This has to do with how instructions for memory access via the stack base pointer register (when keeping the frame pointer) 218 // are smaller than instructions for memory access via the stack pointer register (when omitting the frame pointer). 219 break :b !target.cpu.arch.isX86(); 220 } 221 break :b false; 222 }; 223 224 const sanitize_thread = b: { 225 if (options.inherited.sanitize_thread) |x| break :b x; 226 if (options.parent) |p| break :b p.sanitize_thread; 227 break :b false; 228 }; 229 230 const unwind_tables = b: { 231 if (options.inherited.unwind_tables) |x| break :b x; 232 if (options.parent) |p| break :b p.unwind_tables; 233 234 break :b target_util.defaultUnwindTables( 235 target, 236 options.global.link_libunwind, 237 sanitize_thread or options.global.any_sanitize_thread, 238 ); 239 }; 240 241 const fuzz = b: { 242 if (options.inherited.fuzz) |x| break :b x; 243 if (options.parent) |p| break :b p.fuzz; 244 break :b false; 245 }; 246 247 const code_model: std.lang.CodeModel = b: { 248 if (options.inherited.code_model) |x| break :b x; 249 if (options.parent) |p| break :b p.code_model; 250 break :b .default; 251 }; 252 253 const is_safe_mode = switch (optimize_mode) { 254 .debug, .safe => true, 255 .fast, .small => false, 256 }; 257 258 const sanitize_c: std.zig.SanitizeC = b: { 259 if (options.inherited.sanitize_c) |x| break :b x; 260 if (options.parent) |p| break :b p.sanitize_c; 261 break :b switch (optimize_mode) { 262 .debug => .full, 263 // It's recommended to use the minimal runtime in production 264 // environments due to the security implications of the full runtime. 265 // The minimal runtime doesn't provide much benefit over simply 266 // trapping, however, so we do that instead. 267 .safe => .trap, 268 .fast, .small => .off, 269 }; 270 }; 271 272 const stack_check = b: { 273 if (!target_util.supportsStackProbing(target, zig_backend)) { 274 if (options.inherited.stack_check == true) 275 return error.StackCheckUnsupportedByTarget; 276 break :b false; 277 } 278 if (options.inherited.stack_check) |x| break :b x; 279 if (options.parent) |p| break :b p.stack_check; 280 break :b is_safe_mode; 281 }; 282 283 const stack_protector: u32 = sp: { 284 const use_zig_backend = options.global.have_zcu or 285 (options.global.any_c_source_files and options.global.c_frontend == .aro); 286 if (use_zig_backend and !target_util.supportsStackProtector(target, zig_backend)) { 287 if (options.inherited.stack_protector) |x| { 288 if (x > 0) return error.StackProtectorUnsupportedByTarget; 289 } 290 break :sp 0; 291 } 292 293 if (options.global.any_c_source_files and options.global.c_frontend == .clang and 294 !target_util.clangSupportsStackProtector(target)) 295 { 296 if (options.inherited.stack_protector) |x| { 297 if (x > 0) return error.StackProtectorUnsupportedByTarget; 298 } 299 break :sp 0; 300 } 301 302 // This logic is checking for linking libc because otherwise our start code 303 // which is trying to set up TLS (i.e. the fs/gs registers) but the stack 304 // protection code depends on fs/gs registers being already set up. 305 // If we were able to annotate start code, or perhaps the entire std lib, 306 // as being exempt from stack protection checks, we could change this logic 307 // to supporting stack protection even when not linking libc. 308 // TODO file issue about this 309 if (!options.global.link_libc) { 310 if (options.inherited.stack_protector) |x| { 311 if (x > 0) return error.StackProtectorUnavailableWithoutLibC; 312 } 313 break :sp 0; 314 } 315 316 if (options.inherited.stack_protector) |x| break :sp x; 317 if (options.parent) |p| break :sp p.stack_protector; 318 if (!is_safe_mode) break :sp 0; 319 320 break :sp target_util.default_stack_protector_buffer_size; 321 }; 322 323 const no_builtin = b: { 324 if (options.inherited.no_builtin) |x| break :b x; 325 if (options.parent) |p| break :b p.no_builtin; 326 327 break :b target.cpu.arch.isBpf(); 328 }; 329 330 const patchable_function_entry = b: { 331 const x = options.inherited.patchable_function_entry; 332 if (x > 0) { 333 switch (zig_backend) { 334 .stage2_llvm, 335 .stage2_x86_64, 336 .stage2_aarch64, 337 .stage2_c, 338 .stage2_riscv64, 339 .stage2_loongarch, 340 => {}, 341 342 // Does not apply to this architecture. 343 .stage2_spirv, 344 .zsf_spork8, 345 .stage2_wasm, 346 => return error.PatchableFunctionEntryUnsupportedByBackend, 347 348 // Not implemented. 349 .stage2_sparc64, 350 .stage2_x86, 351 .stage2_arm, 352 .stage2_powerpc, 353 => return error.PatchableFunctionEntryUnsupportedByBackend, 354 355 .other, .stage1, _ => unreachable, 356 } 357 break :b x; 358 } 359 if (options.parent) |p| break :b p.patchable_function_entry; 360 break :b 0; 361 }; 362 363 const llvm_cpu_features: ?[*:0]const u8 = b: { 364 if (resolved_target.llvm_cpu_features) |x| break :b x; 365 if (!options.global.use_llvm) break :b null; 366 367 var buf = std.array_list.Managed(u8).init(arena); 368 var disabled_features = std.array_list.Managed(u8).init(arena); 369 defer disabled_features.deinit(); 370 371 // Append disabled features after enabled ones, so that their effects aren't overwritten. 372 for (target.cpu.arch.allFeaturesList()) |feature| { 373 if (feature.llvm_name) |llvm_name| { 374 // Ignore these until we figure out how to handle the concept of omitting features. 375 // See https://github.com/ziglang/zig/issues/23539 376 if (target_util.isDynamicAMDGCNFeature(target, feature)) continue; 377 378 if (target.cpu.arch.isPowerPC() and @as(std.Target.powerpc.Feature, @fromBackingInt(@intCast(feature.index))) == .@"64bit") continue; 379 if (target.cpu.arch.isX86() and @as(std.Target.x86.Feature, @fromBackingInt(@intCast(feature.index))) == .x32) continue; 380 381 var is_enabled = target.cpu.features.isEnabled(feature.index); 382 if (target.cpu.arch == .s390x and @as(std.Target.s390x.Feature, @fromBackingInt(@intCast(feature.index))) == .backchain) { 383 is_enabled = !omit_frame_pointer; 384 } 385 386 if (is_enabled) { 387 try buf.ensureUnusedCapacity(2 + llvm_name.len); 388 buf.appendAssumeCapacity('+'); 389 buf.appendSliceAssumeCapacity(llvm_name); 390 buf.appendAssumeCapacity(','); 391 } else { 392 try disabled_features.ensureUnusedCapacity(2 + llvm_name.len); 393 disabled_features.appendAssumeCapacity('-'); 394 disabled_features.appendSliceAssumeCapacity(llvm_name); 395 disabled_features.appendAssumeCapacity(','); 396 } 397 } 398 } 399 400 try buf.appendSlice(disabled_features.items); 401 if (buf.items.len == 0) break :b ""; 402 assert(std.mem.endsWith(u8, buf.items, ",")); 403 buf.items[buf.items.len - 1] = 0; 404 buf.shrinkAndFree(buf.items.len); 405 break :b buf.items[0 .. buf.items.len - 1 :0].ptr; 406 }; 407 408 const mod = try arena.create(Module); 409 mod.* = .{ 410 .root = options.paths.root, 411 .root_src_path = options.paths.root_src_path, 412 .fully_qualified_name = options.fully_qualified_name, 413 .resolved_target = .{ 414 .result = target.*, 415 .is_native_os = resolved_target.is_native_os, 416 .is_native_abi = resolved_target.is_native_abi, 417 .is_explicit_dynamic_linker = resolved_target.is_explicit_dynamic_linker, 418 .llvm_cpu_features = llvm_cpu_features, 419 }, 420 .optimize_mode = optimize_mode, 421 .single_threaded = single_threaded, 422 .error_tracing = error_tracing, 423 .valgrind = valgrind, 424 .pic = pic, 425 .strip = strip, 426 .omit_frame_pointer = omit_frame_pointer, 427 .stack_check = stack_check, 428 .stack_protector = stack_protector, 429 .code_model = code_model, 430 .red_zone = red_zone, 431 .sanitize_c = sanitize_c, 432 .sanitize_thread = sanitize_thread, 433 .fuzz = fuzz, 434 .unwind_tables = unwind_tables, 435 .cc_argv = options.cc_argv, 436 .no_builtin = no_builtin, 437 .patchable_function_entry = patchable_function_entry, 438 }; 439 return mod; 440 } 441 442 /// All fields correspond to `CreateOptions`. 443 pub const LimitedOptions = struct { 444 root: Compilation.Path, 445 root_src_path: []const u8, 446 fully_qualified_name: []const u8, 447 }; 448 449 /// This one can only be used if the Module will only be used for AstGen and earlier in 450 /// the pipeline. Illegal behavior occurs if a limited module touches Sema. 451 pub fn createLimited(gpa: Allocator, options: LimitedOptions) Allocator.Error!*Module { 452 const mod = try gpa.create(Module); 453 mod.* = .{ 454 .root = options.root, 455 .root_src_path = options.root_src_path, 456 .fully_qualified_name = options.fully_qualified_name, 457 458 .resolved_target = undefined, 459 .optimize_mode = undefined, 460 .code_model = undefined, 461 .single_threaded = undefined, 462 .error_tracing = undefined, 463 .valgrind = undefined, 464 .pic = undefined, 465 .strip = undefined, 466 .omit_frame_pointer = undefined, 467 .stack_check = undefined, 468 .stack_protector = undefined, 469 .red_zone = undefined, 470 .sanitize_c = undefined, 471 .sanitize_thread = undefined, 472 .fuzz = undefined, 473 .unwind_tables = undefined, 474 .cc_argv = undefined, 475 .no_builtin = undefined, 476 .patchable_function_entry = undefined, 477 }; 478 return mod; 479 } 480 481 /// Does not ensure that the module's root directory exists on-disk; see `Builtin.updateFileOnDisk` for that task. 482 pub fn createBuiltin(arena: Allocator, opts: Builtin, dirs: std.zig.Directories) Allocator.Error!*Module { 483 const sub_path = "b" ++ std.fs.path.sep_str ++ Cache.binToHex(opts.hash()); 484 const new = try arena.create(Module); 485 new.* = .{ 486 .root = try .fromRoot(arena, dirs, .global_cache, sub_path), 487 .root_src_path = "builtin.zig", 488 .fully_qualified_name = "builtin", 489 .resolved_target = .{ 490 .result = opts.target, 491 // These values are not in `opts`, but do not matter because `builtin.zig` contains no runtime code. 492 .is_native_os = false, 493 .is_native_abi = false, 494 .is_explicit_dynamic_linker = false, 495 .llvm_cpu_features = null, 496 }, 497 .optimize_mode = opts.optimize_mode, 498 .single_threaded = opts.single_threaded, 499 .error_tracing = opts.error_tracing, 500 .valgrind = opts.valgrind, 501 .pic = opts.pic, 502 .strip = opts.strip, 503 .omit_frame_pointer = opts.omit_frame_pointer, 504 .code_model = opts.code_model, 505 .sanitize_thread = opts.sanitize_thread, 506 .fuzz = opts.fuzz, 507 .unwind_tables = opts.unwind_tables, 508 .cc_argv = &.{}, 509 // These values are not in `opts`, but do not matter because `builtin.zig` contains no runtime code. 510 .stack_check = false, 511 .stack_protector = 0, 512 .red_zone = false, 513 .sanitize_c = .off, 514 .no_builtin = false, 515 .patchable_function_entry = 0, 516 }; 517 return new; 518 } 519 520 /// Returns the `Builtin` which forms the contents of `@import("builtin")` for this module. 521 pub fn getBuiltinOptions(m: Module, global: Compilation.Config) Builtin { 522 assert(global.have_zcu); 523 return .{ 524 .target = m.resolved_target.result, 525 .zig_backend = target_util.zigBackend(&m.resolved_target.result, global.use_llvm), 526 .output_mode = global.output_mode, 527 .link_mode = global.link_mode, 528 .unwind_tables = m.unwind_tables, 529 .is_test = global.is_test, 530 .single_threaded = m.single_threaded, 531 .link_libc = global.link_libc, 532 .link_libcpp = global.link_libcpp, 533 .optimize_mode = m.optimize_mode, 534 .error_tracing = m.error_tracing, 535 .valgrind = m.valgrind, 536 .sanitize_thread = m.sanitize_thread, 537 .fuzz = m.fuzz, 538 .pic = m.pic, 539 .pie = global.pie, 540 .strip = m.strip, 541 .code_model = m.code_model, 542 .omit_frame_pointer = m.omit_frame_pointer, 543 .wasi_exec_model = global.wasi_exec_model, 544 }; 545 } 546