| ... | ... | @@ -34,7 +34,6 @@ any_error_tracing: bool, |
| 34 | 34 | any_sanitize_thread: bool, |
| 35 | 35 | any_sanitize_c: std.zig.SanitizeC, |
| 36 | 36 | any_fuzz: bool, |
| 37 | | pie: bool, |
| 38 | 37 | /// If this is true then linker code is responsible for making an LLVM IR |
| 39 | 38 | /// Module, outputting it to an object file, and then linking that together |
| 40 | 39 | /// with link options and other objects. Otherwise (depending on `use_lld`) |
| ... | ... | @@ -48,8 +47,9 @@ use_lib_llvm: bool, |
| 48 | 47 | /// and updates the final binary. |
| 49 | 48 | use_lld: bool, |
| 50 | 49 | c_frontend: CFrontend, |
| 51 | | lto: std.zig.LtoMode, |
| 52 | 50 | use_new_linker: bool, |
| 51 | pie: bool, |
| 52 | lto: std.zig.LtoMode, |
| 53 | 53 | incremental: bool, |
| 54 | 54 | /// WASI-only. Type of WASI execution model ("command" or "reactor"). |
| 55 | 55 | /// Always set to `command` for non-WASI targets. |
| ... | ... | @@ -100,13 +100,13 @@ pub const Options = struct { |
| 100 | 100 | link_libc: ?bool = null, |
| 101 | 101 | link_libcpp: ?bool = null, |
| 102 | 102 | link_libunwind: ?bool = null, |
| 103 | | pie: ?bool = null, |
| 104 | 103 | use_llvm: ?bool = null, |
| 105 | 104 | use_lib_llvm: ?bool = null, |
| 106 | 105 | use_lld: ?bool = null, |
| 107 | 106 | use_clang: ?bool = null, |
| 108 | | lto: ?std.zig.LtoMode = null, |
| 109 | 107 | use_new_linker: ?bool = null, |
| 108 | pie: ?bool = null, |
| 109 | lto: ?std.zig.LtoMode = null, |
| 110 | 110 | incremental: bool = false, |
| 111 | 111 | /// WASI-only. Type of WASI execution model ("command" or "reactor"). |
| 112 | 112 | wasi_exec_model: ?std.builtin.WasiExecModel = null, |
| ... | ... | @@ -324,33 +324,6 @@ pub fn resolve(options: Options) ResolveError!Config { |
| 324 | 324 | break :b !import_memory; |
| 325 | 325 | }; |
| 326 | 326 | |
| 327 | | const pie: bool = b: { |
| 328 | | switch (options.output_mode) { |
| 329 | | .Exe => if (target.os.tag == .fuchsia or |
| 330 | | (target.abi.isAndroid() and link_mode == .dynamic)) |
| 331 | | { |
| 332 | | if (options.pie == false) return error.TargetRequiresPie; |
| 333 | | break :b true; |
| 334 | | }, |
| 335 | | .Lib => if (link_mode == .dynamic) { |
| 336 | | if (options.pie == true) return error.DynamicLibraryPrecludesPie; |
| 337 | | break :b false; |
| 338 | | }, |
| 339 | | .Obj => {}, |
| 340 | | } |
| 341 | | if (options.any_sanitize_thread) { |
| 342 | | if (options.pie == false) return error.SanitizeThreadRequiresPie; |
| 343 | | break :b true; |
| 344 | | } |
| 345 | | if (options.pie) |pie| break :b pie; |
| 346 | | break :b if (options.output_mode == .Exe) switch (target.os.tag) { |
| 347 | | .fuchsia, |
| 348 | | .openbsd, |
| 349 | | => true, |
| 350 | | else => target.os.tag.isDarwin(), |
| 351 | | } else false; |
| 352 | | }; |
| 353 | | |
| 354 | 327 | const is_dyn_lib = switch (options.output_mode) { |
| 355 | 328 | .Obj, .Exe => false, |
| 356 | 329 | .Lib => link_mode == .dynamic, |
| ... | ... | @@ -405,6 +378,7 @@ pub fn resolve(options: Options) ResolveError!Config { |
| 405 | 378 | // we are confident in the robustness of the backend. |
| 406 | 379 | break :b !target_util.selfHostedBackendIsAsRobustAsLlvm(target); |
| 407 | 380 | }; |
| 381 | const backend = target_util.zigBackend(target, use_llvm); |
| 408 | 382 | |
| 409 | 383 | if (options.emit_bin and options.have_zcu) { |
| 410 | 384 | if (!use_lib_llvm and use_llvm) { |
| ... | ... | @@ -413,7 +387,7 @@ pub fn resolve(options: Options) ResolveError!Config { |
| 413 | 387 | return error.EmittingBinaryRequiresLlvmLibrary; |
| 414 | 388 | } |
| 415 | 389 | |
| 416 | | if (target_util.zigBackend(target, use_llvm) == .other) { |
| 390 | if (backend == .other) { |
| 417 | 391 | // There is no compiler backend available for this target. |
| 418 | 392 | return error.ZigLacksTargetSupport; |
| 419 | 393 | } |
| ... | ... | @@ -451,26 +425,13 @@ pub fn resolve(options: Options) ResolveError!Config { |
| 451 | 425 | break :b use_llvm; |
| 452 | 426 | }; |
| 453 | 427 | |
| 454 | | const lto: std.zig.LtoMode = b: { |
| 455 | | if (!use_lld) { |
| 456 | | // zig ld LTO support is tracked by |
| 457 | | // https://github.com/ziglang/zig/issues/8680 |
| 458 | | if (options.lto != null and options.lto != .none) return error.LtoRequiresLld; |
| 459 | | break :b .none; |
| 460 | | } |
| 461 | | |
| 462 | | if (options.lto) |x| break :b x; |
| 463 | | |
| 464 | | break :b .none; |
| 465 | | }; |
| 466 | | |
| 467 | 428 | const use_new_linker = b: { |
| 468 | 429 | if (use_lld) { |
| 469 | 430 | if (options.use_new_linker == true) return error.NewLinkerIncompatibleWithLld; |
| 470 | 431 | break :b false; |
| 471 | 432 | } |
| 472 | 433 | |
| 473 | | if (!target_util.hasNewLinkerSupport(target.ofmt)) { |
| 434 | if (!target_util.hasNewLinkerSupport(target.ofmt, backend)) { |
| 474 | 435 | if (options.use_new_linker == true) return error.NewLinkerIncompatibleObjectFormat; |
| 475 | 436 | break :b false; |
| 476 | 437 | } |
| ... | ... | @@ -480,6 +441,46 @@ pub fn resolve(options: Options) ResolveError!Config { |
| 480 | 441 | break :b options.incremental; |
| 481 | 442 | }; |
| 482 | 443 | |
| 444 | const pie = b: { |
| 445 | switch (options.output_mode) { |
| 446 | .Exe => if (target.os.tag == .fuchsia or |
| 447 | (target.abi.isAndroid() and link_mode == .dynamic)) |
| 448 | { |
| 449 | if (options.pie == false) return error.TargetRequiresPie; |
| 450 | break :b true; |
| 451 | }, |
| 452 | .Lib => if (link_mode == .dynamic) { |
| 453 | if (options.pie == true) return error.DynamicLibraryPrecludesPie; |
| 454 | break :b false; |
| 455 | }, |
| 456 | .Obj => {}, |
| 457 | } |
| 458 | if (options.any_sanitize_thread) { |
| 459 | if (options.pie == false) return error.SanitizeThreadRequiresPie; |
| 460 | break :b true; |
| 461 | } |
| 462 | if (options.pie) |pie| break :b pie; |
| 463 | break :b if (options.output_mode == .Exe) switch (target.os.tag) { |
| 464 | .fuchsia, |
| 465 | .openbsd, |
| 466 | => true, |
| 467 | else => target.os.tag.isDarwin(), |
| 468 | } else false; |
| 469 | }; |
| 470 | |
| 471 | const lto: std.zig.LtoMode = b: { |
| 472 | if (!use_lld) { |
| 473 | // zig ld LTO support is tracked by |
| 474 | // https://github.com/ziglang/zig/issues/8680 |
| 475 | if (options.lto != null and options.lto != .none) return error.LtoRequiresLld; |
| 476 | break :b .none; |
| 477 | } |
| 478 | |
| 479 | if (options.lto) |x| break :b x; |
| 480 | |
| 481 | break :b .none; |
| 482 | }; |
| 483 | |
| 483 | 484 | const root_strip = b: { |
| 484 | 485 | if (options.root_strip) |x| break :b x; |
| 485 | 486 | if (root_optimize_mode == .ReleaseSmall) break :b true; |
| ... | ... | @@ -501,7 +502,6 @@ pub fn resolve(options: Options) ResolveError!Config { |
| 501 | 502 | }; |
| 502 | 503 | }; |
| 503 | 504 | |
| 504 | | const backend = target_util.zigBackend(target, use_llvm); |
| 505 | 505 | const backend_supports_error_tracing = target_util.backendSupportsFeature(backend, .error_return_trace); |
| 506 | 506 | |
| 507 | 507 | const root_error_tracing = b: { |
| ... | ... | @@ -551,9 +551,9 @@ pub fn resolve(options: Options) ResolveError!Config { |
| 551 | 551 | .any_fuzz = options.any_fuzz, |
| 552 | 552 | .san_cov_trace_pc_guard = options.san_cov_trace_pc_guard, |
| 553 | 553 | .root_error_tracing = root_error_tracing, |
| 554 | .use_new_linker = use_new_linker, |
| 554 | 555 | .pie = pie, |
| 555 | 556 | .lto = lto, |
| 556 | | .use_new_linker = use_new_linker, |
| 557 | 557 | .incremental = options.incremental, |
| 558 | 558 | .import_memory = import_memory, |
| 559 | 559 | .export_memory = export_memory, |