authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-01-01 18:36:12-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-01-01 18:36:12-05:00
log036a49e97d0bc556ece08562c9dd3c75879598cf
tree9707943a5c063fe196bd091b801c5c626f3f0eb8
parentc0e391e94ab34cb2fcfd85c5c9f93aed8ec1ba79
parent6df8e4bca73309f2e340dbfa9031f1bb16a73bcc

Merge remote-tracking branch 'origin/master' into llvm8


29 files changed, 668 insertions(+), 941 deletions(-)

.builds/freebsd.yml+23-2
...@@ -1,5 +1,4 @@...@@ -1,5 +1,4 @@
1arch: x86_641image: freebsd/latest
2image: freebsd
3packages:2packages:
4 - cmake3 - cmake
5 - ninja4 - ninja
...@@ -14,6 +13,28 @@ tasks:...@@ -14,6 +13,28 @@ tasks:
14 - test: |13 - test: |
15 cd zig/build14 cd zig/build
16 bin/zig test ../test/behavior.zig15 bin/zig test ../test/behavior.zig
16 bin/zig test ../std/special/compiler_rt/index.zig
17
18 bin/zig test ../test/behavior.zig --library c
19 bin/zig test ../std/special/compiler_rt/index.zig --library c
20
21 bin/zig test ../test/behavior.zig --release-fast
22 bin/zig test ../std/special/compiler_rt/index.zig --release-fast
23
24 bin/zig test ../test/behavior.zig --release-fast --library c
25 bin/zig test ../std/special/compiler_rt/index.zig --release-fast --library c
26
27 bin/zig test ../test/behavior.zig --release-small --library c
28 bin/zig test ../std/special/compiler_rt/index.zig --release-small --library c
29
30 bin/zig test ../test/behavior.zig --release-small
31 bin/zig test ../std/special/compiler_rt/index.zig --release-small
32
33 bin/zig test ../test/behavior.zig --release-safe
34 bin/zig test ../std/special/compiler_rt/index.zig --release-safe
35
36 bin/zig test ../test/behavior.zig --release-safe --library c
37 bin/zig test ../std/special/compiler_rt/index.zig --release-safe --library c
17 # TODO enable all tests38 # TODO enable all tests
18 #bin/zig build --build-file ../build.zig test39 #bin/zig build --build-file ../build.zig test
19 # TODO integrate with the download page updater and make a40 # TODO integrate with the download page updater and make a
CMakeLists.txt+1-2
...@@ -586,10 +586,9 @@ set(ZIG_STD_FILES...@@ -586,10 +586,9 @@ set(ZIG_STD_FILES
586 "os/linux/arm64.zig"586 "os/linux/arm64.zig"
587 "os/freebsd/errno.zig"587 "os/freebsd/errno.zig"
588 "os/freebsd/index.zig"588 "os/freebsd/index.zig"
589 "os/freebsd/syscall.zig"
590 "os/freebsd/x86_64.zig"
591 "os/path.zig"589 "os/path.zig"
592 "os/time.zig"590 "os/time.zig"
591 "os/uefi.zig"
593 "os/windows/advapi32.zig"592 "os/windows/advapi32.zig"
594 "os/windows/error.zig"593 "os/windows/error.zig"
595 "os/windows/index.zig"594 "os/windows/index.zig"
README.md+20-20
...@@ -87,26 +87,26 @@ clarity....@@ -87,26 +87,26 @@ clarity.
8787
88#### Support Table88#### Support Table
8989
90| | freestanding | linux | macosx | windows | freebsd | other |90| | freestanding | linux | macosx | windows | freebsd | UEFI | other |
91|--------|--------------|--------|--------|---------|---------|--------|91|--------|--------------|--------|--------|---------|---------|--------|--------|
92|x86_64 | Tier 2 | Tier 1 | Tier 1 | Tier 1 | Tier 2 | Tier 3 |92|x86_64 | Tier 2 | Tier 1 | Tier 1 | Tier 1 | Tier 2 | Tier 2 | Tier 3 |
93|i386 | Tier 2 | Tier 2 | Tier 2 | Tier 2 | Tier 3 | Tier 3 |93|i386 | Tier 2 | Tier 2 | Tier 2 | Tier 2 | Tier 3 | Tier 3 | Tier 3 |
94|arm | Tier 2 | Tier 3 | Tier 3 | Tier 3 | Tier 3 | Tier 3 |94|arm | Tier 2 | Tier 3 | Tier 3 | Tier 3 | Tier 3 | Tier 3 | Tier 3 |
95|arm64 | Tier 2 | Tier 2 | Tier 3 | Tier 3 | Tier 3 | Tier 3 |95|arm64 | Tier 2 | Tier 2 | Tier 3 | Tier 3 | Tier 3 | Tier 3 | Tier 3 |
96|bpf | Tier 3 | Tier 3 | N/A | N/A | Tier 3 | Tier 3 |96|bpf | Tier 3 | Tier 3 | N/A | N/A | Tier 3 | Tier 3 | Tier 3 |
97|hexagon | Tier 3 | Tier 3 | N/A | N/A | Tier 3 | Tier 3 |97|hexagon | Tier 3 | Tier 3 | N/A | N/A | Tier 3 | Tier 3 | Tier 3 |
98|mips | Tier 3 | Tier 3 | N/A | N/A | Tier 3 | Tier 3 |98|mips | Tier 3 | Tier 3 | N/A | N/A | Tier 3 | Tier 3 | Tier 3 |
99|powerpc | Tier 3 | Tier 3 | N/A | N/A | Tier 3 | Tier 3 |99|powerpc | Tier 3 | Tier 3 | N/A | N/A | Tier 3 | Tier 3 | Tier 3 |
100|r600 | Tier 3 | Tier 3 | N/A | N/A | Tier 3 | Tier 3 |100|r600 | Tier 3 | Tier 3 | N/A | N/A | Tier 3 | Tier 3 | Tier 3 |
101|amdgcn | Tier 3 | Tier 3 | N/A | N/A | Tier 3 | Tier 3 |101|amdgcn | Tier 3 | Tier 3 | N/A | N/A | Tier 3 | Tier 3 | Tier 3 |
102|sparc | Tier 3 | Tier 3 | N/A | N/A | Tier 3 | Tier 3 |102|sparc | Tier 3 | Tier 3 | N/A | N/A | Tier 3 | Tier 3 | Tier 3 |
103|s390x | Tier 3 | Tier 3 | N/A | N/A | Tier 3 | Tier 3 |103|s390x | Tier 3 | Tier 3 | N/A | N/A | Tier 3 | Tier 3 | Tier 3 |
104|spir | Tier 3 | Tier 3 | N/A | N/A | Tier 3 | Tier 3 |104|spir | Tier 3 | Tier 3 | N/A | N/A | Tier 3 | Tier 3 | Tier 3 |
105|lanai | Tier 3 | Tier 3 | N/A | N/A | Tier 3 | Tier 3 |105|lanai | Tier 3 | Tier 3 | N/A | N/A | Tier 3 | Tier 3 | Tier 3 |
106|wasm32 | Tier 4 | N/A | N/A | N/A | N/A | N/A |106|wasm32 | Tier 4 | N/A | N/A | N/A | N/A | N/A | N/A |
107|wasm64 | Tier 4 | N/A | N/A | N/A | N/A | N/A |107|wasm64 | Tier 4 | N/A | N/A | N/A | N/A | N/A | N/A |
108|riscv32 | Tier 4 | Tier 4 | N/A | N/A | Tier 4 | Tier 4 |108|riscv32 | Tier 4 | Tier 4 | N/A | N/A | Tier 4 | Tier 4 | Tier 4 |
109|riscv64 | Tier 4 | Tier 4 | N/A | N/A | Tier 4 | Tier 4 |109|riscv64 | Tier 4 | Tier 4 | N/A | N/A | Tier 4 | Tier 4 | Tier 4 |
110110
111## Community111## Community
112112
build.zig+5-2
...@@ -293,11 +293,14 @@ fn configureStage2(b: *Builder, exe: var, ctx: Context) !void {...@@ -293,11 +293,14 @@ fn configureStage2(b: *Builder, exe: var, ctx: Context) !void {
293 try addCxxKnownPath(b, ctx, exe, "libstdc++.a",293 try addCxxKnownPath(b, ctx, exe, "libstdc++.a",
294 \\Unable to determine path to libstdc++.a294 \\Unable to determine path to libstdc++.a
295 \\On Fedora, install libstdc++-static and try again.295 \\On Fedora, install libstdc++-static and try again.
296 \\
297 );296 );
298297
299 exe.linkSystemLibrary("pthread");298 exe.linkSystemLibrary("pthread");
300 } else if (exe.target.isDarwin() or exe.target.isFreeBSD()) {299 } else if (exe.target.isFreeBSD()) {
300 try addCxxKnownPath(b, ctx, exe, "libc++.a", null);
301 exe.linkSystemLibrary("pthread");
302 }
303 else if (exe.target.isDarwin()) {
301 if (addCxxKnownPath(b, ctx, exe, "libgcc_eh.a", "")) {304 if (addCxxKnownPath(b, ctx, exe, "libgcc_eh.a", "")) {
302 // Compiler is GCC.305 // Compiler is GCC.
303 try addCxxKnownPath(b, ctx, exe, "libstdc++.a", null);306 try addCxxKnownPath(b, ctx, exe, "libstdc++.a", null);
src-self-hosted/target.zig+1-1
...@@ -535,7 +535,7 @@ pub const Target = union(enum) {...@@ -535,7 +535,7 @@ pub const Target = union(enum) {
535 => return 64,535 => return 64,
536 },536 },
537537
538 builtin.Os.windows => switch (id) {538 builtin.Os.windows, builtin.Os.uefi => switch (id) {
539 CInt.Id.Short,539 CInt.Id.Short,
540 CInt.Id.UShort,540 CInt.Id.UShort,
541 => return 16,541 => return 16,
src/all_types.hpp+1-2
...@@ -1750,12 +1750,11 @@ struct CodeGen {...@@ -1750,12 +1750,11 @@ struct CodeGen {
1750 BuildMode build_mode;1750 BuildMode build_mode;
1751 OutType out_type;1751 OutType out_type;
1752 ZigTarget zig_target;1752 ZigTarget zig_target;
1753 TargetSubsystem subsystem;
1753 bool is_static;1754 bool is_static;
1754 bool strip_debug_symbols;1755 bool strip_debug_symbols;
1755 bool is_test_build;1756 bool is_test_build;
1756 bool is_native_target;1757 bool is_native_target;
1757 bool windows_subsystem_windows;
1758 bool windows_subsystem_console;
1759 bool linker_rdynamic;1758 bool linker_rdynamic;
1760 bool no_rosegment_workaround;1759 bool no_rosegment_workaround;
1761 bool each_lib_rpath;1760 bool each_lib_rpath;
src/analyze.cpp+6-9
...@@ -3203,14 +3203,12 @@ void add_fn_export(CodeGen *g, ZigFn *fn_table_entry, Buf *symbol_name, GlobalLi...@@ -3203,14 +3203,12 @@ void add_fn_export(CodeGen *g, ZigFn *fn_table_entry, Buf *symbol_name, GlobalLi
3203 if (ccc) {3203 if (ccc) {
3204 if (buf_eql_str(symbol_name, "main") && g->libc_link_lib != nullptr) {3204 if (buf_eql_str(symbol_name, "main") && g->libc_link_lib != nullptr) {
3205 g->have_c_main = true;3205 g->have_c_main = true;
3206 g->windows_subsystem_windows = false;3206 g->subsystem = TargetSubsystemConsole;
3207 g->windows_subsystem_console = true;
3208 } else if (buf_eql_str(symbol_name, "WinMain") &&3207 } else if (buf_eql_str(symbol_name, "WinMain") &&
3209 g->zig_target.os == OsWindows)3208 g->zig_target.os == OsWindows)
3210 {3209 {
3211 g->have_winmain = true;3210 g->have_winmain = true;
3212 g->windows_subsystem_windows = true;3211 g->subsystem = TargetSubsystemWindows;
3213 g->windows_subsystem_console = false;
3214 } else if (buf_eql_str(symbol_name, "WinMainCRTStartup") &&3212 } else if (buf_eql_str(symbol_name, "WinMainCRTStartup") &&
3215 g->zig_target.os == OsWindows)3213 g->zig_target.os == OsWindows)
3216 {3214 {
...@@ -3221,6 +3219,7 @@ void add_fn_export(CodeGen *g, ZigFn *fn_table_entry, Buf *symbol_name, GlobalLi...@@ -3221,6 +3219,7 @@ void add_fn_export(CodeGen *g, ZigFn *fn_table_entry, Buf *symbol_name, GlobalLi
3221 g->have_dllmain_crt_startup = true;3219 g->have_dllmain_crt_startup = true;
3222 }3220 }
3223 }3221 }
3222
3224 FnExport *fn_export = fn_table_entry->export_list.add_one();3223 FnExport *fn_export = fn_table_entry->export_list.add_one();
3225 memset(fn_export, 0, sizeof(FnExport));3224 memset(fn_export, 0, sizeof(FnExport));
3226 buf_init_from_buf(&fn_export->name, symbol_name);3225 buf_init_from_buf(&fn_export->name, symbol_name);
...@@ -4376,8 +4375,7 @@ ImportTableEntry *add_source_file(CodeGen *g, PackageTableEntry *package, Buf *r...@@ -4376,8 +4375,7 @@ ImportTableEntry *add_source_file(CodeGen *g, PackageTableEntry *package, Buf *r
4376 if (is_pub && ok_cc) {4375 if (is_pub && ok_cc) {
4377 if (buf_eql_str(proto_name, "main")) {4376 if (buf_eql_str(proto_name, "main")) {
4378 g->have_pub_main = true;4377 g->have_pub_main = true;
4379 g->windows_subsystem_windows = false;4378 g->subsystem = TargetSubsystemConsole;
4380 g->windows_subsystem_console = true;
4381 } else if (buf_eql_str(proto_name, "panic")) {4379 } else if (buf_eql_str(proto_name, "panic")) {
4382 g->have_pub_panic = true;4380 g->have_pub_panic = true;
4383 }4381 }
...@@ -4592,8 +4590,7 @@ static Buf *get_posix_libc_include_path(void) {...@@ -4592,8 +4590,7 @@ static Buf *get_posix_libc_include_path(void) {
4592void find_libc_include_path(CodeGen *g) {4590void find_libc_include_path(CodeGen *g) {
4593 if (g->libc_include_dir == nullptr) {4591 if (g->libc_include_dir == nullptr) {
4594 if (!g->is_native_target) {4592 if (!g->is_native_target) {
4595 fprintf(stderr, "Unable to determine libc include path. --libc-include-dir");4593 return;
4596 exit(1);
4597 }4594 }
45984595
4599 if (g->zig_target.os == OsWindows) {4596 if (g->zig_target.os == OsWindows) {
...@@ -6377,7 +6374,7 @@ LinkLib *add_link_lib(CodeGen *g, Buf *name) {...@@ -6377,7 +6374,7 @@ LinkLib *add_link_lib(CodeGen *g, Buf *name) {
6377 if (is_libc && g->libc_link_lib != nullptr)6374 if (is_libc && g->libc_link_lib != nullptr)
6378 return g->libc_link_lib;6375 return g->libc_link_lib;
63796376
6380 if (g->enable_cache && is_libc && g->zig_target.os != OsMacOSX && g->zig_target.os != OsIOS) {6377 if (g->enable_cache && is_libc && g->zig_target.os != OsMacOSX && g->zig_target.os != OsIOS && g->zig_target.os != OsFreeBSD) {
6381 fprintf(stderr, "TODO linking against libc is currently incompatible with `--cache on`.\n"6378 fprintf(stderr, "TODO linking against libc is currently incompatible with `--cache on`.\n"
6382 "Zig is not yet capable of determining whether the libc installation has changed on subsequent builds.\n");6379 "Zig is not yet capable of determining whether the libc installation has changed on subsequent builds.\n");
6383 exit(1);6380 exit(1);
src/codegen.cpp+6-11
...@@ -178,7 +178,8 @@ CodeGen *codegen_create(Buf *root_src_path, const ZigTarget *target, OutType out...@@ -178,7 +178,8 @@ CodeGen *codegen_create(Buf *root_src_path, const ZigTarget *target, OutType out
178178
179 // On Darwin/MacOS/iOS, we always link libSystem which contains libc.179 // On Darwin/MacOS/iOS, we always link libSystem which contains libc.
180 if (g->zig_target.os == OsMacOSX ||180 if (g->zig_target.os == OsMacOSX ||
181 g->zig_target.os == OsIOS)181 g->zig_target.os == OsIOS ||
182 g->zig_target.os == OsFreeBSD)
182 {183 {
183 g->libc_link_lib = create_link_lib(buf_create_from_str("c"));184 g->libc_link_lib = create_link_lib(buf_create_from_str("c"));
184 g->link_libs_list.append(g->libc_link_lib);185 g->link_libs_list.append(g->libc_link_lib);
...@@ -291,11 +292,6 @@ void codegen_add_framework(CodeGen *g, const char *framework) {...@@ -291,11 +292,6 @@ void codegen_add_framework(CodeGen *g, const char *framework) {
291 g->darwin_frameworks.append(buf_create_from_str(framework));292 g->darwin_frameworks.append(buf_create_from_str(framework));
292}293}
293294
294void codegen_set_windows_subsystem(CodeGen *g, bool mwindows, bool mconsole) {
295 g->windows_subsystem_windows = mwindows;
296 g->windows_subsystem_console = mconsole;
297}
298
299void codegen_set_mmacosx_version_min(CodeGen *g, Buf *mmacosx_version_min) {295void codegen_set_mmacosx_version_min(CodeGen *g, Buf *mmacosx_version_min) {
300 g->mmacosx_version_min = mmacosx_version_min;296 g->mmacosx_version_min = mmacosx_version_min;
301}297}
...@@ -7236,8 +7232,7 @@ static void init(CodeGen *g) {...@@ -7236,8 +7232,7 @@ static void init(CodeGen *g) {
7236 }7232 }
72377233
7238 if (g->is_test_build) {7234 if (g->is_test_build) {
7239 g->windows_subsystem_windows = false;7235 g->subsystem = TargetSubsystemConsole;
7240 g->windows_subsystem_console = true;
7241 }7236 }
72427237
7243 assert(g->root_out_name);7238 assert(g->root_out_name);
...@@ -7273,7 +7268,7 @@ static void init(CodeGen *g) {...@@ -7273,7 +7268,7 @@ static void init(CodeGen *g) {
7273 // LLVM creates invalid binaries on Windows sometimes.7268 // LLVM creates invalid binaries on Windows sometimes.
7274 // See https://github.com/ziglang/zig/issues/5087269 // See https://github.com/ziglang/zig/issues/508
7275 // As a workaround we do not use target native features on Windows.7270 // As a workaround we do not use target native features on Windows.
7276 if (g->zig_target.os == OsWindows) {7271 if (g->zig_target.os == OsWindows || g->zig_target.os == OsUefi) {
7277 target_specific_cpu_args = "";7272 target_specific_cpu_args = "";
7278 target_specific_features = "";7273 target_specific_features = "";
7279 } else {7274 } else {
...@@ -7519,6 +7514,7 @@ static void gen_root_source(CodeGen *g) {...@@ -7519,6 +7514,7 @@ static void gen_root_source(CodeGen *g) {
7519 report_errors_and_maybe_exit(g);7514 report_errors_and_maybe_exit(g);
75207515
7521 if (!g->is_test_build && g->zig_target.os != OsFreestanding &&7516 if (!g->is_test_build && g->zig_target.os != OsFreestanding &&
7517 g->zig_target.os != OsUefi &&
7522 !g->have_c_main && !g->have_winmain && !g->have_winmain_crt_startup &&7518 !g->have_c_main && !g->have_winmain && !g->have_winmain_crt_startup &&
7523 ((g->have_pub_main && g->out_type == OutTypeObj) || g->out_type == OutTypeExe))7519 ((g->have_pub_main && g->out_type == OutTypeObj) || g->out_type == OutTypeExe))
7524 {7520 {
...@@ -8075,12 +8071,11 @@ static Error check_cache(CodeGen *g, Buf *manifest_dir, Buf *digest) {...@@ -8075,12 +8071,11 @@ static Error check_cache(CodeGen *g, Buf *manifest_dir, Buf *digest) {
8075 cache_int(ch, g->zig_target.os);8071 cache_int(ch, g->zig_target.os);
8076 cache_int(ch, g->zig_target.env_type);8072 cache_int(ch, g->zig_target.env_type);
8077 cache_int(ch, g->zig_target.oformat);8073 cache_int(ch, g->zig_target.oformat);
8074 cache_int(ch, g->subsystem);
8078 cache_bool(ch, g->is_static);8075 cache_bool(ch, g->is_static);
8079 cache_bool(ch, g->strip_debug_symbols);8076 cache_bool(ch, g->strip_debug_symbols);
8080 cache_bool(ch, g->is_test_build);8077 cache_bool(ch, g->is_test_build);
8081 cache_bool(ch, g->is_native_target);8078 cache_bool(ch, g->is_native_target);
8082 cache_bool(ch, g->windows_subsystem_windows);
8083 cache_bool(ch, g->windows_subsystem_console);
8084 cache_bool(ch, g->linker_rdynamic);8079 cache_bool(ch, g->linker_rdynamic);
8085 cache_bool(ch, g->no_rosegment_workaround);8080 cache_bool(ch, g->no_rosegment_workaround);
8086 cache_bool(ch, g->each_lib_rpath);8081 cache_bool(ch, g->each_lib_rpath);
src/codegen.hpp-1
...@@ -33,7 +33,6 @@ void codegen_set_libc_include_dir(CodeGen *codegen, Buf *libc_include_dir);...@@ -33,7 +33,6 @@ void codegen_set_libc_include_dir(CodeGen *codegen, Buf *libc_include_dir);
33void codegen_set_msvc_lib_dir(CodeGen *g, Buf *msvc_lib_dir);33void codegen_set_msvc_lib_dir(CodeGen *g, Buf *msvc_lib_dir);
34void codegen_set_kernel32_lib_dir(CodeGen *codegen, Buf *kernel32_lib_dir);34void codegen_set_kernel32_lib_dir(CodeGen *codegen, Buf *kernel32_lib_dir);
35void codegen_set_dynamic_linker(CodeGen *g, Buf *dynamic_linker);35void codegen_set_dynamic_linker(CodeGen *g, Buf *dynamic_linker);
36void codegen_set_windows_subsystem(CodeGen *g, bool mwindows, bool mconsole);
37void codegen_add_lib_dir(CodeGen *codegen, const char *dir);36void codegen_add_lib_dir(CodeGen *codegen, const char *dir);
38void codegen_add_forbidden_lib(CodeGen *codegen, Buf *lib);37void codegen_add_forbidden_lib(CodeGen *codegen, Buf *lib);
39LinkLib *codegen_add_link_lib(CodeGen *codegen, Buf *lib);38LinkLib *codegen_add_link_lib(CodeGen *codegen, Buf *lib);
src/ir.cpp+33
...@@ -19787,6 +19787,39 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,...@@ -19787,6 +19787,39 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
19787 return ira->codegen->invalid_instruction;19787 return ira->codegen->invalid_instruction;
19788 }19788 }
19789 }19789 }
19790 } else if (switch_type->id == ZigTypeIdBool) {
19791 int seenTrue = 0;
19792 int seenFalse = 0;
19793 for (size_t range_i = 0; range_i < instruction->range_count; range_i += 1) {
19794 IrInstructionCheckSwitchProngsRange *range = &instruction->ranges[range_i];
19795
19796 IrInstruction *value = range->start->child;
19797
19798 IrInstruction *casted_value = ir_implicit_cast(ira, value, switch_type);
19799 if (type_is_invalid(casted_value->value.type))
19800 return ira->codegen->invalid_instruction;
19801
19802 ConstExprValue *const_expr_val = ir_resolve_const(ira, casted_value, UndefBad);
19803 if (!const_expr_val)
19804 return ira->codegen->invalid_instruction;
19805
19806 assert(const_expr_val->type->id == ZigTypeIdBool);
19807
19808 if (const_expr_val->data.x_bool == true) {
19809 seenTrue += 1;
19810 } else {
19811 seenFalse += 1;
19812 }
19813
19814 if ((seenTrue > 1) || (seenFalse > 1)) {
19815 ir_add_error(ira, value, buf_sprintf("duplicate switch value"));
19816 return ira->codegen->invalid_instruction;
19817 }
19818 }
19819 if (((seenTrue < 1) || (seenFalse < 1)) && !instruction->have_else_prong) {
19820 ir_add_error(ira, &instruction->base, buf_sprintf("switch must handle all possibilities"));
19821 return ira->codegen->invalid_instruction;
19822 }
19790 } else if (!instruction->have_else_prong) {19823 } else if (!instruction->have_else_prong) {
19791 ir_add_error(ira, &instruction->base,19824 ir_add_error(ira, &instruction->base,
19792 buf_sprintf("else prong required when switching on type '%s'", buf_ptr(&switch_type->name)));19825 buf_sprintf("else prong required when switching on type '%s'", buf_ptr(&switch_type->name)));
src/link.cpp+177-127
...@@ -444,72 +444,19 @@ static bool zig_lld_link(ZigLLVM_ObjectFormatType oformat, const char **args, si...@@ -444,72 +444,19 @@ static bool zig_lld_link(ZigLLVM_ObjectFormatType oformat, const char **args, si
444 return ZigLLDLink(oformat, args, arg_count, link_diag_callback, diag);444 return ZigLLDLink(oformat, args, arg_count, link_diag_callback, diag);
445}445}
446446
447static void construct_linker_job_coff(LinkJob *lj) {447static void add_uefi_link_args(LinkJob *lj) {
448 CodeGen *g = lj->codegen;448 lj->args.append("/BASE:0");
449449 lj->args.append("/ENTRY:EfiMain");
450 lj->args.append("/ERRORLIMIT:0");450 lj->args.append("/OPT:REF");
451451 lj->args.append("/SAFESEH:NO");
452 if (g->libc_link_lib != nullptr) {452 lj->args.append("/MERGE:.rdata=.data");
453 find_libc_lib_path(g);453 lj->args.append("/ALIGN:32");
454 }454 lj->args.append("/NODEFAULTLIB");
455455 lj->args.append("/SECTION:.xdata,D");
456 lj->args.append("-NOLOGO");456}
457
458 if (!g->strip_debug_symbols) {
459 lj->args.append("-DEBUG");
460 }
461
462 if (g->out_type == OutTypeExe) {
463 // TODO compile time stack upper bound detection
464 lj->args.append("/STACK:16777216");
465 }
466
467 coff_append_machine_arg(g, &lj->args);
468
469 if (g->windows_subsystem_windows) {
470 lj->args.append("/SUBSYSTEM:windows");
471 } else if (g->windows_subsystem_console) {
472 lj->args.append("/SUBSYSTEM:console");
473 }
474 // The commented out stuff is from when we linked with MinGW
475 // Now that we're linking with LLD it remains to be determined
476 // how to handle --target-environ gnu
477 // These comments are a clue
478
479 bool is_library = g->out_type == OutTypeLib;
480 //bool dll = g->out_type == OutTypeLib;
481 //bool shared = !g->is_static && dll;
482 //if (g->is_static) {
483 // lj->args.append("-Bstatic");
484 //} else {
485 // if (dll) {
486 // lj->args.append("--dll");
487 // } else if (shared) {
488 // lj->args.append("--shared");
489 // }
490 // lj->args.append("-Bdynamic");
491 // if (dll || shared) {
492 // lj->args.append("-e");
493 // if (g->zig_target.arch.arch == ZigLLVM_x86) {
494 // lj->args.append("_DllMainCRTStartup@12");
495 // } else {
496 // lj->args.append("DllMainCRTStartup");
497 // }
498 // lj->args.append("--enable-auto-image-base");
499 // }
500 //}
501
502 lj->args.append(buf_ptr(buf_sprintf("-OUT:%s", buf_ptr(&g->output_file_path))));
503
504 if (g->libc_link_lib != nullptr) {
505 lj->args.append(buf_ptr(buf_sprintf("-LIBPATH:%s", buf_ptr(g->msvc_lib_dir))));
506 lj->args.append(buf_ptr(buf_sprintf("-LIBPATH:%s", buf_ptr(g->kernel32_lib_dir))));
507457
508 lj->args.append(buf_ptr(buf_sprintf("-LIBPATH:%s", buf_ptr(g->libc_lib_dir))));458static void add_nt_link_args(LinkJob *lj, bool is_library) {
509 if (g->libc_static_lib_dir != nullptr) {459 CodeGen *g = lj->codegen;
510 lj->args.append(buf_ptr(buf_sprintf("-LIBPATH:%s", buf_ptr(g->libc_static_lib_dir))));
511 }
512 }
513460
514 if (lj->link_in_crt) {461 if (lj->link_in_crt) {
515 const char *lib_str = g->is_static ? "lib" : "";462 const char *lib_str = g->is_static ? "lib" : "";
...@@ -533,29 +480,180 @@ static void construct_linker_job_coff(LinkJob *lj) {...@@ -533,29 +480,180 @@ static void construct_linker_job_coff(LinkJob *lj) {
533 //https://msdn.microsoft.com/en-us/library/bb531344.aspx480 //https://msdn.microsoft.com/en-us/library/bb531344.aspx
534 lj->args.append("legacy_stdio_definitions.lib");481 lj->args.append("legacy_stdio_definitions.lib");
535482
536 //if (shared || dll) {
537 // lj->args.append(get_libc_file(g, "dllcrt2.o"));
538 //} else {
539 // if (g->windows_linker_unicode) {
540 // lj->args.append(get_libc_file(g, "crt2u.o"));
541 // } else {
542 // lj->args.append(get_libc_file(g, "crt2.o"));
543 // }
544 //}
545 //lj->args.append(get_libc_static_file(g, "crtbegin.o"));
546
547 // msvcrt depends on kernel32483 // msvcrt depends on kernel32
548 lj->args.append("kernel32.lib");484 lj->args.append("kernel32.lib");
549 } else {485 } else {
550 lj->args.append("-NODEFAULTLIB");486 lj->args.append("/NODEFAULTLIB");
551 if (!is_library) {487 if (!is_library) {
552 if (g->have_winmain) {488 if (g->have_winmain) {
553 lj->args.append("-ENTRY:WinMain");489 lj->args.append("/ENTRY:WinMain");
554 } else {490 } else {
555 lj->args.append("-ENTRY:WinMainCRTStartup");491 lj->args.append("/ENTRY:WinMainCRTStartup");
556 }492 }
557 }493 }
558 }494 }
495}
496
497// These are n actual command lines from LINK.EXE UEFI builds (app & driver) to be used as guidance cleaning
498// up a bit for building the COFF linker args:
499// /OUT:"J:\coding\nebulae\k\x64\Release\k.efi" /LTCG:incremental /Driver /PDB:"J:\coding\nebulae\k\x64\Release\k.pdb" "UefiApplicationEntryPoint.lib" "UefiRuntimeLib.lib" "UefiHiiLib.lib" "UefiHiiServicesLib.lib" "UefiSortLib.lib" "UefiShellLib.lib" "GlueLib.lib" "BaseLib.lib" "BaseDebugPrintErrorLevelLib.lib" "BasePrintLib.lib" "UefiLib.lib" "UefiBootServicesTableLib.lib" "UefiRuntimeServicesTableLib.lib" "UefiDevicePathLibDevicePathProtocol.lib" "UefiDebugLibConOut.lib" "UefiMemoryLib.lib" "UefiMemoryAllocationLib.lib" "BaseSynchronizationLib.lib" "UefiFileHandleLib.lib" /IMPLIB:"J:\coding\nebulae\k\x64\Release\k.lib" /DEBUG:FASTLINK /BASE:"0" /MACHINE:X64 /ENTRY:"EfiMain" /OPT:REF /SAFESEH:NO /SUBSYSTEM:EFI_APPLICATION /MERGE:".rdata=.data" /NOLOGO /ALIGN:32 /NODEFAULTLIB /SECTION:".xdata,D"
500// /OUT:"J:\coding\VisualUefi\samples\x64\Release\UefiDriver.efi" /LTCG:incremental /Driver /PDB:"J:\coding\VisualUefi\samples\x64\Release\UefiDriver.pdb" "UefiDriverEntryPoint.lib" "UefiHiiLib.lib" "UefiHiiServicesLib.lib" "UefiSortLib.lib" "UefiShellLib.lib" "GlueLib.lib" "BaseLib.lib" "BaseDebugPrintErrorLevelLib.lib" "BasePrintLib.lib" "UefiLib.lib" "UefiBootServicesTableLib.lib" "UefiRuntimeServicesTableLib.lib" "UefiDevicePathLibDevicePathProtocol.lib" "UefiDebugLibConOut.lib" "UefiMemoryLib.lib" "UefiMemoryAllocationLib.lib" "BaseSynchronizationLib.lib" "UefiFileHandleLib.lib" /IMPLIB:"J:\coding\VisualUefi\samples\x64\Release\UefiDriver.lib" /DEBUG:FASTLINK /BASE:"0" /MACHINE:X64 /ENTRY:"EfiMain" /OPT:REF /SAFESEH:NO /SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER /MERGE:".rdata=.data" /NOLOGO /ALIGN:32 /NODEFAULTLIB /SECTION:".xdata,D"
501// This commented out stuff is from when we linked with MinGW
502// Now that we're linking with LLD it remains to be determined
503// how to handle --target-environ gnu
504// These comments are a clue
505//bool dll = g->out_type == OutTypeLib;
506//bool shared = !g->is_static && dll;
507//if (g->is_static) {
508// lj->args.append("-Bstatic");
509//} else {
510// if (dll) {
511// lj->args.append("--dll");
512// } else if (shared) {
513// lj->args.append("--shared");
514// }
515// lj->args.append("-Bdynamic");
516// if (dll || shared) {
517// lj->args.append("-e");
518// if (g->zig_target.arch.arch == ZigLLVM_x86) {
519// lj->args.append("_DllMainCRTStartup@12");
520// } else {
521// lj->args.append("DllMainCRTStartup");
522// }
523// lj->args.append("--enable-auto-image-base");
524// }
525//}
526//if (shared || dll) {
527// lj->args.append(get_libc_file(g, "dllcrt2.o"));
528//} else {
529// if (g->windows_linker_unicode) {
530// lj->args.append(get_libc_file(g, "crt2u.o"));
531// } else {
532// lj->args.append(get_libc_file(g, "crt2.o"));
533// }
534//}
535//lj->args.append(get_libc_static_file(g, "crtbegin.o"));
536//if (g->libc_link_lib != nullptr) {
537//if (g->is_static) {
538// lj->args.append("--start-group");
539//}
540
541//lj->args.append("-lmingw32");
542
543//lj->args.append("-lgcc");
544//bool is_android = (g->zig_target.env_type == ZigLLVM_Android);
545//bool is_cyg_ming = is_target_cyg_mingw(&g->zig_target);
546//if (!g->is_static && !is_android) {
547// if (!is_cyg_ming) {
548// lj->args.append("--as-needed");
549// }
550// //lj->args.append("-lgcc_s");
551// if (!is_cyg_ming) {
552// lj->args.append("--no-as-needed");
553// }
554//}
555//if (g->is_static && !is_android) {
556// //lj->args.append("-lgcc_eh");
557//}
558//if (is_android && !g->is_static) {
559// lj->args.append("-ldl");
560//}
561
562//lj->args.append("-lmoldname");
563//lj->args.append("-lmingwex");
564//lj->args.append("-lmsvcrt");
565
566
567//if (g->windows_subsystem_windows) {
568// lj->args.append("-lgdi32");
569// lj->args.append("-lcomdlg32");
570//}
571//lj->args.append("-ladvapi32");
572//lj->args.append("-lshell32");
573//lj->args.append("-luser32");
574//lj->args.append("-lkernel32");
575
576//if (g->is_static) {
577// lj->args.append("--end-group");
578//}
579
580//if (lj->link_in_crt) {
581// lj->args.append(get_libc_static_file(g, "crtend.o"));
582//}
583//}
584
585
586static void construct_linker_job_coff(LinkJob *lj) {
587 CodeGen *g = lj->codegen;
588
589 lj->args.append("/ERRORLIMIT:0");
590
591 if (g->libc_link_lib != nullptr) {
592 find_libc_lib_path(g);
593 }
594
595 lj->args.append("/NOLOGO");
596
597 if (!g->strip_debug_symbols) {
598 lj->args.append("/DEBUG");
599 }
600
601 if (g->out_type == OutTypeExe) {
602 // TODO compile time stack upper bound detection
603 lj->args.append("/STACK:16777216");
604 }
605
606 coff_append_machine_arg(g, &lj->args);
607
608 bool is_library = g->out_type == OutTypeLib;
609 switch (g->subsystem) {
610 case TargetSubsystemAuto:
611 break;
612 case TargetSubsystemConsole:
613 lj->args.append("/SUBSYSTEM:console");
614 add_nt_link_args(lj, is_library);
615 break;
616 case TargetSubsystemEfiApplication:
617 lj->args.append("/SUBSYSTEM:efi_application");
618 add_uefi_link_args(lj);
619 break;
620 case TargetSubsystemEfiBootServiceDriver:
621 lj->args.append("/SUBSYSTEM:efi_boot_service_driver");
622 add_uefi_link_args(lj);
623 break;
624 case TargetSubsystemEfiRom:
625 lj->args.append("/SUBSYSTEM:efi_rom");
626 add_uefi_link_args(lj);
627 break;
628 case TargetSubsystemEfiRuntimeDriver:
629 lj->args.append("/SUBSYSTEM:efi_runtime_driver");
630 add_uefi_link_args(lj);
631 break;
632 case TargetSubsystemNative:
633 lj->args.append("/SUBSYSTEM:native");
634 add_nt_link_args(lj, is_library);
635 break;
636 case TargetSubsystemPosix:
637 lj->args.append("/SUBSYSTEM:posix");
638 add_nt_link_args(lj, is_library);
639 break;
640 case TargetSubsystemWindows:
641 lj->args.append("/SUBSYSTEM:windows");
642 add_nt_link_args(lj, is_library);
643 break;
644 }
645
646 lj->args.append(buf_ptr(buf_sprintf("-OUT:%s", buf_ptr(&g->output_file_path))));
647
648 if (g->libc_link_lib != nullptr) {
649 lj->args.append(buf_ptr(buf_sprintf("-LIBPATH:%s", buf_ptr(g->msvc_lib_dir))));
650 lj->args.append(buf_ptr(buf_sprintf("-LIBPATH:%s", buf_ptr(g->kernel32_lib_dir))));
651
652 lj->args.append(buf_ptr(buf_sprintf("-LIBPATH:%s", buf_ptr(g->libc_lib_dir))));
653 if (g->libc_static_lib_dir != nullptr) {
654 lj->args.append(buf_ptr(buf_sprintf("-LIBPATH:%s", buf_ptr(g->libc_static_lib_dir))));
655 }
656 }
559657
560 if (is_library && !g->is_static) {658 if (is_library && !g->is_static) {
561 lj->args.append("-DLL");659 lj->args.append("-DLL");
...@@ -627,54 +725,6 @@ static void construct_linker_job_coff(LinkJob *lj) {...@@ -627,54 +725,6 @@ static void construct_linker_job_coff(LinkJob *lj) {
627 }725 }
628 }726 }
629727
630 //if (g->libc_link_lib != nullptr) {
631 //if (g->is_static) {
632 // lj->args.append("--start-group");
633 //}
634
635 //lj->args.append("-lmingw32");
636
637 //lj->args.append("-lgcc");
638 //bool is_android = (g->zig_target.env_type == ZigLLVM_Android);
639 //bool is_cyg_ming = is_target_cyg_mingw(&g->zig_target);
640 //if (!g->is_static && !is_android) {
641 // if (!is_cyg_ming) {
642 // lj->args.append("--as-needed");
643 // }
644 // //lj->args.append("-lgcc_s");
645 // if (!is_cyg_ming) {
646 // lj->args.append("--no-as-needed");
647 // }
648 //}
649 //if (g->is_static && !is_android) {
650 // //lj->args.append("-lgcc_eh");
651 //}
652 //if (is_android && !g->is_static) {
653 // lj->args.append("-ldl");
654 //}
655
656 //lj->args.append("-lmoldname");
657 //lj->args.append("-lmingwex");
658 //lj->args.append("-lmsvcrt");
659
660
661 //if (g->windows_subsystem_windows) {
662 // lj->args.append("-lgdi32");
663 // lj->args.append("-lcomdlg32");
664 //}
665 //lj->args.append("-ladvapi32");
666 //lj->args.append("-lshell32");
667 //lj->args.append("-luser32");
668 //lj->args.append("-lkernel32");
669
670 //if (g->is_static) {
671 // lj->args.append("--end-group");
672 //}
673
674 //if (lj->link_in_crt) {
675 // lj->args.append(get_libc_static_file(g, "crtend.o"));
676 //}
677 //}
678}728}
679729
680730
src/main.cpp+35-9
...@@ -90,8 +90,7 @@ static int print_full_usage(const char *arg0) {...@@ -90,8 +90,7 @@ static int print_full_usage(const char *arg0) {
90 " -rdynamic add all symbols to the dynamic symbol table\n"90 " -rdynamic add all symbols to the dynamic symbol table\n"
91 " -rpath [path] add directory to the runtime library search path\n"91 " -rpath [path] add directory to the runtime library search path\n"
92 " --no-rosegment compromise security to workaround valgrind bug\n"92 " --no-rosegment compromise security to workaround valgrind bug\n"
93 " -mconsole (windows) --subsystem console to the linker\n"93 " --subsystem [subsystem] (windows) /SUBSYSTEM:<subsystem> to the linker\n"
94 " -mwindows (windows) --subsystem windows to the linker\n"
95 " -framework [name] (darwin) link against framework\n"94 " -framework [name] (darwin) link against framework\n"
96 " -mios-version-min [ver] (darwin) set iOS deployment target\n"95 " -mios-version-min [ver] (darwin) set iOS deployment target\n"
97 " -mmacosx-version-min [ver] (darwin) set Mac OS X deployment target\n"96 " -mmacosx-version-min [ver] (darwin) set Mac OS X deployment target\n"
...@@ -371,8 +370,6 @@ int main(int argc, char **argv) {...@@ -371,8 +370,6 @@ int main(int argc, char **argv) {
371 const char *target_arch = nullptr;370 const char *target_arch = nullptr;
372 const char *target_os = nullptr;371 const char *target_os = nullptr;
373 const char *target_environ = nullptr;372 const char *target_environ = nullptr;
374 bool mwindows = false;
375 bool mconsole = false;
376 bool rdynamic = false;373 bool rdynamic = false;
377 const char *mmacosx_version_min = nullptr;374 const char *mmacosx_version_min = nullptr;
378 const char *mios_version_min = nullptr;375 const char *mios_version_min = nullptr;
...@@ -395,6 +392,7 @@ int main(int argc, char **argv) {...@@ -395,6 +392,7 @@ int main(int argc, char **argv) {
395 int runtime_args_start = -1;392 int runtime_args_start = -1;
396 bool no_rosegment_workaround = false;393 bool no_rosegment_workaround = false;
397 bool system_linker_hack = false;394 bool system_linker_hack = false;
395 TargetSubsystem subsystem = TargetSubsystemAuto;
398396
399 if (argc >= 2 && strcmp(argv[1], "build") == 0) {397 if (argc >= 2 && strcmp(argv[1], "build") == 0) {
400 Buf zig_exe_path_buf = BUF_INIT;398 Buf zig_exe_path_buf = BUF_INIT;
...@@ -540,10 +538,6 @@ int main(int argc, char **argv) {...@@ -540,10 +538,6 @@ int main(int argc, char **argv) {
540 verbose_llvm_ir = true;538 verbose_llvm_ir = true;
541 } else if (strcmp(arg, "--verbose-cimport") == 0) {539 } else if (strcmp(arg, "--verbose-cimport") == 0) {
542 verbose_cimport = true;540 verbose_cimport = true;
543 } else if (strcmp(arg, "-mwindows") == 0) {
544 mwindows = true;
545 } else if (strcmp(arg, "-mconsole") == 0) {
546 mconsole = true;
547 } else if (strcmp(arg, "-rdynamic") == 0) {541 } else if (strcmp(arg, "-rdynamic") == 0) {
548 rdynamic = true;542 rdynamic = true;
549 } else if (strcmp(arg, "--no-rosegment") == 0) {543 } else if (strcmp(arg, "--no-rosegment") == 0) {
...@@ -687,6 +681,37 @@ int main(int argc, char **argv) {...@@ -687,6 +681,37 @@ int main(int argc, char **argv) {
687 ver_patch = atoi(argv[i]);681 ver_patch = atoi(argv[i]);
688 } else if (strcmp(arg, "--test-cmd") == 0) {682 } else if (strcmp(arg, "--test-cmd") == 0) {
689 test_exec_args.append(argv[i]);683 test_exec_args.append(argv[i]);
684 } else if (strcmp(arg, "--subsystem") == 0) {
685 if (strcmp(argv[i], "console") == 0) {
686 subsystem = TargetSubsystemConsole;
687 } else if (strcmp(argv[i], "windows") == 0) {
688 subsystem = TargetSubsystemWindows;
689 } else if (strcmp(argv[i], "posix") == 0) {
690 subsystem = TargetSubsystemPosix;
691 } else if (strcmp(argv[i], "native") == 0) {
692 subsystem = TargetSubsystemNative;
693 } else if (strcmp(argv[i], "efi_application") == 0) {
694 subsystem = TargetSubsystemEfiApplication;
695 } else if (strcmp(argv[i], "efi_boot_service_driver") == 0) {
696 subsystem = TargetSubsystemEfiBootServiceDriver;
697 } else if (strcmp(argv[i], "efi_rom") == 0) {
698 subsystem = TargetSubsystemEfiRom;
699 } else if (strcmp(argv[i], "efi_runtime_driver") == 0) {
700 subsystem = TargetSubsystemEfiRuntimeDriver;
701 } else {
702 fprintf(stderr, "invalid: --subsystem %s\n"
703 "Options are:\n"
704 " console\n"
705 " windows\n"
706 " posix\n"
707 " native\n"
708 " efi_application\n"
709 " efi_boot_service_driver\n"
710 " efi_rom\n"
711 " efi_runtime_driver\n"
712 , argv[i]);
713 return EXIT_FAILURE;
714 }
690 } else {715 } else {
691 fprintf(stderr, "Invalid argument: %s\n", arg);716 fprintf(stderr, "Invalid argument: %s\n", arg);
692 return print_error_usage(arg0);717 return print_error_usage(arg0);
...@@ -849,6 +874,8 @@ int main(int argc, char **argv) {...@@ -849,6 +874,8 @@ int main(int argc, char **argv) {
849 buf_out_name = buf_create_from_str("run");874 buf_out_name = buf_create_from_str("run");
850 }875 }
851 CodeGen *g = codegen_create(zig_root_source_file, target, out_type, build_mode, get_zig_lib_dir());876 CodeGen *g = codegen_create(zig_root_source_file, target, out_type, build_mode, get_zig_lib_dir());
877 g->subsystem = subsystem;
878
852 if (disable_pic) {879 if (disable_pic) {
853 if (out_type != OutTypeLib || !is_static) {880 if (out_type != OutTypeLib || !is_static) {
854 fprintf(stderr, "--disable-pic only applies to static libraries");881 fprintf(stderr, "--disable-pic only applies to static libraries");
...@@ -909,7 +936,6 @@ int main(int argc, char **argv) {...@@ -909,7 +936,6 @@ int main(int argc, char **argv) {
909 codegen_add_rpath(g, rpath_list.at(i));936 codegen_add_rpath(g, rpath_list.at(i));
910 }937 }
911938
912 codegen_set_windows_subsystem(g, mwindows, mconsole);
913 codegen_set_rdynamic(g, rdynamic);939 codegen_set_rdynamic(g, rdynamic);
914 g->no_rosegment_workaround = no_rosegment_workaround;940 g->no_rosegment_workaround = no_rosegment_workaround;
915 if (mmacosx_version_min && mios_version_min) {941 if (mmacosx_version_min && mios_version_min) {
src/target.cpp+9-2
...@@ -186,6 +186,7 @@ static const Os os_list[] = {...@@ -186,6 +186,7 @@ static const Os os_list[] = {
186 OsHermitCore,186 OsHermitCore,
187 OsHurd,187 OsHurd,
188 OsZen,188 OsZen,
189 OsUefi,
189};190};
190191
191// Coordinate with zig_llvm.h192// Coordinate with zig_llvm.h
...@@ -294,6 +295,7 @@ ZigLLVM_OSType get_llvm_os_type(Os os_type) {...@@ -294,6 +295,7 @@ ZigLLVM_OSType get_llvm_os_type(Os os_type) {
294 case OsSolaris:295 case OsSolaris:
295 return ZigLLVM_Solaris;296 return ZigLLVM_Solaris;
296 case OsWindows:297 case OsWindows:
298 case OsUefi:
297 return ZigLLVM_Win32;299 return ZigLLVM_Win32;
298 case OsHaiku:300 case OsHaiku:
299 return ZigLLVM_Haiku;301 return ZigLLVM_Haiku;
...@@ -414,6 +416,8 @@ const char *get_target_os_name(Os os_type) {...@@ -414,6 +416,8 @@ const char *get_target_os_name(Os os_type) {
414 return "freestanding";416 return "freestanding";
415 case OsZen:417 case OsZen:
416 return "zen";418 return "zen";
419 case OsUefi:
420 return "uefi";
417 case OsAnanas:421 case OsAnanas:
418 case OsCloudABI:422 case OsCloudABI:
419 case OsDragonFly:423 case OsDragonFly:
...@@ -778,6 +782,7 @@ uint32_t target_c_type_size_in_bits(const ZigTarget *target, CIntType id) {...@@ -778,6 +782,7 @@ uint32_t target_c_type_size_in_bits(const ZigTarget *target, CIntType id) {
778 case CIntTypeCount:782 case CIntTypeCount:
779 zig_unreachable();783 zig_unreachable();
780 }784 }
785 case OsUefi:
781 case OsWindows:786 case OsWindows:
782 switch (id) {787 switch (id) {
783 case CIntTypeShort:788 case CIntTypeShort:
...@@ -827,7 +832,7 @@ uint32_t target_c_type_size_in_bits(const ZigTarget *target, CIntType id) {...@@ -827,7 +832,7 @@ uint32_t target_c_type_size_in_bits(const ZigTarget *target, CIntType id) {
827}832}
828833
829const char *target_o_file_ext(ZigTarget *target) {834const char *target_o_file_ext(ZigTarget *target) {
830 if (target->env_type == ZigLLVM_MSVC || target->os == OsWindows) {835 if (target->env_type == ZigLLVM_MSVC || target->os == OsWindows || target->os == OsUefi) {
831 return ".obj";836 return ".obj";
832 } else {837 } else {
833 return ".o";838 return ".o";
...@@ -845,13 +850,15 @@ const char *target_llvm_ir_file_ext(ZigTarget *target) {...@@ -845,13 +850,15 @@ const char *target_llvm_ir_file_ext(ZigTarget *target) {
845const char *target_exe_file_ext(ZigTarget *target) {850const char *target_exe_file_ext(ZigTarget *target) {
846 if (target->os == OsWindows) {851 if (target->os == OsWindows) {
847 return ".exe";852 return ".exe";
853 } else if (target->os == OsUefi) {
854 return ".efi";
848 } else {855 } else {
849 return "";856 return "";
850 }857 }
851}858}
852859
853const char *target_lib_file_ext(ZigTarget *target, bool is_static, size_t version_major, size_t version_minor, size_t version_patch) {860const char *target_lib_file_ext(ZigTarget *target, bool is_static, size_t version_major, size_t version_minor, size_t version_patch) {
854 if (target->os == OsWindows) {861 if (target->os == OsWindows || target->os == OsUefi) {
855 if (is_static) {862 if (is_static) {
856 return ".lib";863 return ".lib";
857 } else {864 } else {
src/target.hpp+13
...@@ -53,6 +53,19 @@ enum Os {...@@ -53,6 +53,19 @@ enum Os {
53 OsHermitCore,53 OsHermitCore,
54 OsHurd,54 OsHurd,
55 OsZen,55 OsZen,
56 OsUefi,
57};
58
59enum TargetSubsystem {
60 TargetSubsystemAuto, // Zig should infer the subsystem
61 TargetSubsystemConsole,
62 TargetSubsystemWindows,
63 TargetSubsystemPosix,
64 TargetSubsystemNative,
65 TargetSubsystemEfiApplication,
66 TargetSubsystemEfiBootServiceDriver,
67 TargetSubsystemEfiRom,
68 TargetSubsystemEfiRuntimeDriver,
56};69};
5770
58struct ZigTarget {71struct ZigTarget {
src/translate_c.cpp+4-2
...@@ -4784,8 +4784,10 @@ Error parse_h_file(ImportTableEntry *import, ZigList<ErrorMsg *> *errors, const...@@ -4784,8 +4784,10 @@ Error parse_h_file(ImportTableEntry *import, ZigList<ErrorMsg *> *errors, const
4784 clang_argv.append("-isystem");4784 clang_argv.append("-isystem");
4785 clang_argv.append(buf_ptr(codegen->zig_c_headers_dir));4785 clang_argv.append(buf_ptr(codegen->zig_c_headers_dir));
47864786
4787 clang_argv.append("-isystem");4787 if (codegen->libc_include_dir != nullptr) {
4788 clang_argv.append(buf_ptr(codegen->libc_include_dir));4788 clang_argv.append("-isystem");
4789 clang_argv.append(buf_ptr(codegen->libc_include_dir));
4790 }
47894791
4790 // windows c runtime requires -D_DEBUG if using debug libraries4792 // windows c runtime requires -D_DEBUG if using debug libraries
4791 if (codegen->build_mode == BuildModeDebug) {4793 if (codegen->build_mode == BuildModeDebug) {
src/zig_llvm.cpp+1-1
...@@ -606,7 +606,7 @@ ZigLLVMDISubprogram *ZigLLVMCreateFunction(ZigLLVMDIBuilder *dibuilder, ZigLLVMD...@@ -606,7 +606,7 @@ ZigLLVMDISubprogram *ZigLLVMCreateFunction(ZigLLVMDIBuilder *dibuilder, ZigLLVMD
606 lineno,606 lineno,
607 di_sub_type,607 di_sub_type,
608 scope_line,608 scope_line,
609 DINode::FlagZero,609 DINode::FlagStaticMember,
610 DISubprogram::toSPFlags(is_local_to_unit, is_definition, is_optimized),610 DISubprogram::toSPFlags(is_local_to_unit, is_definition, is_optimized),
611 nullptr,611 nullptr,
612 reinterpret_cast<DISubprogram *>(decl_subprogram),612 reinterpret_cast<DISubprogram *>(decl_subprogram),
std/c/freebsd.zig+62-2
...@@ -1,5 +1,3 @@...@@ -1,5 +1,3 @@
1const timespec = @import("../os/freebsd/index.zig").timespec;
2
3extern "c" fn __error() *c_int;1extern "c" fn __error() *c_int;
4pub const _errno = __error;2pub const _errno = __error;
53
...@@ -15,6 +13,15 @@ pub extern "c" fn kevent(...@@ -15,6 +13,15 @@ pub extern "c" fn kevent(
15pub extern "c" fn sysctl(name: [*]c_int, namelen: c_uint, oldp: ?*c_void, oldlenp: ?*usize, newp: ?*c_void, newlen: usize) c_int;13pub extern "c" fn sysctl(name: [*]c_int, namelen: c_uint, oldp: ?*c_void, oldlenp: ?*usize, newp: ?*c_void, newlen: usize) c_int;
16pub extern "c" fn sysctlbyname(name: [*]const u8, oldp: ?*c_void, oldlenp: ?*usize, newp: ?*c_void, newlen: usize) c_int;14pub extern "c" fn sysctlbyname(name: [*]const u8, oldp: ?*c_void, oldlenp: ?*usize, newp: ?*c_void, newlen: usize) c_int;
17pub extern "c" fn sysctlnametomib(name: [*]const u8, mibp: ?*c_int, sizep: ?*usize) c_int;15pub extern "c" fn sysctlnametomib(name: [*]const u8, mibp: ?*c_int, sizep: ?*usize) c_int;
16pub extern "c" fn getdirentries(fd: c_int, buf_ptr: [*]u8, nbytes: usize, basep: *i64) usize;
17pub extern "c" fn getdents(fd: c_int, buf_ptr: [*]u8, nbytes: usize) usize;
18pub extern "c" fn pipe2(arg0: *[2]c_int, arg1: u32) c_int;
19pub extern "c" fn preadv(fd: c_int, iov: *const c_void, iovcnt: c_int, offset: usize) isize;
20pub extern "c" fn pwritev(fd: c_int, iov: *const c_void, iovcnt: c_int, offset: usize) isize;
21pub extern "c" fn openat(fd: c_int, path: ?[*]const u8, flags: c_int) c_int;
22pub extern "c" fn setgid(ruid: c_uint, euid: c_uint) c_int;
23pub extern "c" fn setuid(uid: c_uint) c_int;
24pub extern "c" fn kill(pid: c_int, sig: c_int) c_int;
1825
19/// Renamed from `kevent` to `Kevent` to avoid conflict with function name.26/// Renamed from `kevent` to `Kevent` to avoid conflict with function name.
20pub const Kevent = extern struct {27pub const Kevent = extern struct {
...@@ -31,3 +38,56 @@ pub const pthread_attr_t = extern struct {...@@ -31,3 +38,56 @@ pub const pthread_attr_t = extern struct {
31 __size: [56]u8,38 __size: [56]u8,
32 __align: c_long,39 __align: c_long,
33};40};
41
42pub const msghdr = extern struct {
43 msg_name: *u8,
44 msg_namelen: socklen_t,
45 msg_iov: *iovec,
46 msg_iovlen: i32,
47 __pad1: i32,
48 msg_control: *u8,
49 msg_controllen: socklen_t,
50 __pad2: socklen_t,
51 msg_flags: i32,
52};
53
54pub const Stat = extern struct {
55 dev: u64,
56 ino: u64,
57 nlink: usize,
58
59 mode: u16,
60 __pad0: u16,
61 uid: u32,
62 gid: u32,
63 __pad1: u32,
64 rdev: u64,
65
66 atim: timespec,
67 mtim: timespec,
68 ctim: timespec,
69 birthtim: timespec,
70
71 size: i64,
72 blocks: i64,
73 blksize: isize,
74 flags: u32,
75 gen: u64,
76 __spare: [10]u64,
77};
78
79pub const timespec = extern struct {
80 tv_sec: isize,
81 tv_nsec: isize,
82};
83
84pub const dirent = extern struct {
85 d_fileno: usize,
86 d_off: i64,
87 d_reclen: u16,
88 d_type: u8,
89 d_pad0: u8,
90 d_namlen: u16,
91 d_pad1: u16,
92 d_name: [256]u8,
93};
std/debug/index.zig+4-5
...@@ -264,7 +264,7 @@ pub fn writeCurrentStackTraceWindows(...@@ -264,7 +264,7 @@ pub fn writeCurrentStackTraceWindows(
264pub fn printSourceAtAddress(debug_info: *DebugInfo, out_stream: var, address: usize, tty_color: bool) !void {264pub fn printSourceAtAddress(debug_info: *DebugInfo, out_stream: var, address: usize, tty_color: bool) !void {
265 switch (builtin.os) {265 switch (builtin.os) {
266 builtin.Os.macosx => return printSourceAtAddressMacOs(debug_info, out_stream, address, tty_color),266 builtin.Os.macosx => return printSourceAtAddressMacOs(debug_info, out_stream, address, tty_color),
267 builtin.Os.linux => return printSourceAtAddressLinux(debug_info, out_stream, address, tty_color),267 builtin.Os.linux, builtin.Os.freebsd => return printSourceAtAddressLinux(debug_info, out_stream, address, tty_color),
268 builtin.Os.windows => return printSourceAtAddressWindows(debug_info, out_stream, address, tty_color),268 builtin.Os.windows => return printSourceAtAddressWindows(debug_info, out_stream, address, tty_color),
269 else => return error.UnsupportedOperatingSystem,269 else => return error.UnsupportedOperatingSystem,
270 }270 }
...@@ -717,7 +717,7 @@ pub const OpenSelfDebugInfoError = error{...@@ -717,7 +717,7 @@ pub const OpenSelfDebugInfoError = error{
717717
718pub fn openSelfDebugInfo(allocator: *mem.Allocator) !DebugInfo {718pub fn openSelfDebugInfo(allocator: *mem.Allocator) !DebugInfo {
719 switch (builtin.os) {719 switch (builtin.os) {
720 builtin.Os.linux => return openSelfDebugInfoLinux(allocator),720 builtin.Os.linux, builtin.Os.freebsd => return openSelfDebugInfoLinux(allocator),
721 builtin.Os.macosx, builtin.Os.ios => return openSelfDebugInfoMacOs(allocator),721 builtin.Os.macosx, builtin.Os.ios => return openSelfDebugInfoMacOs(allocator),
722 builtin.Os.windows => return openSelfDebugInfoWindows(allocator),722 builtin.Os.windows => return openSelfDebugInfoWindows(allocator),
723 else => return error.UnsupportedOperatingSystem,723 else => return error.UnsupportedOperatingSystem,
...@@ -1135,14 +1135,13 @@ pub const DebugInfo = switch (builtin.os) {...@@ -1135,14 +1135,13 @@ pub const DebugInfo = switch (builtin.os) {
1135 return self.ofiles.allocator;1135 return self.ofiles.allocator;
1136 }1136 }
1137 },1137 },
1138 builtin.Os.windows => struct {1138 builtin.Os.uefi, builtin.Os.windows => struct {
1139 pdb: pdb.Pdb,1139 pdb: pdb.Pdb,
1140 coff: *coff.Coff,1140 coff: *coff.Coff,
1141 sect_contribs: []pdb.SectionContribEntry,1141 sect_contribs: []pdb.SectionContribEntry,
1142 modules: []Module,1142 modules: []Module,
1143 },1143 },
1144 builtin.Os.linux => DwarfInfo,1144 builtin.Os.linux, builtin.Os.freebsd => DwarfInfo,
1145 builtin.Os.freebsd => struct {},
1146 else => @compileError("Unsupported OS"),1145 else => @compileError("Unsupported OS"),
1147};1146};
11481147
std/os/freebsd/index.zig+105-87
...@@ -1,17 +1,20 @@...@@ -1,17 +1,20 @@
1const assert = @import("../debug.zig").assert;
2const builtin = @import("builtin");1const builtin = @import("builtin");
3const arch = switch (builtin.arch) {2
4 builtin.Arch.x86_64 => @import("x86_64.zig"),
5 else => @compileError("unsupported arch"),
6};
7pub use @import("syscall.zig");
8pub use @import("errno.zig");3pub use @import("errno.zig");
94
10const std = @import("../../index.zig");5const std = @import("../../index.zig");
11const c = std.c;6const c = std.c;
7
8const assert = std.debug.assert;
12const maxInt = std.math.maxInt;9const maxInt = std.math.maxInt;
13pub const Kevent = c.Kevent;10pub const Kevent = c.Kevent;
1411
12pub const CTL_KERN = 1;
13pub const CTL_DEBUG = 5;
14
15pub const KERN_PROC = 14; // struct: process entries
16pub const KERN_PROC_PATHNAME = 12; // path to executable
17
15pub const PATH_MAX = 1024;18pub const PATH_MAX = 1024;
1619
17pub const STDIN_FILENO = 0;20pub const STDIN_FILENO = 0;
...@@ -95,26 +98,33 @@ pub const SIGLIBRT = 33;...@@ -95,26 +98,33 @@ pub const SIGLIBRT = 33;
95pub const SIGRTMIN = 65;98pub const SIGRTMIN = 65;
96pub const SIGRTMAX = 126;99pub const SIGRTMAX = 126;
97100
98pub const O_RDONLY = 0o0;101// access function
99pub const O_WRONLY = 0o1;102pub const F_OK = 0; // test for existence of file
100pub const O_RDWR = 0o2;103pub const X_OK = 1; // test for execute or search permission
101pub const O_ACCMODE = 0o3;104pub const W_OK = 2; // test for write permission
102105pub const R_OK = 4; // test for read permission
103pub const O_CREAT = 0o100;106
104pub const O_EXCL = 0o200;107
105pub const O_NOCTTY = 0o400;108pub const O_RDONLY = 0x0000;
106pub const O_TRUNC = 0o1000;109pub const O_WRONLY = 0x0001;
107pub const O_APPEND = 0o2000;110pub const O_RDWR = 0x0002;
108pub const O_NONBLOCK = 0o4000;111pub const O_ACCMODE = 0x0003;
112
113pub const O_CREAT = 0x0200;
114pub const O_EXCL = 0x0800;
115pub const O_NOCTTY = 0x8000;
116pub const O_TRUNC = 0x0400;
117pub const O_APPEND = 0x0008;
118pub const O_NONBLOCK = 0x0004;
109pub const O_DSYNC = 0o10000;119pub const O_DSYNC = 0o10000;
110pub const O_SYNC = 0o4010000;120pub const O_SYNC = 0x0080;
111pub const O_RSYNC = 0o4010000;121pub const O_RSYNC = 0o4010000;
112pub const O_DIRECTORY = 0o200000;122pub const O_DIRECTORY = 0o200000;
113pub const O_NOFOLLOW = 0o400000;123pub const O_NOFOLLOW = 0x0100;
114pub const O_CLOEXEC = 0o2000000;124pub const O_CLOEXEC = 0x00100000;
115125
116pub const O_ASYNC = 0o20000;126pub const O_ASYNC = 0x0040;
117pub const O_DIRECT = 0o40000;127pub const O_DIRECT = 0x00010000;
118pub const O_LARGEFILE = 0;128pub const O_LARGEFILE = 0;
119pub const O_NOATIME = 0o1000000;129pub const O_NOATIME = 0o1000000;
120pub const O_PATH = 0o10000000;130pub const O_PATH = 0o10000000;
...@@ -539,96 +549,117 @@ pub fn getErrno(r: usize) usize {...@@ -539,96 +549,117 @@ pub fn getErrno(r: usize) usize {
539}549}
540550
541pub fn dup2(old: i32, new: i32) usize {551pub fn dup2(old: i32, new: i32) usize {
542 return arch.syscall2(SYS_dup2, @bitCast(usize, isize(old)), @bitCast(usize, isize(new)));552 return errnoWrap(c.dup2(old, new));
543}553}
544554
545pub fn chdir(path: [*]const u8) usize {555pub fn chdir(path: [*]const u8) usize {
546 return arch.syscall1(SYS_chdir, @ptrToInt(path));556 return errnoWrap(c.chdir(path));
547}557}
548558
549pub fn execve(path: [*]const u8, argv: [*]const ?[*]const u8, envp: [*]const ?[*]const u8) usize {559pub fn execve(path: [*]const u8, argv: [*]const ?[*]const u8, envp: [*]const ?[*]const u8) usize {
550 return arch.syscall3(SYS_execve, @ptrToInt(path), @ptrToInt(argv), @ptrToInt(envp));560 return errnoWrap(c.execve(path, argv, envp));
551}561}
552562
553pub fn fork() usize {563pub fn fork() usize {
554 return arch.syscall0(SYS_fork);564 return errnoWrap(c.fork());
565}
566
567pub fn access(path: [*]const u8, mode: u32) usize {
568 return errnoWrap(c.access(path, mode));
555}569}
556570
557pub fn getcwd(buf: [*]u8, size: usize) usize {571pub fn getcwd(buf: [*]u8, size: usize) usize {
558 return arch.syscall2(SYS___getcwd, @ptrToInt(buf), size);572 return if (c.getcwd(buf, size) == null) @bitCast(usize, -isize(c._errno().*)) else 0;
559}573}
560574
561pub fn getdents(fd: i32, dirp: [*]u8, count: usize) usize {575pub fn getdents(fd: i32, dirp: [*]u8, count: usize) usize {
562 return arch.syscall3(SYS_getdents, @bitCast(usize, isize(fd)), @ptrToInt(dirp), count);576 return errnoWrap(@bitCast(isize, c.getdents(fd, drip, count)));
577}
578
579pub fn getdirentries(fd: i32, buf_ptr: [*]u8, buf_len: usize, basep: *i64) usize {
580 return errnoWrap(@bitCast(isize, c.getdirentries(fd, buf_ptr, buf_len, basep)));
581}
582
583pub fn realpath(noalias filename: [*]const u8, noalias resolved_name: [*]u8) usize {
584 return if (c.realpath(filename, resolved_name) == null) @bitCast(usize, -isize(c._errno().*)) else 0;
563}585}
564586
565pub fn isatty(fd: i32) bool {587pub fn isatty(fd: i32) bool {
566 var wsz: winsize = undefined;588 return c.isatty(fd) != 0;
567 return arch.syscall3(SYS_ioctl, @bitCast(usize, isize(fd)), TIOCGWINSZ, @ptrToInt(&wsz)) == 0;
568}589}
569590
570pub fn readlink(noalias path: [*]const u8, noalias buf_ptr: [*]u8, buf_len: usize) usize {591pub fn readlink(noalias path: [*]const u8, noalias buf_ptr: [*]u8, buf_len: usize) usize {
571 return arch.syscall3(SYS_readlink, @ptrToInt(path), @ptrToInt(buf_ptr), buf_len);592 return errnoWrap(c.readlink(path, buf_ptr, buf_len));
572}593}
573594
574pub fn mkdir(path: [*]const u8, mode: u32) usize {595pub fn mkdir(path: [*]const u8, mode: u32) usize {
575 return arch.syscall2(SYS_mkdir, @ptrToInt(path), mode);596 return errnoWrap(c.mkdir(path, mode));
576}597}
577598
578pub fn mmap(address: ?*u8, length: usize, prot: usize, flags: usize, fd: i32, offset: isize) usize {599pub fn mmap(address: ?[*]u8, length: usize, prot: usize, flags: u32, fd: i32, offset: isize) usize {
579 return arch.syscall6(SYS_mmap, @ptrToInt(address), length, prot, flags, @bitCast(usize, isize(fd)), @bitCast(usize, offset));600 const ptr_result = c.mmap(
601 @ptrCast(*c_void, address),
602 length,
603 @bitCast(c_int, @intCast(c_uint, prot)),
604 @bitCast(c_int, c_uint(flags)),
605 fd,
606 offset,
607 );
608 const isize_result = @bitCast(isize, @ptrToInt(ptr_result));
609 return errnoWrap(isize_result);
580}610}
581611
582pub fn munmap(address: usize, length: usize) usize {612pub fn munmap(address: usize, length: usize) usize {
583 return arch.syscall2(SYS_munmap, address, length);613 return errnoWrap(c.munmap(@intToPtr(*c_void, address), length));
584}614}
585615
586pub fn read(fd: i32, buf: [*]u8, count: usize) usize {616pub fn read(fd: i32, buf: [*]u8, nbyte: usize) usize {
587 return arch.syscall3(SYS_read, @bitCast(usize, isize(fd)), @ptrToInt(buf), count);617 return errnoWrap(c.read(fd, @ptrCast(*c_void, buf), nbyte));
588}618}
589619
590pub fn rmdir(path: [*]const u8) usize {620pub fn rmdir(path: [*]const u8) usize {
591 return arch.syscall1(SYS_rmdir, @ptrToInt(path));621 return errnoWrap(c.rmdir(path));
592}622}
593623
594pub fn symlink(existing: [*]const u8, new: [*]const u8) usize {624pub fn symlink(existing: [*]const u8, new: [*]const u8) usize {
595 return arch.syscall2(SYS_symlink, @ptrToInt(existing), @ptrToInt(new));625 return errnoWrap(c.symlink(existing, new));
596}626}
597627
598pub fn pread(fd: i32, buf: [*]u8, count: usize, offset: usize) usize {628pub fn pread(fd: i32, buf: [*]u8, nbyte: usize, offset: u64) usize {
599 return arch.syscall4(SYS_pread, @bitCast(usize, isize(fd)), @ptrToInt(buf), count, offset);629 return errnoWrap(c.pread(fd, @ptrCast(*c_void, buf), nbyte, offset));
600}630}
601631
602pub fn preadv(fd: i32, iov: [*]const iovec, count: usize, offset: usize) usize {632pub fn preadv(fd: i32, iov: [*]const iovec, count: usize, offset: usize) usize {
603 return arch.syscall4(SYS_preadv, @bitCast(usize, isize(fd)), @ptrToInt(iov), count, offset);633 return errnoWrap(c.preadv(fd, @ptrCast(*const c_void, iov), @intCast(c_int, count), offset));
604}634}
605635
606pub fn pipe(fd: *[2]i32) usize {636pub fn pipe(fd: *[2]i32) usize {
607 return pipe2(fd, 0);637 return pipe2(fd, 0);
608}638}
609639
610pub fn pipe2(fd: *[2]i32, flags: usize) usize {640pub fn pipe2(fd: *[2]i32, flags: u32) usize {
611 return arch.syscall2(SYS_pipe2, @ptrToInt(fd), flags);641 comptime assert(i32.bit_count == c_int.bit_count);
642 return errnoWrap(c.pipe2(@ptrCast(*[2]c_int, fd), flags));
612}643}
613644
614pub fn write(fd: i32, buf: [*]const u8, count: usize) usize {645pub fn write(fd: i32, buf: [*]const u8, nbyte: usize) usize {
615 return arch.syscall3(SYS_write, @bitCast(usize, isize(fd)), @ptrToInt(buf), count);646 return errnoWrap(c.write(fd, @ptrCast(*const c_void, buf), nbyte));
616}647}
617648
618pub fn pwrite(fd: i32, buf: [*]const u8, count: usize, offset: usize) usize {649pub fn pwrite(fd: i32, buf: [*]const u8, nbyte: usize, offset: u64) usize {
619 return arch.syscall4(SYS_pwrite, @bitCast(usize, isize(fd)), @ptrToInt(buf), count, offset);650 return errnoWrap(c.pwrite(fd, @ptrCast(*const c_void, buf), nbyte, offset));
620}651}
621652
622pub fn pwritev(fd: i32, iov: [*]const iovec_const, count: usize, offset: usize) usize {653pub fn pwritev(fd: i32, iov: [*]const iovec_const, count: usize, offset: usize) usize {
623 return arch.syscall4(SYS_pwritev, @bitCast(usize, isize(fd)), @ptrToInt(iov), count, offset);654 return errnoWrap(c.pwritev(fd, @ptrCast(*const c_void, iov), @intCast(c_int, count), offset));
624}655}
625656
626pub fn rename(old: [*]const u8, new: [*]const u8) usize {657pub fn rename(old: [*]const u8, new: [*]const u8) usize {
627 return arch.syscall2(SYS_rename, @ptrToInt(old), @ptrToInt(new));658 return errnoWrap(c.rename(old, new));
628}659}
629660
630pub fn open(path: [*]const u8, flags: u32, perm: usize) usize {661pub fn open(path: [*]const u8, flags: u32, mode: usize) usize {
631 return arch.syscall3(SYS_open, @ptrToInt(path), flags, perm);662 return errnoWrap(c.open(path, @bitCast(c_int, flags), mode));
632}663}
633664
634pub fn create(path: [*]const u8, perm: usize) usize {665pub fn create(path: [*]const u8, perm: usize) usize {
...@@ -636,56 +667,52 @@ pub fn create(path: [*]const u8, perm: usize) usize {...@@ -636,56 +667,52 @@ pub fn create(path: [*]const u8, perm: usize) usize {
636}667}
637668
638pub fn openat(dirfd: i32, path: [*]const u8, flags: usize, mode: usize) usize {669pub fn openat(dirfd: i32, path: [*]const u8, flags: usize, mode: usize) usize {
639 return arch.syscall4(SYS_openat, @bitCast(usize, isize(dirfd)), @ptrToInt(path), flags, mode);670 return errnoWrap(c.openat(@bitCast(usize, isize(dirfd)), @ptrToInt(path), flags, mode));
640}671}
641672
642pub fn close(fd: i32) usize {673pub fn close(fd: i32) usize {
643 return arch.syscall1(SYS_close, @bitCast(usize, isize(fd)));674 return errnoWrap(c.close(fd));
644}
645
646pub fn lseek(fd: i32, offset: isize, ref_pos: usize) usize {
647 return arch.syscall3(SYS_lseek, @bitCast(usize, isize(fd)), @bitCast(usize, offset), ref_pos);
648}675}
649676
650pub fn exit(status: i32) noreturn {677pub fn lseek(fd: i32, offset: isize, whence: c_int) usize {
651 _ = arch.syscall1(SYS_exit, @bitCast(usize, isize(status)));678 return errnoWrap(c.lseek(fd, offset, whence));
652 unreachable;
653}679}
654680
655pub fn getrandom(buf: [*]u8, count: usize, flags: u32) usize {681pub fn exit(code: i32) noreturn {
656 return arch.syscall3(SYS_getrandom, @ptrToInt(buf), count, usize(flags));682 c.exit(code);
657}683}
658684
659pub fn kill(pid: i32, sig: i32) usize {685pub fn kill(pid: i32, sig: i32) usize {
660 return arch.syscall2(SYS_kill, @bitCast(usize, isize(pid)), @bitCast(usize, isize(sig)));686 return errnoWrap(c.kill(pid, sig));
661}687}
662688
663pub fn unlink(path: [*]const u8) usize {689pub fn unlink(path: [*]const u8) usize {
664 return arch.syscall1(SYS_unlink, @ptrToInt(path));690 return errnoWrap(c.unlink(path));
665}691}
666692
667pub fn waitpid(pid: i32, status: *i32, options: i32) usize {693pub fn waitpid(pid: i32, status: *i32, options: u32) usize {
668 return arch.syscall4(SYS_wait4, @bitCast(usize, isize(pid)), @ptrToInt(status), @bitCast(usize, isize(options)), 0);694 comptime assert(i32.bit_count == c_int.bit_count);
695 return errnoWrap(c.waitpid(pid, @ptrCast(*c_int, status), @bitCast(c_int, options)));
669}696}
670697
671pub fn nanosleep(req: *const timespec, rem: ?*timespec) usize {698pub fn nanosleep(req: *const timespec, rem: ?*timespec) usize {
672 return arch.syscall2(SYS_nanosleep, @ptrToInt(req), @ptrToInt(rem));699 return errnoWrap(c.nanosleep(req, rem));
673}700}
674701
675pub fn setuid(uid: u32) usize {702pub fn setuid(uid: u32) usize {
676 return arch.syscall1(SYS_setuid, uid);703 return errnoWrap(c.setuid(uid));
677}704}
678705
679pub fn setgid(gid: u32) usize {706pub fn setgid(gid: u32) usize {
680 return arch.syscall1(SYS_setgid, gid);707 return errnoWrap(c.setgid(gid));
681}708}
682709
683pub fn setreuid(ruid: u32, euid: u32) usize {710pub fn setreuid(ruid: u32, euid: u32) usize {
684 return arch.syscall2(SYS_setreuid, ruid, euid);711 return errnoWrap(c.setreuid(ruid, euid));
685}712}
686713
687pub fn setregid(rgid: u32, egid: u32) usize {714pub fn setregid(rgid: u32, egid: u32) usize {
688 return arch.syscall2(SYS_setregid, rgid, egid);715 return errnoWrap(c.setregid(rgid, egid));
689}716}
690717
691const NSIG = 32;718const NSIG = 32;
...@@ -730,25 +757,16 @@ pub const sigset_t = extern struct {...@@ -730,25 +757,16 @@ pub const sigset_t = extern struct {
730};757};
731758
732pub fn raise(sig: i32) usize {759pub fn raise(sig: i32) usize {
733 // TODO have a chat with the freebsd folks and make sure there's no bug in760 return errnoWrap(c.raise(sig));
734 // their libc. musl-libc blocks signals in between these calls because
735 // if a signal handler runs and forks between the gettid and sending the
736 // signal, the parent will get 2 signals, one from itself and one from the child
737 // if the protection does not belong here, then it belongs in abort(),
738 // like it does in freebsd's libc.
739 var id: usize = undefined;
740 const rc = arch.syscall1(SYS_thr_self, @ptrToInt(&id));
741 if (getErrno(rc) != 0) return rc;
742 return arch.syscall2(SYS_thr_kill, id, @bitCast(usize, isize(sig)));
743}761}
744762
745pub const Stat = arch.Stat;763pub const Stat = c.Stat;
746pub const timespec = arch.timespec;764pub const dirent = c.dirent;
765pub const timespec = c.timespec;
747766
748pub fn fstat(fd: i32, stat_buf: *Stat) usize {767pub fn fstat(fd: i32, buf: *c.Stat) usize {
749 return arch.syscall2(SYS_fstat, @bitCast(usize, isize(fd)), @ptrToInt(stat_buf));768 return errnoWrap(c.fstat(fd, buf));
750}769}
751
752pub const iovec = extern struct {770pub const iovec = extern struct {
753 iov_base: [*]u8,771 iov_base: [*]u8,
754 iov_len: usize,772 iov_len: usize,
std/os/freebsd/syscall.zig deleted-493
...@@ -1,493 +0,0 @@
1pub const SYS_syscall = 0;
2pub const SYS_exit = 1;
3pub const SYS_fork = 2;
4pub const SYS_read = 3;
5pub const SYS_write = 4;
6pub const SYS_open = 5;
7pub const SYS_close = 6;
8pub const SYS_wait4 = 7;
9// 8 is old creat
10pub const SYS_link = 9;
11pub const SYS_unlink = 10;
12// 11 is obsolete execv
13pub const SYS_chdir = 12;
14pub const SYS_fchdir = 13;
15pub const SYS_freebsd11_mknod = 14;
16pub const SYS_chmod = 15;
17pub const SYS_chown = 16;
18pub const SYS_break = 17;
19// 18 is freebsd4 getfsstat
20// 19 is old lseek
21pub const SYS_getpid = 20;
22pub const SYS_mount = 21;
23pub const SYS_unmount = 22;
24pub const SYS_setuid = 23;
25pub const SYS_getuid = 24;
26pub const SYS_geteuid = 25;
27pub const SYS_ptrace = 26;
28pub const SYS_recvmsg = 27;
29pub const SYS_sendmsg = 28;
30pub const SYS_recvfrom = 29;
31pub const SYS_accept = 30;
32pub const SYS_getpeername = 31;
33pub const SYS_getsockname = 32;
34pub const SYS_access = 33;
35pub const SYS_chflags = 34;
36pub const SYS_fchflags = 35;
37pub const SYS_sync = 36;
38pub const SYS_kill = 37;
39// 38 is old stat
40pub const SYS_getppid = 39;
41// 40 is old lstat
42pub const SYS_dup = 41;
43pub const SYS_freebsd10_pipe = 42;
44pub const SYS_getegid = 43;
45pub const SYS_profil = 44;
46pub const SYS_ktrace = 45;
47// 46 is old sigaction
48pub const SYS_getgid = 47;
49// 48 is old sigprocmask
50pub const SYS_getlogin = 49;
51pub const SYS_setlogin = 50;
52pub const SYS_acct = 51;
53// 52 is old sigpending
54pub const SYS_sigaltstack = 53;
55pub const SYS_ioctl = 54;
56pub const SYS_reboot = 55;
57pub const SYS_revoke = 56;
58pub const SYS_symlink = 57;
59pub const SYS_readlink = 58;
60pub const SYS_execve = 59;
61pub const SYS_umask = 60;
62pub const SYS_chroot = 61;
63// 62 is old fstat
64// 63 is old getkerninfo
65// 64 is old getpagesize
66pub const SYS_msync = 65;
67pub const SYS_vfork = 66;
68// 67 is obsolete vread
69// 68 is obsolete vwrite
70// 69 is obsolete sbrk (still present on some platforms)
71pub const SYS_sstk = 70;
72// 71 is old mmap
73pub const SYS_vadvise = 72;
74pub const SYS_munmap = 73;
75pub const SYS_mprotect = 74;
76pub const SYS_madvise = 75;
77// 76 is obsolete vhangup
78// 77 is obsolete vlimit
79pub const SYS_mincore = 78;
80pub const SYS_getgroups = 79;
81pub const SYS_setgroups = 80;
82pub const SYS_getpgrp = 81;
83pub const SYS_setpgid = 82;
84pub const SYS_setitimer = 83;
85// 84 is old wait
86pub const SYS_swapon = 85;
87pub const SYS_getitimer = 86;
88// 87 is old gethostname
89// 88 is old sethostname
90pub const SYS_getdtablesize = 89;
91pub const SYS_dup2 = 90;
92pub const SYS_fcntl = 92;
93pub const SYS_select = 93;
94pub const SYS_fsync = 95;
95pub const SYS_setpriority = 96;
96pub const SYS_socket = 97;
97pub const SYS_connect = 98;
98// 99 is old accept
99pub const SYS_getpriority = 100;
100// 101 is old send
101// 102 is old recv
102// 103 is old sigreturn
103pub const SYS_bind = 104;
104pub const SYS_setsockopt = 105;
105pub const SYS_listen = 106;
106// 107 is obsolete vtimes
107// 108 is old sigvec
108// 109 is old sigblock
109// 110 is old sigsetmask
110// 111 is old sigsuspend
111// 112 is old sigstack
112// 113 is old recvmsg
113// 114 is old sendmsg
114// 115 is obsolete vtrace
115pub const SYS_gettimeofday = 116;
116pub const SYS_getrusage = 117;
117pub const SYS_getsockopt = 118;
118pub const SYS_readv = 120;
119pub const SYS_writev = 121;
120pub const SYS_settimeofday = 122;
121pub const SYS_fchown = 123;
122pub const SYS_fchmod = 124;
123// 125 is old recvfrom
124pub const SYS_setreuid = 126;
125pub const SYS_setregid = 127;
126pub const SYS_rename = 128;
127// 129 is old truncate
128// 130 is old ftruncate
129pub const SYS_flock = 131;
130pub const SYS_mkfifo = 132;
131pub const SYS_sendto = 133;
132pub const SYS_shutdown = 134;
133pub const SYS_socketpair = 135;
134pub const SYS_mkdir = 136;
135pub const SYS_rmdir = 137;
136pub const SYS_utimes = 138;
137// 139 is obsolete 4.2 sigreturn
138pub const SYS_adjtime = 140;
139// 141 is old getpeername
140// 142 is old gethostid
141// 143 is old sethostid
142// 144 is old getrlimit
143// 145 is old setrlimit
144// 146 is old killpg
145pub const SYS_setsid = 147;
146pub const SYS_quotactl = 148;
147// 149 is old quota
148// 150 is old getsockname
149pub const SYS_nlm_syscall = 154;
150pub const SYS_nfssvc = 155;
151// 156 is old getdirentries
152// 157 is freebsd4 statfs
153// 158 is freebsd4 fstatfs
154pub const SYS_lgetfh = 160;
155pub const SYS_getfh = 161;
156// 162 is freebsd4 getdomainname
157// 163 is freebsd4 setdomainname
158// 164 is freebsd4 uname
159pub const SYS_sysarch = 165;
160pub const SYS_rtprio = 166;
161pub const SYS_semsys = 169;
162pub const SYS_msgsys = 170;
163pub const SYS_shmsys = 171;
164// 173 is freebsd6 pread
165// 174 is freebsd6 pwrite
166pub const SYS_setfib = 175;
167pub const SYS_ntp_adjtime = 176;
168pub const SYS_setgid = 181;
169pub const SYS_setegid = 182;
170pub const SYS_seteuid = 183;
171// 184 is obsolete lfs_bmapv
172// 185 is obsolete lfs_markv
173// 186 is obsolete lfs_segclean
174// 187 is obsolete lfs_segwait
175pub const SYS_freebsd11_stat = 188;
176pub const SYS_freebsd11_fstat = 189;
177pub const SYS_freebsd11_lstat = 190;
178pub const SYS_pathconf = 191;
179pub const SYS_fpathconf = 192;
180pub const SYS_getrlimit = 194;
181pub const SYS_setrlimit = 195;
182pub const SYS_freebsd11_getdirentries = 196;
183// 197 is freebsd6 mmap
184pub const SYS___syscall = 198;
185// 199 is freebsd6 lseek
186// 200 is freebsd6 truncate
187// 201 is freebsd6 ftruncate
188pub const SYS___sysctl = 202;
189pub const SYS_mlock = 203;
190pub const SYS_munlock = 204;
191pub const SYS_undelete = 205;
192pub const SYS_futimes = 206;
193pub const SYS_getpgid = 207;
194pub const SYS_poll = 209;
195pub const SYS_freebsd7___semctl = 220;
196pub const SYS_semget = 221;
197pub const SYS_semop = 222;
198pub const SYS_freebsd7_msgctl = 224;
199pub const SYS_msgget = 225;
200pub const SYS_msgsnd = 226;
201pub const SYS_msgrcv = 227;
202pub const SYS_shmat = 228;
203pub const SYS_freebsd7_shmctl = 229;
204pub const SYS_shmdt = 230;
205pub const SYS_shmget = 231;
206pub const SYS_clock_gettime = 232;
207pub const SYS_clock_settime = 233;
208pub const SYS_clock_getres = 234;
209pub const SYS_ktimer_create = 235;
210pub const SYS_ktimer_delete = 236;
211pub const SYS_ktimer_settime = 237;
212pub const SYS_ktimer_gettime = 238;
213pub const SYS_ktimer_getoverrun = 239;
214pub const SYS_nanosleep = 240;
215pub const SYS_ffclock_getcounter = 241;
216pub const SYS_ffclock_setestimate = 242;
217pub const SYS_ffclock_getestimate = 243;
218pub const SYS_clock_nanosleep = 244;
219pub const SYS_clock_getcpuclockid2 = 247;
220pub const SYS_ntp_gettime = 248;
221pub const SYS_minherit = 250;
222pub const SYS_rfork = 251;
223// 252 is obsolete openbsd_poll
224pub const SYS_issetugid = 253;
225pub const SYS_lchown = 254;
226pub const SYS_aio_read = 255;
227pub const SYS_aio_write = 256;
228pub const SYS_lio_listio = 257;
229pub const SYS_freebsd11_getdents = 272;
230pub const SYS_lchmod = 274;
231// 275 is obsolete netbsd_lchown
232pub const SYS_lutimes = 276;
233// 277 is obsolete netbsd_msync
234pub const SYS_freebsd11_nstat = 278;
235pub const SYS_freebsd11_nfstat = 279;
236pub const SYS_freebsd11_nlstat = 280;
237pub const SYS_preadv = 289;
238pub const SYS_pwritev = 290;
239// 297 is freebsd4 fhstatfs
240pub const SYS_fhopen = 298;
241pub const SYS_freebsd11_fhstat = 299;
242pub const SYS_modnext = 300;
243pub const SYS_modstat = 301;
244pub const SYS_modfnext = 302;
245pub const SYS_modfind = 303;
246pub const SYS_kldload = 304;
247pub const SYS_kldunload = 305;
248pub const SYS_kldfind = 306;
249pub const SYS_kldnext = 307;
250pub const SYS_kldstat = 308;
251pub const SYS_kldfirstmod = 309;
252pub const SYS_getsid = 310;
253pub const SYS_setresuid = 311;
254pub const SYS_setresgid = 312;
255// 313 is obsolete signanosleep
256pub const SYS_aio_return = 314;
257pub const SYS_aio_suspend = 315;
258pub const SYS_aio_cancel = 316;
259pub const SYS_aio_error = 317;
260// 318 is freebsd6 aio_read
261// 319 is freebsd6 aio_write
262// 320 is freebsd6 lio_listio
263pub const SYS_yield = 321;
264// 322 is obsolete thr_sleep
265// 323 is obsolete thr_wakeup
266pub const SYS_mlockall = 324;
267pub const SYS_munlockall = 325;
268pub const SYS___getcwd = 326;
269pub const SYS_sched_setparam = 327;
270pub const SYS_sched_getparam = 328;
271pub const SYS_sched_setscheduler = 329;
272pub const SYS_sched_getscheduler = 330;
273pub const SYS_sched_yield = 331;
274pub const SYS_sched_get_priority_max = 332;
275pub const SYS_sched_get_priority_min = 333;
276pub const SYS_sched_rr_get_interval = 334;
277pub const SYS_utrace = 335;
278// 336 is freebsd4 sendfile
279pub const SYS_kldsym = 337;
280pub const SYS_jail = 338;
281pub const SYS_nnpfs_syscall = 339;
282pub const SYS_sigprocmask = 340;
283pub const SYS_sigsuspend = 341;
284// 342 is freebsd4 sigaction
285pub const SYS_sigpending = 343;
286// 344 is freebsd4 sigreturn
287pub const SYS_sigtimedwait = 345;
288pub const SYS_sigwaitinfo = 346;
289pub const SYS___acl_get_file = 347;
290pub const SYS___acl_set_file = 348;
291pub const SYS___acl_get_fd = 349;
292pub const SYS___acl_set_fd = 350;
293pub const SYS___acl_delete_file = 351;
294pub const SYS___acl_delete_fd = 352;
295pub const SYS___acl_aclcheck_file = 353;
296pub const SYS___acl_aclcheck_fd = 354;
297pub const SYS_extattrctl = 355;
298pub const SYS_extattr_set_file = 356;
299pub const SYS_extattr_get_file = 357;
300pub const SYS_extattr_delete_file = 358;
301pub const SYS_aio_waitcomplete = 359;
302pub const SYS_getresuid = 360;
303pub const SYS_getresgid = 361;
304pub const SYS_kqueue = 362;
305pub const SYS_freebsd11_kevent = 363;
306// 364 is obsolete __cap_get_proc
307// 365 is obsolete __cap_set_proc
308// 366 is obsolete __cap_get_fd
309// 367 is obsolete __cap_get_file
310// 368 is obsolete __cap_set_fd
311// 369 is obsolete __cap_set_file
312pub const SYS_extattr_set_fd = 371;
313pub const SYS_extattr_get_fd = 372;
314pub const SYS_extattr_delete_fd = 373;
315pub const SYS___setugid = 374;
316pub const SYS_eaccess = 376;
317pub const SYS_afs3_syscall = 377;
318pub const SYS_nmount = 378;
319// 379 is obsolete kse_exit
320// 380 is obsolete kse_wakeup
321// 381 is obsolete kse_create
322// 382 is obsolete kse_thr_interrupt
323// 383 is obsolete kse_release
324pub const SYS___mac_get_proc = 384;
325pub const SYS___mac_set_proc = 385;
326pub const SYS___mac_get_fd = 386;
327pub const SYS___mac_get_file = 387;
328pub const SYS___mac_set_fd = 388;
329pub const SYS___mac_set_file = 389;
330pub const SYS_kenv = 390;
331pub const SYS_lchflags = 391;
332pub const SYS_uuidgen = 392;
333pub const SYS_sendfile = 393;
334pub const SYS_mac_syscall = 394;
335pub const SYS_freebsd11_getfsstat = 395;
336pub const SYS_freebsd11_statfs = 396;
337pub const SYS_freebsd11_fstatfs = 397;
338pub const SYS_freebsd11_fhstatfs = 398;
339pub const SYS_ksem_close = 400;
340pub const SYS_ksem_post = 401;
341pub const SYS_ksem_wait = 402;
342pub const SYS_ksem_trywait = 403;
343pub const SYS_ksem_init = 404;
344pub const SYS_ksem_open = 405;
345pub const SYS_ksem_unlink = 406;
346pub const SYS_ksem_getvalue = 407;
347pub const SYS_ksem_destroy = 408;
348pub const SYS___mac_get_pid = 409;
349pub const SYS___mac_get_link = 410;
350pub const SYS___mac_set_link = 411;
351pub const SYS_extattr_set_link = 412;
352pub const SYS_extattr_get_link = 413;
353pub const SYS_extattr_delete_link = 414;
354pub const SYS___mac_execve = 415;
355pub const SYS_sigaction = 416;
356pub const SYS_sigreturn = 417;
357pub const SYS_getcontext = 421;
358pub const SYS_setcontext = 422;
359pub const SYS_swapcontext = 423;
360pub const SYS_swapoff = 424;
361pub const SYS___acl_get_link = 425;
362pub const SYS___acl_set_link = 426;
363pub const SYS___acl_delete_link = 427;
364pub const SYS___acl_aclcheck_link = 428;
365pub const SYS_sigwait = 429;
366pub const SYS_thr_create = 430;
367pub const SYS_thr_exit = 431;
368pub const SYS_thr_self = 432;
369pub const SYS_thr_kill = 433;
370pub const SYS_jail_attach = 436;
371pub const SYS_extattr_list_fd = 437;
372pub const SYS_extattr_list_file = 438;
373pub const SYS_extattr_list_link = 439;
374// 440 is obsolete kse_switchin
375pub const SYS_ksem_timedwait = 441;
376pub const SYS_thr_suspend = 442;
377pub const SYS_thr_wake = 443;
378pub const SYS_kldunloadf = 444;
379pub const SYS_audit = 445;
380pub const SYS_auditon = 446;
381pub const SYS_getauid = 447;
382pub const SYS_setauid = 448;
383pub const SYS_getaudit = 449;
384pub const SYS_setaudit = 450;
385pub const SYS_getaudit_addr = 451;
386pub const SYS_setaudit_addr = 452;
387pub const SYS_auditctl = 453;
388pub const SYS__umtx_op = 454;
389pub const SYS_thr_new = 455;
390pub const SYS_sigqueue = 456;
391pub const SYS_kmq_open = 457;
392pub const SYS_kmq_setattr = 458;
393pub const SYS_kmq_timedreceive = 459;
394pub const SYS_kmq_timedsend = 460;
395pub const SYS_kmq_notify = 461;
396pub const SYS_kmq_unlink = 462;
397pub const SYS_abort2 = 463;
398pub const SYS_thr_set_name = 464;
399pub const SYS_aio_fsync = 465;
400pub const SYS_rtprio_thread = 466;
401pub const SYS_sctp_peeloff = 471;
402pub const SYS_sctp_generic_sendmsg = 472;
403pub const SYS_sctp_generic_sendmsg_iov = 473;
404pub const SYS_sctp_generic_recvmsg = 474;
405pub const SYS_pread = 475;
406pub const SYS_pwrite = 476;
407pub const SYS_mmap = 477;
408pub const SYS_lseek = 478;
409pub const SYS_truncate = 479;
410pub const SYS_ftruncate = 480;
411pub const SYS_thr_kill2 = 481;
412pub const SYS_shm_open = 482;
413pub const SYS_shm_unlink = 483;
414pub const SYS_cpuset = 484;
415pub const SYS_cpuset_setid = 485;
416pub const SYS_cpuset_getid = 486;
417pub const SYS_cpuset_getaffinity = 487;
418pub const SYS_cpuset_setaffinity = 488;
419pub const SYS_faccessat = 489;
420pub const SYS_fchmodat = 490;
421pub const SYS_fchownat = 491;
422pub const SYS_fexecve = 492;
423pub const SYS_freebsd11_fstatat = 493;
424pub const SYS_futimesat = 494;
425pub const SYS_linkat = 495;
426pub const SYS_mkdirat = 496;
427pub const SYS_mkfifoat = 497;
428pub const SYS_freebsd11_mknodat = 498;
429pub const SYS_openat = 499;
430pub const SYS_readlinkat = 500;
431pub const SYS_renameat = 501;
432pub const SYS_symlinkat = 502;
433pub const SYS_unlinkat = 503;
434pub const SYS_posix_openpt = 504;
435pub const SYS_gssd_syscall = 505;
436pub const SYS_jail_get = 506;
437pub const SYS_jail_set = 507;
438pub const SYS_jail_remove = 508;
439pub const SYS_closefrom = 509;
440pub const SYS___semctl = 510;
441pub const SYS_msgctl = 511;
442pub const SYS_shmctl = 512;
443pub const SYS_lpathconf = 513;
444// 514 is obsolete cap_new
445pub const SYS___cap_rights_get = 515;
446pub const SYS_cap_enter = 516;
447pub const SYS_cap_getmode = 517;
448pub const SYS_pdfork = 518;
449pub const SYS_pdkill = 519;
450pub const SYS_pdgetpid = 520;
451pub const SYS_pselect = 522;
452pub const SYS_getloginclass = 523;
453pub const SYS_setloginclass = 524;
454pub const SYS_rctl_get_racct = 525;
455pub const SYS_rctl_get_rules = 526;
456pub const SYS_rctl_get_limits = 527;
457pub const SYS_rctl_add_rule = 528;
458pub const SYS_rctl_remove_rule = 529;
459pub const SYS_posix_fallocate = 530;
460pub const SYS_posix_fadvise = 531;
461pub const SYS_wait6 = 532;
462pub const SYS_cap_rights_limit = 533;
463pub const SYS_cap_ioctls_limit = 534;
464pub const SYS_cap_ioctls_get = 535;
465pub const SYS_cap_fcntls_limit = 536;
466pub const SYS_cap_fcntls_get = 537;
467pub const SYS_bindat = 538;
468pub const SYS_connectat = 539;
469pub const SYS_chflagsat = 540;
470pub const SYS_accept4 = 541;
471pub const SYS_pipe2 = 542;
472pub const SYS_aio_mlock = 543;
473pub const SYS_procctl = 544;
474pub const SYS_ppoll = 545;
475pub const SYS_futimens = 546;
476pub const SYS_utimensat = 547;
477// 548 is obsolete numa_getaffinity
478// 549 is obsolete numa_setaffinity
479pub const SYS_fdatasync = 550;
480pub const SYS_fstat = 551;
481pub const SYS_fstatat = 552;
482pub const SYS_fhstat = 553;
483pub const SYS_getdirentries = 554;
484pub const SYS_statfs = 555;
485pub const SYS_fstatfs = 556;
486pub const SYS_getfsstat = 557;
487pub const SYS_fhstatfs = 558;
488pub const SYS_mknodat = 559;
489pub const SYS_kevent = 560;
490pub const SYS_cpuset_getdomain = 561;
491pub const SYS_cpuset_setdomain = 562;
492pub const SYS_getrandom = 563;
493pub const SYS_MAXSYSCALL = 564;
std/os/freebsd/x86_64.zig deleted-136
...@@ -1,136 +0,0 @@
1const freebsd = @import("index.zig");
2const socklen_t = freebsd.socklen_t;
3const iovec = freebsd.iovec;
4
5pub const SYS_sbrk = 69;
6
7pub fn syscall0(number: usize) usize {
8 return asm volatile ("syscall"
9 : [ret] "={rax}" (-> usize)
10 : [number] "{rax}" (number)
11 : "rcx", "r11"
12 );
13}
14
15pub fn syscall1(number: usize, arg1: usize) usize {
16 return asm volatile ("syscall"
17 : [ret] "={rax}" (-> usize)
18 : [number] "{rax}" (number),
19 [arg1] "{rdi}" (arg1)
20 : "rcx", "r11"
21 );
22}
23
24pub fn syscall2(number: usize, arg1: usize, arg2: usize) usize {
25 return asm volatile ("syscall"
26 : [ret] "={rax}" (-> usize)
27 : [number] "{rax}" (number),
28 [arg1] "{rdi}" (arg1),
29 [arg2] "{rsi}" (arg2)
30 : "rcx", "r11"
31 );
32}
33
34pub fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) usize {
35 return asm volatile ("syscall"
36 : [ret] "={rax}" (-> usize)
37 : [number] "{rax}" (number),
38 [arg1] "{rdi}" (arg1),
39 [arg2] "{rsi}" (arg2),
40 [arg3] "{rdx}" (arg3)
41 : "rcx", "r11"
42 );
43}
44
45pub fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize) usize {
46 return asm volatile ("syscall"
47 : [ret] "={rax}" (-> usize)
48 : [number] "{rax}" (number),
49 [arg1] "{rdi}" (arg1),
50 [arg2] "{rsi}" (arg2),
51 [arg3] "{rdx}" (arg3),
52 [arg4] "{r10}" (arg4)
53 : "rcx", "r11"
54 );
55}
56
57pub fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize, arg5: usize) usize {
58 return asm volatile ("syscall"
59 : [ret] "={rax}" (-> usize)
60 : [number] "{rax}" (number),
61 [arg1] "{rdi}" (arg1),
62 [arg2] "{rsi}" (arg2),
63 [arg3] "{rdx}" (arg3),
64 [arg4] "{r10}" (arg4),
65 [arg5] "{r8}" (arg5)
66 : "rcx", "r11"
67 );
68}
69
70pub fn syscall6(
71 number: usize,
72 arg1: usize,
73 arg2: usize,
74 arg3: usize,
75 arg4: usize,
76 arg5: usize,
77 arg6: usize,
78) usize {
79 return asm volatile ("syscall"
80 : [ret] "={rax}" (-> usize)
81 : [number] "{rax}" (number),
82 [arg1] "{rdi}" (arg1),
83 [arg2] "{rsi}" (arg2),
84 [arg3] "{rdx}" (arg3),
85 [arg4] "{r10}" (arg4),
86 [arg5] "{r8}" (arg5),
87 [arg6] "{r9}" (arg6)
88 : "rcx", "r11"
89 );
90}
91
92pub nakedcc fn restore_rt() void {
93 asm volatile ("syscall"
94 :
95 : [number] "{rax}" (usize(SYS_rt_sigreturn))
96 : "rcx", "r11"
97 );
98}
99
100pub const msghdr = extern struct {
101 msg_name: *u8,
102 msg_namelen: socklen_t,
103 msg_iov: *iovec,
104 msg_iovlen: i32,
105 __pad1: i32,
106 msg_control: *u8,
107 msg_controllen: socklen_t,
108 __pad2: socklen_t,
109 msg_flags: i32,
110};
111
112/// Renamed to Stat to not conflict with the stat function.
113pub const Stat = extern struct {
114 dev: u64,
115 ino: u64,
116 nlink: usize,
117
118 mode: u32,
119 uid: u32,
120 gid: u32,
121 __pad0: u32,
122 rdev: u64,
123 size: i64,
124 blksize: isize,
125 blocks: i64,
126
127 atim: timespec,
128 mtim: timespec,
129 ctim: timespec,
130 __unused: [3]isize,
131};
132
133pub const timespec = extern struct {
134 tv_sec: isize,
135 tv_nsec: isize,
136};
std/os/index.zig+75-5
...@@ -18,6 +18,7 @@ test "std.os" {...@@ -18,6 +18,7 @@ test "std.os" {
18 _ = @import("test.zig");18 _ = @import("test.zig");
19 _ = @import("time.zig");19 _ = @import("time.zig");
20 _ = @import("windows/index.zig");20 _ = @import("windows/index.zig");
21 _ = @import("uefi.zig");
21 _ = @import("get_app_data_dir.zig");22 _ = @import("get_app_data_dir.zig");
22}23}
2324
...@@ -26,6 +27,8 @@ pub const darwin = @import("darwin.zig");...@@ -26,6 +27,8 @@ pub const darwin = @import("darwin.zig");
26pub const linux = @import("linux/index.zig");27pub const linux = @import("linux/index.zig");
27pub const freebsd = @import("freebsd/index.zig");28pub const freebsd = @import("freebsd/index.zig");
28pub const zen = @import("zen.zig");29pub const zen = @import("zen.zig");
30pub const uefi = @import("uefi.zig");
31
29pub const posix = switch (builtin.os) {32pub const posix = switch (builtin.os) {
30 Os.linux => linux,33 Os.linux => linux,
31 Os.macosx, Os.ios => darwin,34 Os.macosx, Os.ios => darwin,
...@@ -33,6 +36,7 @@ pub const posix = switch (builtin.os) {...@@ -33,6 +36,7 @@ pub const posix = switch (builtin.os) {
33 Os.zen => zen,36 Os.zen => zen,
34 else => @compileError("Unsupported OS"),37 else => @compileError("Unsupported OS"),
35};38};
39
36pub const net = @import("net.zig");40pub const net = @import("net.zig");
3741
38pub const ChildProcess = @import("child_process.zig").ChildProcess;42pub const ChildProcess = @import("child_process.zig").ChildProcess;
...@@ -103,7 +107,7 @@ const math = std.math;...@@ -103,7 +107,7 @@ const math = std.math;
103/// library implementation.107/// library implementation.
104pub fn getRandomBytes(buf: []u8) !void {108pub fn getRandomBytes(buf: []u8) !void {
105 switch (builtin.os) {109 switch (builtin.os) {
106 Os.linux, Os.freebsd => while (true) {110 Os.linux => while (true) {
107 // TODO check libc version and potentially call c.getrandom.111 // TODO check libc version and potentially call c.getrandom.
108 // See #397112 // See #397
109 const errno = posix.getErrno(posix.getrandom(buf.ptr, buf.len, 0));113 const errno = posix.getErrno(posix.getrandom(buf.ptr, buf.len, 0));
...@@ -116,7 +120,7 @@ pub fn getRandomBytes(buf: []u8) !void {...@@ -116,7 +120,7 @@ pub fn getRandomBytes(buf: []u8) !void {
116 else => return unexpectedErrorPosix(errno),120 else => return unexpectedErrorPosix(errno),
117 }121 }
118 },122 },
119 Os.macosx, Os.ios => return getRandomBytesDevURandom(buf),123 Os.macosx, Os.ios, Os.freebsd => return getRandomBytesDevURandom(buf),
120 Os.windows => {124 Os.windows => {
121 // Call RtlGenRandom() instead of CryptGetRandom() on Windows125 // Call RtlGenRandom() instead of CryptGetRandom() on Windows
122 // https://github.com/rust-lang-nursery/rand/issues/111126 // https://github.com/rust-lang-nursery/rand/issues/111
...@@ -187,6 +191,10 @@ pub fn abort() noreturn {...@@ -187,6 +191,10 @@ pub fn abort() noreturn {
187 }191 }
188 windows.ExitProcess(3);192 windows.ExitProcess(3);
189 },193 },
194 Os.uefi => {
195 // TODO there's gotta be a better thing to do here than loop forever
196 while (true) {}
197 },
190 else => @compileError("Unsupported OS"),198 else => @compileError("Unsupported OS"),
191 }199 }
192}200}
...@@ -1758,8 +1766,57 @@ pub const Dir = struct {...@@ -1758,8 +1766,57 @@ pub const Dir = struct {
1758 }1766 }
17591767
1760 fn nextFreebsd(self: *Dir) !?Entry {1768 fn nextFreebsd(self: *Dir) !?Entry {
1761 //self.handle.buf = try self.allocator.alloc(u8, page_size);1769 start_over: while (true) {
1762 @compileError("TODO implement dirs for FreeBSD");1770 if (self.handle.index >= self.handle.end_index) {
1771 if (self.handle.buf.len == 0) {
1772 self.handle.buf = try self.allocator.alloc(u8, page_size);
1773 }
1774
1775 while (true) {
1776 const result = posix.getdirentries(self.handle.fd, self.handle.buf.ptr, self.handle.buf.len, &self.handle.seek);
1777 const err = posix.getErrno(result);
1778 if (err > 0) {
1779 switch (err) {
1780 posix.EBADF, posix.EFAULT, posix.ENOTDIR => unreachable,
1781 posix.EINVAL => {
1782 self.handle.buf = try self.allocator.realloc(u8, self.handle.buf, self.handle.buf.len * 2);
1783 continue;
1784 },
1785 else => return unexpectedErrorPosix(err),
1786 }
1787 }
1788 if (result == 0) return null;
1789 self.handle.index = 0;
1790 self.handle.end_index = result;
1791 break;
1792 }
1793 }
1794 const freebsd_entry = @ptrCast(*align(1) posix.dirent, &self.handle.buf[self.handle.index]);
1795 const next_index = self.handle.index + freebsd_entry.d_reclen;
1796 self.handle.index = next_index;
1797
1798 const name = @ptrCast([*]u8, &freebsd_entry.d_name)[0..freebsd_entry.d_namlen];
1799
1800 if (mem.eql(u8, name, ".") or mem.eql(u8, name, "..")) {
1801 continue :start_over;
1802 }
1803
1804 const entry_kind = switch (freebsd_entry.d_type) {
1805 posix.DT_BLK => Entry.Kind.BlockDevice,
1806 posix.DT_CHR => Entry.Kind.CharacterDevice,
1807 posix.DT_DIR => Entry.Kind.Directory,
1808 posix.DT_FIFO => Entry.Kind.NamedPipe,
1809 posix.DT_LNK => Entry.Kind.SymLink,
1810 posix.DT_REG => Entry.Kind.File,
1811 posix.DT_SOCK => Entry.Kind.UnixDomainSocket,
1812 posix.DT_WHT => Entry.Kind.Whiteout,
1813 else => Entry.Kind.Unknown,
1814 };
1815 return Entry{
1816 .name = name,
1817 .kind = entry_kind,
1818 };
1819 }
1763 }1820 }
1764};1821};
17651822
...@@ -2247,7 +2304,20 @@ pub fn selfExePathW(out_buffer: *[windows_util.PATH_MAX_WIDE]u16) ![]u16 {...@@ -2247,7 +2304,20 @@ pub fn selfExePathW(out_buffer: *[windows_util.PATH_MAX_WIDE]u16) ![]u16 {
2247pub fn selfExePath(out_buffer: *[MAX_PATH_BYTES]u8) ![]u8 {2304pub fn selfExePath(out_buffer: *[MAX_PATH_BYTES]u8) ![]u8 {
2248 switch (builtin.os) {2305 switch (builtin.os) {
2249 Os.linux => return readLink(out_buffer, "/proc/self/exe"),2306 Os.linux => return readLink(out_buffer, "/proc/self/exe"),
2250 Os.freebsd => return readLink(out_buffer, "/proc/curproc/file"),2307 Os.freebsd => {
2308 var mib = [4]c_int{ posix.CTL_KERN, posix.KERN_PROC, posix.KERN_PROC_PATHNAME, -1};
2309 var out_len: usize = out_buffer.len;
2310 const err = posix.getErrno(posix.sysctl(&mib, 4, out_buffer, &out_len, null, 0));
2311
2312 if (err == 0 ) return mem.toSlice(u8, out_buffer);
2313
2314 return switch (err) {
2315 posix.EFAULT => error.BadAdress,
2316 posix.EPERM => error.PermissionDenied,
2317 else => unexpectedErrorPosix(err),
2318 };
2319
2320 },
2251 Os.windows => {2321 Os.windows => {
2252 var utf16le_buf: [windows_util.PATH_MAX_WIDE]u16 = undefined;2322 var utf16le_buf: [windows_util.PATH_MAX_WIDE]u16 = undefined;
2253 const utf16le_slice = try selfExePathW(&utf16le_buf);2323 const utf16le_slice = try selfExePathW(&utf16le_buf);
std/os/path.zig+1-10
...@@ -1162,7 +1162,7 @@ pub fn realC(out_buffer: *[os.MAX_PATH_BYTES]u8, pathname: [*]const u8) RealErro...@@ -1162,7 +1162,7 @@ pub fn realC(out_buffer: *[os.MAX_PATH_BYTES]u8, pathname: [*]const u8) RealErro
1162 const pathname_w = try windows_util.cStrToPrefixedFileW(pathname);1162 const pathname_w = try windows_util.cStrToPrefixedFileW(pathname);
1163 return realW(out_buffer, pathname_w);1163 return realW(out_buffer, pathname_w);
1164 },1164 },
1165 Os.macosx, Os.ios => {1165 Os.freebsd, Os.macosx, Os.ios => {
1166 // TODO instead of calling the libc function here, port the implementation to Zig1166 // TODO instead of calling the libc function here, port the implementation to Zig
1167 const err = posix.getErrno(posix.realpath(pathname, out_buffer));1167 const err = posix.getErrno(posix.realpath(pathname, out_buffer));
1168 switch (err) {1168 switch (err) {
...@@ -1189,15 +1189,6 @@ pub fn realC(out_buffer: *[os.MAX_PATH_BYTES]u8, pathname: [*]const u8) RealErro...@@ -1189,15 +1189,6 @@ pub fn realC(out_buffer: *[os.MAX_PATH_BYTES]u8, pathname: [*]const u8) RealErro
11891189
1190 return os.readLinkC(out_buffer, proc_path.ptr);1190 return os.readLinkC(out_buffer, proc_path.ptr);
1191 },1191 },
1192 Os.freebsd => { // XXX requires fdescfs
1193 const fd = try os.posixOpenC(pathname, posix.O_PATH | posix.O_NONBLOCK | posix.O_CLOEXEC, 0);
1194 defer os.close(fd);
1195
1196 var buf: ["/dev/fd/-2147483648\x00".len]u8 = undefined;
1197 const proc_path = fmt.bufPrint(buf[0..], "/dev/fd/{}\x00", fd) catch unreachable;
1198
1199 return os.readLinkC(out_buffer, proc_path.ptr);
1200 },
1201 else => @compileError("TODO implement os.path.real for " ++ @tagName(builtin.os)),1192 else => @compileError("TODO implement os.path.real for " ++ @tagName(builtin.os)),
1202 }1193 }
1203}1194}
std/os/time.zig+1-1
...@@ -13,7 +13,7 @@ pub const epoch = @import("epoch.zig");...@@ -13,7 +13,7 @@ pub const epoch = @import("epoch.zig");
13/// Sleep for the specified duration13/// Sleep for the specified duration
14pub fn sleep(nanoseconds: u64) void {14pub fn sleep(nanoseconds: u64) void {
15 switch (builtin.os) {15 switch (builtin.os) {
16 Os.linux, Os.macosx, Os.ios => {16 Os.linux, Os.macosx, Os.ios, Os.freebsd => {
17 const s = nanoseconds / ns_per_s;17 const s = nanoseconds / ns_per_s;
18 const ns = nanoseconds % ns_per_s;18 const ns = nanoseconds % ns_per_s;
19 posixSleep(@intCast(u63, s), @intCast(u63, ns));19 posixSleep(@intCast(u63, s), @intCast(u63, ns));
std/os/uefi.zig created+2
...@@ -0,0 +1,2 @@
1// TODO this is where the extern declarations go. For example, see
2// inc/efilib.h in gnu-efi-code
std/special/bootstrap.zig+4-11
...@@ -20,17 +20,10 @@ comptime {...@@ -20,17 +20,10 @@ comptime {
2020
21nakedcc fn _start() noreturn {21nakedcc fn _start() noreturn {
22 switch (builtin.arch) {22 switch (builtin.arch) {
23 builtin.Arch.x86_64 => switch (builtin.os) {23 builtin.Arch.x86_64 => {
24 builtin.Os.freebsd => {24 argc_ptr = asm ("lea (%%rsp), %[argc]"
25 argc_ptr = asm ("lea (%%rdi), %[argc]"25 : [argc] "=r" (-> [*]usize)
26 : [argc] "=r" (-> [*]usize)26 );
27 );
28 },
29 else => {
30 argc_ptr = asm ("lea (%%rsp), %[argc]"
31 : [argc] "=r" (-> [*]usize)
32 );
33 },
34 },27 },
35 builtin.Arch.i386 => {28 builtin.Arch.i386 => {
36 argc_ptr = asm ("lea (%%esp), %[argc]"29 argc_ptr = asm ("lea (%%esp), %[argc]"
std/special/panic.zig+4
...@@ -13,6 +13,10 @@ pub fn panic(msg: []const u8, error_return_trace: ?*builtin.StackTrace) noreturn...@@ -13,6 +13,10 @@ pub fn panic(msg: []const u8, error_return_trace: ?*builtin.StackTrace) noreturn
13 builtin.Os.freestanding, builtin.Os.zen => {13 builtin.Os.freestanding, builtin.Os.zen => {
14 while (true) {}14 while (true) {}
15 },15 },
16 builtin.Os.uefi => {
17 // TODO look into using the debug info and logging helpful messages
18 std.os.abort();
19 },
16 else => {20 else => {
17 const first_trace_addr = @ptrToInt(@returnAddress());21 const first_trace_addr = @ptrToInt(@returnAddress());
18 std.debug.panicExtra(error_return_trace, first_trace_addr, "{}", msg);22 std.debug.panicExtra(error_return_trace, first_trace_addr, "{}", msg);
test/cases/switch.zig+37
...@@ -232,3 +232,40 @@ test "capture value of switch with all unreachable prongs" {...@@ -232,3 +232,40 @@ test "capture value of switch with all unreachable prongs" {
232 };232 };
233 assert(x == 1);233 assert(x == 1);
234}234}
235
236test "switching on booleans" {
237 testSwitchOnBools();
238 comptime testSwitchOnBools();
239}
240
241fn testSwitchOnBools() void {
242 assert(testSwitchOnBoolsTrueAndFalse(true) == false);
243 assert(testSwitchOnBoolsTrueAndFalse(false) == true);
244
245 assert(testSwitchOnBoolsTrueWithElse(true) == false);
246 assert(testSwitchOnBoolsTrueWithElse(false) == true);
247
248 assert(testSwitchOnBoolsFalseWithElse(true) == false);
249 assert(testSwitchOnBoolsFalseWithElse(false) == true);
250}
251
252fn testSwitchOnBoolsTrueAndFalse(x: bool) bool {
253 return switch (x) {
254 true => false,
255 false => true,
256 };
257}
258
259fn testSwitchOnBoolsTrueWithElse(x: bool) bool {
260 return switch (x) {
261 true => false,
262 else => true,
263 };
264}
265
266fn testSwitchOnBoolsFalseWithElse(x: bool) bool {
267 return switch (x) {
268 false => true,
269 else => false,
270 };
271}
test/compile_errors.zig+38
...@@ -1,6 +1,44 @@...@@ -1,6 +1,44 @@
1const tests = @import("tests.zig");1const tests = @import("tests.zig");
22
3pub fn addCases(cases: *tests.CompileErrorContext) void {3pub fn addCases(cases: *tests.CompileErrorContext) void {
4 cases.add(
5 "duplicate boolean switch value",
6 \\comptime {
7 \\ const x = switch (true) {
8 \\ true => false,
9 \\ false => true,
10 \\ true => false,
11 \\ };
12 \\}
13 \\comptime {
14 \\ const x = switch (true) {
15 \\ false => true,
16 \\ true => false,
17 \\ false => true,
18 \\ };
19 \\}
20 ,
21 ".tmp_source.zig:5:9: error: duplicate switch value",
22 ".tmp_source.zig:12:9: error: duplicate switch value",
23 );
24
25 cases.add(
26 "missing boolean switch value",
27 \\comptime {
28 \\ const x = switch (true) {
29 \\ true => false,
30 \\ };
31 \\}
32 \\comptime {
33 \\ const x = switch (true) {
34 \\ false => true,
35 \\ };
36 \\}
37 ,
38 ".tmp_source.zig:2:15: error: switch must handle all possibilities",
39 ".tmp_source.zig:7:15: error: switch must handle all possibilities",
40 );
41
4 cases.add(42 cases.add(
5 "reading past end of pointer casted array",43 "reading past end of pointer casted array",
6 \\comptime {44 \\comptime {