From 79fb48601749f93541800cff82f3506931dd433c Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Thu, 23 Jan 2020 17:28:13 -0500 Subject: link: update to llvm 10 API --- src/link.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/link.cpp') diff --git a/src/link.cpp b/src/link.cpp index 61a5ad5664..efb60976cb 100644 --- a/src/link.cpp +++ b/src/link.cpp @@ -1894,9 +1894,14 @@ static void link_diag_callback(void *context, const char *ptr, size_t len) { buf_append_mem(diag, ptr, len); } -static bool zig_lld_link(ZigLLVM_ObjectFormatType oformat, const char **args, size_t arg_count, Buf *diag) { +static bool zig_lld_link(ZigLLVM_ObjectFormatType oformat, const char **args, size_t arg_count, + Buf *diag) +{ + Buf *stdout_diag = buf_alloc(); buf_resize(diag, 0); - return ZigLLDLink(oformat, args, arg_count, link_diag_callback, diag); + bool result = ZigLLDLink(oformat, args, arg_count, link_diag_callback, stdout_diag, diag); + buf_destroy(stdout_diag); + return result; } static void add_uefi_link_args(LinkJob *lj) { -- cgit v1.2.3 From 2f21c8f5ba2e73c1a674b481fd2a8ce87726c14c Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Sun, 8 Mar 2020 13:52:51 +0100 Subject: stage1: Link pthread on NetBSD --- src/link.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/link.cpp') diff --git a/src/link.cpp b/src/link.cpp index b340206b14..6c61ee040a 100644 --- a/src/link.cpp +++ b/src/link.cpp @@ -1799,7 +1799,9 @@ static void construct_linker_job_elf(LinkJob *lj) { lj->args.append("-lm"); } - if (g->zig_target->os == OsFreeBSD) { + if (g->zig_target->os == OsFreeBSD || + g->zig_target->os == OsNetBSD) + { lj->args.append("-lpthread"); } } else if (target_is_glibc(g->zig_target)) { -- cgit v1.2.3 From fae6cf09619e7a8e64f61b84cca7d9fcd471262f Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Wed, 25 Mar 2020 20:32:40 -0400 Subject: improved handling of native system directories * `-isystem` instead of `-I` for system include directories fixes a problem with native system directories interfering with zig's bundled libc. * separate Stage2Target.is_native into Stage2Target.is_native_os and Stage2Target.is_native_cpu. --- lib/std/zig/cross_target.zig | 15 +++++++++++---- src-self-hosted/stage2.zig | 6 ++++-- src/codegen.cpp | 15 +++++++++------ src/link.cpp | 6 +++--- src/main.cpp | 12 ++++++++++-- src/stage2.cpp | 6 ++++-- src/stage2.h | 3 ++- src/target.cpp | 3 ++- 8 files changed, 45 insertions(+), 21 deletions(-) (limited to 'src/link.cpp') diff --git a/lib/std/zig/cross_target.zig b/lib/std/zig/cross_target.zig index 130e8cdbc1..bea69b3978 100644 --- a/lib/std/zig/cross_target.zig +++ b/lib/std/zig/cross_target.zig @@ -480,12 +480,19 @@ pub const CrossTarget = struct { return Target.libPrefix_cpu_arch_abi(self.getCpuArch(), self.getAbi()); } - pub fn isNative(self: CrossTarget) bool { + pub fn isNativeCpu(self: CrossTarget) bool { return self.cpu_arch == null and (self.cpu_model == .native or self.cpu_model == .determined_by_cpu_arch) and - self.cpu_features_sub.isEmpty() and self.cpu_features_add.isEmpty() and - self.os_tag == null and self.os_version_min == null and self.os_version_max == null and - self.abi == null and self.dynamic_linker.get() == null and self.glibc_version == null; + self.cpu_features_sub.isEmpty() and self.cpu_features_add.isEmpty(); + } + + pub fn isNativeOs(self: CrossTarget) bool { + return self.os_tag == null and self.os_version_min == null and self.os_version_max == null and + self.dynamic_linker.get() == null and self.glibc_version == null; + } + + pub fn isNative(self: CrossTarget) bool { + return self.isNativeCpu() and self.isNativeOs() and self.abi == null; } pub fn zigTriple(self: CrossTarget, allocator: *mem.Allocator) error{OutOfMemory}![:0]u8 { diff --git a/src-self-hosted/stage2.zig b/src-self-hosted/stage2.zig index 03cdcc5b08..cd0956cae3 100644 --- a/src-self-hosted/stage2.zig +++ b/src-self-hosted/stage2.zig @@ -898,7 +898,8 @@ const Stage2Target = extern struct { abi: c_int, os: c_int, - is_native: bool, + is_native_os: bool, + is_native_cpu: bool, glibc_or_darwin_version: ?*Stage2SemVer, @@ -1166,7 +1167,8 @@ const Stage2Target = extern struct { .os_builtin_str = os_builtin_str_buffer.toOwnedSlice().ptr, .cache_hash = cache_hash_slice.ptr, .cache_hash_len = cache_hash_slice.len, - .is_native = cross_target.isNative(), + .is_native_os = cross_target.isNativeOs(), + .is_native_cpu = cross_target.isNativeCpu(), .glibc_or_darwin_version = glibc_or_darwin_version, .dynamic_linker = dynamic_linker, .standard_dynamic_linker_path = std_dl_z, diff --git a/src/codegen.cpp b/src/codegen.cpp index 3edc99156f..cb1ab6b6b8 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -8782,7 +8782,8 @@ static Error define_builtin_compile_vars(CodeGen *g) { cache_bool(&cache_hash, g->is_single_threaded); cache_bool(&cache_hash, g->test_is_evented); cache_int(&cache_hash, g->code_model); - cache_int(&cache_hash, g->zig_target->is_native); + cache_int(&cache_hash, g->zig_target->is_native_os); + cache_int(&cache_hash, g->zig_target->is_native_cpu); cache_int(&cache_hash, g->zig_target->arch); cache_int(&cache_hash, g->zig_target->vendor); cache_int(&cache_hash, g->zig_target->os); @@ -8917,7 +8918,7 @@ static void init(CodeGen *g) { const char *target_specific_cpu_args = ""; const char *target_specific_features = ""; - if (g->zig_target->is_native) { + if (g->zig_target->is_native_cpu) { target_specific_cpu_args = ZigLLVMGetHostCPUName(); target_specific_features = ZigLLVMGetNativeFeatures(); } @@ -9034,7 +9035,7 @@ static void detect_libc(CodeGen *g) { return; } - if (g->zig_target->is_native) { + if (g->zig_target->is_native_os) { g->libc = heap::c_allocator.create(); // search for native_libc.txt in following dirs: @@ -9672,7 +9673,8 @@ Error create_c_object_cache(CodeGen *g, CacheHash **out_cache_hash, bool verbose cache_int(cache_hash, g->err_color); cache_buf(cache_hash, g->zig_c_headers_dir); cache_list_of_str(cache_hash, g->libc_include_dir_list, g->libc_include_dir_len); - cache_int(cache_hash, g->zig_target->is_native); + cache_int(cache_hash, g->zig_target->is_native_os); + cache_int(cache_hash, g->zig_target->is_native_cpu); cache_int(cache_hash, g->zig_target->arch); cache_int(cache_hash, g->zig_target->vendor); cache_int(cache_hash, g->zig_target->os); @@ -10474,7 +10476,8 @@ static Error check_cache(CodeGen *g, Buf *manifest_dir, Buf *digest) { cache_list_of_buf(ch, g->forbidden_libs.items, g->forbidden_libs.length); cache_int(ch, g->build_mode); cache_int(ch, g->out_type); - cache_bool(ch, g->zig_target->is_native); + cache_bool(ch, g->zig_target->is_native_os); + cache_bool(ch, g->zig_target->is_native_cpu); cache_int(ch, g->zig_target->arch); cache_int(ch, g->zig_target->vendor); cache_int(ch, g->zig_target->os); @@ -10941,7 +10944,7 @@ CodeGen *codegen_create(Buf *main_pkg_path, Buf *root_src_path, const ZigTarget os_path_join(g->zig_std_dir, buf_sprintf("special"), g->zig_std_special_dir); assert(target != nullptr); - if (!target->is_native) { + if (!target->is_native_os) { g->each_lib_rpath = false; } else { g->each_lib_rpath = true; diff --git a/src/link.cpp b/src/link.cpp index d39736e2a7..25b913be21 100644 --- a/src/link.cpp +++ b/src/link.cpp @@ -635,7 +635,7 @@ static const char *build_libunwind(CodeGen *parent, Stage2ProgressNode *progress c_file->args.append("-fPIC"); c_file->args.append("-D_LIBUNWIND_DISABLE_VISIBILITY_ANNOTATIONS"); c_file->args.append("-Wa,--noexecstack"); - if (parent->zig_target->is_native) { + if (parent->zig_target->is_native_os && parent->zig_target->is_native_cpu) { c_file->args.append("-D_LIBUNWIND_IS_NATIVE_ONLY"); } if (parent->build_mode == BuildModeDebug) { @@ -1829,7 +1829,7 @@ static void construct_linker_job_elf(LinkJob *lj) { } } - if (!g->zig_target->is_native) { + if (!g->zig_target->is_native_os) { lj->args.append("--allow-shlib-undefined"); } } @@ -2460,7 +2460,7 @@ static void construct_linker_job_macho(LinkJob *lj) { lj->args.append(buf_ptr(compiler_rt_o_path)); } - if (g->zig_target->is_native) { + if (g->zig_target->is_native_os) { for (size_t lib_i = 0; lib_i < g->link_libs_list.length; lib_i += 1) { LinkLib *link_lib = g->link_libs_list.at(lib_i); if (target_is_libc_lib_name(g->zig_target, buf_ptr(link_lib->name))) { diff --git a/src/main.cpp b/src/main.cpp index dd7cdead6c..a543b43579 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1325,7 +1325,15 @@ static int main0(int argc, char **argv) { return print_error_usage(arg0); } - if (target.is_native && link_libs.length != 0) { + bool any_non_c_link_libs = false; + for (size_t i = 0; i < link_libs.length; i += 1) { + if (!target_is_libc_lib_name(&target, link_libs.at(i))) { + any_non_c_link_libs = true; + break; + } + } + + if (target.is_native_os && any_non_c_link_libs) { Error err; Stage2NativePaths paths; if ((err = stage2_detect_native_paths(&paths))) { @@ -1338,7 +1346,7 @@ static int main0(int argc, char **argv) { } for (size_t i = 0; i < paths.include_dirs_len; i += 1) { const char *include_dir = paths.include_dirs_ptr[i]; - clang_argv.append("-I"); + clang_argv.append("-isystem"); clang_argv.append(include_dir); } for (size_t i = 0; i < paths.lib_dirs_len; i += 1) { diff --git a/src/stage2.cpp b/src/stage2.cpp index c83b1aa77c..f8a485f93b 100644 --- a/src/stage2.cpp +++ b/src/stage2.cpp @@ -181,7 +181,8 @@ static void get_native_target(ZigTarget *target) { &target->abi, &oformat); target->os = get_zig_os_type(os_type); - target->is_native = true; + target->is_native_os = true; + target->is_native_cpu = true; if (target->abi == ZigLLVM_UnknownEnvironment) { target->abi = target_default_abi(target->arch, target->os); } @@ -204,7 +205,8 @@ Error stage2_target_parse(struct ZigTarget *target, const char *zig_triple, cons target->llvm_cpu_features = ZigLLVMGetNativeFeatures(); target->cache_hash = "native\n\n"; } else if (strcmp(mcpu, "baseline") == 0) { - target->is_native = false; + target->is_native_os = false; + target->is_native_cpu = false; target->llvm_cpu_name = ""; target->llvm_cpu_features = ""; target->cache_hash = "baseline\n\n"; diff --git a/src/stage2.h b/src/stage2.h index 00a3b9451e..4b86fdc059 100644 --- a/src/stage2.h +++ b/src/stage2.h @@ -280,7 +280,8 @@ struct ZigTarget { enum ZigLLVM_EnvironmentType abi; Os os; - bool is_native; + bool is_native_os; + bool is_native_cpu; // null means default. this is double-purposed to be darwin min version struct Stage2SemVer *glibc_or_darwin_version; diff --git a/src/target.cpp b/src/target.cpp index db1e4be809..63360fc029 100644 --- a/src/target.cpp +++ b/src/target.cpp @@ -1239,7 +1239,8 @@ void target_libc_enum(size_t index, ZigTarget *out_target) { out_target->os = libcs_available[index].os; out_target->abi = libcs_available[index].abi; out_target->vendor = ZigLLVM_UnknownVendor; - out_target->is_native = false; + out_target->is_native_os = false; + out_target->is_native_cpu = false; } bool target_has_debug_info(const ZigTarget *target) { -- cgit v1.2.3