| author | |
| committer | |
| log | fae6cf09619e7a8e64f61b84cca7d9fcd471262f |
| tree | 373d125e6c7eb97f563af264de62eb48fb6b5baa |
| parent | dd66fbb96a2e1f85e7dacdce18ebc5f85d26d0cc |
| signature |
* `-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.8 files changed, 45 insertions(+), 21 deletions(-)
lib/std/zig/cross_target.zig+11-4| ... | ... | @@ -480,12 +480,19 @@ pub const CrossTarget = struct { |
| 480 | 480 | return Target.libPrefix_cpu_arch_abi(self.getCpuArch(), self.getAbi()); |
| 481 | 481 | } |
| 482 | 482 | |
| 483 | pub fn isNative(self: CrossTarget) bool { | |
| 483 | pub fn isNativeCpu(self: CrossTarget) bool { | |
| 484 | 484 | return self.cpu_arch == null and |
| 485 | 485 | (self.cpu_model == .native or self.cpu_model == .determined_by_cpu_arch) and |
| 486 | self.cpu_features_sub.isEmpty() and self.cpu_features_add.isEmpty() and | |
| 487 | self.os_tag == null and self.os_version_min == null and self.os_version_max == null and | |
| 488 | self.abi == null and self.dynamic_linker.get() == null and self.glibc_version == null; | |
| 486 | self.cpu_features_sub.isEmpty() and self.cpu_features_add.isEmpty(); | |
| 487 | } | |
| 488 | ||
| 489 | pub fn isNativeOs(self: CrossTarget) bool { | |
| 490 | return self.os_tag == null and self.os_version_min == null and self.os_version_max == null and | |
| 491 | self.dynamic_linker.get() == null and self.glibc_version == null; | |
| 492 | } | |
| 493 | ||
| 494 | pub fn isNative(self: CrossTarget) bool { | |
| 495 | return self.isNativeCpu() and self.isNativeOs() and self.abi == null; | |
| 489 | 496 | } |
| 490 | 497 | |
| 491 | 498 | pub fn zigTriple(self: CrossTarget, allocator: *mem.Allocator) error{OutOfMemory}![:0]u8 { |
src-self-hosted/stage2.zig+4-2| ... | ... | @@ -898,7 +898,8 @@ const Stage2Target = extern struct { |
| 898 | 898 | abi: c_int, |
| 899 | 899 | os: c_int, |
| 900 | 900 | |
| 901 | is_native: bool, | |
| 901 | is_native_os: bool, | |
| 902 | is_native_cpu: bool, | |
| 902 | 903 | |
| 903 | 904 | glibc_or_darwin_version: ?*Stage2SemVer, |
| 904 | 905 | |
| ... | ... | @@ -1166,7 +1167,8 @@ const Stage2Target = extern struct { |
| 1166 | 1167 | .os_builtin_str = os_builtin_str_buffer.toOwnedSlice().ptr, |
| 1167 | 1168 | .cache_hash = cache_hash_slice.ptr, |
| 1168 | 1169 | .cache_hash_len = cache_hash_slice.len, |
| 1169 | .is_native = cross_target.isNative(), | |
| 1170 | .is_native_os = cross_target.isNativeOs(), | |
| 1171 | .is_native_cpu = cross_target.isNativeCpu(), | |
| 1170 | 1172 | .glibc_or_darwin_version = glibc_or_darwin_version, |
| 1171 | 1173 | .dynamic_linker = dynamic_linker, |
| 1172 | 1174 | .standard_dynamic_linker_path = std_dl_z, |
src/codegen.cpp+9-6| ... | ... | @@ -8782,7 +8782,8 @@ static Error define_builtin_compile_vars(CodeGen *g) { |
| 8782 | 8782 | cache_bool(&cache_hash, g->is_single_threaded); |
| 8783 | 8783 | cache_bool(&cache_hash, g->test_is_evented); |
| 8784 | 8784 | cache_int(&cache_hash, g->code_model); |
| 8785 | cache_int(&cache_hash, g->zig_target->is_native); | |
| 8785 | cache_int(&cache_hash, g->zig_target->is_native_os); | |
| 8786 | cache_int(&cache_hash, g->zig_target->is_native_cpu); | |
| 8786 | 8787 | cache_int(&cache_hash, g->zig_target->arch); |
| 8787 | 8788 | cache_int(&cache_hash, g->zig_target->vendor); |
| 8788 | 8789 | cache_int(&cache_hash, g->zig_target->os); |
| ... | ... | @@ -8917,7 +8918,7 @@ static void init(CodeGen *g) { |
| 8917 | 8918 | const char *target_specific_cpu_args = ""; |
| 8918 | 8919 | const char *target_specific_features = ""; |
| 8919 | 8920 | |
| 8920 | if (g->zig_target->is_native) { | |
| 8921 | if (g->zig_target->is_native_cpu) { | |
| 8921 | 8922 | target_specific_cpu_args = ZigLLVMGetHostCPUName(); |
| 8922 | 8923 | target_specific_features = ZigLLVMGetNativeFeatures(); |
| 8923 | 8924 | } |
| ... | ... | @@ -9034,7 +9035,7 @@ static void detect_libc(CodeGen *g) { |
| 9034 | 9035 | return; |
| 9035 | 9036 | } |
| 9036 | 9037 | |
| 9037 | if (g->zig_target->is_native) { | |
| 9038 | if (g->zig_target->is_native_os) { | |
| 9038 | 9039 | g->libc = heap::c_allocator.create<Stage2LibCInstallation>(); |
| 9039 | 9040 | |
| 9040 | 9041 | // 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 |
| 9672 | 9673 | cache_int(cache_hash, g->err_color); |
| 9673 | 9674 | cache_buf(cache_hash, g->zig_c_headers_dir); |
| 9674 | 9675 | cache_list_of_str(cache_hash, g->libc_include_dir_list, g->libc_include_dir_len); |
| 9675 | cache_int(cache_hash, g->zig_target->is_native); | |
| 9676 | cache_int(cache_hash, g->zig_target->is_native_os); | |
| 9677 | cache_int(cache_hash, g->zig_target->is_native_cpu); | |
| 9676 | 9678 | cache_int(cache_hash, g->zig_target->arch); |
| 9677 | 9679 | cache_int(cache_hash, g->zig_target->vendor); |
| 9678 | 9680 | cache_int(cache_hash, g->zig_target->os); |
| ... | ... | @@ -10474,7 +10476,8 @@ static Error check_cache(CodeGen *g, Buf *manifest_dir, Buf *digest) { |
| 10474 | 10476 | cache_list_of_buf(ch, g->forbidden_libs.items, g->forbidden_libs.length); |
| 10475 | 10477 | cache_int(ch, g->build_mode); |
| 10476 | 10478 | cache_int(ch, g->out_type); |
| 10477 | cache_bool(ch, g->zig_target->is_native); | |
| 10479 | cache_bool(ch, g->zig_target->is_native_os); | |
| 10480 | cache_bool(ch, g->zig_target->is_native_cpu); | |
| 10478 | 10481 | cache_int(ch, g->zig_target->arch); |
| 10479 | 10482 | cache_int(ch, g->zig_target->vendor); |
| 10480 | 10483 | cache_int(ch, g->zig_target->os); |
| ... | ... | @@ -10941,7 +10944,7 @@ CodeGen *codegen_create(Buf *main_pkg_path, Buf *root_src_path, const ZigTarget |
| 10941 | 10944 | os_path_join(g->zig_std_dir, buf_sprintf("special"), g->zig_std_special_dir); |
| 10942 | 10945 | |
| 10943 | 10946 | assert(target != nullptr); |
| 10944 | if (!target->is_native) { | |
| 10947 | if (!target->is_native_os) { | |
| 10945 | 10948 | g->each_lib_rpath = false; |
| 10946 | 10949 | } else { |
| 10947 | 10950 | g->each_lib_rpath = true; |
src/link.cpp+3-3| ... | ... | @@ -635,7 +635,7 @@ static const char *build_libunwind(CodeGen *parent, Stage2ProgressNode *progress |
| 635 | 635 | c_file->args.append("-fPIC"); |
| 636 | 636 | c_file->args.append("-D_LIBUNWIND_DISABLE_VISIBILITY_ANNOTATIONS"); |
| 637 | 637 | c_file->args.append("-Wa,--noexecstack"); |
| 638 | if (parent->zig_target->is_native) { | |
| 638 | if (parent->zig_target->is_native_os && parent->zig_target->is_native_cpu) { | |
| 639 | 639 | c_file->args.append("-D_LIBUNWIND_IS_NATIVE_ONLY"); |
| 640 | 640 | } |
| 641 | 641 | if (parent->build_mode == BuildModeDebug) { |
| ... | ... | @@ -1829,7 +1829,7 @@ static void construct_linker_job_elf(LinkJob *lj) { |
| 1829 | 1829 | } |
| 1830 | 1830 | } |
| 1831 | 1831 | |
| 1832 | if (!g->zig_target->is_native) { | |
| 1832 | if (!g->zig_target->is_native_os) { | |
| 1833 | 1833 | lj->args.append("--allow-shlib-undefined"); |
| 1834 | 1834 | } |
| 1835 | 1835 | } |
| ... | ... | @@ -2460,7 +2460,7 @@ static void construct_linker_job_macho(LinkJob *lj) { |
| 2460 | 2460 | lj->args.append(buf_ptr(compiler_rt_o_path)); |
| 2461 | 2461 | } |
| 2462 | 2462 | |
| 2463 | if (g->zig_target->is_native) { | |
| 2463 | if (g->zig_target->is_native_os) { | |
| 2464 | 2464 | for (size_t lib_i = 0; lib_i < g->link_libs_list.length; lib_i += 1) { |
| 2465 | 2465 | LinkLib *link_lib = g->link_libs_list.at(lib_i); |
| 2466 | 2466 | if (target_is_libc_lib_name(g->zig_target, buf_ptr(link_lib->name))) { |
src/main.cpp+10-2| ... | ... | @@ -1325,7 +1325,15 @@ static int main0(int argc, char **argv) { |
| 1325 | 1325 | return print_error_usage(arg0); |
| 1326 | 1326 | } |
| 1327 | 1327 | |
| 1328 | if (target.is_native && link_libs.length != 0) { | |
| 1328 | bool any_non_c_link_libs = false; | |
| 1329 | for (size_t i = 0; i < link_libs.length; i += 1) { | |
| 1330 | if (!target_is_libc_lib_name(&target, link_libs.at(i))) { | |
| 1331 | any_non_c_link_libs = true; | |
| 1332 | break; | |
| 1333 | } | |
| 1334 | } | |
| 1335 | ||
| 1336 | if (target.is_native_os && any_non_c_link_libs) { | |
| 1329 | 1337 | Error err; |
| 1330 | 1338 | Stage2NativePaths paths; |
| 1331 | 1339 | if ((err = stage2_detect_native_paths(&paths))) { |
| ... | ... | @@ -1338,7 +1346,7 @@ static int main0(int argc, char **argv) { |
| 1338 | 1346 | } |
| 1339 | 1347 | for (size_t i = 0; i < paths.include_dirs_len; i += 1) { |
| 1340 | 1348 | const char *include_dir = paths.include_dirs_ptr[i]; |
| 1341 | clang_argv.append("-I"); | |
| 1349 | clang_argv.append("-isystem"); | |
| 1342 | 1350 | clang_argv.append(include_dir); |
| 1343 | 1351 | } |
| 1344 | 1352 | for (size_t i = 0; i < paths.lib_dirs_len; i += 1) { |
src/stage2.cpp+4-2| ... | ... | @@ -181,7 +181,8 @@ static void get_native_target(ZigTarget *target) { |
| 181 | 181 | &target->abi, |
| 182 | 182 | &oformat); |
| 183 | 183 | target->os = get_zig_os_type(os_type); |
| 184 | target->is_native = true; | |
| 184 | target->is_native_os = true; | |
| 185 | target->is_native_cpu = true; | |
| 185 | 186 | if (target->abi == ZigLLVM_UnknownEnvironment) { |
| 186 | 187 | target->abi = target_default_abi(target->arch, target->os); |
| 187 | 188 | } |
| ... | ... | @@ -204,7 +205,8 @@ Error stage2_target_parse(struct ZigTarget *target, const char *zig_triple, cons |
| 204 | 205 | target->llvm_cpu_features = ZigLLVMGetNativeFeatures(); |
| 205 | 206 | target->cache_hash = "native\n\n"; |
| 206 | 207 | } else if (strcmp(mcpu, "baseline") == 0) { |
| 207 | target->is_native = false; | |
| 208 | target->is_native_os = false; | |
| 209 | target->is_native_cpu = false; | |
| 208 | 210 | target->llvm_cpu_name = ""; |
| 209 | 211 | target->llvm_cpu_features = ""; |
| 210 | 212 | target->cache_hash = "baseline\n\n"; |
src/stage2.h+2-1| ... | ... | @@ -280,7 +280,8 @@ struct ZigTarget { |
| 280 | 280 | enum ZigLLVM_EnvironmentType abi; |
| 281 | 281 | Os os; |
| 282 | 282 | |
| 283 | bool is_native; | |
| 283 | bool is_native_os; | |
| 284 | bool is_native_cpu; | |
| 284 | 285 | |
| 285 | 286 | // null means default. this is double-purposed to be darwin min version |
| 286 | 287 | struct Stage2SemVer *glibc_or_darwin_version; |
src/target.cpp+2-1| ... | ... | @@ -1239,7 +1239,8 @@ void target_libc_enum(size_t index, ZigTarget *out_target) { |
| 1239 | 1239 | out_target->os = libcs_available[index].os; |
| 1240 | 1240 | out_target->abi = libcs_available[index].abi; |
| 1241 | 1241 | out_target->vendor = ZigLLVM_UnknownVendor; |
| 1242 | out_target->is_native = false; | |
| 1242 | out_target->is_native_os = false; | |
| 1243 | out_target->is_native_cpu = false; | |
| 1243 | 1244 | } |
| 1244 | 1245 | |
| 1245 | 1246 | bool target_has_debug_info(const ZigTarget *target) { |