From 2c0280ba085893984007706fb40c7b291f43074d Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Mon, 27 May 2019 20:59:19 -0400 Subject: improve the stack check CLI options See #2526 --- src/link.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/link.cpp') diff --git a/src/link.cpp b/src/link.cpp index b47da87c68..4c3b3d4769 100644 --- a/src/link.cpp +++ b/src/link.cpp @@ -25,7 +25,7 @@ static CodeGen *create_child_codegen(CodeGen *parent_gen, Buf *root_src_path, Ou CodeGen *child_gen = codegen_create(nullptr, root_src_path, parent_gen->zig_target, out_type, parent_gen->build_mode, parent_gen->zig_lib_dir, parent_gen->zig_std_dir, libc, get_stage1_cache_path()); child_gen->disable_gen_h = true; - child_gen->disable_stack_probing = true; + child_gen->want_stack_check = WantStackCheckDisabled; child_gen->verbose_tokenize = parent_gen->verbose_tokenize; child_gen->verbose_ast = parent_gen->verbose_ast; child_gen->verbose_link = parent_gen->verbose_link; -- cgit v1.2.3 From 1ab0ac3ea2a187648b9d13de7f3e0bd1c7c4bf4a Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Wed, 29 May 2019 11:56:36 -0400 Subject: cleanups for windows subsystem in builtin.zig --- src/all_types.hpp | 2 +- src/analyze.cpp | 3 --- src/codegen.cpp | 81 ++++++++++++++++++++++++++++++------------------------- src/codegen.hpp | 2 ++ src/link.cpp | 4 +-- src/target.hpp | 6 ++++- 6 files changed, 55 insertions(+), 43 deletions(-) (limited to 'src/link.cpp') diff --git a/src/all_types.hpp b/src/all_types.hpp index 91676d0c39..4bb76ff64f 100644 --- a/src/all_types.hpp +++ b/src/all_types.hpp @@ -1857,7 +1857,7 @@ struct CodeGen { BuildMode build_mode; OutType out_type; const ZigTarget *zig_target; - TargetSubsystem subsystem; + TargetSubsystem subsystem; // careful using this directly; see detect_subsystem ValgrindSupport valgrind_support; bool strip_debug_symbols; bool is_test_build; diff --git a/src/analyze.cpp b/src/analyze.cpp index 182bcc93a6..3769ae47c2 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -2722,12 +2722,10 @@ void add_fn_export(CodeGen *g, ZigFn *fn_table_entry, Buf *symbol_name, GlobalLi if (ccc) { if (buf_eql_str(symbol_name, "main") && g->libc_link_lib != nullptr) { g->have_c_main = true; - g->subsystem = g->subsystem == TargetSubsystemAuto ? TargetSubsystemConsole : g->subsystem; } else if (buf_eql_str(symbol_name, "WinMain") && g->zig_target->os == OsWindows) { g->have_winmain = true; - g->subsystem = g->subsystem == TargetSubsystemAuto ? TargetSubsystemWindows : g->subsystem; } else if (buf_eql_str(symbol_name, "WinMainCRTStartup") && g->zig_target->os == OsWindows) { @@ -3966,7 +3964,6 @@ ZigType *add_source_file(CodeGen *g, ZigPackage *package, Buf *resolved_path, Bu if (is_pub) { if (buf_eql_str(proto_name, "main")) { g->have_pub_main = true; - g->subsystem = g->subsystem == TargetSubsystemAuto ? TargetSubsystemConsole : g->subsystem; } else if (buf_eql_str(proto_name, "panic")) { g->have_pub_panic = true; } diff --git a/src/codegen.cpp b/src/codegen.cpp index ef3851006f..57f895dedb 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -7417,6 +7417,21 @@ static const char *build_mode_to_str(BuildMode build_mode) { zig_unreachable(); } +static const char *subsystem_to_str(TargetSubsystem subsystem) { + switch (subsystem) { + case TargetSubsystemConsole: return "Console"; + case TargetSubsystemWindows: return "Windows"; + case TargetSubsystemPosix: return "Posix"; + case TargetSubsystemNative: return "Native"; + case TargetSubsystemEfiApplication: return "EfiApplication"; + case TargetSubsystemEfiBootServiceDriver: return "EfiBootServiceDriver"; + case TargetSubsystemEfiRom: return "EfiRom"; + case TargetSubsystemEfiRuntimeDriver: return "EfiRuntimeDriver"; + case TargetSubsystemAuto: zig_unreachable(); + } + zig_unreachable(); +} + static bool detect_dynamic_link(CodeGen *g) { if (g->is_dynamic) return true; @@ -7462,6 +7477,23 @@ static bool detect_stack_probing(CodeGen *g) { zig_unreachable(); } +// Returns TargetSubsystemAuto to mean "no subsystem" +TargetSubsystem detect_subsystem(CodeGen *g) { + if (g->subsystem != TargetSubsystemAuto) + return g->subsystem; + if (g->zig_target->os == OsWindows) { + if (g->have_dllmain_crt_startup || (g->out_type == OutTypeLib && g->is_dynamic)) + return TargetSubsystemAuto; + if (g->have_c_main || g->have_pub_main || g->is_test_build) + return TargetSubsystemConsole; + if (g->have_winmain || g->have_winmain_crt_startup) + return TargetSubsystemWindows; + } else if (g->zig_target->os == OsUefi) { + return TargetSubsystemEfiApplication; + } + return TargetSubsystemAuto; +} + static bool detect_single_threaded(CodeGen *g) { if (g->want_single_threaded) return true; @@ -7882,14 +7914,14 @@ Buf *codegen_generate_builtin_source(CodeGen *g) { " EfiRuntimeDriver,\n" "};\n\n"); - assert(TargetSubsystemConsole == 1); - assert(TargetSubsystemWindows == 2); - assert(TargetSubsystemPosix == 3); - assert(TargetSubsystemNative == 4); - assert(TargetSubsystemEfiApplication == 5); - assert(TargetSubsystemEfiBootServiceDriver == 6); - assert(TargetSubsystemEfiRom == 7); - assert(TargetSubsystemEfiRuntimeDriver == 8); + assert(TargetSubsystemConsole == 0); + assert(TargetSubsystemWindows == 1); + assert(TargetSubsystemPosix == 2); + assert(TargetSubsystemNative == 3); + assert(TargetSubsystemEfiApplication == 4); + assert(TargetSubsystemEfiBootServiceDriver == 5); + assert(TargetSubsystemEfiRom == 6); + assert(TargetSubsystemEfiRuntimeDriver == 7); } { const char *endian_str = g->is_big_endian ? "Endian.Big" : "Endian.Little"; @@ -7908,29 +7940,10 @@ Buf *codegen_generate_builtin_source(CodeGen *g) { buf_appendf(contents, "pub const position_independent_code = %s;\n", bool_to_str(g->have_pic)); { - static const char* subsystem_strings[] = { - "Console", - "Windows", - "Posix", - "Native", - "EfiApplication", - "EfiBootServiceDriver", - "EfiRom", - "EfiRuntimeDriver", - }; - - if (g->zig_target->os != OsWindows || g->zig_target->os != OsUefi || g->have_dllmain_crt_startup || g->out_type == OutTypeLib) { - buf_appendf(contents, "pub const subsystem = null;\n"); - } else if (g->subsystem == TargetSubsystemAuto) { - if (g->have_c_main || g->have_pub_main) { - buf_appendf(contents, "pub const subsystem = SubSystem.%s;\n", subsystem_strings[TargetSubsystemConsole - 1]); - } else if (g->have_winmain || g->have_winmain_crt_startup) { - buf_appendf(contents, "pub const subsystem = SubSystem.%s;\n", subsystem_strings[TargetSubsystemWindows - 1]); - } - } else { - buf_appendf(contents, "pub const subsystem = SubSystem.%s;\n", subsystem_strings[g->subsystem - 1]); + TargetSubsystem detected_subsystem = detect_subsystem(g); + if (detected_subsystem != TargetSubsystemAuto) { + buf_appendf(contents, "pub const subsystem = SubSystem.%s;\n", subsystem_to_str(detected_subsystem)); } - } if (g->is_test_build) { @@ -7976,7 +7989,7 @@ static Error define_builtin_compile_vars(CodeGen *g) { cache_bool(&cache_hash, g->have_err_ret_tracing); cache_bool(&cache_hash, g->libc_link_lib != nullptr); cache_bool(&cache_hash, g->valgrind_support); - cache_int(&cache_hash, g->subsystem - 1); + cache_int(&cache_hash, detect_subsystem(g)); Buf digest = BUF_INIT; buf_resize(&digest, 0); @@ -8044,10 +8057,6 @@ static void init(CodeGen *g) { g->is_single_threaded = true; } - if (g->is_test_build) { - g->subsystem = g->subsystem == TargetSubsystemAuto ? TargetSubsystemConsole : g->subsystem; - } - assert(g->root_out_name); g->module = LLVMModuleCreateWithName(buf_ptr(g->root_out_name)); @@ -9401,7 +9410,7 @@ static Error check_cache(CodeGen *g, Buf *manifest_dir, Buf *digest) { cache_int(ch, g->zig_target->vendor); cache_int(ch, g->zig_target->os); cache_int(ch, g->zig_target->abi); - cache_int(ch, g->subsystem); + cache_int(ch, detect_subsystem(g)); cache_bool(ch, g->strip_debug_symbols); cache_bool(ch, g->is_test_build); if (g->is_test_build) { diff --git a/src/codegen.hpp b/src/codegen.hpp index 47c0097e4b..9a340d7205 100644 --- a/src/codegen.hpp +++ b/src/codegen.hpp @@ -56,4 +56,6 @@ void codegen_translate_c(CodeGen *g, Buf *full_path, FILE *out_file, bool use_us Buf *codegen_generate_builtin_source(CodeGen *g); +TargetSubsystem detect_subsystem(CodeGen *g); + #endif diff --git a/src/link.cpp b/src/link.cpp index 4c3b3d4769..f94b1219f6 100644 --- a/src/link.cpp +++ b/src/link.cpp @@ -1225,7 +1225,7 @@ static void add_mingw_link_args(LinkJob *lj, bool is_library) { lj->args.append(get_libc_file(g->libc, "libmingwex.a")); lj->args.append(get_libc_file(g->libc, "libmsvcrt.a")); - if (g->subsystem == TargetSubsystemWindows) { + if (detect_subsystem(g) == TargetSubsystemWindows) { lj->args.append(get_libc_file(g->libc, "libgdi32.a")); lj->args.append(get_libc_file(g->libc, "libcomdlg32.a")); } @@ -1307,7 +1307,7 @@ static void construct_linker_job_coff(LinkJob *lj) { lj->args.append((const char *)buf_ptr(g->link_objects.at(i))); } - switch (g->subsystem) { + switch (detect_subsystem(g)) { case TargetSubsystemAuto: if (g->zig_target->os == OsUefi) { add_uefi_link_args(lj); diff --git a/src/target.hpp b/src/target.hpp index f3cde902a0..7fa99bcda8 100644 --- a/src/target.hpp +++ b/src/target.hpp @@ -62,7 +62,6 @@ enum SubArchList { }; enum TargetSubsystem { - TargetSubsystemAuto, // Zig should infer the subsystem TargetSubsystemConsole, TargetSubsystemWindows, TargetSubsystemPosix, @@ -71,6 +70,11 @@ enum TargetSubsystem { TargetSubsystemEfiBootServiceDriver, TargetSubsystemEfiRom, TargetSubsystemEfiRuntimeDriver, + + // This means Zig should infer the subsystem. + // It's last so that the indexes of other items can line up + // with the enum in builtin.zig. + TargetSubsystemAuto }; struct ZigTarget { -- cgit v1.2.3 From 291aaee97773e2f9c40e061410db52ca00f4d651 Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Sat, 1 Jun 2019 16:59:12 +0200 Subject: Stop the musl builder from skipping necessary files The code assumed that the architecture-specific bits, found in the arch/ subfolder, were only overrides for the generic .c files. Changed the logic to always include the whole architecture-specific implementations and discard the generic ones, this way we won't exclude files with no .c counterpart. --- src/link.cpp | 55 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 29 insertions(+), 26 deletions(-) (limited to 'src/link.cpp') diff --git a/src/link.cpp b/src/link.cpp index f94b1219f6..fe5a73a52b 100644 --- a/src/link.cpp +++ b/src/link.cpp @@ -528,9 +528,6 @@ static const char *build_musl(CodeGen *parent) { Buf noextbasename = BUF_INIT; Buf dirbasename = BUF_INIT; Buf before_arch_dir = BUF_INIT; - Buf override_c = BUF_INIT; - Buf override_s = BUF_INIT; - Buf override_S = BUF_INIT; auto source_it = source_table.entry_iterator(); for (;;) { @@ -543,31 +540,37 @@ static const char *build_musl(CodeGen *parent) { os_path_split(src_file, &dirname, &basename); os_path_extname(&basename, &noextbasename, nullptr); os_path_split(&dirname, &before_arch_dir, &dirbasename); + + bool is_arch_specific = false; + // Architecture-specific implementations are under a / folder. if (is_musl_arch_name(buf_ptr(&dirbasename))) { - // We find these by explicitly looking for overrides. - continue; + // Not the architecture we're compiling for. + if (strcmp(buf_ptr(&dirbasename), target_musl_arch_name) != 0) + continue; + is_arch_specific = true; } - // Look for an arch specific override. - buf_resize(&override_c, 0); - buf_resize(&override_s, 0); - buf_resize(&override_S, 0); - - buf_appendf(&override_c, "%s" OS_SEP "%s" OS_SEP "%s.c", - buf_ptr(&dirname), target_musl_arch_name, buf_ptr(&noextbasename)); - buf_appendf(&override_s, "%s" OS_SEP "%s" OS_SEP "%s.s", - buf_ptr(&dirname), target_musl_arch_name, buf_ptr(&noextbasename)); - buf_appendf(&override_S, "%s" OS_SEP "%s" OS_SEP "%s.S", - buf_ptr(&dirname), target_musl_arch_name, buf_ptr(&noextbasename)); - - if (source_table.maybe_get(&override_c) != nullptr) { - src_file = &override_c; - src_kind = (src_kind == MuslSrcAsm) ? MuslSrcNormal : src_kind; - } else if (source_table.maybe_get(&override_s) != nullptr) { - src_file = &override_s; - src_kind = MuslSrcAsm; - } else if (source_table.maybe_get(&override_S) != nullptr) { - src_file = &override_S; - src_kind = MuslSrcAsm; + + if (!is_arch_specific) { + Buf override_path = BUF_INIT; + + // Look for an arch specific override. + buf_resize(&override_path, 0); + buf_appendf(&override_path, "%s" OS_SEP "%s" OS_SEP "%s.s", + buf_ptr(&dirname), target_musl_arch_name, buf_ptr(&noextbasename)); + if (source_table.maybe_get(&override_path) != nullptr) + continue; + + buf_resize(&override_path, 0); + buf_appendf(&override_path, "%s" OS_SEP "%s" OS_SEP "%s.S", + buf_ptr(&dirname), target_musl_arch_name, buf_ptr(&noextbasename)); + if (source_table.maybe_get(&override_path) != nullptr) + continue; + + buf_resize(&override_path, 0); + buf_appendf(&override_path, "%s" OS_SEP "%s" OS_SEP "%s.c", + buf_ptr(&dirname), target_musl_arch_name, buf_ptr(&noextbasename)); + if (source_table.maybe_get(&override_path) != nullptr) + continue; } Buf *full_path = buf_sprintf("%s" OS_SEP "libc" OS_SEP "%s", -- cgit v1.2.3 From 5784631fab1fdcc4dcf9c04db11c4136d530413a Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Fri, 7 Jun 2019 12:20:02 -0400 Subject: update the default macos version min to 10.14 --- src-self-hosted/link.zig | 2 +- src/codegen.cpp | 2 +- src/link.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src/link.cpp') diff --git a/src-self-hosted/link.zig b/src-self-hosted/link.zig index a47dbbbe92..838cbbc480 100644 --- a/src-self-hosted/link.zig +++ b/src-self-hosted/link.zig @@ -670,7 +670,7 @@ const DarwinPlatform = struct { Compilation.DarwinVersionMin.None => blk: { assert(comp.target.getOs() == .macosx); result.kind = Kind.MacOS; - break :blk "10.10"; + break :blk "10.14"; }, }; diff --git a/src/codegen.cpp b/src/codegen.cpp index 4f1cb51a12..12b07ea6bc 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -48,7 +48,7 @@ static void init_darwin_native(CodeGen *g) { } else if (ios_target) { g->mios_version_min = buf_create_from_str(ios_target); } else if (g->zig_target->os != OsIOS) { - g->mmacosx_version_min = buf_create_from_str("10.10"); + g->mmacosx_version_min = buf_create_from_str("10.14"); } } diff --git a/src/link.cpp b/src/link.cpp index fe5a73a52b..3a437e4eda 100644 --- a/src/link.cpp +++ b/src/link.cpp @@ -1474,7 +1474,7 @@ static void get_darwin_platform(LinkJob *lj, DarwinPlatform *platform) { platform->kind = IPhoneOS; } else if (g->zig_target->os == OsMacOSX) { platform->kind = MacOS; - g->mmacosx_version_min = buf_create_from_str("10.10"); + g->mmacosx_version_min = buf_create_from_str("10.14"); } else { zig_panic("unable to infer -mmacosx-version-min or -mios-version-min"); } -- cgit v1.2.3