aboutsummaryrefslogtreecommitdiff
path: root/src/target.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2023-12-10 15:25:06 -0700
committerAndrew Kelley <andrew@ziglang.org>2024-01-01 17:51:18 -0700
commit12de7e3472cb2292e75578d33a8b8cc91f1ef0b0 (patch)
tree77d38282ed0b8cc4911df38b702c09762b52c681 /src/target.zig
parentb92e30ff0bd2b77a486451b21d17666a311407f3 (diff)
downloadzig-12de7e3472cb2292e75578d33a8b8cc91f1ef0b0.tar.gz
zig-12de7e3472cb2292e75578d33a8b8cc91f1ef0b0.zip
WIP: move many global settings to become per-Module
Much of the logic from Compilation.create() is extracted into Compilation.Config.resolve() which accepts many optional settings and produces concrete settings. This separate step is needed by API users of Compilation so that they can pass the resolved global settings to the Module creation function, which itself needs to resolve per-Module settings. Since the target and other things are no longer global settings, I did not want them stored in link.File (in the `options` field). That options field was already a kludge; those options should be resolved into concrete settings. This commit also starts to work on that, deleting link.Options, moving the fields into Compilation and ObjectFormat-specific structs instead. Some fields were ephemeral and should not have been stored at all, such as symbol_size_hint. The link.File object of Compilation is now a `?*link.File` and `null` when -fno-emit-bin is passed. It is now arena-allocated along with Compilation itself, avoiding some messy cleanup code that was there before. On the command line, it is now possible to configure the standard library itself by using `--mod std` just like any other module. This meant that the CLI needed to create the standard library module rather than having Compilation create it. There are a lot of changes in this commit and it's still not done. I didn't realize how quickly this changeset was going to balloon out of control, and there are still many lines that need to be changed before it even compiles successfully. * introduce std.Build.Cache.HashHelper.oneShot * add error_tracing to std.Build.Module * extract build.zig file generation into src/Builtin.zig * each CSourceFile and RcSourceFile now has a Module owner, which determines some of the C compiler flags.
Diffstat (limited to 'src/target.zig')
-rw-r--r--src/target.zig61
1 files changed, 54 insertions, 7 deletions
diff --git a/src/target.zig b/src/target.zig
index 624a67d043..f610e55fb0 100644
--- a/src/target.zig
+++ b/src/target.zig
@@ -3,6 +3,8 @@ const Type = @import("type.zig").Type;
const AddressSpace = std.builtin.AddressSpace;
const Alignment = @import("InternPool.zig").Alignment;
+pub const default_stack_protector_buffer_size = 4;
+
pub const ArchOsAbi = struct {
arch: std.Target.Cpu.Arch,
os: std.Target.Os.Tag,
@@ -204,11 +206,18 @@ pub fn supports_fpic(target: std.Target) bool {
return target.os.tag != .windows and target.os.tag != .uefi;
}
-pub fn isSingleThreaded(target: std.Target) bool {
+pub fn alwaysSingleThreaded(target: std.Target) bool {
_ = target;
return false;
}
+pub fn defaultSingleThreaded(target: std.Target) bool {
+ return switch (target.cpu.arch) {
+ .wasm32, .wasm64 => true,
+ else => false,
+ };
+}
+
/// Valgrind supports more, but Zig does not support them yet.
pub fn hasValgrindSupport(target: std.Target) bool {
switch (target.cpu.arch) {
@@ -375,12 +384,17 @@ pub fn classifyCompilerRtLibName(target: std.Target, name: []const u8) CompilerR
}
pub fn hasDebugInfo(target: std.Target) bool {
- if (target.cpu.arch.isNvptx()) {
- // TODO: not sure how to test "ptx >= 7.5" with featureset
- return std.Target.nvptx.featureSetHas(target.cpu.features, .ptx75);
- }
-
- return true;
+ return switch (target.cpu.arch) {
+ .nvptx, .nvptx64 => std.Target.nvptx.featureSetHas(target.cpu.features, .ptx75) or
+ std.Target.nvptx.featureSetHas(target.cpu.features, .ptx76) or
+ std.Target.nvptx.featureSetHas(target.cpu.features, .ptx77) or
+ std.Target.nvptx.featureSetHas(target.cpu.features, .ptx78) or
+ std.Target.nvptx.featureSetHas(target.cpu.features, .ptx80) or
+ std.Target.nvptx.featureSetHas(target.cpu.features, .ptx81),
+ .wasm32, .wasm64 => false,
+ .bpfel, .bpfeb => false,
+ else => true,
+ };
}
pub fn defaultCompilerRtOptimizeMode(target: std.Target) std.builtin.OptimizeMode {
@@ -619,3 +633,36 @@ pub fn fnCallConvAllowsZigTypes(target: std.Target, cc: std.builtin.CallingConve
else => false,
};
}
+
+pub fn zigBackend(target: std.Target, use_llvm: bool) std.builtin.CompilerBackend {
+ if (use_llvm) return .stage2_llvm;
+ if (target.ofmt == .c) return .stage2_c;
+ return switch (target.cpu.arch) {
+ .wasm32, .wasm64 => std.builtin.CompilerBackend.stage2_wasm,
+ .arm, .armeb, .thumb, .thumbeb => .stage2_arm,
+ .x86_64 => .stage2_x86_64,
+ .x86 => .stage2_x86,
+ .aarch64, .aarch64_be, .aarch64_32 => .stage2_aarch64,
+ .riscv64 => .stage2_riscv64,
+ .sparc64 => .stage2_sparc64,
+ .spirv64 => .stage2_spirv64,
+ else => .other,
+ };
+}
+
+pub fn defaultEntrySymbolName(
+ target: std.Target,
+ /// May be `undefined` when `target` is not WASI.
+ wasi_exec_model: std.builtin.WasiExecModel,
+) ?[]const u8 {
+ return switch (target.ofmt) {
+ .coff => "wWinMainCRTStartup",
+ .macho => "_main",
+ .elf, .plan9 => "_start",
+ .wasm => switch (wasi_exec_model) {
+ .reactor => "_initialize",
+ .command => "_start",
+ },
+ else => null,
+ };
+}