authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-04-12 16:43:50-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-04-15 19:06:39-07:00
log429cd2b5dd27bec15a4a3351114ce1bcd12d8d01
tree6f0dda8c4a63d7944046bf9a580e20ba304de814
parenta4bb7c8bb17a4ac692401946df6b9f4cc3e5b1b2

std: change `@import("builtin")` to `std.builtin`


86 files changed, 264 insertions(+), 269 deletions(-)

lib/std/Thread/AutoResetEvent.zig+1-1
...@@ -32,7 +32,7 @@...@@ -32,7 +32,7 @@
32state: usize = UNSET,32state: usize = UNSET,
3333
34const std = @import("../std.zig");34const std = @import("../std.zig");
35const builtin = @import("builtin");35const builtin = std.builtin;
36const testing = std.testing;36const testing = std.testing;
37const assert = std.debug.assert;37const assert = std.debug.assert;
38const StaticResetEvent = std.Thread.StaticResetEvent;38const StaticResetEvent = std.Thread.StaticResetEvent;
lib/std/array_hash_map.zig+1-1
...@@ -14,7 +14,7 @@ const trait = meta.trait;...@@ -14,7 +14,7 @@ const trait = meta.trait;
14const autoHash = std.hash.autoHash;14const autoHash = std.hash.autoHash;
15const Wyhash = std.hash.Wyhash;15const Wyhash = std.hash.Wyhash;
16const Allocator = mem.Allocator;16const Allocator = mem.Allocator;
17const builtin = @import("builtin");17const builtin = std.builtin;
18const hash_map = @This();18const hash_map = @This();
1919
20pub fn AutoArrayHashMap(comptime K: type, comptime V: type) type {20pub fn AutoArrayHashMap(comptime K: type, comptime V: type) type {
lib/std/atomic/queue.zig+1-1
...@@ -4,7 +4,7 @@...@@ -4,7 +4,7 @@
4// The MIT license requires this copyright notice to be included in all copies4// The MIT license requires this copyright notice to be included in all copies
5// and substantial portions of the software.5// and substantial portions of the software.
6const std = @import("../std.zig");6const std = @import("../std.zig");
7const builtin = @import("builtin");7const builtin = std.builtin;
8const assert = std.debug.assert;8const assert = std.debug.assert;
9const expect = std.testing.expect;9const expect = std.testing.expect;
1010
lib/std/atomic/stack.zig+1-1
...@@ -4,7 +4,7 @@...@@ -4,7 +4,7 @@
4// The MIT license requires this copyright notice to be included in all copies4// The MIT license requires this copyright notice to be included in all copies
5// and substantial portions of the software.5// and substantial portions of the software.
6const assert = std.debug.assert;6const assert = std.debug.assert;
7const builtin = @import("builtin");7const builtin = std.builtin;
8const expect = std.testing.expect;8const expect = std.testing.expect;
99
10/// Many reader, many writer, non-allocating, thread-safe10/// Many reader, many writer, non-allocating, thread-safe
lib/std/build.zig+2-2
...@@ -1409,7 +1409,7 @@ pub const LibExeObjStep = struct {...@@ -1409,7 +1409,7 @@ pub const LibExeObjStep = struct {
14091409
1410 red_zone: ?bool = null,1410 red_zone: ?bool = null,
14111411
1412 subsystem: ?builtin.SubSystem = null,1412 subsystem: ?std.Target.SubSystem = null,
14131413
1414 /// Overrides the default stack size1414 /// Overrides the default stack size
1415 stack_size: ?u64 = null,1415 stack_size: ?u64 = null,
...@@ -1961,7 +1961,7 @@ pub const LibExeObjStep = struct {...@@ -1961,7 +1961,7 @@ pub const LibExeObjStep = struct {
1961 },1961 },
1962 std.builtin.Version => {1962 std.builtin.Version => {
1963 out.print(1963 out.print(
1964 \\pub const {}: @import("builtin").Version = .{{1964 \\pub const {}: @import("std").builtin.Version = .{{
1965 \\ .major = {d},1965 \\ .major = {d},
1966 \\ .minor = {d},1966 \\ .minor = {d},
1967 \\ .patch = {d},1967 \\ .patch = {d},
lib/std/builtin.zig+28-27
...@@ -3,39 +3,40 @@...@@ -3,39 +3,40 @@
3// This file is part of [zig](https://ziglang.org/), which is MIT licensed.3// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
4// The MIT license requires this copyright notice to be included in all copies4// The MIT license requires this copyright notice to be included in all copies
5// and substantial portions of the software.5// and substantial portions of the software.
6pub usingnamespace @import("builtin");6const builtin = @import("builtin");
77
8/// Deprecated: use `std.Target`.8// These are all deprecated.
9pub const Target = std.Target;9pub const zig_version = builtin.zig_version;
1010pub const zig_is_stage2 = builtin.zig_is_stage2;
11/// Deprecated: use `std.Target.Os`.11pub const output_mode = builtin.output_mode;
12pub const Os = std.Target.Os;12pub const link_mode = builtin.link_mode;
1313pub const is_test = builtin.is_test;
14/// Deprecated: use `std.Target.Cpu.Arch`.14pub const single_threaded = builtin.single_threaded;
15pub const Arch = std.Target.Cpu.Arch;15pub const abi = builtin.abi;
1616pub const cpu = builtin.cpu;
17/// Deprecated: use `std.Target.Abi`.17pub const os = builtin.os;
18pub const Abi = std.Target.Abi;18pub const target = builtin.target;
1919pub const object_format = builtin.object_format;
20/// Deprecated: use `std.Target.ObjectFormat`.20pub const mode = builtin.mode;
21pub const ObjectFormat = std.Target.ObjectFormat;21pub const link_libc = builtin.link_libc;
2222pub const link_libcpp = builtin.link_libcpp;
23/// Deprecated: use `std.Target.SubSystem`.23pub const have_error_return_tracing = builtin.have_error_return_tracing;
24pub const SubSystem = std.Target.SubSystem;24pub const valgrind_support = builtin.valgrind_support;
2525pub const position_independent_code = builtin.position_independent_code;
26/// Deprecated: use `std.Target.Cpu`.26pub const position_independent_executable = builtin.position_independent_executable;
27pub const Cpu = std.Target.Cpu;27pub const strip_debug_info = builtin.strip_debug_info;
28pub const code_model = builtin.code_model;
2829
29/// `explicit_subsystem` is missing when the subsystem is automatically detected,30/// `explicit_subsystem` is missing when the subsystem is automatically detected,
30/// so Zig standard library has the subsystem detection logic here. This should generally be31/// so Zig standard library has the subsystem detection logic here. This should generally be
31/// used rather than `explicit_subsystem`.32/// used rather than `explicit_subsystem`.
32/// On non-Windows targets, this is `null`.33/// On non-Windows targets, this is `null`.
33pub const subsystem: ?SubSystem = blk: {34pub const subsystem: ?std.Target.SubSystem = blk: {
34 if (@hasDecl(@This(), "explicit_subsystem")) break :blk explicit_subsystem;35 if (@hasDecl(builtin, "explicit_subsystem")) break :blk explicit_subsystem;
35 switch (os.tag) {36 switch (os.tag) {
36 .windows => {37 .windows => {
37 if (is_test) {38 if (is_test) {
38 break :blk SubSystem.Console;39 break :blk std.Target.SubSystem.Console;
39 }40 }
40 if (@hasDecl(root, "main") or41 if (@hasDecl(root, "main") or
41 @hasDecl(root, "WinMain") or42 @hasDecl(root, "WinMain") or
...@@ -43,9 +44,9 @@ pub const subsystem: ?SubSystem = blk: {...@@ -43,9 +44,9 @@ pub const subsystem: ?SubSystem = blk: {
43 @hasDecl(root, "WinMainCRTStartup") or44 @hasDecl(root, "WinMainCRTStartup") or
44 @hasDecl(root, "wWinMainCRTStartup"))45 @hasDecl(root, "wWinMainCRTStartup"))
45 {46 {
46 break :blk SubSystem.Windows;47 break :blk std.Target.SubSystem.Windows;
47 } else {48 } else {
48 break :blk SubSystem.Console;49 break :blk std.Target.SubSystem.Console;
49 }50 }
50 },51 },
51 else => break :blk null,52 else => break :blk null,
lib/std/c/linux.zig+8-6
...@@ -3,12 +3,14 @@...@@ -3,12 +3,14 @@
3// This file is part of [zig](https://ziglang.org/), which is MIT licensed.3// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
4// The MIT license requires this copyright notice to be included in all copies4// The MIT license requires this copyright notice to be included in all copies
5// and substantial portions of the software.5// and substantial portions of the software.
6const builtin = @import("builtin");
7const std = @import("../std.zig");6const std = @import("../std.zig");
8const maxInt = std.math.maxInt;7const maxInt = std.math.maxInt;
8const abi = std.Target.current.abi;
9const arch = std.Target.current.cpu.arch;
10const os_tag = std.Target.current.os.tag;
9usingnamespace std.c;11usingnamespace std.c;
1012
11pub const _errno = switch (builtin.abi) {13pub const _errno = switch (abi) {
12 .android => struct {14 .android => struct {
13 extern "c" var __errno: c_int;15 extern "c" var __errno: c_int;
14 fn getErrno() *c_int {16 fn getErrno() *c_int {
...@@ -124,7 +126,7 @@ pub const pthread_mutex_t = extern struct {...@@ -124,7 +126,7 @@ pub const pthread_mutex_t = extern struct {
124pub const pthread_cond_t = extern struct {126pub const pthread_cond_t = extern struct {
125 size: [__SIZEOF_PTHREAD_COND_T]u8 align(@alignOf(usize)) = [_]u8{0} ** __SIZEOF_PTHREAD_COND_T,127 size: [__SIZEOF_PTHREAD_COND_T]u8 align(@alignOf(usize)) = [_]u8{0} ** __SIZEOF_PTHREAD_COND_T,
126};128};
127pub const pthread_rwlock_t = switch (std.builtin.abi) {129pub const pthread_rwlock_t = switch (abi) {
128 .android => switch (@sizeOf(usize)) {130 .android => switch (@sizeOf(usize)) {
129 4 => extern struct {131 4 => extern struct {
130 lock: std.c.pthread_mutex_t = std.c.PTHREAD_MUTEX_INITIALIZER,132 lock: std.c.pthread_mutex_t = std.c.PTHREAD_MUTEX_INITIALIZER,
...@@ -155,11 +157,11 @@ pub const sem_t = extern struct {...@@ -155,11 +157,11 @@ pub const sem_t = extern struct {
155};157};
156158
157const __SIZEOF_PTHREAD_COND_T = 48;159const __SIZEOF_PTHREAD_COND_T = 48;
158const __SIZEOF_PTHREAD_MUTEX_T = if (builtin.os.tag == .fuchsia) 40 else switch (builtin.abi) {160const __SIZEOF_PTHREAD_MUTEX_T = if (os_tag == .fuchsia) 40 else switch (abi) {
159 .musl, .musleabi, .musleabihf => if (@sizeOf(usize) == 8) 40 else 24,161 .musl, .musleabi, .musleabihf => if (@sizeOf(usize) == 8) 40 else 24,
160 .gnu, .gnuabin32, .gnuabi64, .gnueabi, .gnueabihf, .gnux32 => switch (builtin.arch) {162 .gnu, .gnuabin32, .gnuabi64, .gnueabi, .gnueabihf, .gnux32 => switch (arch) {
161 .aarch64 => 48,163 .aarch64 => 48,
162 .x86_64 => if (builtin.abi == .gnux32) 40 else 32,164 .x86_64 => if (abi == .gnux32) 40 else 32,
163 .mips64, .powerpc64, .powerpc64le, .sparcv9 => 40,165 .mips64, .powerpc64, .powerpc64le, .sparcv9 => 40,
164 else => if (@sizeOf(usize) == 8) 40 else 24,166 else => if (@sizeOf(usize) == 8) 40 else 24,
165 },167 },
lib/std/child_process.zig+1-1
...@@ -15,7 +15,7 @@ const windows = os.windows;...@@ -15,7 +15,7 @@ const windows = os.windows;
15const mem = std.mem;15const mem = std.mem;
16const debug = std.debug;16const debug = std.debug;
17const BufMap = std.BufMap;17const BufMap = std.BufMap;
18const builtin = @import("builtin");18const builtin = std.builtin;
19const Os = builtin.Os;19const Os = builtin.Os;
20const TailQueue = std.TailQueue;20const TailQueue = std.TailQueue;
21const maxInt = std.math.maxInt;21const maxInt = std.math.maxInt;
lib/std/coff.zig+1-1
...@@ -3,7 +3,7 @@...@@ -3,7 +3,7 @@
3// This file is part of [zig](https://ziglang.org/), which is MIT licensed.3// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
4// The MIT license requires this copyright notice to be included in all copies4// The MIT license requires this copyright notice to be included in all copies
5// and substantial portions of the software.5// and substantial portions of the software.
6const builtin = @import("builtin");6const builtin = std.builtin;
7const std = @import("std.zig");7const std = @import("std.zig");
8const io = std.io;8const io = std.io;
9const mem = std.mem;9const mem = std.mem;
lib/std/cstr.zig+1-1
...@@ -4,7 +4,7 @@...@@ -4,7 +4,7 @@
4// The MIT license requires this copyright notice to be included in all copies4// The MIT license requires this copyright notice to be included in all copies
5// and substantial portions of the software.5// and substantial portions of the software.
6const std = @import("std.zig");6const std = @import("std.zig");
7const builtin = @import("builtin");7const builtin = std.builtin;
8const debug = std.debug;8const debug = std.debug;
9const mem = std.mem;9const mem = std.mem;
10const testing = std.testing;10const testing = std.testing;
lib/std/debug.zig+25-22
...@@ -21,6 +21,9 @@ const root = @import("root");...@@ -21,6 +21,9 @@ const root = @import("root");
21const maxInt = std.math.maxInt;21const maxInt = std.math.maxInt;
22const File = std.fs.File;22const File = std.fs.File;
23const windows = std.os.windows;23const windows = std.os.windows;
24const native_arch = std.Target.current.cpu.arch;
25const native_os = std.Target.current.os.tag;
26const native_endian = native_arch.endian();
2427
25pub const runtime_safety = switch (builtin.mode) {28pub const runtime_safety = switch (builtin.mode) {
26 .Debug, .ReleaseSafe => true,29 .Debug, .ReleaseSafe => true,
...@@ -90,7 +93,7 @@ pub fn detectTTYConfig() TTY.Config {...@@ -90,7 +93,7 @@ pub fn detectTTYConfig() TTY.Config {
90 const stderr_file = io.getStdErr();93 const stderr_file = io.getStdErr();
91 if (stderr_file.supportsAnsiEscapeCodes()) {94 if (stderr_file.supportsAnsiEscapeCodes()) {
92 return .escape_codes;95 return .escape_codes;
93 } else if (builtin.os.tag == .windows and stderr_file.isTty()) {96 } else if (native_os == .windows and stderr_file.isTty()) {
94 return .windows_api;97 return .windows_api;
95 } else {98 } else {
96 return .no_color;99 return .no_color;
...@@ -148,7 +151,7 @@ pub fn dumpStackTraceFromBase(bp: usize, ip: usize) void {...@@ -148,7 +151,7 @@ pub fn dumpStackTraceFromBase(bp: usize, ip: usize) void {
148/// chopping off the irrelevant frames and shifting so that the returned addresses pointer151/// chopping off the irrelevant frames and shifting so that the returned addresses pointer
149/// equals the passed in addresses pointer.152/// equals the passed in addresses pointer.
150pub fn captureStackTrace(first_address: ?usize, stack_trace: *builtin.StackTrace) void {153pub fn captureStackTrace(first_address: ?usize, stack_trace: *builtin.StackTrace) void {
151 if (builtin.os.tag == .windows) {154 if (native_os == .windows) {
152 const addrs = stack_trace.instruction_addresses;155 const addrs = stack_trace.instruction_addresses;
153 const u32_addrs_len = @intCast(u32, addrs.len);156 const u32_addrs_len = @intCast(u32, addrs.len);
154 const first_addr = first_address orelse {157 const first_addr = first_address orelse {
...@@ -226,7 +229,7 @@ pub fn assert(ok: bool) void {...@@ -226,7 +229,7 @@ pub fn assert(ok: bool) void {
226pub fn panic(comptime format: []const u8, args: anytype) noreturn {229pub fn panic(comptime format: []const u8, args: anytype) noreturn {
227 @setCold(true);230 @setCold(true);
228 // TODO: remove conditional once wasi / LLVM defines __builtin_return_address231 // TODO: remove conditional once wasi / LLVM defines __builtin_return_address
229 const first_trace_addr = if (builtin.os.tag == .wasi) null else @returnAddress();232 const first_trace_addr = if (native_os == .wasi) null else @returnAddress();
230 panicExtra(null, first_trace_addr, format, args);233 panicExtra(null, first_trace_addr, format, args);
231}234}
232235
...@@ -343,25 +346,25 @@ pub const StackIterator = struct {...@@ -343,25 +346,25 @@ pub const StackIterator = struct {
343 }346 }
344347
345 // Offset of the saved BP wrt the frame pointer.348 // Offset of the saved BP wrt the frame pointer.
346 const fp_offset = if (builtin.arch.isRISCV())349 const fp_offset = if (native_arch.isRISCV())
347 // On RISC-V the frame pointer points to the top of the saved register350 // On RISC-V the frame pointer points to the top of the saved register
348 // area, on pretty much every other architecture it points to the stack351 // area, on pretty much every other architecture it points to the stack
349 // slot where the previous frame pointer is saved.352 // slot where the previous frame pointer is saved.
350 2 * @sizeOf(usize)353 2 * @sizeOf(usize)
351 else if (builtin.arch.isSPARC())354 else if (native_arch.isSPARC())
352 // On SPARC the previous frame pointer is stored at 14 slots past %fp+BIAS.355 // On SPARC the previous frame pointer is stored at 14 slots past %fp+BIAS.
353 14 * @sizeOf(usize)356 14 * @sizeOf(usize)
354 else357 else
355 0;358 0;
356359
357 const fp_bias = if (builtin.arch.isSPARC())360 const fp_bias = if (native_arch.isSPARC())
358 // On SPARC frame pointers are biased by a constant.361 // On SPARC frame pointers are biased by a constant.
359 2047362 2047
360 else363 else
361 0;364 0;
362365
363 // Positive offset of the saved PC wrt the frame pointer.366 // Positive offset of the saved PC wrt the frame pointer.
364 const pc_offset = if (builtin.arch == .powerpc64le)367 const pc_offset = if (native_arch == .powerpc64le)
365 2 * @sizeOf(usize)368 2 * @sizeOf(usize)
366 else369 else
367 @sizeOf(usize);370 @sizeOf(usize);
...@@ -380,7 +383,7 @@ pub const StackIterator = struct {...@@ -380,7 +383,7 @@ pub const StackIterator = struct {
380 }383 }
381384
382 fn next_internal(self: *StackIterator) ?usize {385 fn next_internal(self: *StackIterator) ?usize {
383 const fp = if (builtin.arch.isSPARC())386 const fp = if (native_arch.isSPARC())
384 // On SPARC the offset is positive. (!)387 // On SPARC the offset is positive. (!)
385 math.add(usize, self.fp, fp_offset) catch return null388 math.add(usize, self.fp, fp_offset) catch return null
386 else389 else
...@@ -416,7 +419,7 @@ pub fn writeCurrentStackTrace(...@@ -416,7 +419,7 @@ pub fn writeCurrentStackTrace(
416 tty_config: TTY.Config,419 tty_config: TTY.Config,
417 start_addr: ?usize,420 start_addr: ?usize,
418) !void {421) !void {
419 if (builtin.os.tag == .windows) {422 if (native_os == .windows) {
420 return writeCurrentStackTraceWindows(out_stream, debug_info, tty_config, start_addr);423 return writeCurrentStackTraceWindows(out_stream, debug_info, tty_config, start_addr);
421 }424 }
422 var it = StackIterator.init(start_addr, null);425 var it = StackIterator.init(start_addr, null);
...@@ -473,7 +476,7 @@ pub const TTY = struct {...@@ -473,7 +476,7 @@ pub const TTY = struct {
473 .Dim => out_stream.writeAll(DIM) catch return,476 .Dim => out_stream.writeAll(DIM) catch return,
474 .Reset => out_stream.writeAll(RESET) catch return,477 .Reset => out_stream.writeAll(RESET) catch return,
475 },478 },
476 .windows_api => if (builtin.os.tag == .windows) {479 .windows_api => if (native_os == .windows) {
477 const stderr_file = io.getStdErr();480 const stderr_file = io.getStdErr();
478 const S = struct {481 const S = struct {
479 var attrs: windows.WORD = undefined;482 var attrs: windows.WORD = undefined;
...@@ -675,7 +678,7 @@ pub fn openSelfDebugInfo(allocator: *mem.Allocator) anyerror!DebugInfo {...@@ -675,7 +678,7 @@ pub fn openSelfDebugInfo(allocator: *mem.Allocator) anyerror!DebugInfo {
675 if (@hasDecl(root, "os") and @hasDecl(root.os, "debug") and @hasDecl(root.os.debug, "openSelfDebugInfo")) {678 if (@hasDecl(root, "os") and @hasDecl(root.os, "debug") and @hasDecl(root.os.debug, "openSelfDebugInfo")) {
676 return root.os.debug.openSelfDebugInfo(allocator);679 return root.os.debug.openSelfDebugInfo(allocator);
677 }680 }
678 switch (builtin.os.tag) {681 switch (native_os) {
679 .linux,682 .linux,
680 .freebsd,683 .freebsd,
681 .netbsd,684 .netbsd,
...@@ -888,7 +891,7 @@ pub fn readElfDebugInfo(allocator: *mem.Allocator, elf_file: File) !ModuleDebugI...@@ -888,7 +891,7 @@ pub fn readElfDebugInfo(allocator: *mem.Allocator, elf_file: File) !ModuleDebugI
888 elf.ELFDATA2MSB => .Big,891 elf.ELFDATA2MSB => .Big,
889 else => return error.InvalidElfEndian,892 else => return error.InvalidElfEndian,
890 };893 };
891 assert(endian == std.builtin.endian); // this is our own debug info894 assert(endian == native_endian); // this is our own debug info
892895
893 const shoff = hdr.e_shoff;896 const shoff = hdr.e_shoff;
894 const str_section_off = shoff + @as(u64, hdr.e_shentsize) * @as(u64, hdr.e_shstrndx);897 const str_section_off = shoff + @as(u64, hdr.e_shentsize) * @as(u64, hdr.e_shstrndx);
...@@ -1123,9 +1126,9 @@ pub const DebugInfo = struct {...@@ -1123,9 +1126,9 @@ pub const DebugInfo = struct {
1123 pub fn getModuleForAddress(self: *DebugInfo, address: usize) !*ModuleDebugInfo {1126 pub fn getModuleForAddress(self: *DebugInfo, address: usize) !*ModuleDebugInfo {
1124 if (comptime std.Target.current.isDarwin()) {1127 if (comptime std.Target.current.isDarwin()) {
1125 return self.lookupModuleDyld(address);1128 return self.lookupModuleDyld(address);
1126 } else if (builtin.os.tag == .windows) {1129 } else if (native_os == .windows) {
1127 return self.lookupModuleWin32(address);1130 return self.lookupModuleWin32(address);
1128 } else if (builtin.os.tag == .haiku) {1131 } else if (native_os == .haiku) {
1129 return self.lookupModuleHaiku(address);1132 return self.lookupModuleHaiku(address);
1130 } else {1133 } else {
1131 return self.lookupModuleDl(address);1134 return self.lookupModuleDl(address);
...@@ -1353,7 +1356,7 @@ const SymbolInfo = struct {...@@ -1353,7 +1356,7 @@ const SymbolInfo = struct {
1353 }1356 }
1354};1357};
13551358
1356pub const ModuleDebugInfo = switch (builtin.os.tag) {1359pub const ModuleDebugInfo = switch (native_os) {
1357 .macos, .ios, .watchos, .tvos => struct {1360 .macos, .ios, .watchos, .tvos => struct {
1358 base_address: usize,1361 base_address: usize,
1359 mapped_memory: []const u8,1362 mapped_memory: []const u8,
...@@ -1720,7 +1723,7 @@ fn getDebugInfoAllocator() *mem.Allocator {...@@ -1720,7 +1723,7 @@ fn getDebugInfoAllocator() *mem.Allocator {
1720}1723}
17211724
1722/// Whether or not the current target can print useful debug information when a segfault occurs.1725/// Whether or not the current target can print useful debug information when a segfault occurs.
1723pub const have_segfault_handling_support = switch (builtin.os.tag) {1726pub const have_segfault_handling_support = switch (native_os) {
1724 .linux, .netbsd => true,1727 .linux, .netbsd => true,
1725 .windows => true,1728 .windows => true,
1726 .freebsd, .openbsd => @hasDecl(os, "ucontext_t"),1729 .freebsd, .openbsd => @hasDecl(os, "ucontext_t"),
...@@ -1744,7 +1747,7 @@ pub fn attachSegfaultHandler() void {...@@ -1744,7 +1747,7 @@ pub fn attachSegfaultHandler() void {
1744 if (!have_segfault_handling_support) {1747 if (!have_segfault_handling_support) {
1745 @compileError("segfault handler not supported for this target");1748 @compileError("segfault handler not supported for this target");
1746 }1749 }
1747 if (builtin.os.tag == .windows) {1750 if (native_os == .windows) {
1748 windows_segfault_handle = windows.kernel32.AddVectoredExceptionHandler(0, handleSegfaultWindows);1751 windows_segfault_handle = windows.kernel32.AddVectoredExceptionHandler(0, handleSegfaultWindows);
1749 return;1752 return;
1750 }1753 }
...@@ -1760,7 +1763,7 @@ pub fn attachSegfaultHandler() void {...@@ -1760,7 +1763,7 @@ pub fn attachSegfaultHandler() void {
1760}1763}
17611764
1762fn resetSegfaultHandler() void {1765fn resetSegfaultHandler() void {
1763 if (builtin.os.tag == .windows) {1766 if (native_os == .windows) {
1764 if (windows_segfault_handle) |handle| {1767 if (windows_segfault_handle) |handle| {
1765 assert(windows.kernel32.RemoveVectoredExceptionHandler(handle) != 0);1768 assert(windows.kernel32.RemoveVectoredExceptionHandler(handle) != 0);
1766 windows_segfault_handle = null;1769 windows_segfault_handle = null;
...@@ -1783,7 +1786,7 @@ fn handleSegfaultLinux(sig: i32, info: *const os.siginfo_t, ctx_ptr: ?*const c_v...@@ -1783,7 +1786,7 @@ fn handleSegfaultLinux(sig: i32, info: *const os.siginfo_t, ctx_ptr: ?*const c_v
1783 // and the resulting segfault will crash the process rather than continually dump stack traces.1786 // and the resulting segfault will crash the process rather than continually dump stack traces.
1784 resetSegfaultHandler();1787 resetSegfaultHandler();
17851788
1786 const addr = switch (builtin.os.tag) {1789 const addr = switch (native_os) {
1787 .linux => @ptrToInt(info.fields.sigfault.addr),1790 .linux => @ptrToInt(info.fields.sigfault.addr),
1788 .freebsd => @ptrToInt(info.addr),1791 .freebsd => @ptrToInt(info.addr),
1789 .netbsd => @ptrToInt(info.info.reason.fault.addr),1792 .netbsd => @ptrToInt(info.info.reason.fault.addr),
...@@ -1802,7 +1805,7 @@ fn handleSegfaultLinux(sig: i32, info: *const os.siginfo_t, ctx_ptr: ?*const c_v...@@ -1802,7 +1805,7 @@ fn handleSegfaultLinux(sig: i32, info: *const os.siginfo_t, ctx_ptr: ?*const c_v
1802 } catch os.abort();1805 } catch os.abort();
1803 }1806 }
18041807
1805 switch (builtin.arch) {1808 switch (native_arch) {
1806 .i386 => {1809 .i386 => {
1807 const ctx = @ptrCast(*const os.ucontext_t, @alignCast(@alignOf(os.ucontext_t), ctx_ptr));1810 const ctx = @ptrCast(*const os.ucontext_t, @alignCast(@alignOf(os.ucontext_t), ctx_ptr));
1808 const ip = @intCast(usize, ctx.mcontext.gregs[os.REG_EIP]);1811 const ip = @intCast(usize, ctx.mcontext.gregs[os.REG_EIP]);
...@@ -1811,13 +1814,13 @@ fn handleSegfaultLinux(sig: i32, info: *const os.siginfo_t, ctx_ptr: ?*const c_v...@@ -1811,13 +1814,13 @@ fn handleSegfaultLinux(sig: i32, info: *const os.siginfo_t, ctx_ptr: ?*const c_v
1811 },1814 },
1812 .x86_64 => {1815 .x86_64 => {
1813 const ctx = @ptrCast(*const os.ucontext_t, @alignCast(@alignOf(os.ucontext_t), ctx_ptr));1816 const ctx = @ptrCast(*const os.ucontext_t, @alignCast(@alignOf(os.ucontext_t), ctx_ptr));
1814 const ip = switch (builtin.os.tag) {1817 const ip = switch (native_os) {
1815 .linux, .netbsd => @intCast(usize, ctx.mcontext.gregs[os.REG_RIP]),1818 .linux, .netbsd => @intCast(usize, ctx.mcontext.gregs[os.REG_RIP]),
1816 .freebsd => @intCast(usize, ctx.mcontext.rip),1819 .freebsd => @intCast(usize, ctx.mcontext.rip),
1817 .openbsd => @intCast(usize, ctx.sc_rip),1820 .openbsd => @intCast(usize, ctx.sc_rip),
1818 else => unreachable,1821 else => unreachable,
1819 };1822 };
1820 const bp = switch (builtin.os.tag) {1823 const bp = switch (native_os) {
1821 .linux, .netbsd => @intCast(usize, ctx.mcontext.gregs[os.REG_RBP]),1824 .linux, .netbsd => @intCast(usize, ctx.mcontext.gregs[os.REG_RBP]),
1822 .openbsd => @intCast(usize, ctx.sc_rbp),1825 .openbsd => @intCast(usize, ctx.sc_rbp),
1823 .freebsd => @intCast(usize, ctx.mcontext.rbp),1826 .freebsd => @intCast(usize, ctx.mcontext.rbp),
lib/std/dwarf.zig+1-1
...@@ -4,7 +4,7 @@...@@ -4,7 +4,7 @@
4// The MIT license requires this copyright notice to be included in all copies4// The MIT license requires this copyright notice to be included in all copies
5// and substantial portions of the software.5// and substantial portions of the software.
6const std = @import("std.zig");6const std = @import("std.zig");
7const builtin = @import("builtin");7const builtin = std.builtin;
8const debug = std.debug;8const debug = std.debug;
9const fs = std.fs;9const fs = std.fs;
10const io = std.io;10const io = std.io;
lib/std/dynamic_library.zig+1-1
...@@ -3,7 +3,7 @@...@@ -3,7 +3,7 @@
3// This file is part of [zig](https://ziglang.org/), which is MIT licensed.3// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
4// The MIT license requires this copyright notice to be included in all copies4// The MIT license requires this copyright notice to be included in all copies
5// and substantial portions of the software.5// and substantial portions of the software.
6const builtin = @import("builtin");6const builtin = std.builtin;
77
8const std = @import("std.zig");8const std = @import("std.zig");
9const mem = std.mem;9const mem = std.mem;
lib/std/event/channel.zig+1-1
...@@ -4,7 +4,7 @@...@@ -4,7 +4,7 @@
4// The MIT license requires this copyright notice to be included in all copies4// The MIT license requires this copyright notice to be included in all copies
5// and substantial portions of the software.5// and substantial portions of the software.
6const std = @import("../std.zig");6const std = @import("../std.zig");
7const builtin = @import("builtin");7const builtin = std.builtin;
8const assert = std.debug.assert;8const assert = std.debug.assert;
9const testing = std.testing;9const testing = std.testing;
10const Loop = std.event.Loop;10const Loop = std.event.Loop;
lib/std/event/future.zig+1-1
...@@ -6,7 +6,7 @@...@@ -6,7 +6,7 @@
6const std = @import("../std.zig");6const std = @import("../std.zig");
7const assert = std.debug.assert;7const assert = std.debug.assert;
8const testing = std.testing;8const testing = std.testing;
9const builtin = @import("builtin");9const builtin = std.builtin;
10const Lock = std.event.Lock;10const Lock = std.event.Lock;
1111
12/// This is a value that starts out unavailable, until resolve() is called12/// This is a value that starts out unavailable, until resolve() is called
lib/std/event/group.zig+1-1
...@@ -4,7 +4,7 @@...@@ -4,7 +4,7 @@
4// The MIT license requires this copyright notice to be included in all copies4// The MIT license requires this copyright notice to be included in all copies
5// and substantial portions of the software.5// and substantial portions of the software.
6const std = @import("../std.zig");6const std = @import("../std.zig");
7const builtin = @import("builtin");7const builtin = std.builtin;
8const Lock = std.event.Lock;8const Lock = std.event.Lock;
9const testing = std.testing;9const testing = std.testing;
10const Allocator = std.mem.Allocator;10const Allocator = std.mem.Allocator;
lib/std/event/lock.zig+1-1
...@@ -4,7 +4,7 @@...@@ -4,7 +4,7 @@
4// The MIT license requires this copyright notice to be included in all copies4// The MIT license requires this copyright notice to be included in all copies
5// and substantial portions of the software.5// and substantial portions of the software.
6const std = @import("../std.zig");6const std = @import("../std.zig");
7const builtin = @import("builtin");7const builtin = std.builtin;
8const assert = std.debug.assert;8const assert = std.debug.assert;
9const testing = std.testing;9const testing = std.testing;
10const mem = std.mem;10const mem = std.mem;
lib/std/event/loop.zig+1-1
...@@ -4,7 +4,7 @@...@@ -4,7 +4,7 @@
4// The MIT license requires this copyright notice to be included in all copies4// The MIT license requires this copyright notice to be included in all copies
5// and substantial portions of the software.5// and substantial portions of the software.
6const std = @import("../std.zig");6const std = @import("../std.zig");
7const builtin = @import("builtin");7const builtin = std.builtin;
8const root = @import("root");8const root = @import("root");
9const assert = std.debug.assert;9const assert = std.debug.assert;
10const testing = std.testing;10const testing = std.testing;
lib/std/event/rwlock.zig+1-1
...@@ -4,7 +4,7 @@...@@ -4,7 +4,7 @@
4// The MIT license requires this copyright notice to be included in all copies4// The MIT license requires this copyright notice to be included in all copies
5// and substantial portions of the software.5// and substantial portions of the software.
6const std = @import("../std.zig");6const std = @import("../std.zig");
7const builtin = @import("builtin");7const builtin = std.builtin;
8const assert = std.debug.assert;8const assert = std.debug.assert;
9const testing = std.testing;9const testing = std.testing;
10const mem = std.mem;10const mem = std.mem;
lib/std/event/wait_group.zig+1-1
...@@ -4,7 +4,7 @@...@@ -4,7 +4,7 @@
4// The MIT license requires this copyright notice to be included in all copies4// The MIT license requires this copyright notice to be included in all copies
5// and substantial portions of the software.5// and substantial portions of the software.
6const std = @import("../std.zig");6const std = @import("../std.zig");
7const builtin = @import("builtin");7const builtin = std.builtin;
8const Loop = std.event.Loop;8const Loop = std.event.Loop;
99
10/// A WaitGroup keeps track and waits for a group of async tasks to finish.10/// A WaitGroup keeps track and waits for a group of async tasks to finish.
lib/std/fmt.zig+1-1
...@@ -9,7 +9,7 @@ const assert = std.debug.assert;...@@ -9,7 +9,7 @@ const assert = std.debug.assert;
9const mem = std.mem;9const mem = std.mem;
10const unicode = std.unicode;10const unicode = std.unicode;
11const meta = std.meta;11const meta = std.meta;
12const builtin = @import("builtin");12const builtin = std.builtin;
13const errol = @import("fmt/errol.zig");13const errol = @import("fmt/errol.zig");
14const lossyCast = std.math.lossyCast;14const lossyCast = std.math.lossyCast;
15const expectFmt = std.testing.expectFmt;15const expectFmt = std.testing.expectFmt;
lib/std/fs.zig+1-1
...@@ -3,7 +3,7 @@...@@ -3,7 +3,7 @@
3// This file is part of [zig](https://ziglang.org/), which is MIT licensed.3// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
4// The MIT license requires this copyright notice to be included in all copies4// The MIT license requires this copyright notice to be included in all copies
5// and substantial portions of the software.5// and substantial portions of the software.
6const builtin = @import("builtin");6const builtin = std.builtin;
7const std = @import("std.zig");7const std = @import("std.zig");
8const os = std.os;8const os = std.os;
9const mem = std.mem;9const mem = std.mem;
lib/std/fs/file.zig+1-1
...@@ -4,7 +4,7 @@...@@ -4,7 +4,7 @@
4// The MIT license requires this copyright notice to be included in all copies4// The MIT license requires this copyright notice to be included in all copies
5// and substantial portions of the software.5// and substantial portions of the software.
6const std = @import("../std.zig");6const std = @import("../std.zig");
7const builtin = @import("builtin");7const builtin = std.builtin;
8const os = std.os;8const os = std.os;
9const io = std.io;9const io = std.io;
10const mem = std.mem;10const mem = std.mem;
lib/std/fs/get_app_data_dir.zig+1-1
...@@ -4,7 +4,7 @@...@@ -4,7 +4,7 @@
4// The MIT license requires this copyright notice to be included in all copies4// The MIT license requires this copyright notice to be included in all copies
5// and substantial portions of the software.5// and substantial portions of the software.
6const std = @import("../std.zig");6const std = @import("../std.zig");
7const builtin = @import("builtin");7const builtin = std.builtin;
8const unicode = std.unicode;8const unicode = std.unicode;
9const mem = std.mem;9const mem = std.mem;
10const fs = std.fs;10const fs = std.fs;
lib/std/fs/path.zig+1-1
...@@ -3,7 +3,7 @@...@@ -3,7 +3,7 @@
3// This file is part of [zig](https://ziglang.org/), which is MIT licensed.3// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
4// The MIT license requires this copyright notice to be included in all copies4// The MIT license requires this copyright notice to be included in all copies
5// and substantial portions of the software.5// and substantial portions of the software.
6const builtin = @import("builtin");6const builtin = std.builtin;
7const std = @import("../std.zig");7const std = @import("../std.zig");
8const debug = std.debug;8const debug = std.debug;
9const assert = debug.assert;9const assert = debug.assert;
lib/std/fs/wasi.zig+1-1
...@@ -167,7 +167,7 @@ pub const PreopenList = struct {...@@ -167,7 +167,7 @@ pub const PreopenList = struct {
167};167};
168168
169test "extracting WASI preopens" {169test "extracting WASI preopens" {
170 if (@import("builtin").os.tag != .wasi) return error.SkipZigTest;170 if (std.builtin.os.tag != .wasi) return error.SkipZigTest;
171171
172 var preopens = PreopenList.init(std.testing.allocator);172 var preopens = PreopenList.init(std.testing.allocator);
173 defer preopens.deinit();173 defer preopens.deinit();
lib/std/fs/watch.zig+1-1
...@@ -4,7 +4,7 @@...@@ -4,7 +4,7 @@
4// The MIT license requires this copyright notice to be included in all copies4// The MIT license requires this copyright notice to be included in all copies
5// and substantial portions of the software.5// and substantial portions of the software.
6const std = @import("std");6const std = @import("std");
7const builtin = @import("builtin");7const builtin = std.builtin;
8const event = std.event;8const event = std.event;
9const assert = std.debug.assert;9const assert = std.debug.assert;
10const testing = std.testing;10const testing = std.testing;
lib/std/hash/auto_hash.zig+3-3
...@@ -4,10 +4,10 @@...@@ -4,10 +4,10 @@
4// The MIT license requires this copyright notice to be included in all copies4// The MIT license requires this copyright notice to be included in all copies
5// and substantial portions of the software.5// and substantial portions of the software.
6const std = @import("std");6const std = @import("std");
7const builtin = @import("builtin");
8const assert = std.debug.assert;7const assert = std.debug.assert;
9const mem = std.mem;8const mem = std.mem;
10const meta = std.meta;9const meta = std.meta;
10const builtin = std.builtin;
1111
12/// Describes how pointer types should be hashed.12/// Describes how pointer types should be hashed.
13pub const HashStrategy = enum {13pub const HashStrategy = enum {
...@@ -239,7 +239,7 @@ fn testHashDeepRecursive(key: anytype) u64 {...@@ -239,7 +239,7 @@ fn testHashDeepRecursive(key: anytype) u64 {
239239
240test "typeContainsSlice" {240test "typeContainsSlice" {
241 comptime {241 comptime {
242 testing.expect(!typeContainsSlice(meta.Tag(std.builtin.TypeInfo)));242 testing.expect(!typeContainsSlice(meta.Tag(builtin.TypeInfo)));
243243
244 testing.expect(typeContainsSlice([]const u8));244 testing.expect(typeContainsSlice([]const u8));
245 testing.expect(!typeContainsSlice(u8));245 testing.expect(!typeContainsSlice(u8));
...@@ -400,7 +400,7 @@ test "testHash union" {...@@ -400,7 +400,7 @@ test "testHash union" {
400400
401test "testHash vector" {401test "testHash vector" {
402 // Disabled because of #3317402 // Disabled because of #3317
403 if (@import("builtin").arch == .mipsel or @import("builtin").arch == .mips) return error.SkipZigTest;403 if (builtin.target.cpu.arch == .mipsel or builtin.target.cpu.arch == .mips) return error.SkipZigTest;
404404
405 const a: meta.Vector(4, u32) = [_]u32{ 1, 2, 3, 4 };405 const a: meta.Vector(4, u32) = [_]u32{ 1, 2, 3, 4 };
406 const b: meta.Vector(4, u32) = [_]u32{ 1, 2, 3, 5 };406 const b: meta.Vector(4, u32) = [_]u32{ 1, 2, 3, 5 };
lib/std/hash/benchmark.zig+1-1
...@@ -5,7 +5,7 @@...@@ -5,7 +5,7 @@
5// and substantial portions of the software.5// and substantial portions of the software.
6// zig run benchmark.zig --release-fast --override-lib-dir ..6// zig run benchmark.zig --release-fast --override-lib-dir ..
77
8const builtin = @import("builtin");8const builtin = std.builtin;
9const std = @import("std");9const std = @import("std");
10const time = std.time;10const time = std.time;
11const Timer = time.Timer;11const Timer = time.Timer;
lib/std/hash/cityhash.zig+1-1
...@@ -4,7 +4,7 @@...@@ -4,7 +4,7 @@
4// The MIT license requires this copyright notice to be included in all copies4// The MIT license requires this copyright notice to be included in all copies
5// and substantial portions of the software.5// and substantial portions of the software.
6const std = @import("std");6const std = @import("std");
7const builtin = @import("builtin");7const builtin = std.builtin;
88
9fn offsetPtr(ptr: [*]const u8, offset: usize) callconv(.Inline) [*]const u8 {9fn offsetPtr(ptr: [*]const u8, offset: usize) callconv(.Inline) [*]const u8 {
10 // ptr + offset doesn't work at comptime so we need this instead.10 // ptr + offset doesn't work at comptime so we need this instead.
lib/std/hash/murmur.zig+1-1
...@@ -4,7 +4,7 @@...@@ -4,7 +4,7 @@
4// The MIT license requires this copyright notice to be included in all copies4// The MIT license requires this copyright notice to be included in all copies
5// and substantial portions of the software.5// and substantial portions of the software.
6const std = @import("std");6const std = @import("std");
7const builtin = @import("builtin");7const builtin = std.builtin;
8const testing = std.testing;8const testing = std.testing;
99
10const default_seed: u32 = 0xc70f6907;10const default_seed: u32 = 0xc70f6907;
lib/std/hash_map.zig-1
...@@ -4,7 +4,6 @@...@@ -4,7 +4,6 @@
4// The MIT license requires this copyright notice to be included in all copies4// The MIT license requires this copyright notice to be included in all copies
5// and substantial portions of the software.5// and substantial portions of the software.
6const std = @import("std.zig");6const std = @import("std.zig");
7const builtin = @import("builtin");
8const assert = debug.assert;7const assert = debug.assert;
9const autoHash = std.hash.autoHash;8const autoHash = std.hash.autoHash;
10const debug = std.debug;9const debug = std.debug;
lib/std/heap.zig+1-1
...@@ -10,7 +10,7 @@ const assert = debug.assert;...@@ -10,7 +10,7 @@ const assert = debug.assert;
10const testing = std.testing;10const testing = std.testing;
11const mem = std.mem;11const mem = std.mem;
12const os = std.os;12const os = std.os;
13const builtin = @import("builtin");13const builtin = std.builtin;
14const c = std.c;14const c = std.c;
15const maxInt = std.math.maxInt;15const maxInt = std.math.maxInt;
1616
lib/std/io.zig+1-1
...@@ -4,7 +4,7 @@...@@ -4,7 +4,7 @@
4// The MIT license requires this copyright notice to be included in all copies4// The MIT license requires this copyright notice to be included in all copies
5// and substantial portions of the software.5// and substantial portions of the software.
6const std = @import("std.zig");6const std = @import("std.zig");
7const builtin = @import("builtin");7const builtin = std.builtin;
8const root = @import("root");8const root = @import("root");
9const c = std.c;9const c = std.c;
1010
lib/std/math/acosh.zig-1
...@@ -9,7 +9,6 @@...@@ -9,7 +9,6 @@
9// https://git.musl-libc.org/cgit/musl/tree/src/math/acoshf.c9// https://git.musl-libc.org/cgit/musl/tree/src/math/acoshf.c
10// https://git.musl-libc.org/cgit/musl/tree/src/math/acosh.c10// https://git.musl-libc.org/cgit/musl/tree/src/math/acosh.c
1111
12const builtin = @import("builtin");
13const std = @import("../std.zig");12const std = @import("../std.zig");
14const math = std.math;13const math = std.math;
15const expect = std.testing.expect;14const expect = std.testing.expect;
lib/std/math/ceil.zig-1
...@@ -9,7 +9,6 @@...@@ -9,7 +9,6 @@
9// https://git.musl-libc.org/cgit/musl/tree/src/math/ceilf.c9// https://git.musl-libc.org/cgit/musl/tree/src/math/ceilf.c
10// https://git.musl-libc.org/cgit/musl/tree/src/math/ceil.c10// https://git.musl-libc.org/cgit/musl/tree/src/math/ceil.c
1111
12const builtin = @import("builtin");
13const std = @import("../std.zig");12const std = @import("../std.zig");
14const math = std.math;13const math = std.math;
15const expect = std.testing.expect;14const expect = std.testing.expect;
lib/std/math/complex/atan.zig-1
...@@ -10,7 +10,6 @@...@@ -10,7 +10,6 @@
10// https://git.musl-libc.org/cgit/musl/tree/src/complex/catan.c10// https://git.musl-libc.org/cgit/musl/tree/src/complex/catan.c
1111
12const std = @import("../../std.zig");12const std = @import("../../std.zig");
13const builtin = @import("builtin");
14const testing = std.testing;13const testing = std.testing;
15const math = std.math;14const math = std.math;
16const cmath = math.complex;15const cmath = math.complex;
lib/std/math/complex/cosh.zig-1
...@@ -9,7 +9,6 @@...@@ -9,7 +9,6 @@
9// https://git.musl-libc.org/cgit/musl/tree/src/complex/ccoshf.c9// https://git.musl-libc.org/cgit/musl/tree/src/complex/ccoshf.c
10// https://git.musl-libc.org/cgit/musl/tree/src/complex/ccosh.c10// https://git.musl-libc.org/cgit/musl/tree/src/complex/ccosh.c
1111
12const builtin = @import("builtin");
13const std = @import("../../std.zig");12const std = @import("../../std.zig");
14const testing = std.testing;13const testing = std.testing;
15const math = std.math;14const math = std.math;
lib/std/math/complex/exp.zig-1
...@@ -9,7 +9,6 @@...@@ -9,7 +9,6 @@
9// https://git.musl-libc.org/cgit/musl/tree/src/complex/cexpf.c9// https://git.musl-libc.org/cgit/musl/tree/src/complex/cexpf.c
10// https://git.musl-libc.org/cgit/musl/tree/src/complex/cexp.c10// https://git.musl-libc.org/cgit/musl/tree/src/complex/cexp.c
1111
12const builtin = @import("builtin");
13const std = @import("../../std.zig");12const std = @import("../../std.zig");
14const testing = std.testing;13const testing = std.testing;
15const math = std.math;14const math = std.math;
lib/std/math/complex/sinh.zig-1
...@@ -9,7 +9,6 @@...@@ -9,7 +9,6 @@
9// https://git.musl-libc.org/cgit/musl/tree/src/complex/csinhf.c9// https://git.musl-libc.org/cgit/musl/tree/src/complex/csinhf.c
10// https://git.musl-libc.org/cgit/musl/tree/src/complex/csinh.c10// https://git.musl-libc.org/cgit/musl/tree/src/complex/csinh.c
1111
12const builtin = @import("builtin");
13const std = @import("../../std.zig");12const std = @import("../../std.zig");
14const testing = std.testing;13const testing = std.testing;
15const math = std.math;14const math = std.math;
lib/std/math/complex/tanh.zig-1
...@@ -9,7 +9,6 @@...@@ -9,7 +9,6 @@
9// https://git.musl-libc.org/cgit/musl/tree/src/complex/ctanhf.c9// https://git.musl-libc.org/cgit/musl/tree/src/complex/ctanhf.c
10// https://git.musl-libc.org/cgit/musl/tree/src/complex/ctanh.c10// https://git.musl-libc.org/cgit/musl/tree/src/complex/ctanh.c
1111
12const builtin = @import("builtin");
13const std = @import("../../std.zig");12const std = @import("../../std.zig");
14const testing = std.testing;13const testing = std.testing;
15const math = std.math;14const math = std.math;
lib/std/math/cos.zig-1
...@@ -8,7 +8,6 @@...@@ -8,7 +8,6 @@
8//8//
9// https://golang.org/src/math/sin.go9// https://golang.org/src/math/sin.go
1010
11const builtin = @import("builtin");
12const std = @import("../std.zig");11const std = @import("../std.zig");
13const math = std.math;12const math = std.math;
14const expect = std.testing.expect;13const expect = std.testing.expect;
lib/std/math/cosh.zig-1
...@@ -9,7 +9,6 @@...@@ -9,7 +9,6 @@
9// https://git.musl-libc.org/cgit/musl/tree/src/math/coshf.c9// https://git.musl-libc.org/cgit/musl/tree/src/math/coshf.c
10// https://git.musl-libc.org/cgit/musl/tree/src/math/cosh.c10// https://git.musl-libc.org/cgit/musl/tree/src/math/cosh.c
1111
12const builtin = @import("builtin");
13const std = @import("../std.zig");12const std = @import("../std.zig");
14const math = std.math;13const math = std.math;
15const expo2 = @import("expo2.zig").expo2;14const expo2 = @import("expo2.zig").expo2;
lib/std/math/expm1.zig-1
...@@ -11,7 +11,6 @@...@@ -11,7 +11,6 @@
1111
12// TODO: Updated recently.12// TODO: Updated recently.
1313
14const builtin = @import("builtin");
15const std = @import("../std.zig");14const std = @import("../std.zig");
16const math = std.math;15const math = std.math;
17const expect = std.testing.expect;16const expect = std.testing.expect;
lib/std/math/floor.zig-1
...@@ -9,7 +9,6 @@...@@ -9,7 +9,6 @@
9// https://git.musl-libc.org/cgit/musl/tree/src/math/floorf.c9// https://git.musl-libc.org/cgit/musl/tree/src/math/floorf.c
10// https://git.musl-libc.org/cgit/musl/tree/src/math/floor.c10// https://git.musl-libc.org/cgit/musl/tree/src/math/floor.c
1111
12const builtin = @import("builtin");
13const expect = std.testing.expect;12const expect = std.testing.expect;
14const std = @import("../std.zig");13const std = @import("../std.zig");
15const math = std.math;14const math = std.math;
lib/std/math/log1p.zig-1
...@@ -9,7 +9,6 @@...@@ -9,7 +9,6 @@
9// https://git.musl-libc.org/cgit/musl/tree/src/math/log1pf.c9// https://git.musl-libc.org/cgit/musl/tree/src/math/log1pf.c
10// https://git.musl-libc.org/cgit/musl/tree/src/math/log1p.c10// https://git.musl-libc.org/cgit/musl/tree/src/math/log1p.c
1111
12const builtin = @import("builtin");
13const std = @import("../std.zig");12const std = @import("../std.zig");
14const math = std.math;13const math = std.math;
15const expect = std.testing.expect;14const expect = std.testing.expect;
lib/std/math/pow.zig-1
...@@ -8,7 +8,6 @@...@@ -8,7 +8,6 @@
8//8//
9// https://golang.org/src/math/pow.go9// https://golang.org/src/math/pow.go
1010
11const builtin = @import("builtin");
12const std = @import("../std.zig");11const std = @import("../std.zig");
13const math = std.math;12const math = std.math;
14const expect = std.testing.expect;13const expect = std.testing.expect;
lib/std/math/powi.zig-1
...@@ -8,7 +8,6 @@...@@ -8,7 +8,6 @@
8//8//
9// https://github.com/rust-lang/rust/blob/360432f1e8794de58cd94f34c9c17ad65871e5b5/src/libcore/num/mod.rs#L34239// https://github.com/rust-lang/rust/blob/360432f1e8794de58cd94f34c9c17ad65871e5b5/src/libcore/num/mod.rs#L3423
1010
11const builtin = @import("builtin");
12const std = @import("../std.zig");11const std = @import("../std.zig");
13const math = std.math;12const math = std.math;
14const assert = std.debug.assert;13const assert = std.debug.assert;
lib/std/math/round.zig-1
...@@ -9,7 +9,6 @@...@@ -9,7 +9,6 @@
9// https://git.musl-libc.org/cgit/musl/tree/src/math/roundf.c9// https://git.musl-libc.org/cgit/musl/tree/src/math/roundf.c
10// https://git.musl-libc.org/cgit/musl/tree/src/math/round.c10// https://git.musl-libc.org/cgit/musl/tree/src/math/round.c
1111
12const builtin = @import("builtin");
13const expect = std.testing.expect;12const expect = std.testing.expect;
14const std = @import("../std.zig");13const std = @import("../std.zig");
15const math = std.math;14const math = std.math;
lib/std/math/sin.zig-1
...@@ -8,7 +8,6 @@...@@ -8,7 +8,6 @@
8//8//
9// https://golang.org/src/math/sin.go9// https://golang.org/src/math/sin.go
1010
11const builtin = @import("builtin");
12const std = @import("../std.zig");11const std = @import("../std.zig");
13const math = std.math;12const math = std.math;
14const expect = std.testing.expect;13const expect = std.testing.expect;
lib/std/math/sinh.zig-1
...@@ -9,7 +9,6 @@...@@ -9,7 +9,6 @@
9// https://git.musl-libc.org/cgit/musl/tree/src/math/sinhf.c9// https://git.musl-libc.org/cgit/musl/tree/src/math/sinhf.c
10// https://git.musl-libc.org/cgit/musl/tree/src/math/sinh.c10// https://git.musl-libc.org/cgit/musl/tree/src/math/sinh.c
1111
12const builtin = @import("builtin");
13const std = @import("../std.zig");12const std = @import("../std.zig");
14const math = std.math;13const math = std.math;
15const expect = std.testing.expect;14const expect = std.testing.expect;
lib/std/math/sqrt.zig+1-2
...@@ -6,8 +6,7 @@...@@ -6,8 +6,7 @@
6const std = @import("../std.zig");6const std = @import("../std.zig");
7const math = std.math;7const math = std.math;
8const expect = std.testing.expect;8const expect = std.testing.expect;
9const builtin = @import("builtin");9const TypeId = std.builtin.TypeId;
10const TypeId = builtin.TypeId;
11const maxInt = std.math.maxInt;10const maxInt = std.math.maxInt;
1211
13/// Returns the square root of x.12/// Returns the square root of x.
lib/std/math/tan.zig-1
...@@ -8,7 +8,6 @@...@@ -8,7 +8,6 @@
8//8//
9// https://golang.org/src/math/tan.go9// https://golang.org/src/math/tan.go
1010
11const builtin = @import("builtin");
12const std = @import("../std.zig");11const std = @import("../std.zig");
13const math = std.math;12const math = std.math;
14const expect = std.testing.expect;13const expect = std.testing.expect;
lib/std/math/tanh.zig-1
...@@ -9,7 +9,6 @@...@@ -9,7 +9,6 @@
9// https://git.musl-libc.org/cgit/musl/tree/src/math/tanhf.c9// https://git.musl-libc.org/cgit/musl/tree/src/math/tanhf.c
10// https://git.musl-libc.org/cgit/musl/tree/src/math/tanh.c10// https://git.musl-libc.org/cgit/musl/tree/src/math/tanh.c
1111
12const builtin = @import("builtin");
13const std = @import("../std.zig");12const std = @import("../std.zig");
14const math = std.math;13const math = std.math;
15const expect = std.testing.expect;14const expect = std.testing.expect;
lib/std/mem.zig+46-45
...@@ -7,17 +7,18 @@ const std = @import("std.zig");...@@ -7,17 +7,18 @@ const std = @import("std.zig");
7const debug = std.debug;7const debug = std.debug;
8const assert = debug.assert;8const assert = debug.assert;
9const math = std.math;9const math = std.math;
10const builtin = std.builtin;
11const mem = @This();10const mem = @This();
12const meta = std.meta;11const meta = std.meta;
13const trait = meta.trait;12const trait = meta.trait;
14const testing = std.testing;13const testing = std.testing;
14const Endian = std.builtin.Endian;
15const native_endian = std.Target.current.cpu.arch.endian();
1516
16/// Compile time known minimum page size.17/// Compile time known minimum page size.
17/// https://github.com/ziglang/zig/issues/408218/// https://github.com/ziglang/zig/issues/4082
18pub const page_size = switch (builtin.arch) {19pub const page_size = switch (std.Target.current.cpu.arch) {
19 .wasm32, .wasm64 => 64 * 1024,20 .wasm32, .wasm64 => 64 * 1024,
20 .aarch64 => switch (builtin.os.tag) {21 .aarch64 => switch (std.Target.current.os.tag) {
21 .macos, .ios, .watchos, .tvos => 16 * 1024,22 .macos, .ios, .watchos, .tvos => 16 * 1024,
22 else => 4 * 1024,23 else => 4 * 1024,
23 },24 },
...@@ -1042,7 +1043,7 @@ test "mem.containsAtLeast" {...@@ -1042,7 +1043,7 @@ test "mem.containsAtLeast" {
1042/// Reads an integer from memory with size equal to bytes.len.1043/// Reads an integer from memory with size equal to bytes.len.
1043/// T specifies the return type, which must be large enough to store1044/// T specifies the return type, which must be large enough to store
1044/// the result.1045/// the result.
1045pub fn readVarInt(comptime ReturnType: type, bytes: []const u8, endian: builtin.Endian) ReturnType {1046pub fn readVarInt(comptime ReturnType: type, bytes: []const u8, endian: Endian) ReturnType {
1046 var result: ReturnType = 0;1047 var result: ReturnType = 0;
1047 switch (endian) {1048 switch (endian) {
1048 .Big => {1049 .Big => {
...@@ -1077,12 +1078,12 @@ pub fn readIntForeign(comptime T: type, bytes: *const [@divExact(@typeInfo(T).In...@@ -1077,12 +1078,12 @@ pub fn readIntForeign(comptime T: type, bytes: *const [@divExact(@typeInfo(T).In
1077 return @byteSwap(T, readIntNative(T, bytes));1078 return @byteSwap(T, readIntNative(T, bytes));
1078}1079}
10791080
1080pub const readIntLittle = switch (builtin.endian) {1081pub const readIntLittle = switch (native_endian) {
1081 .Little => readIntNative,1082 .Little => readIntNative,
1082 .Big => readIntForeign,1083 .Big => readIntForeign,
1083};1084};
10841085
1085pub const readIntBig = switch (builtin.endian) {1086pub const readIntBig = switch (native_endian) {
1086 .Little => readIntForeign,1087 .Little => readIntForeign,
1087 .Big => readIntNative,1088 .Big => readIntNative,
1088};1089};
...@@ -1106,12 +1107,12 @@ pub fn readIntSliceForeign(comptime T: type, bytes: []const u8) T {...@@ -1106,12 +1107,12 @@ pub fn readIntSliceForeign(comptime T: type, bytes: []const u8) T {
1106 return @byteSwap(T, readIntSliceNative(T, bytes));1107 return @byteSwap(T, readIntSliceNative(T, bytes));
1107}1108}
11081109
1109pub const readIntSliceLittle = switch (builtin.endian) {1110pub const readIntSliceLittle = switch (native_endian) {
1110 .Little => readIntSliceNative,1111 .Little => readIntSliceNative,
1111 .Big => readIntSliceForeign,1112 .Big => readIntSliceForeign,
1112};1113};
11131114
1114pub const readIntSliceBig = switch (builtin.endian) {1115pub const readIntSliceBig = switch (native_endian) {
1115 .Little => readIntSliceForeign,1116 .Little => readIntSliceForeign,
1116 .Big => readIntSliceNative,1117 .Big => readIntSliceNative,
1117};1118};
...@@ -1119,8 +1120,8 @@ pub const readIntSliceBig = switch (builtin.endian) {...@@ -1119,8 +1120,8 @@ pub const readIntSliceBig = switch (builtin.endian) {
1119/// Reads an integer from memory with bit count specified by T.1120/// Reads an integer from memory with bit count specified by T.
1120/// The bit count of T must be evenly divisible by 8.1121/// The bit count of T must be evenly divisible by 8.
1121/// This function cannot fail and cannot cause undefined behavior.1122/// This function cannot fail and cannot cause undefined behavior.
1122pub fn readInt(comptime T: type, bytes: *const [@divExact(@typeInfo(T).Int.bits, 8)]u8, endian: builtin.Endian) T {1123pub fn readInt(comptime T: type, bytes: *const [@divExact(@typeInfo(T).Int.bits, 8)]u8, endian: Endian) T {
1123 if (endian == builtin.endian) {1124 if (endian == native_endian) {
1124 return readIntNative(T, bytes);1125 return readIntNative(T, bytes);
1125 } else {1126 } else {
1126 return readIntForeign(T, bytes);1127 return readIntForeign(T, bytes);
...@@ -1130,7 +1131,7 @@ pub fn readInt(comptime T: type, bytes: *const [@divExact(@typeInfo(T).Int.bits,...@@ -1130,7 +1131,7 @@ pub fn readInt(comptime T: type, bytes: *const [@divExact(@typeInfo(T).Int.bits,
1130/// Asserts that bytes.len >= @typeInfo(T).Int.bits / 8. Reads the integer starting from index 01131/// Asserts that bytes.len >= @typeInfo(T).Int.bits / 8. Reads the integer starting from index 0
1131/// and ignores extra bytes.1132/// and ignores extra bytes.
1132/// The bit count of T must be evenly divisible by 8.1133/// The bit count of T must be evenly divisible by 8.
1133pub fn readIntSlice(comptime T: type, bytes: []const u8, endian: builtin.Endian) T {1134pub fn readIntSlice(comptime T: type, bytes: []const u8, endian: Endian) T {
1134 const n = @divExact(@typeInfo(T).Int.bits, 8);1135 const n = @divExact(@typeInfo(T).Int.bits, 8);
1135 assert(bytes.len >= n);1136 assert(bytes.len >= n);
1136 return readInt(T, bytes[0..n], endian);1137 return readInt(T, bytes[0..n], endian);
...@@ -1188,12 +1189,12 @@ pub fn writeIntForeign(comptime T: type, buf: *[@divExact(@typeInfo(T).Int.bits,...@@ -1188,12 +1189,12 @@ pub fn writeIntForeign(comptime T: type, buf: *[@divExact(@typeInfo(T).Int.bits,
1188 writeIntNative(T, buf, @byteSwap(T, value));1189 writeIntNative(T, buf, @byteSwap(T, value));
1189}1190}
11901191
1191pub const writeIntLittle = switch (builtin.endian) {1192pub const writeIntLittle = switch (native_endian) {
1192 .Little => writeIntNative,1193 .Little => writeIntNative,
1193 .Big => writeIntForeign,1194 .Big => writeIntForeign,
1194};1195};
11951196
1196pub const writeIntBig = switch (builtin.endian) {1197pub const writeIntBig = switch (native_endian) {
1197 .Little => writeIntForeign,1198 .Little => writeIntForeign,
1198 .Big => writeIntNative,1199 .Big => writeIntNative,
1199};1200};
...@@ -1201,8 +1202,8 @@ pub const writeIntBig = switch (builtin.endian) {...@@ -1201,8 +1202,8 @@ pub const writeIntBig = switch (builtin.endian) {
1201/// Writes an integer to memory, storing it in twos-complement.1202/// Writes an integer to memory, storing it in twos-complement.
1202/// This function always succeeds, has defined behavior for all inputs, but1203/// This function always succeeds, has defined behavior for all inputs, but
1203/// the integer bit width must be divisible by 8.1204/// the integer bit width must be divisible by 8.
1204pub fn writeInt(comptime T: type, buffer: *[@divExact(@typeInfo(T).Int.bits, 8)]u8, value: T, endian: builtin.Endian) void {1205pub fn writeInt(comptime T: type, buffer: *[@divExact(@typeInfo(T).Int.bits, 8)]u8, value: T, endian: Endian) void {
1205 if (endian == builtin.endian) {1206 if (endian == native_endian) {
1206 return writeIntNative(T, buffer, value);1207 return writeIntNative(T, buffer, value);
1207 } else {1208 } else {
1208 return writeIntForeign(T, buffer, value);1209 return writeIntForeign(T, buffer, value);
...@@ -1252,12 +1253,12 @@ pub fn writeIntSliceBig(comptime T: type, buffer: []u8, value: T) void {...@@ -1252,12 +1253,12 @@ pub fn writeIntSliceBig(comptime T: type, buffer: []u8, value: T) void {
1252 }1253 }
1253}1254}
12541255
1255pub const writeIntSliceNative = switch (builtin.endian) {1256pub const writeIntSliceNative = switch (native_endian) {
1256 .Little => writeIntSliceLittle,1257 .Little => writeIntSliceLittle,
1257 .Big => writeIntSliceBig,1258 .Big => writeIntSliceBig,
1258};1259};
12591260
1260pub const writeIntSliceForeign = switch (builtin.endian) {1261pub const writeIntSliceForeign = switch (native_endian) {
1261 .Little => writeIntSliceBig,1262 .Little => writeIntSliceBig,
1262 .Big => writeIntSliceLittle,1263 .Big => writeIntSliceLittle,
1263};1264};
...@@ -1268,7 +1269,7 @@ pub const writeIntSliceForeign = switch (builtin.endian) {...@@ -1268,7 +1269,7 @@ pub const writeIntSliceForeign = switch (builtin.endian) {
1268/// Any extra bytes in buffer not part of the integer are set to zero, with1269/// Any extra bytes in buffer not part of the integer are set to zero, with
1269/// respect to endianness. To avoid the branch to check for extra buffer bytes,1270/// respect to endianness. To avoid the branch to check for extra buffer bytes,
1270/// use writeInt instead.1271/// use writeInt instead.
1271pub fn writeIntSlice(comptime T: type, buffer: []u8, value: T, endian: builtin.Endian) void {1272pub fn writeIntSlice(comptime T: type, buffer: []u8, value: T, endian: Endian) void {
1272 comptime assert(@typeInfo(T).Int.bits % 8 == 0);1273 comptime assert(@typeInfo(T).Int.bits % 8 == 0);
1273 return switch (endian) {1274 return switch (endian) {
1274 .Little => writeIntSliceLittle(T, buffer, value),1275 .Little => writeIntSliceLittle(T, buffer, value),
...@@ -1678,10 +1679,10 @@ fn testReadIntImpl() void {...@@ -1678,10 +1679,10 @@ fn testReadIntImpl() void {
1678 0x56,1679 0x56,
1679 0x78,1680 0x78,
1680 };1681 };
1681 testing.expect(readInt(u32, &bytes, builtin.Endian.Big) == 0x12345678);1682 testing.expect(readInt(u32, &bytes, Endian.Big) == 0x12345678);
1682 testing.expect(readIntBig(u32, &bytes) == 0x12345678);1683 testing.expect(readIntBig(u32, &bytes) == 0x12345678);
1683 testing.expect(readIntBig(i32, &bytes) == 0x12345678);1684 testing.expect(readIntBig(i32, &bytes) == 0x12345678);
1684 testing.expect(readInt(u32, &bytes, builtin.Endian.Little) == 0x78563412);1685 testing.expect(readInt(u32, &bytes, Endian.Little) == 0x78563412);
1685 testing.expect(readIntLittle(u32, &bytes) == 0x78563412);1686 testing.expect(readIntLittle(u32, &bytes) == 0x78563412);
1686 testing.expect(readIntLittle(i32, &bytes) == 0x78563412);1687 testing.expect(readIntLittle(i32, &bytes) == 0x78563412);
1687 }1688 }
...@@ -1692,7 +1693,7 @@ fn testReadIntImpl() void {...@@ -1692,7 +1693,7 @@ fn testReadIntImpl() void {
1692 0x12,1693 0x12,
1693 0x34,1694 0x34,
1694 };1695 };
1695 const answer = readInt(u32, &buf, builtin.Endian.Big);1696 const answer = readInt(u32, &buf, Endian.Big);
1696 testing.expect(answer == 0x00001234);1697 testing.expect(answer == 0x00001234);
1697 }1698 }
1698 {1699 {
...@@ -1702,7 +1703,7 @@ fn testReadIntImpl() void {...@@ -1702,7 +1703,7 @@ fn testReadIntImpl() void {
1702 0x00,1703 0x00,
1703 0x00,1704 0x00,
1704 };1705 };
1705 const answer = readInt(u32, &buf, builtin.Endian.Little);1706 const answer = readInt(u32, &buf, Endian.Little);
1706 testing.expect(answer == 0x00003412);1707 testing.expect(answer == 0x00003412);
1707 }1708 }
1708 {1709 {
...@@ -1724,19 +1725,19 @@ test "writeIntSlice" {...@@ -1724,19 +1725,19 @@ test "writeIntSlice" {
1724fn testWriteIntImpl() void {1725fn testWriteIntImpl() void {
1725 var bytes: [8]u8 = undefined;1726 var bytes: [8]u8 = undefined;
17261727
1727 writeIntSlice(u0, bytes[0..], 0, builtin.Endian.Big);1728 writeIntSlice(u0, bytes[0..], 0, Endian.Big);
1728 testing.expect(eql(u8, &bytes, &[_]u8{1729 testing.expect(eql(u8, &bytes, &[_]u8{
1729 0x00, 0x00, 0x00, 0x00,1730 0x00, 0x00, 0x00, 0x00,
1730 0x00, 0x00, 0x00, 0x00,1731 0x00, 0x00, 0x00, 0x00,
1731 }));1732 }));
17321733
1733 writeIntSlice(u0, bytes[0..], 0, builtin.Endian.Little);1734 writeIntSlice(u0, bytes[0..], 0, Endian.Little);
1734 testing.expect(eql(u8, &bytes, &[_]u8{1735 testing.expect(eql(u8, &bytes, &[_]u8{
1735 0x00, 0x00, 0x00, 0x00,1736 0x00, 0x00, 0x00, 0x00,
1736 0x00, 0x00, 0x00, 0x00,1737 0x00, 0x00, 0x00, 0x00,
1737 }));1738 }));
17381739
1739 writeIntSlice(u64, bytes[0..], 0x12345678CAFEBABE, builtin.Endian.Big);1740 writeIntSlice(u64, bytes[0..], 0x12345678CAFEBABE, Endian.Big);
1740 testing.expect(eql(u8, &bytes, &[_]u8{1741 testing.expect(eql(u8, &bytes, &[_]u8{
1741 0x12,1742 0x12,
1742 0x34,1743 0x34,
...@@ -1748,7 +1749,7 @@ fn testWriteIntImpl() void {...@@ -1748,7 +1749,7 @@ fn testWriteIntImpl() void {
1748 0xBE,1749 0xBE,
1749 }));1750 }));
17501751
1751 writeIntSlice(u64, bytes[0..], 0xBEBAFECA78563412, builtin.Endian.Little);1752 writeIntSlice(u64, bytes[0..], 0xBEBAFECA78563412, Endian.Little);
1752 testing.expect(eql(u8, &bytes, &[_]u8{1753 testing.expect(eql(u8, &bytes, &[_]u8{
1753 0x12,1754 0x12,
1754 0x34,1755 0x34,
...@@ -1760,7 +1761,7 @@ fn testWriteIntImpl() void {...@@ -1760,7 +1761,7 @@ fn testWriteIntImpl() void {
1760 0xBE,1761 0xBE,
1761 }));1762 }));
17621763
1763 writeIntSlice(u32, bytes[0..], 0x12345678, builtin.Endian.Big);1764 writeIntSlice(u32, bytes[0..], 0x12345678, Endian.Big);
1764 testing.expect(eql(u8, &bytes, &[_]u8{1765 testing.expect(eql(u8, &bytes, &[_]u8{
1765 0x00,1766 0x00,
1766 0x00,1767 0x00,
...@@ -1772,7 +1773,7 @@ fn testWriteIntImpl() void {...@@ -1772,7 +1773,7 @@ fn testWriteIntImpl() void {
1772 0x78,1773 0x78,
1773 }));1774 }));
17741775
1775 writeIntSlice(u32, bytes[0..], 0x78563412, builtin.Endian.Little);1776 writeIntSlice(u32, bytes[0..], 0x78563412, Endian.Little);
1776 testing.expect(eql(u8, &bytes, &[_]u8{1777 testing.expect(eql(u8, &bytes, &[_]u8{
1777 0x12,1778 0x12,
1778 0x34,1779 0x34,
...@@ -1784,7 +1785,7 @@ fn testWriteIntImpl() void {...@@ -1784,7 +1785,7 @@ fn testWriteIntImpl() void {
1784 0x00,1785 0x00,
1785 }));1786 }));
17861787
1787 writeIntSlice(u16, bytes[0..], 0x1234, builtin.Endian.Big);1788 writeIntSlice(u16, bytes[0..], 0x1234, Endian.Big);
1788 testing.expect(eql(u8, &bytes, &[_]u8{1789 testing.expect(eql(u8, &bytes, &[_]u8{
1789 0x00,1790 0x00,
1790 0x00,1791 0x00,
...@@ -1796,7 +1797,7 @@ fn testWriteIntImpl() void {...@@ -1796,7 +1797,7 @@ fn testWriteIntImpl() void {
1796 0x34,1797 0x34,
1797 }));1798 }));
17981799
1799 writeIntSlice(u16, bytes[0..], 0x1234, builtin.Endian.Little);1800 writeIntSlice(u16, bytes[0..], 0x1234, Endian.Little);
1800 testing.expect(eql(u8, &bytes, &[_]u8{1801 testing.expect(eql(u8, &bytes, &[_]u8{
1801 0x34,1802 0x34,
1802 0x12,1803 0x12,
...@@ -1949,7 +1950,7 @@ test "replaceOwned" {...@@ -1949,7 +1950,7 @@ test "replaceOwned" {
19491950
1950/// Converts a little-endian integer to host endianness.1951/// Converts a little-endian integer to host endianness.
1951pub fn littleToNative(comptime T: type, x: T) T {1952pub fn littleToNative(comptime T: type, x: T) T {
1952 return switch (builtin.endian) {1953 return switch (native_endian) {
1953 .Little => x,1954 .Little => x,
1954 .Big => @byteSwap(T, x),1955 .Big => @byteSwap(T, x),
1955 };1956 };
...@@ -1957,14 +1958,14 @@ pub fn littleToNative(comptime T: type, x: T) T {...@@ -1957,14 +1958,14 @@ pub fn littleToNative(comptime T: type, x: T) T {
19571958
1958/// Converts a big-endian integer to host endianness.1959/// Converts a big-endian integer to host endianness.
1959pub fn bigToNative(comptime T: type, x: T) T {1960pub fn bigToNative(comptime T: type, x: T) T {
1960 return switch (builtin.endian) {1961 return switch (native_endian) {
1961 .Little => @byteSwap(T, x),1962 .Little => @byteSwap(T, x),
1962 .Big => x,1963 .Big => x,
1963 };1964 };
1964}1965}
19651966
1966/// Converts an integer from specified endianness to host endianness.1967/// Converts an integer from specified endianness to host endianness.
1967pub fn toNative(comptime T: type, x: T, endianness_of_x: builtin.Endian) T {1968pub fn toNative(comptime T: type, x: T, endianness_of_x: Endian) T {
1968 return switch (endianness_of_x) {1969 return switch (endianness_of_x) {
1969 .Little => littleToNative(T, x),1970 .Little => littleToNative(T, x),
1970 .Big => bigToNative(T, x),1971 .Big => bigToNative(T, x),
...@@ -1972,7 +1973,7 @@ pub fn toNative(comptime T: type, x: T, endianness_of_x: builtin.Endian) T {...@@ -1972,7 +1973,7 @@ pub fn toNative(comptime T: type, x: T, endianness_of_x: builtin.Endian) T {
1972}1973}
19731974
1974/// Converts an integer which has host endianness to the desired endianness.1975/// Converts an integer which has host endianness to the desired endianness.
1975pub fn nativeTo(comptime T: type, x: T, desired_endianness: builtin.Endian) T {1976pub fn nativeTo(comptime T: type, x: T, desired_endianness: Endian) T {
1976 return switch (desired_endianness) {1977 return switch (desired_endianness) {
1977 .Little => nativeToLittle(T, x),1978 .Little => nativeToLittle(T, x),
1978 .Big => nativeToBig(T, x),1979 .Big => nativeToBig(T, x),
...@@ -1981,7 +1982,7 @@ pub fn nativeTo(comptime T: type, x: T, desired_endianness: builtin.Endian) T {...@@ -1981,7 +1982,7 @@ pub fn nativeTo(comptime T: type, x: T, desired_endianness: builtin.Endian) T {
19811982
1982/// Converts an integer which has host endianness to little endian.1983/// Converts an integer which has host endianness to little endian.
1983pub fn nativeToLittle(comptime T: type, x: T) T {1984pub fn nativeToLittle(comptime T: type, x: T) T {
1984 return switch (builtin.endian) {1985 return switch (native_endian) {
1985 .Little => x,1986 .Little => x,
1986 .Big => @byteSwap(T, x),1987 .Big => @byteSwap(T, x),
1987 };1988 };
...@@ -1989,13 +1990,13 @@ pub fn nativeToLittle(comptime T: type, x: T) T {...@@ -1989,13 +1990,13 @@ pub fn nativeToLittle(comptime T: type, x: T) T {
19891990
1990/// Converts an integer which has host endianness to big endian.1991/// Converts an integer which has host endianness to big endian.
1991pub fn nativeToBig(comptime T: type, x: T) T {1992pub fn nativeToBig(comptime T: type, x: T) T {
1992 return switch (builtin.endian) {1993 return switch (native_endian) {
1993 .Little => @byteSwap(T, x),1994 .Little => @byteSwap(T, x),
1994 .Big => x,1995 .Big => x,
1995 };1996 };
1996}1997}
19971998
1998fn CopyPtrAttrs(comptime source: type, comptime size: builtin.TypeInfo.Pointer.Size, comptime child: type) type {1999fn CopyPtrAttrs(comptime source: type, comptime size: std.builtin.TypeInfo.Pointer.Size, comptime child: type) type {
1999 const info = @typeInfo(source).Pointer;2000 const info = @typeInfo(source).Pointer;
2000 return @Type(.{2001 return @Type(.{
2001 .Pointer = .{2002 .Pointer = .{
...@@ -2027,7 +2028,7 @@ pub fn asBytes(ptr: anytype) AsBytesReturnType(@TypeOf(ptr)) {...@@ -2027,7 +2028,7 @@ pub fn asBytes(ptr: anytype) AsBytesReturnType(@TypeOf(ptr)) {
20272028
2028test "asBytes" {2029test "asBytes" {
2029 const deadbeef = @as(u32, 0xDEADBEEF);2030 const deadbeef = @as(u32, 0xDEADBEEF);
2030 const deadbeef_bytes = switch (builtin.endian) {2031 const deadbeef_bytes = switch (native_endian) {
2031 .Big => "\xDE\xAD\xBE\xEF",2032 .Big => "\xDE\xAD\xBE\xEF",
2032 .Little => "\xEF\xBE\xAD\xDE",2033 .Little => "\xEF\xBE\xAD\xDE",
2033 };2034 };
...@@ -2080,13 +2081,13 @@ pub fn toBytes(value: anytype) [@sizeOf(@TypeOf(value))]u8 {...@@ -2080,13 +2081,13 @@ pub fn toBytes(value: anytype) [@sizeOf(@TypeOf(value))]u8 {
20802081
2081test "toBytes" {2082test "toBytes" {
2082 var my_bytes = toBytes(@as(u32, 0x12345678));2083 var my_bytes = toBytes(@as(u32, 0x12345678));
2083 switch (builtin.endian) {2084 switch (native_endian) {
2084 .Big => testing.expect(eql(u8, &my_bytes, "\x12\x34\x56\x78")),2085 .Big => testing.expect(eql(u8, &my_bytes, "\x12\x34\x56\x78")),
2085 .Little => testing.expect(eql(u8, &my_bytes, "\x78\x56\x34\x12")),2086 .Little => testing.expect(eql(u8, &my_bytes, "\x78\x56\x34\x12")),
2086 }2087 }
20872088
2088 my_bytes[0] = '\x99';2089 my_bytes[0] = '\x99';
2089 switch (builtin.endian) {2090 switch (native_endian) {
2090 .Big => testing.expect(eql(u8, &my_bytes, "\x99\x34\x56\x78")),2091 .Big => testing.expect(eql(u8, &my_bytes, "\x99\x34\x56\x78")),
2091 .Little => testing.expect(eql(u8, &my_bytes, "\x99\x56\x34\x12")),2092 .Little => testing.expect(eql(u8, &my_bytes, "\x99\x56\x34\x12")),
2092 }2093 }
...@@ -2113,14 +2114,14 @@ pub fn bytesAsValue(comptime T: type, bytes: anytype) BytesAsValueReturnType(T,...@@ -2113,14 +2114,14 @@ pub fn bytesAsValue(comptime T: type, bytes: anytype) BytesAsValueReturnType(T,
21132114
2114test "bytesAsValue" {2115test "bytesAsValue" {
2115 const deadbeef = @as(u32, 0xDEADBEEF);2116 const deadbeef = @as(u32, 0xDEADBEEF);
2116 const deadbeef_bytes = switch (builtin.endian) {2117 const deadbeef_bytes = switch (native_endian) {
2117 .Big => "\xDE\xAD\xBE\xEF",2118 .Big => "\xDE\xAD\xBE\xEF",
2118 .Little => "\xEF\xBE\xAD\xDE",2119 .Little => "\xEF\xBE\xAD\xDE",
2119 };2120 };
21202121
2121 testing.expect(deadbeef == bytesAsValue(u32, deadbeef_bytes).*);2122 testing.expect(deadbeef == bytesAsValue(u32, deadbeef_bytes).*);
21222123
2123 var codeface_bytes: [4]u8 = switch (builtin.endian) {2124 var codeface_bytes: [4]u8 = switch (native_endian) {
2124 .Big => "\xC0\xDE\xFA\xCE",2125 .Big => "\xC0\xDE\xFA\xCE",
2125 .Little => "\xCE\xFA\xDE\xC0",2126 .Little => "\xCE\xFA\xDE\xC0",
2126 }.*;2127 }.*;
...@@ -2168,7 +2169,7 @@ pub fn bytesToValue(comptime T: type, bytes: anytype) T {...@@ -2168,7 +2169,7 @@ pub fn bytesToValue(comptime T: type, bytes: anytype) T {
2168 return bytesAsValue(T, bytes).*;2169 return bytesAsValue(T, bytes).*;
2169}2170}
2170test "bytesToValue" {2171test "bytesToValue" {
2171 const deadbeef_bytes = switch (builtin.endian) {2172 const deadbeef_bytes = switch (native_endian) {
2172 .Big => "\xDE\xAD\xBE\xEF",2173 .Big => "\xDE\xAD\xBE\xEF",
2173 .Little => "\xEF\xBE\xAD\xDE",2174 .Little => "\xEF\xBE\xAD\xDE",
2174 };2175 };
...@@ -2297,7 +2298,7 @@ test "sliceAsBytes" {...@@ -2297,7 +2298,7 @@ test "sliceAsBytes" {
2297 const bytes = [_]u16{ 0xDEAD, 0xBEEF };2298 const bytes = [_]u16{ 0xDEAD, 0xBEEF };
2298 const slice = sliceAsBytes(bytes[0..]);2299 const slice = sliceAsBytes(bytes[0..]);
2299 testing.expect(slice.len == 4);2300 testing.expect(slice.len == 4);
2300 testing.expect(eql(u8, slice, switch (builtin.endian) {2301 testing.expect(eql(u8, slice, switch (native_endian) {
2301 .Big => "\xDE\xAD\xBE\xEF",2302 .Big => "\xDE\xAD\xBE\xEF",
2302 .Little => "\xAD\xDE\xEF\xBE",2303 .Little => "\xAD\xDE\xEF\xBE",
2303 }));2304 }));
...@@ -2319,7 +2320,7 @@ test "sliceAsBytes packed struct at runtime and comptime" {...@@ -2319,7 +2320,7 @@ test "sliceAsBytes packed struct at runtime and comptime" {
2319 var foo: Foo = undefined;2320 var foo: Foo = undefined;
2320 var slice = sliceAsBytes(@as(*[1]Foo, &foo)[0..1]);2321 var slice = sliceAsBytes(@as(*[1]Foo, &foo)[0..1]);
2321 slice[0] = 0x13;2322 slice[0] = 0x13;
2322 switch (builtin.endian) {2323 switch (native_endian) {
2323 .Big => {2324 .Big => {
2324 testing.expect(foo.a == 0x1);2325 testing.expect(foo.a == 0x1);
2325 testing.expect(foo.b == 0x3);2326 testing.expect(foo.b == 0x3);
lib/std/meta.zig+1-1
...@@ -4,7 +4,7 @@...@@ -4,7 +4,7 @@
4// The MIT license requires this copyright notice to be included in all copies4// The MIT license requires this copyright notice to be included in all copies
5// and substantial portions of the software.5// and substantial portions of the software.
6const std = @import("std.zig");6const std = @import("std.zig");
7const builtin = @import("builtin");7const builtin = std.builtin;
8const debug = std.debug;8const debug = std.debug;
9const mem = std.mem;9const mem = std.mem;
10const math = std.math;10const math = std.math;
lib/std/net.zig+1-1
...@@ -4,7 +4,7 @@...@@ -4,7 +4,7 @@
4// The MIT license requires this copyright notice to be included in all copies4// The MIT license requires this copyright notice to be included in all copies
5// and substantial portions of the software.5// and substantial portions of the software.
6const std = @import("std.zig");6const std = @import("std.zig");
7const builtin = @import("builtin");7const builtin = std.builtin;
8const assert = std.debug.assert;8const assert = std.debug.assert;
9const net = @This();9const net = @This();
10const mem = std.mem;10const mem = std.mem;
lib/std/os.zig+1-1
...@@ -21,7 +21,7 @@...@@ -21,7 +21,7 @@
2121
22const root = @import("root");22const root = @import("root");
23const std = @import("std.zig");23const std = @import("std.zig");
24const builtin = @import("builtin");24const builtin = std.builtin;
25const assert = std.debug.assert;25const assert = std.debug.assert;
26const math = std.math;26const math = std.math;
27const mem = std.mem;27const mem = std.mem;
lib/std/os/bits/linux.zig+12-12
...@@ -3,17 +3,17 @@...@@ -3,17 +3,17 @@
3// This file is part of [zig](https://ziglang.org/), which is MIT licensed.3// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
4// The MIT license requires this copyright notice to be included in all copies4// The MIT license requires this copyright notice to be included in all copies
5// and substantial portions of the software.5// and substantial portions of the software.
6const builtin = @import("builtin");
7const std = @import("../../std.zig");6const std = @import("../../std.zig");
8const maxInt = std.math.maxInt;7const maxInt = std.math.maxInt;
8const arch = std.Target.current.cpu.arch;
9usingnamespace @import("../bits.zig");9usingnamespace @import("../bits.zig");
1010
11pub usingnamespace switch (builtin.arch) {11pub usingnamespace switch (arch) {
12 .mips, .mipsel => @import("linux/errno-mips.zig"),12 .mips, .mipsel => @import("linux/errno-mips.zig"),
13 else => @import("linux/errno-generic.zig"),13 else => @import("linux/errno-generic.zig"),
14};14};
1515
16pub usingnamespace switch (builtin.arch) {16pub usingnamespace switch (arch) {
17 .i386 => @import("linux/i386.zig"),17 .i386 => @import("linux/i386.zig"),
18 .x86_64 => @import("linux/x86_64.zig"),18 .x86_64 => @import("linux/x86_64.zig"),
19 .aarch64 => @import("linux/arm64.zig"),19 .aarch64 => @import("linux/arm64.zig"),
...@@ -30,9 +30,9 @@ pub usingnamespace @import("linux/netlink.zig");...@@ -30,9 +30,9 @@ pub usingnamespace @import("linux/netlink.zig");
30pub usingnamespace @import("linux/prctl.zig");30pub usingnamespace @import("linux/prctl.zig");
31pub usingnamespace @import("linux/securebits.zig");31pub usingnamespace @import("linux/securebits.zig");
3232
33const is_mips = builtin.arch.isMIPS();33const is_mips = arch.isMIPS();
34const is_ppc64 = builtin.arch.isPPC64();34const is_ppc64 = arch.isPPC64();
35const is_sparc = builtin.arch.isSPARC();35const is_sparc = arch.isSPARC();
3636
37pub const pid_t = i32;37pub const pid_t = i32;
38pub const fd_t = i32;38pub const fd_t = i32;
...@@ -134,7 +134,7 @@ pub const PROT_WRITE = 0x2;...@@ -134,7 +134,7 @@ pub const PROT_WRITE = 0x2;
134pub const PROT_EXEC = 0x4;134pub const PROT_EXEC = 0x4;
135135
136/// page may be used for atomic ops136/// page may be used for atomic ops
137pub const PROT_SEM = switch (builtin.arch) {137pub const PROT_SEM = switch (arch) {
138 // TODO: also xtensa138 // TODO: also xtensa
139 .mips, .mipsel, .mips64, .mips64el => 0x10,139 .mips, .mipsel, .mips64, .mips64el => 0x10,
140 else => 0x8,140 else => 0x8,
...@@ -1004,7 +1004,7 @@ pub const sigset_t = [1024 / 32]u32;...@@ -1004,7 +1004,7 @@ pub const sigset_t = [1024 / 32]u32;
1004pub const all_mask: sigset_t = [_]u32{0xffffffff} ** sigset_t.len;1004pub const all_mask: sigset_t = [_]u32{0xffffffff} ** sigset_t.len;
1005pub const app_mask: sigset_t = [2]u32{ 0xfffffffc, 0x7fffffff } ++ [_]u32{0xffffffff} ** 30;1005pub const app_mask: sigset_t = [2]u32{ 0xfffffffc, 0x7fffffff } ++ [_]u32{0xffffffff} ** 30;
10061006
1007pub const k_sigaction = switch (builtin.arch) {1007pub const k_sigaction = switch (arch) {
1008 .mips, .mipsel => extern struct {1008 .mips, .mipsel => extern struct {
1009 flags: c_uint,1009 flags: c_uint,
1010 handler: ?fn (c_int) callconv(.C) void,1010 handler: ?fn (c_int) callconv(.C) void,
...@@ -1121,7 +1121,7 @@ pub const epoll_data = extern union {...@@ -1121,7 +1121,7 @@ pub const epoll_data = extern union {
11211121
1122// On x86_64 the structure is packed so that it matches the definition of its1122// On x86_64 the structure is packed so that it matches the definition of its
1123// 32bit counterpart1123// 32bit counterpart
1124pub const epoll_event = switch (builtin.arch) {1124pub const epoll_event = switch (arch) {
1125 .x86_64 => packed struct {1125 .x86_64 => packed struct {
1126 events: u32,1126 events: u32,
1127 data: epoll_data,1127 data: epoll_data,
...@@ -1288,12 +1288,12 @@ pub fn CPU_COUNT(set: cpu_set_t) cpu_count_t {...@@ -1288,12 +1288,12 @@ pub fn CPU_COUNT(set: cpu_set_t) cpu_count_t {
1288//#define CPU_ZERO(set) CPU_ZERO_S(sizeof(cpu_set_t),set)1288//#define CPU_ZERO(set) CPU_ZERO_S(sizeof(cpu_set_t),set)
1289//#define CPU_EQUAL(s1,s2) CPU_EQUAL_S(sizeof(cpu_set_t),s1,s2)1289//#define CPU_EQUAL(s1,s2) CPU_EQUAL_S(sizeof(cpu_set_t),s1,s2)
12901290
1291pub const MINSIGSTKSZ = switch (builtin.arch) {1291pub const MINSIGSTKSZ = switch (arch) {
1292 .i386, .x86_64, .arm, .mipsel => 2048,1292 .i386, .x86_64, .arm, .mipsel => 2048,
1293 .aarch64 => 5120,1293 .aarch64 => 5120,
1294 else => @compileError("MINSIGSTKSZ not defined for this architecture"),1294 else => @compileError("MINSIGSTKSZ not defined for this architecture"),
1295};1295};
1296pub const SIGSTKSZ = switch (builtin.arch) {1296pub const SIGSTKSZ = switch (arch) {
1297 .i386, .x86_64, .arm, .mipsel => 8192,1297 .i386, .x86_64, .arm, .mipsel => 8192,
1298 .aarch64 => 16384,1298 .aarch64 => 16384,
1299 else => @compileError("SIGSTKSZ not defined for this architecture"),1299 else => @compileError("SIGSTKSZ not defined for this architecture"),
...@@ -2053,7 +2053,7 @@ pub const B3000000 = 0o0010015;...@@ -2053,7 +2053,7 @@ pub const B3000000 = 0o0010015;
2053pub const B3500000 = 0o0010016;2053pub const B3500000 = 0o0010016;
2054pub const B4000000 = 0o0010017;2054pub const B4000000 = 0o0010017;
20552055
2056pub usingnamespace switch (builtin.arch) {2056pub usingnamespace switch (arch) {
2057 .powerpc, .powerpc64, .powerpc64le => struct {2057 .powerpc, .powerpc64, .powerpc64le => struct {
2058 pub const VINTR = 0;2058 pub const VINTR = 0;
2059 pub const VQUIT = 1;2059 pub const VQUIT = 1;
lib/std/os/darwin.zig-1
...@@ -3,7 +3,6 @@...@@ -3,7 +3,6 @@
3// This file is part of [zig](https://ziglang.org/), which is MIT licensed.3// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
4// The MIT license requires this copyright notice to be included in all copies4// The MIT license requires this copyright notice to be included in all copies
5// and substantial portions of the software.5// and substantial portions of the software.
6const builtin = @import("builtin");
7const std = @import("../std.zig");6const std = @import("../std.zig");
8pub usingnamespace std.c;7pub usingnamespace std.c;
9pub usingnamespace @import("bits.zig");8pub usingnamespace @import("bits.zig");
lib/std/os/linux.zig+24-23
...@@ -11,14 +11,15 @@...@@ -11,14 +11,15 @@
11// provide `rename` when only the `renameat` syscall exists.11// provide `rename` when only the `renameat` syscall exists.
12// * Does not support POSIX thread cancellation.12// * Does not support POSIX thread cancellation.
13const std = @import("../std.zig");13const std = @import("../std.zig");
14const builtin = std.builtin;
15const assert = std.debug.assert;14const assert = std.debug.assert;
16const maxInt = std.math.maxInt;15const maxInt = std.math.maxInt;
17const elf = std.elf;16const elf = std.elf;
18const vdso = @import("linux/vdso.zig");17const vdso = @import("linux/vdso.zig");
19const dl = @import("../dynamic_library.zig");18const dl = @import("../dynamic_library.zig");
19const native_arch = std.Target.current.cpu.arch;
20const native_endian = native_arch.endian();
2021
21pub usingnamespace switch (builtin.arch) {22pub usingnamespace switch (native_arch) {
22 .i386 => @import("linux/i386.zig"),23 .i386 => @import("linux/i386.zig"),
23 .x86_64 => @import("linux/x86_64.zig"),24 .x86_64 => @import("linux/x86_64.zig"),
24 .aarch64 => @import("linux/arm64.zig"),25 .aarch64 => @import("linux/arm64.zig"),
...@@ -58,7 +59,7 @@ const require_aligned_register_pair =...@@ -58,7 +59,7 @@ const require_aligned_register_pair =
5859
59// Split a 64bit value into a {LSB,MSB} pair.60// Split a 64bit value into a {LSB,MSB} pair.
60fn splitValue64(val: u64) [2]u32 {61fn splitValue64(val: u64) [2]u32 {
61 switch (builtin.endian) {62 switch (native_endian) {
62 .Little => return [2]u32{63 .Little => return [2]u32{
63 @truncate(u32, val),64 @truncate(u32, val),
64 @truncate(u32, val >> 32),65 @truncate(u32, val >> 32),
...@@ -113,7 +114,7 @@ pub fn execve(path: [*:0]const u8, argv: [*:null]const ?[*:0]const u8, envp: [*:...@@ -113,7 +114,7 @@ pub fn execve(path: [*:0]const u8, argv: [*:null]const ?[*:0]const u8, envp: [*:
113}114}
114115
115pub fn fork() usize {116pub fn fork() usize {
116 if (comptime builtin.arch.isSPARC()) {117 if (comptime native_arch.isSPARC()) {
117 return syscall_fork();118 return syscall_fork();
118 } else if (@hasField(SYS, "fork")) {119 } else if (@hasField(SYS, "fork")) {
119 return syscall0(.fork);120 return syscall0(.fork);
...@@ -431,7 +432,7 @@ pub fn faccessat(dirfd: i32, path: [*:0]const u8, mode: u32, flags: u32) usize {...@@ -431,7 +432,7 @@ pub fn faccessat(dirfd: i32, path: [*:0]const u8, mode: u32, flags: u32) usize {
431}432}
432433
433pub fn pipe(fd: *[2]i32) usize {434pub fn pipe(fd: *[2]i32) usize {
434 if (comptime (builtin.arch.isMIPS() or builtin.arch.isSPARC())) {435 if (comptime (native_arch.isMIPS() or native_arch.isSPARC())) {
435 return syscall_pipe(fd);436 return syscall_pipe(fd);
436 } else if (@hasField(SYS, "pipe")) {437 } else if (@hasField(SYS, "pipe")) {
437 return syscall1(.pipe, @ptrToInt(fd));438 return syscall1(.pipe, @ptrToInt(fd));
...@@ -912,7 +913,7 @@ pub fn sigaction(sig: u6, noalias act: ?*const Sigaction, noalias oact: ?*Sigact...@@ -912,7 +913,7 @@ pub fn sigaction(sig: u6, noalias act: ?*const Sigaction, noalias oact: ?*Sigact
912 const ksa_arg = if (act != null) @ptrToInt(&ksa) else 0;913 const ksa_arg = if (act != null) @ptrToInt(&ksa) else 0;
913 const oldksa_arg = if (oact != null) @ptrToInt(&oldksa) else 0;914 const oldksa_arg = if (oact != null) @ptrToInt(&oldksa) else 0;
914915
915 const result = switch (builtin.arch) {916 const result = switch (native_arch) {
916 // The sparc version of rt_sigaction needs the restorer function to be passed as an argument too.917 // The sparc version of rt_sigaction needs the restorer function to be passed as an argument too.
917 .sparc, .sparcv9 => syscall5(.rt_sigaction, sig, ksa_arg, oldksa_arg, @ptrToInt(ksa.restorer), mask_size),918 .sparc, .sparcv9 => syscall5(.rt_sigaction, sig, ksa_arg, oldksa_arg, @ptrToInt(ksa.restorer), mask_size),
918 else => syscall4(.rt_sigaction, sig, ksa_arg, oldksa_arg, mask_size),919 else => syscall4(.rt_sigaction, sig, ksa_arg, oldksa_arg, mask_size),
...@@ -944,42 +945,42 @@ pub fn sigismember(set: *const sigset_t, sig: u6) bool {...@@ -944,42 +945,42 @@ pub fn sigismember(set: *const sigset_t, sig: u6) bool {
944}945}
945946
946pub fn getsockname(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t) usize {947pub fn getsockname(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t) usize {
947 if (builtin.arch == .i386) {948 if (native_arch == .i386) {
948 return socketcall(SC_getsockname, &[3]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @ptrToInt(len) });949 return socketcall(SC_getsockname, &[3]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @ptrToInt(len) });
949 }950 }
950 return syscall3(.getsockname, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @ptrToInt(len));951 return syscall3(.getsockname, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @ptrToInt(len));
951}952}
952953
953pub fn getpeername(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t) usize {954pub fn getpeername(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t) usize {
954 if (builtin.arch == .i386) {955 if (native_arch == .i386) {
955 return socketcall(SC_getpeername, &[3]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @ptrToInt(len) });956 return socketcall(SC_getpeername, &[3]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @ptrToInt(len) });
956 }957 }
957 return syscall3(.getpeername, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @ptrToInt(len));958 return syscall3(.getpeername, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @ptrToInt(len));
958}959}
959960
960pub fn socket(domain: u32, socket_type: u32, protocol: u32) usize {961pub fn socket(domain: u32, socket_type: u32, protocol: u32) usize {
961 if (builtin.arch == .i386) {962 if (native_arch == .i386) {
962 return socketcall(SC_socket, &[3]usize{ domain, socket_type, protocol });963 return socketcall(SC_socket, &[3]usize{ domain, socket_type, protocol });
963 }964 }
964 return syscall3(.socket, domain, socket_type, protocol);965 return syscall3(.socket, domain, socket_type, protocol);
965}966}
966967
967pub fn setsockopt(fd: i32, level: u32, optname: u32, optval: [*]const u8, optlen: socklen_t) usize {968pub fn setsockopt(fd: i32, level: u32, optname: u32, optval: [*]const u8, optlen: socklen_t) usize {
968 if (builtin.arch == .i386) {969 if (native_arch == .i386) {
969 return socketcall(SC_setsockopt, &[5]usize{ @bitCast(usize, @as(isize, fd)), level, optname, @ptrToInt(optval), @intCast(usize, optlen) });970 return socketcall(SC_setsockopt, &[5]usize{ @bitCast(usize, @as(isize, fd)), level, optname, @ptrToInt(optval), @intCast(usize, optlen) });
970 }971 }
971 return syscall5(.setsockopt, @bitCast(usize, @as(isize, fd)), level, optname, @ptrToInt(optval), @intCast(usize, optlen));972 return syscall5(.setsockopt, @bitCast(usize, @as(isize, fd)), level, optname, @ptrToInt(optval), @intCast(usize, optlen));
972}973}
973974
974pub fn getsockopt(fd: i32, level: u32, optname: u32, noalias optval: [*]u8, noalias optlen: *socklen_t) usize {975pub fn getsockopt(fd: i32, level: u32, optname: u32, noalias optval: [*]u8, noalias optlen: *socklen_t) usize {
975 if (builtin.arch == .i386) {976 if (native_arch == .i386) {
976 return socketcall(SC_getsockopt, &[5]usize{ @bitCast(usize, @as(isize, fd)), level, optname, @ptrToInt(optval), @ptrToInt(optlen) });977 return socketcall(SC_getsockopt, &[5]usize{ @bitCast(usize, @as(isize, fd)), level, optname, @ptrToInt(optval), @ptrToInt(optlen) });
977 }978 }
978 return syscall5(.getsockopt, @bitCast(usize, @as(isize, fd)), level, optname, @ptrToInt(optval), @ptrToInt(optlen));979 return syscall5(.getsockopt, @bitCast(usize, @as(isize, fd)), level, optname, @ptrToInt(optval), @ptrToInt(optlen));
979}980}
980981
981pub fn sendmsg(fd: i32, msg: *const msghdr_const, flags: u32) usize {982pub fn sendmsg(fd: i32, msg: *const msghdr_const, flags: u32) usize {
982 if (builtin.arch == .i386) {983 if (native_arch == .i386) {
983 return socketcall(SC_sendmsg, &[3]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(msg), flags });984 return socketcall(SC_sendmsg, &[3]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(msg), flags });
984 }985 }
985 return syscall3(.sendmsg, @bitCast(usize, @as(isize, fd)), @ptrToInt(msg), flags);986 return syscall3(.sendmsg, @bitCast(usize, @as(isize, fd)), @ptrToInt(msg), flags);
...@@ -1026,49 +1027,49 @@ pub fn sendmmsg(fd: i32, msgvec: [*]mmsghdr_const, vlen: u32, flags: u32) usize...@@ -1026,49 +1027,49 @@ pub fn sendmmsg(fd: i32, msgvec: [*]mmsghdr_const, vlen: u32, flags: u32) usize
1026}1027}
10271028
1028pub fn connect(fd: i32, addr: *const c_void, len: socklen_t) usize {1029pub fn connect(fd: i32, addr: *const c_void, len: socklen_t) usize {
1029 if (builtin.arch == .i386) {1030 if (native_arch == .i386) {
1030 return socketcall(SC_connect, &[3]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), len });1031 return socketcall(SC_connect, &[3]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), len });
1031 }1032 }
1032 return syscall3(.connect, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), len);1033 return syscall3(.connect, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), len);
1033}1034}
10341035
1035pub fn recvmsg(fd: i32, msg: *msghdr, flags: u32) usize {1036pub fn recvmsg(fd: i32, msg: *msghdr, flags: u32) usize {
1036 if (builtin.arch == .i386) {1037 if (native_arch == .i386) {
1037 return socketcall(SC_recvmsg, &[3]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(msg), flags });1038 return socketcall(SC_recvmsg, &[3]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(msg), flags });
1038 }1039 }
1039 return syscall3(.recvmsg, @bitCast(usize, @as(isize, fd)), @ptrToInt(msg), flags);1040 return syscall3(.recvmsg, @bitCast(usize, @as(isize, fd)), @ptrToInt(msg), flags);
1040}1041}
10411042
1042pub fn recvfrom(fd: i32, noalias buf: [*]u8, len: usize, flags: u32, noalias addr: ?*sockaddr, noalias alen: ?*socklen_t) usize {1043pub fn recvfrom(fd: i32, noalias buf: [*]u8, len: usize, flags: u32, noalias addr: ?*sockaddr, noalias alen: ?*socklen_t) usize {
1043 if (builtin.arch == .i386) {1044 if (native_arch == .i386) {
1044 return socketcall(SC_recvfrom, &[6]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), len, flags, @ptrToInt(addr), @ptrToInt(alen) });1045 return socketcall(SC_recvfrom, &[6]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), len, flags, @ptrToInt(addr), @ptrToInt(alen) });
1045 }1046 }
1046 return syscall6(.recvfrom, @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), len, flags, @ptrToInt(addr), @ptrToInt(alen));1047 return syscall6(.recvfrom, @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), len, flags, @ptrToInt(addr), @ptrToInt(alen));
1047}1048}
10481049
1049pub fn shutdown(fd: i32, how: i32) usize {1050pub fn shutdown(fd: i32, how: i32) usize {
1050 if (builtin.arch == .i386) {1051 if (native_arch == .i386) {
1051 return socketcall(SC_shutdown, &[2]usize{ @bitCast(usize, @as(isize, fd)), @bitCast(usize, @as(isize, how)) });1052 return socketcall(SC_shutdown, &[2]usize{ @bitCast(usize, @as(isize, fd)), @bitCast(usize, @as(isize, how)) });
1052 }1053 }
1053 return syscall2(.shutdown, @bitCast(usize, @as(isize, fd)), @bitCast(usize, @as(isize, how)));1054 return syscall2(.shutdown, @bitCast(usize, @as(isize, fd)), @bitCast(usize, @as(isize, how)));
1054}1055}
10551056
1056pub fn bind(fd: i32, addr: *const sockaddr, len: socklen_t) usize {1057pub fn bind(fd: i32, addr: *const sockaddr, len: socklen_t) usize {
1057 if (builtin.arch == .i386) {1058 if (native_arch == .i386) {
1058 return socketcall(SC_bind, &[3]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @intCast(usize, len) });1059 return socketcall(SC_bind, &[3]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @intCast(usize, len) });
1059 }1060 }
1060 return syscall3(.bind, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @intCast(usize, len));1061 return syscall3(.bind, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @intCast(usize, len));
1061}1062}
10621063
1063pub fn listen(fd: i32, backlog: u32) usize {1064pub fn listen(fd: i32, backlog: u32) usize {
1064 if (builtin.arch == .i386) {1065 if (native_arch == .i386) {
1065 return socketcall(SC_listen, &[2]usize{ @bitCast(usize, @as(isize, fd)), backlog });1066 return socketcall(SC_listen, &[2]usize{ @bitCast(usize, @as(isize, fd)), backlog });
1066 }1067 }
1067 return syscall2(.listen, @bitCast(usize, @as(isize, fd)), backlog);1068 return syscall2(.listen, @bitCast(usize, @as(isize, fd)), backlog);
1068}1069}
10691070
1070pub fn sendto(fd: i32, buf: [*]const u8, len: usize, flags: u32, addr: ?*const sockaddr, alen: socklen_t) usize {1071pub fn sendto(fd: i32, buf: [*]const u8, len: usize, flags: u32, addr: ?*const sockaddr, alen: socklen_t) usize {
1071 if (builtin.arch == .i386) {1072 if (native_arch == .i386) {
1072 return socketcall(SC_sendto, &[6]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), len, flags, @ptrToInt(addr), @intCast(usize, alen) });1073 return socketcall(SC_sendto, &[6]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), len, flags, @ptrToInt(addr), @intCast(usize, alen) });
1073 }1074 }
1074 return syscall6(.sendto, @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), len, flags, @ptrToInt(addr), @intCast(usize, alen));1075 return syscall6(.sendto, @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), len, flags, @ptrToInt(addr), @intCast(usize, alen));
...@@ -1095,21 +1096,21 @@ pub fn sendfile(outfd: i32, infd: i32, offset: ?*i64, count: usize) usize {...@@ -1095,21 +1096,21 @@ pub fn sendfile(outfd: i32, infd: i32, offset: ?*i64, count: usize) usize {
1095}1096}
10961097
1097pub fn socketpair(domain: i32, socket_type: i32, protocol: i32, fd: [2]i32) usize {1098pub fn socketpair(domain: i32, socket_type: i32, protocol: i32, fd: [2]i32) usize {
1098 if (builtin.arch == .i386) {1099 if (native_arch == .i386) {
1099 return socketcall(SC_socketpair, &[4]usize{ @intCast(usize, domain), @intCast(usize, socket_type), @intCast(usize, protocol), @ptrToInt(&fd[0]) });1100 return socketcall(SC_socketpair, &[4]usize{ @intCast(usize, domain), @intCast(usize, socket_type), @intCast(usize, protocol), @ptrToInt(&fd[0]) });
1100 }1101 }
1101 return syscall4(.socketpair, @intCast(usize, domain), @intCast(usize, socket_type), @intCast(usize, protocol), @ptrToInt(&fd[0]));1102 return syscall4(.socketpair, @intCast(usize, domain), @intCast(usize, socket_type), @intCast(usize, protocol), @ptrToInt(&fd[0]));
1102}1103}
11031104
1104pub fn accept(fd: i32, noalias addr: ?*sockaddr, noalias len: ?*socklen_t) usize {1105pub fn accept(fd: i32, noalias addr: ?*sockaddr, noalias len: ?*socklen_t) usize {
1105 if (builtin.arch == .i386) {1106 if (native_arch == .i386) {
1106 return socketcall(SC_accept, &[4]usize{ fd, addr, len, 0 });1107 return socketcall(SC_accept, &[4]usize{ fd, addr, len, 0 });
1107 }1108 }
1108 return accept4(fd, addr, len, 0);1109 return accept4(fd, addr, len, 0);
1109}1110}
11101111
1111pub fn accept4(fd: i32, noalias addr: ?*sockaddr, noalias len: ?*socklen_t, flags: u32) usize {1112pub fn accept4(fd: i32, noalias addr: ?*sockaddr, noalias len: ?*socklen_t, flags: u32) usize {
1112 if (builtin.arch == .i386) {1113 if (native_arch == .i386) {
1113 return socketcall(SC_accept4, &[4]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @ptrToInt(len), flags });1114 return socketcall(SC_accept4, &[4]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @ptrToInt(len), flags });
1114 }1115 }
1115 return syscall4(.accept4, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @ptrToInt(len), flags);1116 return syscall4(.accept4, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @ptrToInt(len), flags);
...@@ -1388,7 +1389,7 @@ pub fn madvise(address: [*]u8, len: usize, advice: u32) usize {...@@ -1388,7 +1389,7 @@ pub fn madvise(address: [*]u8, len: usize, advice: u32) usize {
1388}1389}
13891390
1390test {1391test {
1391 if (builtin.os.tag == .linux) {1392 if (std.Target.current.os.tag == .linux) {
1392 _ = @import("linux/test.zig");1393 _ = @import("linux/test.zig");
1393 }1394 }
1394}1395}
lib/std/os/linux/start_pie.zig+1-1
...@@ -1,6 +1,6 @@...@@ -1,6 +1,6 @@
1const std = @import("std");1const std = @import("std");
2const elf = std.elf;2const elf = std.elf;
3const builtin = @import("builtin");3const builtin = std.builtin;
4const assert = std.debug.assert;4const assert = std.debug.assert;
55
6const R_AMD64_RELATIVE = 8;6const R_AMD64_RELATIVE = 8;
lib/std/os/linux/test.zig+1-1
...@@ -4,7 +4,7 @@...@@ -4,7 +4,7 @@
4// The MIT license requires this copyright notice to be included in all copies4// The MIT license requires this copyright notice to be included in all copies
5// and substantial portions of the software.5// and substantial portions of the software.
6const std = @import("../../std.zig");6const std = @import("../../std.zig");
7const builtin = @import("builtin");7const builtin = std.builtin;
8const linux = std.os.linux;8const linux = std.os.linux;
9const mem = std.mem;9const mem = std.mem;
10const elf = std.elf;10const elf = std.elf;
lib/std/os/linux/tls.zig+8-8
...@@ -4,12 +4,12 @@...@@ -4,12 +4,12 @@
4// The MIT license requires this copyright notice to be included in all copies4// The MIT license requires this copyright notice to be included in all copies
5// and substantial portions of the software.5// and substantial portions of the software.
6const std = @import("std");6const std = @import("std");
7const builtin = std.builtin;
8const os = std.os;7const os = std.os;
9const mem = std.mem;8const mem = std.mem;
10const elf = std.elf;9const elf = std.elf;
11const math = std.math;10const math = std.math;
12const assert = std.debug.assert;11const assert = std.debug.assert;
12const native_arch = std.Target.current.cpu.arch;
1313
14// This file implements the two TLS variants [1] used by ELF-based systems.14// This file implements the two TLS variants [1] used by ELF-based systems.
15//15//
...@@ -52,14 +52,14 @@ const TLSVariant = enum {...@@ -52,14 +52,14 @@ const TLSVariant = enum {
52 VariantII,52 VariantII,
53};53};
5454
55const tls_variant = switch (builtin.arch) {55const tls_variant = switch (native_arch) {
56 .arm, .armeb, .aarch64, .aarch64_be, .riscv32, .riscv64, .mips, .mipsel, .powerpc, .powerpc64, .powerpc64le => TLSVariant.VariantI,56 .arm, .armeb, .aarch64, .aarch64_be, .riscv32, .riscv64, .mips, .mipsel, .powerpc, .powerpc64, .powerpc64le => TLSVariant.VariantI,
57 .x86_64, .i386, .sparcv9 => TLSVariant.VariantII,57 .x86_64, .i386, .sparcv9 => TLSVariant.VariantII,
58 else => @compileError("undefined tls_variant for this architecture"),58 else => @compileError("undefined tls_variant for this architecture"),
59};59};
6060
61// Controls how many bytes are reserved for the Thread Control Block61// Controls how many bytes are reserved for the Thread Control Block
62const tls_tcb_size = switch (builtin.arch) {62const tls_tcb_size = switch (native_arch) {
63 // ARM EABI mandates enough space for two pointers: the first one points to63 // ARM EABI mandates enough space for two pointers: the first one points to
64 // the DTV while the second one is unspecified but reserved64 // the DTV while the second one is unspecified but reserved
65 .arm, .armeb, .aarch64, .aarch64_be => 2 * @sizeOf(usize),65 .arm, .armeb, .aarch64, .aarch64_be => 2 * @sizeOf(usize),
...@@ -68,7 +68,7 @@ const tls_tcb_size = switch (builtin.arch) {...@@ -68,7 +68,7 @@ const tls_tcb_size = switch (builtin.arch) {
68};68};
6969
70// Controls if the TP points to the end of the TCB instead of its beginning70// Controls if the TP points to the end of the TCB instead of its beginning
71const tls_tp_points_past_tcb = switch (builtin.arch) {71const tls_tp_points_past_tcb = switch (native_arch) {
72 .riscv32, .riscv64, .mips, .mipsel, .powerpc, .powerpc64, .powerpc64le => true,72 .riscv32, .riscv64, .mips, .mipsel, .powerpc, .powerpc64, .powerpc64le => true,
73 else => false,73 else => false,
74};74};
...@@ -76,12 +76,12 @@ const tls_tp_points_past_tcb = switch (builtin.arch) {...@@ -76,12 +76,12 @@ const tls_tp_points_past_tcb = switch (builtin.arch) {
76// Some architectures add some offset to the tp and dtv addresses in order to76// Some architectures add some offset to the tp and dtv addresses in order to
77// make the generated code more efficient77// make the generated code more efficient
7878
79const tls_tp_offset = switch (builtin.arch) {79const tls_tp_offset = switch (native_arch) {
80 .mips, .mipsel, .powerpc, .powerpc64, .powerpc64le => 0x7000,80 .mips, .mipsel, .powerpc, .powerpc64, .powerpc64le => 0x7000,
81 else => 0,81 else => 0,
82};82};
8383
84const tls_dtv_offset = switch (builtin.arch) {84const tls_dtv_offset = switch (native_arch) {
85 .mips, .mipsel, .powerpc, .powerpc64, .powerpc64le => 0x8000,85 .mips, .mipsel, .powerpc, .powerpc64, .powerpc64le => 0x8000,
86 .riscv32, .riscv64 => 0x800,86 .riscv32, .riscv64 => 0x800,
87 else => 0,87 else => 0,
...@@ -114,7 +114,7 @@ const TLSImage = struct {...@@ -114,7 +114,7 @@ const TLSImage = struct {
114pub var tls_image: TLSImage = undefined;114pub var tls_image: TLSImage = undefined;
115115
116pub fn setThreadPointer(addr: usize) void {116pub fn setThreadPointer(addr: usize) void {
117 switch (builtin.arch) {117 switch (native_arch) {
118 .i386 => {118 .i386 => {
119 var user_desc = std.os.linux.user_desc{119 var user_desc = std.os.linux.user_desc{
120 .entry_number = tls_image.gdt_entry_number,120 .entry_number = tls_image.gdt_entry_number,
...@@ -228,7 +228,7 @@ fn initTLS() void {...@@ -228,7 +228,7 @@ fn initTLS() void {
228 // ARMv6 targets (and earlier) have no support for TLS in hardware228 // ARMv6 targets (and earlier) have no support for TLS in hardware
229 // FIXME: Elide the check for targets >= ARMv7 when the target feature API229 // FIXME: Elide the check for targets >= ARMv7 when the target feature API
230 // becomes less verbose (and more usable).230 // becomes less verbose (and more usable).
231 if (comptime builtin.arch.isARM()) {231 if (comptime native_arch.isARM()) {
232 if (at_hwcap & std.os.linux.HWCAP_TLS == 0) {232 if (at_hwcap & std.os.linux.HWCAP_TLS == 0) {
233 // FIXME: Make __aeabi_read_tp call the kernel helper kuser_get_tls233 // FIXME: Make __aeabi_read_tp call the kernel helper kuser_get_tls
234 // For the time being use a simple abort instead of a @panic call to234 // For the time being use a simple abort instead of a @panic call to
lib/std/os/test.zig+1-1
...@@ -18,7 +18,7 @@ const Thread = std.Thread;...@@ -18,7 +18,7 @@ const Thread = std.Thread;
1818
19const a = std.testing.allocator;19const a = std.testing.allocator;
2020
21const builtin = @import("builtin");21const builtin = std.builtin;
22const AtomicRmwOp = builtin.AtomicRmwOp;22const AtomicRmwOp = builtin.AtomicRmwOp;
23const AtomicOrder = builtin.AtomicOrder;23const AtomicOrder = builtin.AtomicOrder;
24const tmpDir = std.testing.tmpDir;24const tmpDir = std.testing.tmpDir;
lib/std/os/windows.zig+1-1
...@@ -9,7 +9,7 @@...@@ -9,7 +9,7 @@
9// * When null-terminated or UTF16LE byte buffers are required, provide APIs which accept9// * When null-terminated or UTF16LE byte buffers are required, provide APIs which accept
10// slices as well as APIs which accept null-terminated UTF16LE byte buffers.10// slices as well as APIs which accept null-terminated UTF16LE byte buffers.
1111
12const builtin = @import("builtin");12const builtin = std.builtin;
13const std = @import("../std.zig");13const std = @import("../std.zig");
14const mem = std.mem;14const mem = std.mem;
15const assert = std.debug.assert;15const assert = std.debug.assert;
lib/std/os/windows/bits.zig+3-3
...@@ -5,10 +5,10 @@...@@ -5,10 +5,10 @@
5// and substantial portions of the software.5// and substantial portions of the software.
6// Platform-dependent types and values that are used along with OS-specific APIs.6// Platform-dependent types and values that are used along with OS-specific APIs.
77
8const builtin = @import("builtin");
9const std = @import("../../std.zig");8const std = @import("../../std.zig");
10const assert = std.debug.assert;9const assert = std.debug.assert;
11const maxInt = std.math.maxInt;10const maxInt = std.math.maxInt;
11const arch = std.Target.current.cpu.arch;
1212
13pub usingnamespace @import("win32error.zig");13pub usingnamespace @import("win32error.zig");
14pub usingnamespace @import("ntstatus.zig");14pub usingnamespace @import("ntstatus.zig");
...@@ -24,7 +24,7 @@ pub const STD_OUTPUT_HANDLE = maxInt(DWORD) - 11 + 1;...@@ -24,7 +24,7 @@ pub const STD_OUTPUT_HANDLE = maxInt(DWORD) - 11 + 1;
24/// The standard error device. Initially, this is the active console screen buffer, CONOUT$.24/// The standard error device. Initially, this is the active console screen buffer, CONOUT$.
25pub const STD_ERROR_HANDLE = maxInt(DWORD) - 12 + 1;25pub const STD_ERROR_HANDLE = maxInt(DWORD) - 12 + 1;
2626
27pub const WINAPI: builtin.CallingConvention = if (builtin.arch == .i386)27pub const WINAPI: std.builtin.CallingConvention = if (arch == .i386)
28 .Stdcall28 .Stdcall
29else29else
30 .C;30 .C;
...@@ -937,7 +937,7 @@ pub const EXCEPTION_RECORD = extern struct {...@@ -937,7 +937,7 @@ pub const EXCEPTION_RECORD = extern struct {
937 ExceptionInformation: [15]usize,937 ExceptionInformation: [15]usize,
938};938};
939939
940pub usingnamespace switch (builtin.arch) {940pub usingnamespace switch (arch) {
941 .i386 => struct {941 .i386 => struct {
942 pub const FLOATING_SAVE_AREA = extern struct {942 pub const FLOATING_SAVE_AREA = extern struct {
943 ControlWord: DWORD,943 ControlWord: DWORD,
lib/std/os/windows/user32.zig+1-1
...@@ -5,7 +5,7 @@...@@ -5,7 +5,7 @@
5// and substantial portions of the software.5// and substantial portions of the software.
6usingnamespace @import("bits.zig");6usingnamespace @import("bits.zig");
7const std = @import("std");7const std = @import("std");
8const builtin = @import("builtin");8const builtin = std.builtin;
9const assert = std.debug.assert;9const assert = std.debug.assert;
10const windows = @import("../windows.zig");10const windows = @import("../windows.zig");
11const unexpectedError = windows.unexpectedError;11const unexpectedError = windows.unexpectedError;
lib/std/packed_int_array.zig+1-1
...@@ -4,7 +4,7 @@...@@ -4,7 +4,7 @@
4// The MIT license requires this copyright notice to be included in all copies4// The MIT license requires this copyright notice to be included in all copies
5// and substantial portions of the software.5// and substantial portions of the software.
6const std = @import("std");6const std = @import("std");
7const builtin = @import("builtin");7const builtin = std.builtin;
8const debug = std.debug;8const debug = std.debug;
9const testing = std.testing;9const testing = std.testing;
1010
lib/std/pdb.zig+1-1
...@@ -3,7 +3,7 @@...@@ -3,7 +3,7 @@
3// This file is part of [zig](https://ziglang.org/), which is MIT licensed.3// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
4// The MIT license requires this copyright notice to be included in all copies4// The MIT license requires this copyright notice to be included in all copies
5// and substantial portions of the software.5// and substantial portions of the software.
6const builtin = @import("builtin");6const builtin = std.builtin;
7const std = @import("std.zig");7const std = @import("std.zig");
8const io = std.io;8const io = std.io;
9const math = std.math;9const math = std.math;
lib/std/rand.zig+1-1
...@@ -13,7 +13,7 @@...@@ -13,7 +13,7 @@
13//! TODO(tiehuis): Benchmark these against other reference implementations.13//! TODO(tiehuis): Benchmark these against other reference implementations.
1414
15const std = @import("std.zig");15const std = @import("std.zig");
16const builtin = @import("builtin");16const builtin = std.builtin;
17const assert = std.debug.assert;17const assert = std.debug.assert;
18const expect = std.testing.expect;18const expect = std.testing.expect;
19const expectEqual = std.testing.expectEqual;19const expectEqual = std.testing.expectEqual;
lib/std/sort.zig+1-1
...@@ -8,7 +8,7 @@ const assert = std.debug.assert;...@@ -8,7 +8,7 @@ const assert = std.debug.assert;
8const testing = std.testing;8const testing = std.testing;
9const mem = std.mem;9const mem = std.mem;
10const math = std.math;10const math = std.math;
11const builtin = @import("builtin");11const builtin = std.builtin;
1212
13pub fn binarySearch(13pub fn binarySearch(
14 comptime T: type,14 comptime T: type,
lib/std/special/c.zig+10-7
...@@ -10,19 +10,22 @@...@@ -10,19 +10,22 @@
10// such as memcpy, memset, and some math functions.10// such as memcpy, memset, and some math functions.
1111
12const std = @import("std");12const std = @import("std");
13const builtin = @import("builtin");13const builtin = std.builtin;
14const maxInt = std.math.maxInt;14const maxInt = std.math.maxInt;
15const isNan = std.math.isNan;15const isNan = std.math.isNan;
16const native_arch = std.Target.current.cpu.arch;
17const native_abi = std.Target.current.abi;
18const native_os = std.Target.current.os.tag;
1619
17const is_wasm = switch (builtin.arch) {20const is_wasm = switch (native_arch) {
18 .wasm32, .wasm64 => true,21 .wasm32, .wasm64 => true,
19 else => false,22 else => false,
20};23};
21const is_msvc = switch (builtin.abi) {24const is_msvc = switch (native_abi) {
22 .msvc => true,25 .msvc => true,
23 else => false,26 else => false,
24};27};
25const is_freestanding = switch (builtin.os.tag) {28const is_freestanding = switch (native_os) {
26 .freestanding => true,29 .freestanding => true,
27 else => false,30 else => false,
28};31};
...@@ -174,7 +177,7 @@ pub fn panic(msg: []const u8, error_return_trace: ?*builtin.StackTrace) noreturn...@@ -174,7 +177,7 @@ pub fn panic(msg: []const u8, error_return_trace: ?*builtin.StackTrace) noreturn
174 @setCold(true);177 @setCold(true);
175 std.debug.panic("{s}", .{msg});178 std.debug.panic("{s}", .{msg});
176 }179 }
177 if (builtin.os.tag != .freestanding and builtin.os.tag != .other) {180 if (native_os != .freestanding and native_os != .other) {
178 std.os.abort();181 std.os.abort();
179 }182 }
180 while (true) {}183 while (true) {}
...@@ -275,7 +278,7 @@ test "test_bcmp" {...@@ -275,7 +278,7 @@ test "test_bcmp" {
275}278}
276279
277comptime {280comptime {
278 if (builtin.os.tag == .linux) {281 if (native_os == .linux) {
279 @export(clone, .{ .name = "clone" });282 @export(clone, .{ .name = "clone" });
280 }283 }
281}284}
...@@ -284,7 +287,7 @@ comptime {...@@ -284,7 +287,7 @@ comptime {
284// it causes a segfault in release mode. this is a workaround of calling it287// it causes a segfault in release mode. this is a workaround of calling it
285// across .o file boundaries. fix comptime @ptrCast of nakedcc functions.288// across .o file boundaries. fix comptime @ptrCast of nakedcc functions.
286fn clone() callconv(.Naked) void {289fn clone() callconv(.Naked) void {
287 switch (builtin.arch) {290 switch (native_arch) {
288 .i386 => {291 .i386 => {
289 // __clone(func, stack, flags, arg, ptid, tls, ctid)292 // __clone(func, stack, flags, arg, ptid, tls, ctid)
290 // +8, +12, +16, +20, +24, +28, +32293 // +8, +12, +16, +20, +24, +28, +32
lib/std/special/compiler_rt.zig+12-9
...@@ -6,15 +6,18 @@...@@ -6,15 +6,18 @@
6const std = @import("std");6const std = @import("std");
7const builtin = std.builtin;7const builtin = std.builtin;
8const is_test = builtin.is_test;8const is_test = builtin.is_test;
9const os_tag = std.Target.current.os.tag;
10const arch = std.Target.current.cpu.arch;
11const abi = std.Target.current.abi;
912
10const is_gnu = std.Target.current.abi.isGnu();13const is_gnu = abi.isGnu();
11const is_mingw = builtin.os.tag == .windows and is_gnu;14const is_mingw = os_tag == .windows and is_gnu;
1215
13comptime {16comptime {
14 const linkage = if (is_test) builtin.GlobalLinkage.Internal else builtin.GlobalLinkage.Weak;17 const linkage = if (is_test) builtin.GlobalLinkage.Internal else builtin.GlobalLinkage.Weak;
15 const strong_linkage = if (is_test) builtin.GlobalLinkage.Internal else builtin.GlobalLinkage.Strong;18 const strong_linkage = if (is_test) builtin.GlobalLinkage.Internal else builtin.GlobalLinkage.Strong;
1619
17 switch (builtin.arch) {20 switch (arch) {
18 .i386,21 .i386,
19 .x86_64,22 .x86_64,
20 => @export(@import("compiler_rt/stack_probe.zig").zig_probe_stack, .{23 => @export(@import("compiler_rt/stack_probe.zig").zig_probe_stack, .{
...@@ -167,11 +170,11 @@ comptime {...@@ -167,11 +170,11 @@ comptime {
167170
168 @export(@import("compiler_rt/clzsi2.zig").__clzsi2, .{ .name = "__clzsi2", .linkage = linkage });171 @export(@import("compiler_rt/clzsi2.zig").__clzsi2, .{ .name = "__clzsi2", .linkage = linkage });
169172
170 if (builtin.link_libc and builtin.os.tag == .openbsd) {173 if (builtin.link_libc and os_tag == .openbsd) {
171 @export(@import("compiler_rt/emutls.zig").__emutls_get_address, .{ .name = "__emutls_get_address", .linkage = linkage });174 @export(@import("compiler_rt/emutls.zig").__emutls_get_address, .{ .name = "__emutls_get_address", .linkage = linkage });
172 }175 }
173176
174 if ((builtin.arch.isARM() or builtin.arch.isThumb()) and !is_test) {177 if ((arch.isARM() or arch.isThumb()) and !is_test) {
175 @export(@import("compiler_rt/arm.zig").__aeabi_unwind_cpp_pr0, .{ .name = "__aeabi_unwind_cpp_pr0", .linkage = linkage });178 @export(@import("compiler_rt/arm.zig").__aeabi_unwind_cpp_pr0, .{ .name = "__aeabi_unwind_cpp_pr0", .linkage = linkage });
176 @export(@import("compiler_rt/arm.zig").__aeabi_unwind_cpp_pr1, .{ .name = "__aeabi_unwind_cpp_pr1", .linkage = linkage });179 @export(@import("compiler_rt/arm.zig").__aeabi_unwind_cpp_pr1, .{ .name = "__aeabi_unwind_cpp_pr1", .linkage = linkage });
177 @export(@import("compiler_rt/arm.zig").__aeabi_unwind_cpp_pr2, .{ .name = "__aeabi_unwind_cpp_pr2", .linkage = linkage });180 @export(@import("compiler_rt/arm.zig").__aeabi_unwind_cpp_pr2, .{ .name = "__aeabi_unwind_cpp_pr2", .linkage = linkage });
...@@ -202,7 +205,7 @@ comptime {...@@ -202,7 +205,7 @@ comptime {
202 @export(@import("compiler_rt/arm.zig").__aeabi_memclr, .{ .name = "__aeabi_memclr4", .linkage = linkage });205 @export(@import("compiler_rt/arm.zig").__aeabi_memclr, .{ .name = "__aeabi_memclr4", .linkage = linkage });
203 @export(@import("compiler_rt/arm.zig").__aeabi_memclr, .{ .name = "__aeabi_memclr8", .linkage = linkage });206 @export(@import("compiler_rt/arm.zig").__aeabi_memclr, .{ .name = "__aeabi_memclr8", .linkage = linkage });
204207
205 if (builtin.os.tag == .linux) {208 if (os_tag == .linux) {
206 @export(@import("compiler_rt/arm.zig").__aeabi_read_tp, .{ .name = "__aeabi_read_tp", .linkage = linkage });209 @export(@import("compiler_rt/arm.zig").__aeabi_read_tp, .{ .name = "__aeabi_read_tp", .linkage = linkage });
207 }210 }
208211
...@@ -269,7 +272,7 @@ comptime {...@@ -269,7 +272,7 @@ comptime {
269 @export(@import("compiler_rt/compareXf2.zig").__aeabi_dcmpun, .{ .name = "__aeabi_dcmpun", .linkage = linkage });272 @export(@import("compiler_rt/compareXf2.zig").__aeabi_dcmpun, .{ .name = "__aeabi_dcmpun", .linkage = linkage });
270 }273 }
271274
272 if (builtin.arch == .i386 and builtin.abi == .msvc) {275 if (arch == .i386 and abi == .msvc) {
273 // Don't let LLVM apply the stdcall name mangling on those MSVC builtins276 // Don't let LLVM apply the stdcall name mangling on those MSVC builtins
274 @export(@import("compiler_rt/aulldiv.zig")._alldiv, .{ .name = "\x01__alldiv", .linkage = strong_linkage });277 @export(@import("compiler_rt/aulldiv.zig")._alldiv, .{ .name = "\x01__alldiv", .linkage = strong_linkage });
275 @export(@import("compiler_rt/aulldiv.zig")._aulldiv, .{ .name = "\x01__aulldiv", .linkage = strong_linkage });278 @export(@import("compiler_rt/aulldiv.zig")._aulldiv, .{ .name = "\x01__aulldiv", .linkage = strong_linkage });
...@@ -277,7 +280,7 @@ comptime {...@@ -277,7 +280,7 @@ comptime {
277 @export(@import("compiler_rt/aullrem.zig")._aullrem, .{ .name = "\x01__aullrem", .linkage = strong_linkage });280 @export(@import("compiler_rt/aullrem.zig")._aullrem, .{ .name = "\x01__aullrem", .linkage = strong_linkage });
278 }281 }
279282
280 if (builtin.arch.isSPARC()) {283 if (arch.isSPARC()) {
281 // SPARC systems use a different naming scheme284 // SPARC systems use a different naming scheme
282 @export(@import("compiler_rt/sparc.zig")._Qp_add, .{ .name = "_Qp_add", .linkage = linkage });285 @export(@import("compiler_rt/sparc.zig")._Qp_add, .{ .name = "_Qp_add", .linkage = linkage });
283 @export(@import("compiler_rt/sparc.zig")._Qp_div, .{ .name = "_Qp_div", .linkage = linkage });286 @export(@import("compiler_rt/sparc.zig")._Qp_div, .{ .name = "_Qp_div", .linkage = linkage });
...@@ -334,7 +337,7 @@ comptime {...@@ -334,7 +337,7 @@ comptime {
334 @export(@import("compiler_rt/stack_probe.zig").__chkstk, .{ .name = "__chkstk", .linkage = strong_linkage });337 @export(@import("compiler_rt/stack_probe.zig").__chkstk, .{ .name = "__chkstk", .linkage = strong_linkage });
335 }338 }
336339
337 switch (builtin.arch) {340 switch (arch) {
338 .i386 => {341 .i386 => {
339 @export(@import("compiler_rt/divti3.zig").__divti3, .{ .name = "__divti3", .linkage = linkage });342 @export(@import("compiler_rt/divti3.zig").__divti3, .{ .name = "__divti3", .linkage = linkage });
340 @export(@import("compiler_rt/modti3.zig").__modti3, .{ .name = "__modti3", .linkage = linkage });343 @export(@import("compiler_rt/modti3.zig").__modti3, .{ .name = "__modti3", .linkage = linkage });
lib/std/special/compiler_rt/atomics.zig+3-2
...@@ -5,6 +5,7 @@...@@ -5,6 +5,7 @@
5// and substantial portions of the software.5// and substantial portions of the software.
6const std = @import("std");6const std = @import("std");
7const builtin = std.builtin;7const builtin = std.builtin;
8const arch = std.Target.current.cpu.arch;
89
9const linkage: builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;10const linkage: builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
1011
...@@ -13,7 +14,7 @@ const linkage: builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak...@@ -13,7 +14,7 @@ const linkage: builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak
13// Some architectures support atomic load/stores but no CAS, but we ignore this14// Some architectures support atomic load/stores but no CAS, but we ignore this
14// detail to keep the export logic clean and because we need some kind of CAS to15// detail to keep the export logic clean and because we need some kind of CAS to
15// implement the spinlocks.16// implement the spinlocks.
16const supports_atomic_ops = switch (builtin.arch) {17const supports_atomic_ops = switch (arch) {
17 .msp430, .avr => false,18 .msp430, .avr => false,
18 .arm, .armeb, .thumb, .thumbeb =>19 .arm, .armeb, .thumb, .thumbeb =>
19 // The ARM v6m ISA has no ldrex/strex and so it's impossible to do CAS20 // The ARM v6m ISA has no ldrex/strex and so it's impossible to do CAS
...@@ -27,7 +28,7 @@ const supports_atomic_ops = switch (builtin.arch) {...@@ -27,7 +28,7 @@ const supports_atomic_ops = switch (builtin.arch) {
27// The size (in bytes) of the biggest object that the architecture can28// The size (in bytes) of the biggest object that the architecture can
28// load/store atomically.29// load/store atomically.
29// Objects bigger than this threshold require the use of a lock.30// Objects bigger than this threshold require the use of a lock.
30const largest_atomic_size = switch (builtin.arch) {31const largest_atomic_size = switch (arch) {
31 // XXX: On x86/x86_64 we could check the presence of cmpxchg8b/cmpxchg16b32 // XXX: On x86/x86_64 we could check the presence of cmpxchg8b/cmpxchg16b
32 // and set this parameter accordingly.33 // and set this parameter accordingly.
33 else => @sizeOf(usize),34 else => @sizeOf(usize),
lib/std/special/compiler_rt/muldi3.zig+6-4
...@@ -3,14 +3,16 @@...@@ -3,14 +3,16 @@
3// This file is part of [zig](https://ziglang.org/), which is MIT licensed.3// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
4// The MIT license requires this copyright notice to be included in all copies4// The MIT license requires this copyright notice to be included in all copies
5// and substantial portions of the software.5// and substantial portions of the software.
6const builtin = @import("builtin");6const std = @import("std");
7const is_test = std.builtin.is_test;
8const native_endian = std.Target.current.cpu.arch.endian();
79
8// Ported from10// Ported from
9// https://github.com/llvm/llvm-project/blob/llvmorg-9.0.0/compiler-rt/lib/builtins/muldi3.c11// https://github.com/llvm/llvm-project/blob/llvmorg-9.0.0/compiler-rt/lib/builtins/muldi3.c
1012
11const dwords = extern union {13const dwords = extern union {
12 all: i64,14 all: i64,
13 s: switch (builtin.endian) {15 s: switch (native_endian) {
14 .Little => extern struct {16 .Little => extern struct {
15 low: u32,17 low: u32,
16 high: u32,18 high: u32,
...@@ -23,7 +25,7 @@ const dwords = extern union {...@@ -23,7 +25,7 @@ const dwords = extern union {
23};25};
2426
25fn __muldsi3(a: u32, b: u32) i64 {27fn __muldsi3(a: u32, b: u32) i64 {
26 @setRuntimeSafety(builtin.is_test);28 @setRuntimeSafety(is_test);
2729
28 const bits_in_word_2 = @sizeOf(i32) * 8 / 2;30 const bits_in_word_2 = @sizeOf(i32) * 8 / 2;
29 const lower_mask = (~@as(u32, 0)) >> bits_in_word_2;31 const lower_mask = (~@as(u32, 0)) >> bits_in_word_2;
...@@ -45,7 +47,7 @@ fn __muldsi3(a: u32, b: u32) i64 {...@@ -45,7 +47,7 @@ fn __muldsi3(a: u32, b: u32) i64 {
45}47}
4648
47pub fn __muldi3(a: i64, b: i64) callconv(.C) i64 {49pub fn __muldi3(a: i64, b: i64) callconv(.C) i64 {
48 @setRuntimeSafety(builtin.is_test);50 @setRuntimeSafety(is_test);
4951
50 const x = dwords{ .all = a };52 const x = dwords{ .all = a };
51 const y = dwords{ .all = b };53 const y = dwords{ .all = b };
lib/std/special/compiler_rt/multi3.zig+5-3
...@@ -3,15 +3,17 @@...@@ -3,15 +3,17 @@
3// This file is part of [zig](https://ziglang.org/), which is MIT licensed.3// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
4// The MIT license requires this copyright notice to be included in all copies4// The MIT license requires this copyright notice to be included in all copies
5// and substantial portions of the software.5// and substantial portions of the software.
6const builtin = @import("builtin");
7const compiler_rt = @import("../compiler_rt.zig");6const compiler_rt = @import("../compiler_rt.zig");
7const std = @import("std");
8const is_test = std.builtin.is_test;
9const native_endian = std.Target.current.cpu.arch.endian();
810
9// Ported from git@github.com:llvm-project/llvm-project-20170507.git11// Ported from git@github.com:llvm-project/llvm-project-20170507.git
10// ae684fad6d34858c014c94da69c15e7774a633c312// ae684fad6d34858c014c94da69c15e7774a633c3
11// 2018-08-1313// 2018-08-13
1214
13pub fn __multi3(a: i128, b: i128) callconv(.C) i128 {15pub fn __multi3(a: i128, b: i128) callconv(.C) i128 {
14 @setRuntimeSafety(builtin.is_test);16 @setRuntimeSafety(is_test);
15 const x = twords{ .all = a };17 const x = twords{ .all = a };
16 const y = twords{ .all = b };18 const y = twords{ .all = b };
17 var r = twords{ .all = __mulddi3(x.s.low, y.s.low) };19 var r = twords{ .all = __mulddi3(x.s.low, y.s.low) };
...@@ -50,7 +52,7 @@ const twords = extern union {...@@ -50,7 +52,7 @@ const twords = extern union {
50 all: i128,52 all: i128,
51 s: S,53 s: S,
5254
53 const S = if (builtin.endian == .Little)55 const S = if (native_endian == .Little)
54 struct {56 struct {
55 low: u64,57 low: u64,
56 high: u64,58 high: u64,
lib/std/special/compiler_rt/shift.zig+2-2
...@@ -4,8 +4,8 @@...@@ -4,8 +4,8 @@
4// The MIT license requires this copyright notice to be included in all copies4// The MIT license requires this copyright notice to be included in all copies
5// and substantial portions of the software.5// and substantial portions of the software.
6const std = @import("std");6const std = @import("std");
7const builtin = std.builtin;
8const Log2Int = std.math.Log2Int;7const Log2Int = std.math.Log2Int;
8const native_endian = std.Target.current.cpu.arch.endian();
99
10fn Dwords(comptime T: type, comptime signed_half: bool) type {10fn Dwords(comptime T: type, comptime signed_half: bool) type {
11 return extern union {11 return extern union {
...@@ -15,7 +15,7 @@ fn Dwords(comptime T: type, comptime signed_half: bool) type {...@@ -15,7 +15,7 @@ fn Dwords(comptime T: type, comptime signed_half: bool) type {
15 pub const HalfT = if (signed_half) HalfTS else HalfTU;15 pub const HalfT = if (signed_half) HalfTS else HalfTU;
1616
17 all: T,17 all: T,
18 s: if (builtin.endian == .Little)18 s: if (native_endian == .Little)
19 struct { low: HalfT, high: HalfT }19 struct { low: HalfT, high: HalfT }
20 else20 else
21 struct { high: HalfT, low: HalfT },21 struct { high: HalfT, low: HalfT },
lib/std/special/compiler_rt/stack_probe.zig+5-5
...@@ -3,7 +3,7 @@...@@ -3,7 +3,7 @@
3// This file is part of [zig](https://ziglang.org/), which is MIT licensed.3// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
4// The MIT license requires this copyright notice to be included in all copies4// The MIT license requires this copyright notice to be included in all copies
5// and substantial portions of the software.5// and substantial portions of the software.
6const builtin = @import("builtin");6const native_arch = @import("std").Target.current.cpu.arch;
77
8// Zig's own stack-probe routine (available only on x86 and x86_64)8// Zig's own stack-probe routine (available only on x86 and x86_64)
9pub fn zig_probe_stack() callconv(.Naked) void {9pub fn zig_probe_stack() callconv(.Naked) void {
...@@ -13,7 +13,7 @@ pub fn zig_probe_stack() callconv(.Naked) void {...@@ -13,7 +13,7 @@ pub fn zig_probe_stack() callconv(.Naked) void {
13 // invalid so let's update it on the go, otherwise we'll get a segfault13 // invalid so let's update it on the go, otherwise we'll get a segfault
14 // instead of triggering the stack growth.14 // instead of triggering the stack growth.
1515
16 switch (builtin.arch) {16 switch (native_arch) {
17 .x86_64 => {17 .x86_64 => {
18 // %rax = probe length, %rsp = stack pointer18 // %rax = probe length, %rsp = stack pointer
19 asm volatile (19 asm volatile (
...@@ -65,7 +65,7 @@ pub fn zig_probe_stack() callconv(.Naked) void {...@@ -65,7 +65,7 @@ pub fn zig_probe_stack() callconv(.Naked) void {
65fn win_probe_stack_only() void {65fn win_probe_stack_only() void {
66 @setRuntimeSafety(false);66 @setRuntimeSafety(false);
6767
68 switch (builtin.arch) {68 switch (native_arch) {
69 .x86_64 => {69 .x86_64 => {
70 asm volatile (70 asm volatile (
71 \\ push %%rcx71 \\ push %%rcx
...@@ -117,7 +117,7 @@ fn win_probe_stack_only() void {...@@ -117,7 +117,7 @@ fn win_probe_stack_only() void {
117fn win_probe_stack_adjust_sp() void {117fn win_probe_stack_adjust_sp() void {
118 @setRuntimeSafety(false);118 @setRuntimeSafety(false);
119119
120 switch (builtin.arch) {120 switch (native_arch) {
121 .x86_64 => {121 .x86_64 => {
122 asm volatile (122 asm volatile (
123 \\ push %%rcx123 \\ push %%rcx
...@@ -191,7 +191,7 @@ pub fn _chkstk() callconv(.Naked) void {...@@ -191,7 +191,7 @@ pub fn _chkstk() callconv(.Naked) void {
191}191}
192pub fn __chkstk() callconv(.Naked) void {192pub fn __chkstk() callconv(.Naked) void {
193 @setRuntimeSafety(false);193 @setRuntimeSafety(false);
194 switch (builtin.arch) {194 switch (native_arch) {
195 .i386 => @call(.{ .modifier = .always_inline }, win_probe_stack_adjust_sp, .{}),195 .i386 => @call(.{ .modifier = .always_inline }, win_probe_stack_adjust_sp, .{}),
196 .x86_64 => @call(.{ .modifier = .always_inline }, win_probe_stack_only, .{}),196 .x86_64 => @call(.{ .modifier = .always_inline }, win_probe_stack_only, .{}),
197 else => unreachable,197 else => unreachable,
lib/std/special/compiler_rt/udivmod.zig+2-1
...@@ -5,8 +5,9 @@...@@ -5,8 +5,9 @@
5// and substantial portions of the software.5// and substantial portions of the software.
6const builtin = @import("builtin");6const builtin = @import("builtin");
7const is_test = builtin.is_test;7const is_test = builtin.is_test;
8const native_endian = @import("std").Target.current.cpu.arch.endian();
89
9const low = switch (builtin.endian) {10const low = switch (native_endian) {
10 .Big => 1,11 .Big => 1,
11 .Little => 0,12 .Little => 0,
12};13};
lib/std/start.zig+13-13
...@@ -11,10 +11,12 @@ const builtin = @import("builtin");...@@ -11,10 +11,12 @@ const builtin = @import("builtin");
11const assert = std.debug.assert;11const assert = std.debug.assert;
12const uefi = std.os.uefi;12const uefi = std.os.uefi;
13const tlcsprng = @import("crypto/tlcsprng.zig");13const tlcsprng = @import("crypto/tlcsprng.zig");
14const native_arch = std.Target.current.cpu.arch;
15const native_os = std.Target.current.os.tag;
1416
15var argc_argv_ptr: [*]usize = undefined;17var argc_argv_ptr: [*]usize = undefined;
1618
17const start_sym_name = if (builtin.arch.isMIPS()) "__start" else "_start";19const start_sym_name = if (native_arch.isMIPS()) "__start" else "_start";
1820
19comptime {21comptime {
20 // The self-hosted compiler is not fully capable of handling all of this start.zig file.22 // The self-hosted compiler is not fully capable of handling all of this start.zig file.
...@@ -23,9 +25,7 @@ comptime {...@@ -23,9 +25,7 @@ comptime {
23 if (builtin.zig_is_stage2) {25 if (builtin.zig_is_stage2) {
24 if (builtin.output_mode == .Exe) {26 if (builtin.output_mode == .Exe) {
25 if (builtin.link_libc or builtin.object_format == .c) {27 if (builtin.link_libc or builtin.object_format == .c) {
26 if (!@hasDecl(root, "main")) {28 @export(main2, "main");
27 @export(main2, "main");
28 }
29 } else {29 } else {
30 if (!@hasDecl(root, "_start")) {30 if (!@hasDecl(root, "_start")) {
31 @export(_start2, "_start");31 @export(_start2, "_start");
...@@ -34,7 +34,7 @@ comptime {...@@ -34,7 +34,7 @@ comptime {
34 }34 }
35 } else {35 } else {
36 if (builtin.output_mode == .Lib and builtin.link_mode == .Dynamic) {36 if (builtin.output_mode == .Lib and builtin.link_mode == .Dynamic) {
37 if (builtin.os.tag == .windows and !@hasDecl(root, "_DllMainCRTStartup")) {37 if (native_os == .windows and !@hasDecl(root, "_DllMainCRTStartup")) {
38 @export(_DllMainCRTStartup, .{ .name = "_DllMainCRTStartup" });38 @export(_DllMainCRTStartup, .{ .name = "_DllMainCRTStartup" });
39 }39 }
40 } else if (builtin.output_mode == .Exe or @hasDecl(root, "main")) {40 } else if (builtin.output_mode == .Exe or @hasDecl(root, "main")) {
...@@ -42,7 +42,7 @@ comptime {...@@ -42,7 +42,7 @@ comptime {
42 if (@typeInfo(@TypeOf(root.main)).Fn.calling_convention != .C) {42 if (@typeInfo(@TypeOf(root.main)).Fn.calling_convention != .C) {
43 @export(main, .{ .name = "main", .linkage = .Weak });43 @export(main, .{ .name = "main", .linkage = .Weak });
44 }44 }
45 } else if (builtin.os.tag == .windows) {45 } else if (native_os == .windows) {
46 if (!@hasDecl(root, "WinMain") and !@hasDecl(root, "WinMainCRTStartup") and46 if (!@hasDecl(root, "WinMain") and !@hasDecl(root, "WinMainCRTStartup") and
47 !@hasDecl(root, "wWinMain") and !@hasDecl(root, "wWinMainCRTStartup"))47 !@hasDecl(root, "wWinMain") and !@hasDecl(root, "wWinMainCRTStartup"))
48 {48 {
...@@ -56,11 +56,11 @@ comptime {...@@ -56,11 +56,11 @@ comptime {
56 {56 {
57 @export(wWinMainCRTStartup, .{ .name = "wWinMainCRTStartup" });57 @export(wWinMainCRTStartup, .{ .name = "wWinMainCRTStartup" });
58 }58 }
59 } else if (builtin.os.tag == .uefi) {59 } else if (native_os == .uefi) {
60 if (!@hasDecl(root, "EfiMain")) @export(EfiMain, .{ .name = "EfiMain" });60 if (!@hasDecl(root, "EfiMain")) @export(EfiMain, .{ .name = "EfiMain" });
61 } else if (builtin.arch.isWasm() and builtin.os.tag == .freestanding) {61 } else if (native_arch.isWasm() and native_os == .freestanding) {
62 if (!@hasDecl(root, start_sym_name)) @export(wasm_freestanding_start, .{ .name = start_sym_name });62 if (!@hasDecl(root, start_sym_name)) @export(wasm_freestanding_start, .{ .name = start_sym_name });
63 } else if (builtin.os.tag != .other and builtin.os.tag != .freestanding) {63 } else if (native_os != .other and native_os != .freestanding) {
64 if (!@hasDecl(root, start_sym_name)) @export(_start, .{ .name = start_sym_name });64 if (!@hasDecl(root, start_sym_name)) @export(_start, .{ .name = start_sym_name });
65 }65 }
66 }66 }
...@@ -80,7 +80,7 @@ fn _start2() callconv(.Naked) noreturn {...@@ -80,7 +80,7 @@ fn _start2() callconv(.Naked) noreturn {
80}80}
8181
82fn exit2(code: u8) noreturn {82fn exit2(code: u8) noreturn {
83 switch (builtin.arch) {83 switch (native_arch) {
84 .x86_64 => {84 .x86_64 => {
85 asm volatile ("syscall"85 asm volatile ("syscall"
86 :86 :
...@@ -157,13 +157,13 @@ fn EfiMain(handle: uefi.Handle, system_table: *uefi.tables.SystemTable) callconv...@@ -157,13 +157,13 @@ fn EfiMain(handle: uefi.Handle, system_table: *uefi.tables.SystemTable) callconv
157}157}
158158
159fn _start() callconv(.Naked) noreturn {159fn _start() callconv(.Naked) noreturn {
160 if (builtin.os.tag == .wasi) {160 if (native_os == .wasi) {
161 // This is marked inline because for some reason LLVM in release mode fails to inline it,161 // This is marked inline because for some reason LLVM in release mode fails to inline it,
162 // and we want fewer call frames in stack traces.162 // and we want fewer call frames in stack traces.
163 std.os.wasi.proc_exit(@call(.{ .modifier = .always_inline }, callMain, .{}));163 std.os.wasi.proc_exit(@call(.{ .modifier = .always_inline }, callMain, .{}));
164 }164 }
165165
166 switch (builtin.arch) {166 switch (native_arch) {
167 .x86_64 => {167 .x86_64 => {
168 argc_argv_ptr = asm volatile (168 argc_argv_ptr = asm volatile (
169 \\ xor %%rbp, %%rbp169 \\ xor %%rbp, %%rbp
...@@ -273,7 +273,7 @@ fn posixCallMainAndExit() noreturn {...@@ -273,7 +273,7 @@ fn posixCallMainAndExit() noreturn {
273 while (envp_optional[envp_count]) |_| : (envp_count += 1) {}273 while (envp_optional[envp_count]) |_| : (envp_count += 1) {}
274 const envp = @ptrCast([*][*:0]u8, envp_optional)[0..envp_count];274 const envp = @ptrCast([*][*:0]u8, envp_optional)[0..envp_count];
275275
276 if (builtin.os.tag == .linux) {276 if (native_os == .linux) {
277 // Find the beginning of the auxiliary vector277 // Find the beginning of the auxiliary vector
278 const auxv = @ptrCast([*]std.elf.Auxv, @alignCast(@alignOf(usize), envp.ptr + envp_count + 1));278 const auxv = @ptrCast([*]std.elf.Auxv, @alignCast(@alignOf(usize), envp.ptr + envp_count + 1));
279 std.os.linux.elf_aux_maybe = auxv;279 std.os.linux.elf_aux_maybe = auxv;
lib/std/target.zig+1-5
...@@ -1225,11 +1225,7 @@ pub const Target = struct {...@@ -1225,11 +1225,7 @@ pub const Target = struct {
1225 }1225 }
1226 };1226 };
12271227
1228 pub const current = Target{1228 pub const current = builtin.target;
1229 .cpu = builtin.cpu,
1230 .os = builtin.os,
1231 .abi = builtin.abi,
1232 };
12331229
1234 pub const stack_align = 16;1230 pub const stack_align = 16;
12351231
lib/std/testing.zig+1-1
...@@ -309,7 +309,7 @@ pub const TmpDir = struct {...@@ -309,7 +309,7 @@ pub const TmpDir = struct {
309};309};
310310
311fn getCwdOrWasiPreopen() std.fs.Dir {311fn getCwdOrWasiPreopen() std.fs.Dir {
312 if (@import("builtin").os.tag == .wasi) {312 if (std.builtin.os.tag == .wasi) {
313 var preopens = std.fs.wasi.PreopenList.init(allocator);313 var preopens = std.fs.wasi.PreopenList.init(allocator);
314 defer preopens.deinit();314 defer preopens.deinit();
315 preopens.populate() catch315 preopens.populate() catch
lib/std/unicode.zig+1-1
...@@ -4,7 +4,7 @@...@@ -4,7 +4,7 @@
4// The MIT license requires this copyright notice to be included in all copies4// The MIT license requires this copyright notice to be included in all copies
5// and substantial portions of the software.5// and substantial portions of the software.
6const std = @import("./std.zig");6const std = @import("./std.zig");
7const builtin = @import("builtin");7const builtin = std.builtin;
8const assert = std.debug.assert;8const assert = std.debug.assert;
9const testing = std.testing;9const testing = std.testing;
10const mem = std.mem;10const mem = std.mem;
lib/std/valgrind.zig+1-1
...@@ -3,7 +3,7 @@...@@ -3,7 +3,7 @@
3// This file is part of [zig](https://ziglang.org/), which is MIT licensed.3// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
4// The MIT license requires this copyright notice to be included in all copies4// The MIT license requires this copyright notice to be included in all copies
5// and substantial portions of the software.5// and substantial portions of the software.
6const builtin = @import("builtin");6const builtin = std.builtin;
7const std = @import("std.zig");7const std = @import("std.zig");
8const math = std.math;8const math = std.math;
99
lib/std/zig/system.zig+2-1
...@@ -14,6 +14,7 @@ const process = std.process;...@@ -14,6 +14,7 @@ const process = std.process;
14const Target = std.Target;14const Target = std.Target;
15const CrossTarget = std.zig.CrossTarget;15const CrossTarget = std.zig.CrossTarget;
16const macos = @import("system/macos.zig");16const macos = @import("system/macos.zig");
17const native_endian = std.Target.current.cpu.arch.endian();
17pub const windows = @import("system/windows.zig");18pub const windows = @import("system/windows.zig");
1819
19pub const getSDKPath = macos.getSDKPath;20pub const getSDKPath = macos.getSDKPath;
...@@ -603,7 +604,7 @@ pub const NativeTargetInfo = struct {...@@ -603,7 +604,7 @@ pub const NativeTargetInfo = struct {
603 elf.ELFDATA2MSB => .Big,604 elf.ELFDATA2MSB => .Big,
604 else => return error.InvalidElfEndian,605 else => return error.InvalidElfEndian,
605 };606 };
606 const need_bswap = elf_endian != std.builtin.endian;607 const need_bswap = elf_endian != native_endian;
607 if (hdr32.e_ident[elf.EI_VERSION] != 1) return error.InvalidElfVersion;608 if (hdr32.e_ident[elf.EI_VERSION] != 1) return error.InvalidElfVersion;
608609
609 const is_64 = switch (hdr32.e_ident[elf.EI_CLASS]) {610 const is_64 = switch (hdr32.e_ident[elf.EI_CLASS]) {